im using 8051 and had a problem writing a code to interface the LED using serial port interface.Im using the I/O controller.the problem is when i ON the LED it light all the 7 leds.There is 7 output port. i try to use a bitwise as to ON the LED of bit 0: if((c&0x01)=='0'){ OPORT=0x00;}
else if(c=='1') { OPORT=0xff; }
thanks
"Turning on a single bit can be done by: x |= (1 << bitpos); Turning off a single bit can be done by: x &= ~(1 << bitpos);"
This is standard 'C' - general and applicable to any compiler and any target; it is Portable
The 8051 has a particular feature that some addresses are bit-addressable; ie, individual bits can be addressed directly.
Keil C51 provides some specific, proprietary extensions to the 'C' standard to allow you to take advantage of this feature; of course, this is non-Portable
Ports P0-P3 are bit addressable...
Yes, I'm aware of the bit-addressing in the 8051.
Note the specific sentence in the first post: "the problem is when i ON the LED it light all the 7 leds.There is 7 output port."
Then note that the OP used the declaration:
char xdata OPORT _at_ 0x0000;
and then performed assigns:
OPORT = 0xff;
or
OPORT = 0x00;
To my eyes, that doesn't look like an attempt at using bit-addressable variables - hence my comment about the general method to set or clear a bit.
I think that the OP code will need a number of refining steps, and I don't think it is a good idea to just post a complete rewrite of the code. Each single change to the code must be followed my an understanding why.
I feel that switching to bdata, sbit, overloading of the ^ operator etc is a separate step.