由于STM32没有位处理,所以STM32不像51单片机一样支持BIT变量,下面教大家怎么在STM32中实现位变量
1、首先定义一个结构体
typedef struct
{
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
} BIT8;
2、然后宏定义就行
unsigned char addrNewCode;
#define addrNewBit0 (((BIT8*) & addrNewCode) -> b0)
#define addrNewBit1 (((BIT8*) & addrNewCode) -> b1)
#define addrNewBit2 (((BIT8*) & addrNewCode) -> b2)
#define addrNewBit3 (((BIT8*) & addrNewCode) -> b3)
#define addrNewBit4 (((BIT8*) & addrNewCode) -> b4)
#define addrNewBit5 (((BIT8*) & addrNewCode) -> b5)
#define addrNewBit6 (((BIT8*) & addrNewCode) -> b6)
#define addrNewBit7 (((BIT8*) & addrNewCode) -> b7)
3、这样的话addrNewBit0 等等就能当成位变量使用了
|