将PC11配置成输入管脚,
定义如下宏
#define GPIO_PWON_PORT GPIOC
#define GPIO_PWON_PIN GPIO_Pin_11
使用下面的库函数进行读取,管教状态正确
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
uint8_t bitstatus = 0x00;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
{
bitstatus = (uint8_t)Bit_SET;
}
else
{
bitstatus = (uint8_t)Bit_RESET;
}
return bitstatus;
}
感觉这个函数写的过于啰嗦,自己又重写一次,写成下面的形式
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
uint8_t
PWONStatus_Read(void)
{
return (GPIO_PWON_PORT->IDR & GPIO_PWON_PIN);
}
包含了对应的头文件
结果用自己写的函数读不到管脚状态,一直都是0
有点迷糊,不知道怎么回事,求大神指导