This works for x.b0 ^= 1;
Code:
typedef union {
struct {
unsigned b0:1;
unsigned b1:1;
unsigned b2:1;
unsigned b3:1;
unsigned b4:1;
unsigned b5:1;
unsigned b6:1;
unsigned b7:1;
};
struct {
unsigned asByte:8;
};
} bitByte;
....
bitByte x;
x.b3=1;
x.asByte = 0x55;
The downside is that you must say x.asByte=123 and that you have to say x.b0 instead of x.0. Neither is a big deal if you are used to structures.
The upside is that you can use variables on the RHS;
Generated asm
Code:
131: bitByte ii;
132:
133: ii.b3=1;
0152 0E01 MOVLW 0x1
0154 86DB BSF 0xfdb, 0x3, ACCESS
134:
135: ii.asByte = 0x55;
0156 52DE MOVF 0xfde, F, ACCESS
0158 0E55 MOVLW 0x55
015A 6EDD MOVWF 0xfdd, ACCESS
3v0