用lcd1602显示接受的字符串
//接送字符串
#include "lcd1602.h"
uchar a[32]=" ";
uchar rxcount = 0;
void PutString(uchar *ptr);
void main()
{
// Stop watchdog timer to prevent time out reset
uchar j;
WDTCTL = WDTPW + WDTHOLD;
//使用外部高频晶体振荡器
BCSCTL1&=~XT2OFF;
do{
IFG1&=~OFIFG;
for(j=0XFF;j>0;j--);
}while((IFG1&OFIFG));
BCSCTL2|=SELM_2;
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= URXE0 + UTXE0; // Enable USART0 T/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00; //
UMCTL0 = 0x4A; //
UCTL0 &= ~SWRST; // 复位
IE1=URXIE0;
_EINT();
init_lcd();
delay(10);//等待初始化完毕
while(1)
{
display_string(a,0x80,16);
display_string(a+16,0xc0,16);
}
}
#pragma vector=UART0RX_VECTOR
__interrupt void UART0_RX_ISR(void)
{
a[rxcount++] = RXBUF0;//将接收到的数据存起来
if(rxcount==32)
rxcount=0;
TXBUF0=RXBUF0;//将接收到的数据发出去
while((UTCTL0&0X01)==0);//等待数据发送完毕
} |