I'm having trouble with something that I feel must be easy, but it's confounding me.
I want to clear certain bits of a port without touching others, and without setting a PORT pin to a 0 as an intermediate step if it's supposed to be a 1 at the end of the assignment. The problem is the middle of the port cannot be touched (input pins, TXD, etc). Example:
DDRC = 0b11000011; // PORTC might be 0b11xxxx11 // new value should be 0x10xxxx01
thereby setting bit 6 and 1 to zero while leaving 7 and 0 intact and not writing to the input bits at all.
I can't figure out a way to do it without clearing pin values and then resetting with
PORTC |= (1<<n);
and a mask. Is there a better way than a mask and four |= assignments? One other thing, I only have to clear bits, not set them.
Can anyone set me on the right path?