uint receive_deco(void) //解码
{
uchar j,k1=0,k2=0;
uint w_receive;
for(j=16;j;j--)
{
gas_led=1;
while(!wireless_in)//如果接收引脚是低电平 则计时
{
delay_50us(1);//计算有几个50us
k1++;
k2++;
}
while(wireless_in))//如果接收引脚是高电平 则计时
{
delay_50us(1);
k2++;
}
if((k2>30)&&(k2<=46)&&(k1<=(k2/3)))//1500us~2300us
{
if((k1>6)&&(k1<=11))
{//300~550us
w_receive&=0xfffe;
w_receive<<=1;
}
if((k1>=24)&&(k1<36))
{//1200~1800us
w_receive|=0x0001;
w_receive<<=1;
}
}
return="return" w_receive;
}
/////////////////////////////////////////////////
//接收头码、地址和数据
////////////////////////////////////////////////
uint wireless_receive(void) //reentrant//使此函数可重入
{ //接收遥控码(解码程序)
uint="uint" re_data,i=0,j=0;
//检测50ms内有没有编码接收,因为发送完十六位数据需要1500*16=24ms 头码11ms 延时300us
while(!wireless_in)
{
delay_50us(1);
i++;
}
if((i>=180)&&(i<=260))
{//如果有9--13毫秒左右的头码 则看延时时间
while(wireless_in)
{
delay_50us(1);
j++;
}
if((j>6)&&(j<=11))
{//有300--550微秒左右的低电平延时
re_data=receive_deco(); //解码
return re_data;
}
else
{
re_data=0x0000;
}
}
else
{
re_data=0x0000;
}
return re_data;
}
|