我正在学习微控制器,但我很难理解如何使用联合来设置 gpio 端口上的各个位。
typedef union _BYTE
{
byte _byte;
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;
}Bit;
} BYTE;
我正在使用上述内容来访问字节的各个位,但是如何使用它以下列方式分配 io 端口值?
MCF_GPIO_PORTDD.Bit.b0 = 1;
我宁愿不分配 _BYTE 类型,然后将端口分配给它。
#define MCF_GPIO_PORTDD (*(vuint8 *)(&__IPSBAR[0x100009]))
MCF_GPIO_PORTDD 只是一个内存地址。