typedef struct{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}bits;
typedef union{
uchar data_char;
bits data_bits;
}utype;
uchar *addr = (uchar*)0x10;
utype value;
value.data_char = *addr;
//如果要查看某个位比如第3位
//直接看 value.data_bits.bit3就可以了。
// 如果要设置某个位,比如设置第0位为1,第7位为0
value.data_bits.bit0 = 1;
value.data_bits.bit7 = 0;
*addr = value.data_char;
原文:https://www.cnblogs.com/ghx-kevin/p/12659629.html