|
发表于 2012-6-21 17:29:43
|
显示全部楼层
以前用在STC芯片上的,对遥控器无要求
程序没整理有点乱,将就看吧![](static/image/smiley/default/biggrin.gif)
#include <config.h>
bit PT2272(uint HDa,uint LDa)
{static uchar Id;
static uint SMin,SMax,LMin,LMax,DMin,DMax;
static uint32 ChDa;
if(!Head)
{if(Up)
{DMin=HDa*29;//<<5-IntDa;
DMax=HDa*33;//<<5+UpDa;
SMin =HDa-Min;
SMax =HDa+Max;
LMin =(HDa<<1)+HDa-Min; //UpDa*3-Min;
LMax =(HDa<<1)+HDa+Max;
}
else
{if(Down)
{if(DMin<LDa&&DMax>LDa)
{Head=1;
Id=0;
RfDa=0;
}
else
Head=0;
}
}
}
else
{if(Up)
{if(HDa>SMin&&HDa<SMax) //短高脉冲
{RfDa+=0x01;
RfDa<<=1;
Id++;
}
else
{if(HDa>LMin&&HDa<LMax) //长高脉冲
{RfDa+=0x00;
RfDa<<=1;
Id++;
}
else
{Head=0;
return(0);
}
}
}
else
{if(Down)
{if(!(LDa>SMin||LDa>LMax))
{Head=0;
return(0);
}
}
}
if(Id>23)
{if(ChDa==RfDa)
{Head=0;
ChDa=0;
Id=0;
return(1);
}
else
{ChDa=RfDa;
Head=0;
RfDa=0;
Id=0;
return(0);
}
}
}
return(0);
}
/********************************信号中断********************************************/
void RFIn() interrupt 7
{if(CCF1)
{CR=0;
CL=CH=0;
CR=1;
if(RFin)
{((uchar *)&DownDa)[0]=CCAP1H; //低电平宽度
((uchar *)&DownDa)[1]=CCAP1L;
Down=1;
}
else
{((uchar *)&UpDa)[0]=CCAP1H; //高电平宽度
((uchar *)&UpDa)[1]=CCAP1L;
Up=1;
Down=0;
}
CCAP1L=CCAP1H=0;
}
CF=CCF0=CCF1=0;
} |
|