#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit OP=P4^1;
uint count;
void delayms(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x11;
TH0=0xff;
TL0=0xe6;
EA=1;
ET0=1;
count=0;
OP=0;
}
void
tim0() interrupt 1
{
OP=~OP;
}
void Trans_0()
{
TH1=(65536-560)/256; //0.56低电平
TL1=(65536-560)%256;
TR1=1;
TR0=1;
while(!TF1);
TR0=0;
TR1=0;
TH1=(65536-560)/256; //0.56 间隔
TL1=(65536-560)%256;
TR1=1;
while(!TF1);
}
void Trans_1()
{
TH1=(65536-560)/256;
TL1=(65536-560)%256;
TR1=1;
TR0=1;
while(!TF1);
TR0=0;
TR1=0;
TH1=(65536-1680)/256;
TL1=(65536-1680)%256;
TR0=1;
TR1=1;
while(!TF1);
TR0=0;
TR1=0;
}
void Trans_data(uchar num) //发送八位
{
uint i;
for(i=0;i<8;i++)
{
num=num>>1;
if(CY)
Trans_1();
else
Trans_0();
}
}
void Trans_begin(uint a,uint b,uint c,uint d)
{
TH1=(65536-9000)/256;
TL1=(65536-9000)%256; //9ms引导码
TR0=1;
TR1=1;
while(!TF1);
TR0=0;
TR1=0;
TH1=(65536-4500)/256; //4.5引导码
TL1=(65536-4500)%256;
TR1=1;
while(!TF1);
Trans_data(a); //高地址
Trans_data(b); //低地址
Trans_data(c); //数据码
Trans_data(d); //数据反码
}
void send()
{
uint temp1;
P2=0xfe;
temp1=P1;
temp1=temp1&0xf0;
if(temp1!=0xf0)
{
delayms(10);
temp1=P1;
temp1=temp1&0xf0;
if(temp1!=0xf0)
{
temp1=P1;
switch(temp1)
{
case 0xee: Trans_begin(0x03,0xfc,0x16,0xe9);
break;
case 0xde: Trans_begin(0x03,0xfc,0x16,0xe9);
break;
case 0xbe: Trans_begin(0x03,0xfc,0x16,0xe9);
break;
case 0x7e: Trans_begin(0x03,0xfc,0x16,0xe9);
break;
}
while(temp1!=0xf0)
{
temp1=P1;
temp1=temp1&0xf0;
}
}
}
P1=0xff;
}
void main()
{
init();
send();
while(1);
}
发射后对方一直没有反应
一周热门 更多>