I Know one can be set as;
{PORTA |= (1<<PA4);}
Without touching any other bits on PORTA, But how to clear it and leave the remaining bits intact?
I Know one can be set as;
{PORTA |= (1<<PA4);}
Without touching any other bits on PORTA, But how to clear it and leave the remaining bits intact?
The XOR operator ( ^ ) is your friend.
I believe this may be what you are after, it requires a read though:
{PORTA &= ~(1<<PA4);}
HazardsMind:
The XOR operator ( ^ ) is your friend.
The XOR operator togles the output while the condition is true, so not really what I need.
pYro_65:
I believe this may be what you are after, it requires a read though:{PORTA &= ~(1<<PA4);}
It is indeed. Thank you very much.
I Tried the "and" alone and it did not work. What does the ~ do?
B11000111 | B00001000(0x08) = B11001111
B11001111 ^ B00001000(0x08) = B11000111
What does the ~ do?
it inverts the byte, so B0100 -> (~B0100) = B1011
amvcs08:
I Tried the "and" alone and it did not work. What does the ~ do?
This should explain it: How does Python's bitwise complement operator (~ tilde) work? - Stack Overflow
HazardsMind:
B11000111 | B00001000(0x08) = B11001111B11001111 ^ B00001000(0x08) = B11000111
The Xor operator is only useful when you know the state of a bit, I.e toggling.
If you want to ensure a bit is off, you must mask it and remove it from the set.
B11001111 ^ B00010000
I guess If you want to make sure the bit is really off, you can use x &= ~(some value)
But in my example the OP already knows the bit is on, so using the XOR operator will work, but if by some weird chance the XOR is called again, it will go back on.
myVariable != B00010000 will change to a 1 all the bits that have a 1 and will leave all the others unchanged
myVariable &= B00010000 will change to a 0 all the bits that have a 0 and will leave all the others unchanged
I don't think there is a single instruction that allows you to ensure some bits are set and others are cleared while the rest are unchanged.
...R