| |||||
Technical Support Support Resources
Product Information | C51: BIT ADDRESSABLE ARRAYSInformation in this article applies to:
QUESTIONI have declared an array in bdata and I wish to use a loop to access each bit and assign it to a flag. I have written the following code but it doesn't work. What am I doing wrong?
unsigned char bdata barray[3] = {0xAA, 0x55, 0xA5};
bit flag;
void main(void)
{
unsigned char i;
for (i = 0; i < 8; i++)
{
flag = barray[0] ^ i;
}
while(1);
}
ANSWERYou cannot use the '^' character to access bits unless it is an sbit declaration. Outside of an sbit declaration, it is the Exclusive OR operator. Also you cannot use a variable after the '^' character when accessing bits, it must be a constant. There are two solutions to this problem.
MORE INFORMATION
Last Reviewed: Tuesday, March 27, 2007 | ||||
| |||||