本帖最后由 yklstudent 于 2015-12-11 17:10 编辑
最近突发奇想,想引用位变量结构体控制引脚,具体想法如下所示:
1、首先定义位变量结构体
typedef union
{
unsigned int ALL;
struct
{
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 LED16 :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;
4、测试结果确是GPIOC的PIN5和PIN8引脚可以实现翻转功能,PIN6和PIN9引脚却没法实现电平翻转;在线调试也看到GPIOC->ODR的PIN5、PIN6、PIN8和PIN9都在不断的翻转,但引脚输出却没有跟着改变
经过二楼朋友的提醒,问题已经解决了。 |