用LaunchPad G2插上MSP430G2553在CCS v6.0下测试中断程序。
P1.3上的Push Button为中断源ToggleP1.0上的LED,程序执行没问题。
在此基础上再加一段用USCI A0完成的串行通讯代码与PC通讯也没问题(用超级终端),但是上述P1.3的中断程序却不执行了。
学习MSP430有半年了,俩星期了还没明白。求各位老师指教。如下是代码:
#include <msp430.h>
int main(void){
WDTCTL = WDTPW + WDTHOLD;
//**********setting USCI_A as UART
P1SEL = BIT1 + BIT2; //P1.1 and P1.2 are RxD and TxD
P1SEL2 = BIT1 + BIT2; //
UCA0CTL1 |= UCSWRST + UCSSEL_2; //clock = SMCLK
UCA0BR0 = 0x68; //
UCA0BR1 = 0x00; //9600 buad rate
UCA0MCTL = UCBRS2; //
UCA0CTL1 &=~UCSWRST; //start UART
IE2 |= UCA0TXIE + UCA0RXIE; //USCI_A UART interrupt enable
//********setting P1.3 as IO interrupt source P1.0 LED as indicator
P1DIR |= BIT0; // Set P1.0 to output direction
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1REN |= BIT3; // Enable Pull Up on SW2 (P1.3)
P1IFG &= ~BIT3; // P1.3 IFG cleared;
//********device wakeup from sleep by interrupt
__bis_SR_register(LPM4_bits + GIE); //Enter LPM4 w/interrupt
}
#pragma vector = USCIAB0TX_VECTOR //UART transmit ISR
__interrupt void UCABOTX_ISR(void){
}
#pragma vector = USCIAB0RX_VECTOR //UART receive ISR
__interrupt void UCABORX_ISR(void){
UCA0TXBUF = UCA0RXBUF; // output echo
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void){
P1OUT ^= BIT0; // P1.0 = toggle
P1IFG &= ~BIT3; // P1.3 IFG cleared
}
zhaoju he:
回复 灰小子:
谢谢您!我想过这点,但您指出后我才相信自己。我这就修改!