#include "detect.h" #include "gpio_it.h" // 确保包含 GPIO 中断相关头文件 #include "bsp_delay.h" int key=0; // 按键中断回调函数 void detect_exit(void) { delay_ms(10); // 延时10ms key++; // 按键按下时变量自增 __HAL_GPIO_EXTI_CLEAR_IT(KEY_Pin); // 清除中断标志位 } void detect_led(void) { delay_ms(10); // 延时10ms key++; // 按键按下时变量自增 __HAL_GPIO_EXTI_CLEAR_IT(ext_up_Pin); // 清除中断标志位 } void detect_init(void) { BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit); BSP_GPIO_RegisterCallback(ext_up_Pin, detect_led); // 注册按键中断回调函数 if (BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit) != BSP_OK) { // 错误处理 } // 启用按键中断 if (BSP_GPIO_EnableIRQ(KEY_Pin) != BSP_OK) { // 错误处理 } if (BSP_GPIO_EnableIRQ(ext_up_Pin) != BSP_OK) { // 错误处理 } }