看了下pt2262的手册,明白了协议,用TCNT0来测量脉冲宽度
LCD1602来显示,获得编码后,再利用发射电路发射出去
BOOL PT2262_Read(void)
{
UCHAR temp = 0, timer;
ULONG DATA = 0;
for(temp=0;temp<24;temp++)
{
TCNT0 = 0;
while(IrInput)
{
if(TCNT0>MaxWide) goto end;
}
timer = TCNT0;
while(!IrInput)
{
if(TCNT0>(MaxWide+MaxNarr)) goto end;//if(TCNT0 > 112) goto end;
}
if(TCNT0<MinWide)
{
goto end;
}
DATA <<= 1;
if(timer<MaxNarr)
{
if(!((timer<MaxNarr)&(timer>MinNarr))) goto end;
DATA += 0;
}
else
{
if(!((timer<MaxWide)&(timer>MinWide))) goto end;
DATA += 1;
}
}
if(DATA&0x1) LED(1);
else LED(0);
for(temp=0;temp<12;temp++)
{
if((DATA & 0xC00000)==0)
{
IrCode[temp] = '0';
}
else if((DATA & 0xC00000)==0xC00000)
{
IrCode[temp] = '1';
}
else if((DATA & 0xC00000)==0x400000)
{
IrCode[temp] = 'F';
}
else
{
IrCode[temp] = 'E';
}
DATA<<=2;
}
return 1;
end:
return 0;
}//接受代码 |