void UART0_Init(void)
{
SCON0 = 0x10; //选择串口方式1
CKCON |= 0x08; //定时器1使用系统时钟
TMOD |= 0x20; //选择T1,方式2,自动再装入8位计数器 ·
TH1 = 0xFD; //T1初值,根据波特率,时钟等计算. 0xFD, bps=9600bps
TL1 = 0XFD;
TR1 = 1; //启动定时器T1
ES0 = 1; //UART0中断开启
}
void UART0_ISR(void) interrupt 4
{
PCA0CPH4=0xff;
if(RI0) //中断标志 RI0=1 数据完整接收
{
RI0 = 0; //软件清零
BUFDATA = SBUF0; //读缓冲
if(POINT==0)
{
if(BUFDATA==0x68)
{
RECEIVR_BUFFER[0] = BUFDATA;
POINT++;
}
else
{POINT = 0;}
}
else RECEIVR_BUFFER[POINT++] = BUFDATA;
}
if(TI0)
{
TI0=0;
SBUF0=BUFDATA;
}
} |