There is a BUG in the compilation of a bit definition:
unsigned int bdata my_int; sbit bit15 = my_int ^ 15; sbit bit7 = my_int ^ 7; void main() { my_int = 0x8000; if(bit15) { // Here we shall not appear,as compiller // will be erroneous to check 7-bit of // a variable my_int instead of 15-bit // (as this variable place in memory in // little endian order) // ... } if(bit7) { // oops! we here! // ... } }
hi,
unsigned int bdata my_int; sbit bit15 = my_int ^ 15; sbit bit7 = my_int ^ 7;
void main() { my_int = 0x8000; if((my_int & 0x8000) != 0) // check for bit 15 { } if((my_int & 0x0080) != 0) // check bit 7 { } } Regards, Oleg
Hi. Keil realy transletes my code to this:
unsigned int bdata my_int; sbit bit15 = my_int ^ 15; sbit bit7 = my_int ^ 7; void main() { my_int = 0x8000; if((my_int & 0x0080) != 0) // <- if(bit15) { } if((my_int & 0x8000) != 0) // <- if(bit7) { } }
void main() { my_int = 0x8000; if((my_int & 0x8000) != 0) // check bit 15 { } if((my_int & 0x0080) != 0) // check bit 7 { } }
sbit bit15 = my_int ^ 15; you can only use sbit for bit addressable bytes Erik
Do you read Cx51 User's Guide? Probably, no. Here a part from it: -------------------------------------------- Bit-Addressable Objects Bit-addressable objects are objects that may be addressed as words or as bits. Only data objects that occupy the bit-addressable area of the 8051 internal memory fall into this category. The Cx51 Compiler places variables declared with the bdata memory type into the bit-addressable area. Furthermore, variables declared with the bdata memory type must be global (declared outside the scope of a function). You may declare these variables as shown below:
int bdata ibase; /* Bit-addressable int */ char bdata bary [4]; /* Bit-addressable array */
sbit mybit0 = ibase ^ 0; /* bit 0 of ibase */ sbit mybit15 = ibase ^ 15; /* bit 15 of ibase */ sbit Ary07 = bary[0] ^ 7; /* bit 7 of bary[0] */ sbit Ary37 = bary[3] ^ 7; /* bit 7 of bary[3] */
Isn't it interesting that when the software does not behave in the way someone want it to do (forget what the manual says) it is always a BUG. Never a "problem" "possible misunderstanding" no absolutely a BUG! Erik