我有3个按钮,每次按下或释放时都会产生中断,我遇到的问题是,我需要分析实际发生的事情(重新按下或按下按钮),这是我的代码:
..................
ISR(PORTA_INT0_vect){
if(!(PORTA.IN & PIN1_bm)){ // Green LED pressed
printf(" Green button pressed\n");
}
if(!(PORTA.IN & PIN3_bm)){ // Blue LED pressed
printf(" Blue button pressed\n");
}
if (!(PORTA.IN & PIN5_bm)){ // Red LED
printf(" Red button pressed \n");
}
}
ISR(PORTA_INT1_vect){
printf(" I'm in \n");
if((PORTA.IN & PIN1_bm)){// Green LED released
printf("Green button released \n");
}
else if((PORTA.IN & PIN3_bm)){// Blue LED released
printf("Blue button released \n");
}
else if((PORTA.IN & PIN5_bm)){// Red LED released
printf("Red button released \n");
}
}
void buttonINT(){
// PORTA
PORTA.PIN1CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_FALLING_gc ;
PORTA.PIN3CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_FALLING_gc ;
PORTA.PIN5CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_FALLING_gc ;
PORTA.INT0MASK = PIN1_bm | PIN3_bm | PIN5_bm;
PORTA.INTCTRL = PORT_INT0LVL0_bm;
PMIC.CTRL |= PMIC_LOLVLEN_bm;
sei();
}
void buttonINT2(){
// PORTA
PORTA.PIN1CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_RISING_gc ;
PORTA.PIN3CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_RISING_gc ;
PORTA.PIN5CTRL = PORT_OPC_PULLUP_gc| PORT_ISC_RISING_gc ;
PORTA.INT1MASK = PIN1_bm | PIN3_bm | PIN5_bm;
PORTA.INTCTRL = PORT_INT1LVL1_bm;
PMIC.CTRL |= PMIC_LOLVLEN_bm;
sei();
}
我得到的问题是程序根本没有通过上升沿产生中断?
知道我在这里做错了什么吗?
答案 0 :(得分:1)
我建议使用定时器生成的中断每隔10毫秒轮询一次密钥。你可以在这里
main()