高级会员

- 积分
- 862
- 金钱
- 862
- 注册时间
- 2015-2-12
- 在线时间
- 354 小时
|
发表于 2019-7-19 14:39:48
|
显示全部楼层
#define PERIPH_BASE ((uint32_t)0x40000000)
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define GPIOD_BASE (APB2PERIPH_BASE + 0x1400)
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
typedef struct
{
__IO uint32_t CRL; //端口配置低寄存器 偏移地址:0x00
__IO uint32_t CRH; //端口配置高寄存器 偏移地址:0x04
__IO uint32_t IDR; //端口输入数据寄存器 偏移地址:0x08
__IO uint32_t ODR; //端口输出数据寄存器 偏移地址:0x0C
__IO uint32_t BSRR; //端口位设置/清除寄存器 偏移地址:0x10
__IO uint32_t BRR; //端口位清除寄存器 偏移地址:0x14
__IO uint32_t LCKR; //端口配置锁定寄存器 偏移地址:0x18
} GPIO_TypeDef;
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
assert_param(IS_GPIO_BIT_ACTION(BitVal));
if (BitVal != Bit_RESET)
{
GPIOx->BSRR = GPIO_Pin;
}
else
{
GPIOx->BRR = GPIO_Pin;
}
}
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
GPIOx->ODR = PortVal;
}
1、从上述可以看出,函数库实际操作时,想清除某端口位时,并没有对BSRR高16位(bit16-bit31)操作,而是另外用到BRR寄存器。
2、你可以BSRR进行32位数据操作,但函数库就不是这样写了。另外还要注意一句话:“注:如果同时设置了BSy和BRy的对应位,BSy位起作用。 ” |
|