This is a silly question, but I can't seem to figure out how to
set a bit in a register LOW in C. I know how to do it in assembly,
but for some reason I can't do it in C.
Let me give you an example:
I have a 8 position DIP switch on PORTB. I want to ignore RB6 and RB7
but get the values of the other 6 positions. So I am reading in portb into
a shadow register and I want to set RB6 and RB7 LOW.
I am drawing a blank, and I searched for this but something tells me it is
so simple that I am the only person "that doesn't get it" ...
Thanks in advance.
Steve
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
Posted: Sat Apr 24, 2010 10:45 am
Code:
#define MASK 0x3F // =0b00111111 Pre-processor directive
unsigned int DIP_Sw; // Variable to store the the DIP switch value
main()
{
DIP_Sw = PORTB & MASK; // Read the whole PORTB, then AND with MASK and place the result in the variable DIP_Sw
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum