https://bbs.21ic.com/icview-3325360-1-1.html
参靠了上面的神贴思路,尝试了一下啊。
- #include "mcc_generated_files/system/system.h"
- bool SW_flag = 0; //记录是否发生了下降沿中断
- bool SW_Button_active_flag =0; //有效按键激活标记
- void SW_Button_Interrupt_Handle(void)
- {
- if(SW_GetValue()==LOW)
- {
- SW_flag = 1;
- }
- else if( ( SW_GetValue()==HIGH ) && (SW_flag == 1) )
- {
- SW_Button_active_flag =1;
- SW_flag = 0;
- }
- }
- /*
- Main application
- */
- int main(void)
- {
- SYSTEM_Initialize();
- // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
- // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts
- // Use the following macros to:
- // Enable the Global Interrupts
- INTERRUPT_GlobalInterruptEnable();
- // Disable the Global Interrupts
- //INTERRUPT_GlobalInterruptDisable();
- SW_SetInterruptHandler(SW_Button_Interrupt_Handle);
- while(1)
- {
- if(SW_Button_active_flag == 1)
- {
- SW_Button_active_flag = 0;
- LED_Toggle();
- }
- }
- }
试了一下,效果很好
|