#include <msp430f5529.h>
void UART_Init(void);
void putchar(unsigned char c);
void putstring(unsigned char *s);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR|=BIT0;
P1OUT|=BIT0;
UART_Init();
//putchar('s');
//__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
//__no_operation(); // For debugger
while(1)
{
// putchar('s');
// __delay_cycles(10000);
}
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
while (!(UCA1IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
UCA1IFG&=~UCTXIFG;
P1OUT^=BIT0;
}
void UART_Init(void)
{
P4SEL |= BIT4+BIT5; // P3.3,4 = USCI_A0 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**澶嶄綅浣胯兘
UCA1CTL1 |= UCSSEL_2; // SMCLK 閫夊彇SMLK鏃堕挓
UCA1BR0 = 9; // 1MHz 115200 (see User's Guide)1M/115200=8.68锛屽洓鑸嶄簲鍏ヤ负9
UCA1BR1 = 0; // 1MHz 115200 楂樺叓浣嶄负闆? UCA1MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
_EINT();
}
void putchar(unsigned char c)
{
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = c;
UCA1IFG&=~UCTXIFG;
}
void putstring(unsigned char *s)
{
while((*s)!='@')
{
putchar(*s);
s++;
}
|