一、配置
二、代码
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
uint8_t keyFalg = 0; // =1按键被按下
/* USER CODE END PD */
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == KEY_Pin){
keyFalg = 1;
}
}
/* USER CODE END 4 */
/* USER CODE BEGIN WHILE */
while (1)
{
if(keyFalg == 1){
HAL_Delay(20);
if(HAL_GPIO_ReadPin(GPIOB,KEY_Pin) == GPIO_PIN_RESET){
HAL_GPIO_TogglePin(GPIOC,LED_Pin);
while(HAL_GPIO_ReadPin(GPIOB,KEY_Pin) == GPIO_PIN_RESET);
}
keyFalg = 0;
}
/* USER CODE END WHILE */