PDA

View Full Version : Exclusive bit settings (i.e. PORTS)



flotulopex
- 31st March 2007, 21:08
Hello,

I want to set exclusively 3 bits on a PORT.

Let's say I have PORTB = %10011001 and want to set ONLY the three LSB.

I can use PORTB = PORTB | 7, I get %1001111 and this is fine.

How do I do if I want to change from %10011001 to %00001001?

skimask
- 31st March 2007, 21:17
Hello,
I want to set exclusively 3 bits on a PORT.
Let's say I have PORTB = %10011001 and want to set ONLY the three LSB.
I can use PORTB = PORTB | 7, I get %1001111 and this is fine.
How do I do if I want to change from %10011001 to %00001001?

PortB = PortB & %00001111
AND function
keeps the lower four bits, dumps the upper four, but that's only one case of bit changing. If you want to be able to change any bits at any time while retaining others, it's going to take more than one step.

flotulopex
- 31st March 2007, 21:37
Thanks for the help.

I'm not used yet with these operators.

Gone a have some trials...