#include <51.h>
#define uchar unsigned char
#define uint unsigned int
uchar trdata[]={0xaa,0x01,0x03,0x0f,0x00,0x05};
uchar rece;
uchar j;
//uchar code trdata1[]={'R','I','C','H','M','C','U',0x0d,0x0a,0x00};
uchar flag=1;
void delay1ms(uint i)
{
uchar j;
while(i--)
{
for(j=0;j<115;j++) //1ms基准延时程序
{
;
}
}
}
main()
{
uchar i;
SCON= 0x50; //串口方式允许接收
//SM0=0;
//SM1=1;
//REN=0;
PCON= 0x00; //SMOD=0
TMOD= 0x20; //定时器1定时方式2
TH1= 0xfd; //11.0592M 9600波特率
TL1= 0xfd;
TR1= 1; //启动定时器
EA=1;
while(1)
{
if(flag==1){
ES=0;
i=0;
while(trdata!=0x05)
{
P0=trdata;
SBUF=trdata;
while(!TI);
TI=0;
i++;
delay1ms(1000);
}
if(i>4)
{
flag=0;
ES=1;
}
}
}
}
void INT_UartRcv(void) interrupt 4
{
if(RI==1){
RI=0;
rece=SBUF;
P0=0xff;
j++;
delay1ms(100);
// bulb=1;
// bulb1=1;
if(j>12){
flag=1;
j=0;
ES=0;
}
}
} |