在使用430IO口中断的时候发现无法进入中断,代码是这样的:
#define LED_CHARGE_INIT do{P2DIR |= BIT6;}while(0)
#define LED_CHARGE_ON do{P2OUT |= BIT6;}while(0)
#define LED_CHARGE_OFF do{P2OUT &= ~BIT6;}while(0)
#define USB_IN_INIT do{ \
P1SEL0 &= ~BIT4; /* io function */ \
P1DIR &= ~BIT4; /* input */ \
P1REN |= BIT4; /* internal pull enable */ \
P1OUT &= ~BIT4; /* pull down inside */ \
P1IES &= ~BIT4; /* raise edge interrupt */ \
}while(0)
#define USB_IN_IRQ_EN do{ \
P1IFG &= ~BIT4; /* clear interrupt */ \
P1IE |= BIT4; /* enable interrupt */ \
}while(0)
#define USB_IN_IRQ_DIS do{ \
P1IFG &= ~BIT4; /* clear interrupt */ \
P1IE &= ~BIT4; /* disable interrupt */ \
}while(0)
#define CHARGE_IN_INIT do{ \
P1SEL0 &= ~BIT2; /* io function */ \
P1DIR &= ~BIT2; /* input */ \
P1REN |= BIT2; /* internal pull enable */ \
P1OUT |= BIT2; /* pull up inside */ \
P1IES |= BIT2; /* fall edge interrupt */ \
}while(0)
#define CHARGE_IN_IRQ_EN do{ \
P1IFG &= ~BIT2; /* clear interrupt */ \
P1IE |= BIT2; /* enable interrupt */ \
}while(0)
#define CHARGE_IN_IRQ_DIS do{ \
P1IFG &= ~BIT2; /* clear interrupt */ \
P1IE &= ~BIT2; /* disable interrupt */ \
}while(0)
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P7OUT |= BIT1;
switch(__even_in_range(P1IV,P1IV_P1IFG6))
{
case P1IV_NONE:break;
case P1IV_P1IFG0:break;
case P1IV_P1IFG1:break;
case P1IV_P1IFG2:
P1IFG &= ~BIT2;
LED_CHARGE_ON;
break;
case P1IV_P1IFG3:break;
case P1IV_P1IFG4:
USB_IN_IRQ_DIS;
P1IFG &= ~BIT4;
P1IES ^= BIT4;
if(P1IN & BIT4){
//LED_CHARGE_ON;
P7OUT |= BIT1;
}
else{
//LED_CHARGE_OFF;
P7OUT &= ~BIT1;
}
USB_IN_IRQ_EN;
break;
case P1IV_P1IFG5:break;
case P1IV_P1IFG6:
break;
default:break;
}
}
void main()
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
init_sclk();
init_gpio();
P7SEL0 &= ~BIT1;
P7DIR |= BIT1;
charge_init();
init_rtc();
LED_CHARGE_OFF;
P7OUT &= ~BIT1;
while(1){
__bis_SR_register(GIE);
}
}
P1.4为USB插入检测,当USB插入的时候该IO口电平变高,用查询模式去扫描该IO口电平时可以的,但是用中断方式就是进不去中断,P7.1接了一个LED灯,LED没有任何反应
请问我这段代码哪里有问题吗,我看了中断相关的寄存器,我都配了,就是没有进入中断
HG:
觉得好乱,你用官方程序试一下
int main(void){ WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure GPIO P1OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state P1DIR |= BIT0; // Set P1.0 to output direction
P1OUT |= BIT3; // Configure P1.3 as pulled-up P1REN |= BIT3; // P1.3 pull-up register enable P1IES |= BIT3; // P1.3 Hi/Low edge P1IE |= BIT3; // P1.3 interrupt enabled
// Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; P1IFG &= ~BIT3; // P1.3 IFG cleared while(1) { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/interrupt __no_operation(); // For debugger P1OUT ^= BIT0; // P1.0 = toggle }}
P1.3改成P1.4,P1IES |= BIT3; // P1.3 Hi/Low edge改成上升沿触发试一下。
灰小子:
回复 HG:
建议单独测试一下这个io。不要和其他程序混在一起。测试没问题再联合调试