/* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ /* Prevent unused argument(s) compilation warning */ if(GPIO_Pin == KEY_Pin) //如果发生外部中断的是KEY_Pin { while(HAL_GPIO_ReadPin(KEY_GPIO_Port,KEY_Pin)==GPIO_PIN_RESET);//等待按键松开,避免LED状态重复翻转 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);//翻转LED状态 } UNUSED(GPIO_Pin); /* NOTE: This function Should not be modified, when the callback is needed, the HAL_GPIO_EXTI_Callback could be implemented in the user file */}/* USER CODE END 4 */避免长时间按下按键不放开,可能导致阻塞,程序其他部分不能正常运行。
3.编译并烧录代码
/* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ /* Prevent unused argument(s) compilation warning */ if(GPIO_Pin == KEY_Pin) //如果发生外部中断的是KEY_Pin { while(HAL_GPIO_ReadPin(KEY_GPIO_Port,KEY_Pin)==GPIO_PIN_RESET);//等待按键松开,避免LED状态重复翻转 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);//翻转LED状态 } UNUSED(GPIO_Pin); /* NOTE: This function Should not be modified, when the callback is needed, the HAL_GPIO_EXTI_Callback could be implemented in the user file */}/* USER CODE END 4 */避免长时间按下按键不放开,可能导致阻塞,程序其他部分不能正常运行。
3.编译并烧录代码