在使用Cube配置完GPIO后,使用下面函数进行操作:
//读取GPIO状态
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
//控制GPIO状态
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
//GPIO电平翻转
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
其中
GPIOx 为 GPIOA、B、C......
GPIO_PIN为 GPIO_PIN_0,1,2.....
GPIO状态的数据类型如下
typedef enum
{
GPIO_PIN_RESET = 0,
GPIO_PIN_SET
}GPIO_PinState;
HAL_Delay(500);为HAL库自带的延时函数,单位毫秒