小编hop*_*man的帖子

如何实现两次按钮中断PIC

我正在使用 16F1703 PIC mcu,我想通过触摸按钮(A1)开始一个 7 段液晶循环(0-9)循环,之后如果我触摸按钮(A1)两次,我想要图片进入睡眠模式。

为此,我实现了这个:

#include <test_interrupt.h>
byte const DataExit[10]={0b01000100,
                               0b01011111,  
                               0b01100010,
                               0b01001010,
                               0b01011001,
                               0b11001000,
                               0b11000000,
                               0b01011110,
                               0b01000000,
                               0b01001000};
byte const bitMask[8]={1,2,4,8,16,32,64,128};

//show seven numbers
void segmentCycle(void){
   int i, j; 
   for(i=0;i<10;i++){
         for (j=0; j<8;j++){
            output_low(CLK);
            output_bit(DATA,DataExit[i] & bitMask[j]);
            output_high(CLK);  
         }

         delay_ms(7000);
         output_low(CLR);
         delay_ms(6000);
         output_high(CLR); 
   }
}

#INT_IOC
void  IOC_isr(void) 
{
  segmentCycle(); 
  sleep(); 

}

void main()
{
   port_a_pullups(0x02);
   enable_interrupts(INT_IOC_A1);
   enable_interrupts(INT_IOC_A1_H2L);
   enable_interrupts(GLOBAL);

   while(TRUE);

}
Run Code Online (Sandbox Code Playgroud)

现在,如果我触摸按钮,有时它会启动,否则不会。你有什么建议?

我正在使用 ccs 编译器。

c embedded microcontroller interrupt pic

0
推荐指数
1
解决办法
884
查看次数

标签 统计

c ×1

embedded ×1

interrupt ×1

microcontroller ×1

pic ×1