#include
#define uchar unsigned char //byte
#define uint unsigned int //word
sbit led1=P0^0;
sbit led2=P0^1;
#define INBUF_LEN 8 //数据长度
unsigned char inbuf[INBUF_LEN]; //存储数据数组
unsigned char count3; //计数器
//向串口发送一个字符
void send_char_com( unsigned char ch)
{
SBUF=ch;
while (TI== 0 );
TI= 0 ;
}
//向串口发送一个字符串,strlen为该字符串长度
void send_string_com( unsigned char *str, unsigned int strlen)
{
unsigned int k= 0 ;
do
{
send_char_com(*(str + k));
k++;
} while (k < strlen);
}
void main(void)
{ //串口初始化
TMOD=0x20;
PCON=0x00;
SCON=0x50;
TL1=0xfd;
TH1=0xfd;
TR1=1;
//计数
count3= 0 ;
while(1)//动态现实是接纳多个数据
{
if (RI)
{
//接纳数据
unsigned char ch;
RI = 0 ;
ch=SBUF;
inbuf[count3]=ch; //存储数据
count3++; //计数器添加
if ( (count3==INBUF_LEN ))
{ count3= 0 ; //计数器清零
send_string_com(&inbuf,INBUF_LEN);//向串口发送一个字符串
}
}
//串口数据的查验,能够删去
if(inbuf[3]==0x11 )
{led1=0;}
}
}