Hi, I get a curious result when compiling such a following code :
typedef union { unsigned char cCtrlFullByte; struct { unsigned char bEnable : 1; unsigned char cUnused : 7; } cCtrlStruct; } CtrlUnion; void main (void) { unsigned char dummy = 0x55; CtrlUnion xdata bitUnion; bitUnion.cCtrlStruct.bEnable = dummy & 0x40; return; }
MOV A,#0x55 ANL A,#0x00 MOV R7,A MOV DPTR, #0x0000 MOVX A,@DPTR ANL A,#0xFE ORL A,R7 MOVX @DPTR, A
The code in Araund's example is correct. The first example where C is set from E0.6 (actually Accumulator bit 6 .. E0 is the ACC sfr) is exactly the value specified. In the second example, the and with 0x44 and add 0xff sets carry if either of the two bits in the mask are non-zero. Looks to me like the compiler did exactly as it should.
You're right. It does exactly what it should when the destination is a Keil "bit" type. If the type of the destination is a 1-bit wide field in a bit-field structure, the result will be different. For me, that should not happen. Regards Arnaud