我想用430F5529写个小程序,当上位机(串口助手)发一个字符a时,将IO口P1.4翻转~程序如下,不知道为什么UCA1RXBUF和aaa的值都没有~波特率设置为115200~~~~
程序无法实现功能,请大神们帮我看看~~~
- #include <msp430.h>
- char aaa;
- int main(void)
- {
- P4SEL = BIT4+BIT5;
- P1DIR |= BIT4;
-
- UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
- UCA1CTL1 |= UCSSEL__SMCLK;
- UCA1BR0 = 0x09; //
- UCA1BR1 = 0x00; //
- UCA1MCTL |= UCBRS_1+UCBRF_0; //
- UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
- UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt
-
- __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled
- __no_operation(); // For debugger
- }
- // Echo back RXed character, confirm TX buffer is ready first
- #pragma vector=USCI_A1_VECTOR
- __interrupt void USCI_A1_ISR(void)
- {
- switch(__even_in_range(UCA1IV,4))
- {
- case 0:break; // Vector 0 - no interrupt
- case 2: // Vector 2 - RXIFG
- while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
- UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
- aaa = UCA1RXBUF;
- //uart_tx_string(aaa);
- if(aaa == 'a')
- {
- P1OUT ^= BIT4;
- }
-
- break;
- case 4:break; // Vector 4 - TXIFG
- default: break;
- }
- }