PIC單片機(jī)紅外遙控編碼與解碼的問題分析
相應(yīng)的C代碼如下:
unsigned char rfcount,
loop,
rftime,//查詢定時(shí)器
k;
bit rfbit, //接收完標(biāo)制
lowbit1,
lowbit2,
downbit,
rfgobit;
unsigned char dispcount[5];//結(jié)果
#define rfin RC6
////////////////////////////////////////////////////////////////////////////////
rf( )//遙控接收
{
if(rfbit==0)
{
if((lowbit1==0)(rfin==0))
{
downbit=1;
rftime=0;
lowbit1=1;
return;
}
if((lowbit1==1)(rfin==1))
{
lowbit2=1;
return;
}
if((lowbit1==1)(lowbit2==1)(RC6==0))
{
lowbit1=0;
lowbit2=0;
if((rftime>=40)(downbit==1))//遙控接收;
{
rfgobit=1;
loop=0;
rfcount=0;
k=1;
rftime=0;
return;
}
rfcount=rfcount+1;
loop=loop+1;
if(rfcount>=31)
{
rfgobit=0;
downbit=0;
rfcount=0;
rfbit=1;
loop=0;
return;
}
if((rftime>=7)(rfgobit==1))
{
dispcount[k]=dispcount[k]|0x80;
rftime=0;
if(loop==8)
{
k=k+1;
loop=0;
return;
}
dispcount[k]=dispcount[k]>>1;
return;
}
if((rftime5)(rfgobit==1))
{
dispcount[k]=dispcount[k]0x7f;
rftime=0;
if(loop==8)
{
k=k+1;
loop=0;
return;
}
dispcount[k]=dispcount[k]>>1;
return;
}
}
}
}
(查詢子程序同匯編)
紅外遙控器相關(guān)文章:紅外遙控器原理
評(píng)論