#include <msp430.h>
#include "FG12864A.h"
#include "UCS.h"
volatile uint8_t rx_complete = 0;
unsigned char rx_buff[100];
unsigned char tx_buff[]={"nihao"};
int main(void) {
void send_buf(unsigned char *ptr);
P4SEL = BIT4+BIT5;
WDTCTL = WDTPW | WDTHOLD;// stop watchdog timer
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA1BR1 = 0x00; //9600
UCA1MCTL = UCBRS_3+UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE;
P1DIR |=BIT0;
P4DIR |= BIT7;
send_buf(tx_buff);
__bis_SR_register(LPM3_bits + GIE);
}
#pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{ void send_buf(unsigned char *ptr);
char ch;
int i=0;
if(rx_complete==0)
{while((ch=UCA1RXBUF)!='\r')
{
rx_buff[i++]=ch;
while(!(UCA1IFG & UCRXIFG));
}
rx_buff[i]='\0';
rx_complete=1;
}
else
{ send_buf(rx_buff);
rx_complete=0;
}
}
void send_buf(unsigned char *ptr)
{
while( *ptr !='\0')
{
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF = *ptr;
ptr++;
delay_ms(10);
}
}