#include void delay(unsigned int j) { unsigned int i; for(i=0; i<=j; i++) { __delay_cycles(50000); __delay_cycles(50000); } } void UART_init() { // Setup P3.0 UCA0RXD, P3.1 UCA0TXD P3SEL0 |= BIT0 | BIT1; // Set P3.0, P3.1 to non-IO P3DIR |= BIT0 | BIT1; // Enable UCA0RXD, UCA0TXD P1DIR |= BIT2; // ACLK set out to pin P1SEL0 |= BIT2; // P1.2 for debugging purposes. // Setup LFXT1 UCSCTL6 &= ~(XT1OFF); // XT1 On UCSCTL6 |= XCAP_3; // Internal load cap // Setup eUSCI_A0 UCA0CTLW0 |= UCSWRST; // **Put state machine in reset** UCA0CTLW0 |= UCSSEL_1; // CLK = ACLK UCA0BRW_L = 0x03; // 32kHz/9600=3.41 (see User's Guide) UCA0BRW_H = 0x00; // UCA0MCTLW = 0x5300; // Modulation UCBRSx=0x53, UCBRFx=0 UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine** // UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt } void UART_Tx(unsigned char a) { while (!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = a; } unsigned char UART_Rx() { unsigned char rx; rx = UCA0RXBUF; while (!(UCA0IFG & UCRXIFG)); // USCI_A0 TX buffer ready? return rx; } void UART_Str(unsigned char *a) { while(*a!='\0') { UART_Tx(*a); a++; } } void main(void) { unsigned char read; WDTCTL = WDTPW | WDTHOLD; // Stop WDT UART_init(); while(1) { UART_Str("EMDC..."); } }