按键设置不解:这是MSP430F5529USB 板按键原理图
按键程序如下
void Buttons_init(uint16_t buttonsMask)
{
BUTTON_PORT_OUT |= buttonsMask; //buttons are active low
BUTTON_PORT_REN |= buttonsMask; //pullup resistor
BUTTON_PORT_SEL &= ~buttonsMask;
}
void Buttons_interruptEnable(uint16_t buttonsMask)
{
BUTTON_PORT_IES &= ~buttonsMask; //select falling edge trigger
BUTTON_PORT_IFG &= ~buttonsMask; //clear flags
BUTTON_PORT_IE |= buttonsMask; //enable interrupts
}
BUTTON_PORT_IES &= ~buttonsMask; 这个是上升沿中断
为什么不是 BUTTON_PORT_IES |= buttonsMask;
我改成BUTTON_PORT_IES |= buttonsMask; 也是可以。
还有就是没有清除中断标志
__interrupt void Port2_ISR(void)
{
//
// Context save interrupt flag before calling interrupt vector.
// Reading interrupt vector generator will automatically clear IFG flag
//
buttonsPressed = PAIFG & BUTTON_ALL;
{
// Vector P2IV_NONE: No Interrupt pending
case P2IV_NONE:
break;
case P2IV_P2IFG0:
break;
case P2IV_P2IFG1:
break;
case P2IV_P2IFG2:
if (buttonDebounce == 1)
{
buttonDebounce = 2;
Buttons_startWDT();
__bic_SR_register_on_exit(LPM3_bits);
}
else if (buttonDebounce == 0)
{
__bic_SR_register_on_exit(LPM4_bits);
}
//P2IFG=0;
break;
case P2IV_P2IFG3:
break;
case P2IV_P2IFG4:
break;
case P2IV_P2IFG5:
break;
case P2IV_P2IFG6:
break;
case P2IV_P2IFG7:
break;
default:
break;
}
}
// Reading interrupt vector generator will automatically clear IFG flag//这句注释是读取自动清除中断标志码吗
不是要手动清除吗
user3854913:
回复 Ling Zhu2:
谢谢,我理解了,我想知到在哪里能查到外部中断标志会自动清零
user3854913:
回复 Ling Zhu2:
例1:#pragma vector = PORT2_VECTOR__interrupt void port2(void){ switch(P2IV) { case P2IV_P2IFG6: P1OUT ^= BIT0;break; //LED1 亮灭 case P2IV_P2IFG7: P1OUT ^= BIT1;break; //LED2 亮灭 default :break; }}例2:#pragma vector = PORT2_VECTOR__interrupt void port2(void){ if(P1IFG&BIT6){ P2IFG &=~BIT6; } if(P1IFG&BIT7){ P2IFG &=~BIT7; } }
一个是中断向量,一个是中断标志,在使用中断向量时不需要清除标志,那么是不是意味例2中可以嵌套
Ling Zhu2:
回复 灰小子:
dirtwillfly
430默认的是关闭中断嵌套的,除非你在一个中断程序中再次开总中断EINT;