ATmega168
I have a 3to8 decoder connected to pins 2,3, and 4 on PORTD
How would I change these 3 bits without affecting the others.
In other words, if I wanted to send 5 to the decoder it would look like this.
PORTD INITIAL: 01101101
5 = 00000101
so 5<<2 00010100 and put on PORTD without changing the other pins
PORTD FINAL: 01110101
This was my idea
temp = PORTD;
temp &= 0xE3;
temp |= (5<<2);
PORTD = temp;
/* VISUAL REPRESENTATION
PORTD INITIAL: 01101101
5 put on 2,3,4: 00010100
PORTD FINAL: 01110101
*/
This seems a lil clunky, any better ideas?