This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

请问为什么这个按键中断程序按了五六次之后就失效了,要复位一下才行,每次都这样,很郁闷



#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output direction
P1OUT &= ~BIT0;
P1REN |= BIT4; // Enable P1.4 internal resistance
P1OUT |= BIT4; // Set P1.4 as pull-Up resistance
P1IES &= ~BIT4; // P1.4 Lo/Hi edge
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IE |= BIT4; // P1.4 interrupt enabled

while(1)
{
__bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/interrupt
__no_operation(); // For debugger
P1OUT ^= BIT0; // P1.0 = toggle
P1IES &= ~BIT4; // Toggle between H-L and L-H transition triggers
P1IE |= BIT4; // Enable port interrupt
}
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT4; // Clear P1.4 IFG
P1IE &= ~ BIT4; // Clear P1.4 IE
_BIC_SR_IRQ(LPM4_bits); // Exit LPM4
}

  • 你在按键上面并联一个1K电阻和102电容试试。

  • 1.检查程序是否在跑,可以使用一个闪烁的LED来检测。

    2.检测按钮按一下进入了几次中断?

    3.进入中断处理程序后关掉中断,处理完了再打开。

  • 楼主,建议从以下方面进行检查:

    1.可以使用CCS的仿真调试JLINK 或者JTAG,查看程序的运行状态是否跟自己的预期结果一样

    2.可以外接一个简单的电路,比如一个二极管,测试输出有没有错误和程序的错误

    3.检查一下按钮的函数有没有问题,还有数据的处理流程以及时序有没有逻辑问题。。

    4.对于中断,进入中断处理程序后关掉中断,处理数据结束后再打开中断试试。

    希望对你有帮助。。