Deep Enrichment: Bit Banging Strategies, Techniques, Algorithms, and Applications


Introductory Exercises (2020 01 22) (Reference:

  1. Create an Arduino sketch for the UNO (328P) entitled BitBanging (You could do this for other AVRs but we could use the services of the Serial Monitor to confirm our results)
  2. Declare the following variable: uint8_t value = 0; and use it exclusively for the manipulations below. Echo value to the Serial Monitor after each modification.
  3. With full knowledge of C++'s order of operator precedence to avoid unnecessary brackets, undertake the following, in sequence, within your setup() function,
    1. set bit 5
    2. set bit 3, while leaving all other bits unaffected
    3. clear bit 5, while leaving all other bits unaffected
    4. invert all bits
    5. invert only bit 3
    6. assign value the BCD equivalent of 27
    7. clear (mask off) the high nibble
    8. make the high nibble the same as the low nibble

GPIO Register-Level Exercises (2020 01 28) (p. 12:

  1. How many GPIO Ports does the 328P have? What are their (letter) names?
  2. How many Registers are associated with each of the ports? What are their names and what are their purposes?
  3. Insert a bicolor LED into the UNO pins 12 and 13, and any LED in pins 10 and 11.
  4. What port of the ATmega328P are these pins associated with? What port BITS are these pins mapped to?
  5. Within your setup() function, use the relevant GPIO register name to declare ALL of port B's (available) digital pins for output (in lieu of the high-level pinMode() function).
  6. (Register-Level Blink Sketch) Within your loop() function, employ precise bit-level IO register statements (in lieu of digitalWrite() statements) targeted at pins 12 and 13, add code to have pin 13 provide the anode signal and pin 12, the cathode signal. Upload the sketch and confirm.
  7. Add code to provide a 1s delay, before employing precision register-level statements to pins 12 and 13 to reverse the anode and cathode. Add another 1s delay before uploading and confirming.
  8. Can the alternation described in tasks 6 and 7 be done with a single assignment statement and delay?

Statements for YOUR Consideration

What do each of the following GPIO Register-Level assignment statements accomplish? (the last two are beauties as they have particular meaning for us) Attention 11s and 12s: Be the FIRST to correctly identify what (recent) special purpose BOTH of these hold for ACES, in SINGLE email to the ICS3UForum under the Subject Line: Bit Banging and you will win a LARGE bag of Bits & Bites ->>>>

  1. DDRD = 0xF0;                  //insert comment here
  2. PORTB |= 1;                   //insert comment here
  3. PORTC = ~PORTC;               //insert comment here
  4. PORTD &= 0x0F;                //insert comment here
  5. PORTD |= 1;                   //insert comment here
  6. PORTB |= 1<<PB5 | 1<<PB2;     //insert comment here
  7. PORTD ^= PORTD;               //insert comment here
  8. PIND |= 1<<PD2;               //insert comment here
  9. response = PIND;              //insert comment here

Further Topics...

  1. Defining literals
  2. Displaying numeric literals
  3. Explore binary-related methods of the Integer Class
  4. Counting Bits (Parity)
  5. Bit Shifting: <<, >>
  6. Masking Bits: Odd/Even; Upper- or Lowercase
  7. Negative Numbers (2's Complement Strategy)
  8. Arithmetic. Adders (Half Adders and Full Adders)