|
就不多说了!直接上程序!如下:
#include
#include
unsigned char uart_data_one;
int con = 0;
volatile unsigned int i; // Use volatile to prevent removal
unsigned char TD[70];
void delay(int x)
{
while(x--);
}
/*************************数据接收部分********************************/
void COM()
{
FLL_CTL0 |= XCAP18PF; // Configure load caps
P2SEL |= 0x30; // P2.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL1; // UCLK = SMCLK
UBR00 = 0x6D; // 1MHz 9600
UBR10 = 0x00; // 1MHz 9600
UMCTL0 = 0x03; // modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
P2DIR |= 0x10; // P2.4 output direction
TXBUF0='O','K';
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
/**********************************主函数部分*************************************/
char GPS[60];
void main(void)
{ // by compiler optimization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
COM();
}
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
// while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
uart_data_one = RXBUF0;
con++;
if(con==1)
{
if(uart_data_one!='M')
{
con=0;
}
else
{
TD[0]='M';
}
}
if(con==2)
{
if(uart_data_one!='C')
{
con=0;
}
else
{
TD[1]='C';
}
}
if(con>4)
{
if(uart_data_one=='*')
{
con=0;
}
}
if(con>=3)
{
TD[con-1]=uart_data_one;
}
} |
|