1、首先定义位变量结构体
typedef union
{
unsigned int ALL;
struct
{
unsigned int LED01 :1;
unsigned int LED01 :1;
unsigned int LED02 :1;
unsigned int LED03 :1;
unsigned int LED04 :1;
unsigned int LED05 :1;
unsigned int LED06 :1;
unsigned int LED07 :1;
unsigned int LED08 :1;
unsigned int LED09 :1;
unsigned int LED10 :1;
unsigned int LED11 :1;
unsigned int LED12 :1;
unsigned int LED13 :1;
unsigned int LED14 :1;
unsigned int LED15 :1;
unsigned int reserver :16;
}BIT;
}LEDbits_t;
2、定义位结构体变量,并且定义变量到STM32F070的GPIOC->ODR寄存器处:
LEDbits_t LEDPort __attribute__ ((at(0x48000814)));
3、然后通过如下方式控制引脚电平实现翻转功能:
LEDPort.BIT.LED05 ^= 1;
LEDPort.BIT.LED06 ^= 1;
LEDPort.BIT.LED08 ^= 1;
LEDPort.BIT.LED09 ^= 1;
|