如何检查按钮是否在 500 毫秒内按下两次(PIC16)?
我有一个连接到RB1的开关按钮。此按钮可作为重置,但需要将其按两次才能正常工作。如果第二压在500毫秒后发生(相对于初始按下),则不会做任何事情。
我认为我应该利用计时器或CCP模块,但我不确定如何实施这些模块。你建议什么?
编辑(我的ISR):
void interrupt ISR(void){
GIE = 0;
if(INTF){
INTF = 0;
if(reset_press == 0){
TMR1 = 0x0BDC; // counter starts counting at 0x0BDC (3036)
TMR1ON = 1; // Turns on Timer1 (T1CON reg)
}
reset_press++;
}
else if(TMR1IF==1){ // checks Timer1 interrupt flag
TMR1IF = 0; // clears interrupt flag
if(reset_press == 2){
reset_count(); // reset function
}
TMR1ON = 0; // Turns off Timer1 (T1CON reg)
reset_press = 0;
}
GIE = 1;
}
I have a switch button that is connected to RB1. This button acts as a reset but it needs to be pressed twice for it to work. If the second press happens after 500 ms (relative to the initial press), it will do nothing.
I think I should make use of timers or ccp module but I am not sure how to implement those. What do you suggest?
Edit (My ISR):
void interrupt ISR(void){
GIE = 0;
if(INTF){
INTF = 0;
if(reset_press == 0){
TMR1 = 0x0BDC; // counter starts counting at 0x0BDC (3036)
TMR1ON = 1; // Turns on Timer1 (T1CON reg)
}
reset_press++;
}
else if(TMR1IF==1){ // checks Timer1 interrupt flag
TMR1IF = 0; // clears interrupt flag
if(reset_press == 2){
reset_count(); // reset function
}
TMR1ON = 0; // Turns off Timer1 (T1CON reg)
reset_press = 0;
}
GIE = 1;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)