|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2009-3-4 21:47:55
|
显示全部楼层
//rm_hs0038.c
sint detectrisepulse(unsigned char *exitflag)
{
char tmp;
tmp=DtRisePulse(&ControllPort,ControllPin,exitflag);
return tmp;
}
sint detectdownpulse(unsigned char *exitflag)
{
char tmp;
tmp=DtDownPulse(&ControllPort,ControllPin,exitflag);
return tmp;
}
void init7461()
{
LC7461.p="LC7461";
LC7461.QDH=9000;
LC7461.QDL=4500;
LC7461.HI=2250;
LC7461.LI=1250;
LC7461.usercode=0;
LC7461.datacode=0;
LC7461.usercode_not=0;
LC7461.datacode_not=0;
LC7461.decode_error=0;
}
unsigned char nearby(int compin,int compin1,int weakvalue)
{
if ((compin-compin1)>=0)
{
if ((compin-compin1)<=weakvalue) return 1;
}
else
{
if ((-(compin-compin1))<=weakvalue) return 1;
}
return 0;
}
//检查前导码,判断前导码类型 参数一:高电平持续时间 参数二:低电平持续时间
int CheckQD(unsigned int HLevel,unsigned int LLevel)
{
unsigned char tmp,tmp1;
tmp=nearby(LC7461.QDH,HLevel,500);
tmp1=nearby(LC7461.QDL,LLevel,500);
if (tmp&&tmp1) return 1;
//这儿加其他前导码型
return 0;
}
//解码,参数一:截获的高电平时间数据 参数二:截获的低电平时间数据
void DeCode(unsigned int *HData,unsigned int *LData)
{
int i,da,codetmp=0x0;
unsigned int *tmp,*tmp1,*tmp2,*tmp3;
tmp=HData;
tmp1=LData;
switch (CheckQD(*tmp,*tmp1)){
case 1:
//解用户码
tmp++;
tmp1++;
for (i=0;i<13;i++)
{
da=DataTran(*tmp,*tmp1);
if (da==-1)
{
break;
}
codetmp|=da;
codetmp=codetmp<<1;
tmp++;
tmp1++;
}
codetmp=codetmp>>1;
LC7461.usercode=codetmp;
//解用户反码
for (i=0;i<13;i++)
{
da=DataTran(*tmp,*tmp1);
if (da==-1)
{
break;
}
LC7461.usercode_not|=da;
LC7461.usercode_not<<=1;
tmp++;
tmp1++;
}
LC7461.usercode_not>>=1;
if ((LC7461.usercode^LC7461.usercode_not)!=0x1fff)
{
LC7461.decode_error=1;
break;
}
//解数据
codetmp=0x0;
for (i=0;i<8;i++)
{
da=DataTran(*tmp,*tmp1);
if (da==-1)
{
break;
}
codetmp|=da;
codetmp<<=1;
tmp++;
tmp1++;
}
codetmp>>=1;
LC7461.datacode=codetmp;
//解数据反码
codetmp=0x0;
for (i=0;i<8;i++)
{
da=DataTran(*tmp,*tmp1);
if (da==-1)
{
break;
}
codetmp|=da;
codetmp<<=1;
tmp++;
tmp1++;
}
codetmp>>=1;
LC7461.datacode_not=codetmp;
if ((LC7461.datacode^LC7461.datacode_not)!=0xff)
{
LC7461.decode_error=1;
break;
}
//
//
break;
default:
return;
}
return;
}
int DataTran(int hd,int ld)
{
int tmp;
tmp=hd+ld;
if (nearby(tmp,LC7461.HI,200)) return 1;
if (nearby(tmp,LC7461.LI,200)) return 0;
return -1;
} |
|