现在正在做一个用C51单片机模拟2272的解码程序,用的普通IO口循环检测进行,的找的论坛里的代码,但是怎么也调试不通,坛子里有人有模拟解码的代码能共享下吗?或者帮忙看看下面的代码哪里有错误啊,万分感谢大家了
#include "315MHz.h"
#define uchar unsigned char
#define uint unsigned int
bit bdata recv_flg = 0;//bit right or fault
bit bdata lianji_flg = 0; //long or short(1,0)
void d40us(uchar n) //40us delay
{
uchar data i,j;
for(j=n;j>0;j--)
{
for(i=100;i>0;i--)
_nop_();
}
}
unsigned long decode(void)
{
unsigned long DATA;
unsigned char i,count;
DATA = 0;
for(count=0;count<25;count++)
{
i=0;
while(Rx_315&(1))
{
d40us(1);
i++;
if (i>45) goto end;
}
DATA*=2;
if(i<12) //·Ö±æ¸ßµÍ
{
if (!((i<12)&&(i>5))) goto end;//µçƽºÏ·¨
DATA+=0;
}
else
{
if (!((i>24)&&(i<32))) goto end;
DATA+=1;
}
//while (!(Rx_315&(1))) //µÍλ¼ÆÊý
//{
//d40us(1);
//i++;
//if (i>40) goto end; //ÏÞʱ½âÂë
//else break;
//}
//if (i<3) goto end; //¶Ô±È¿í¶È
}
return DATA;
end:
return 0;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
AUXR &= 0xBF; //定时器时钟12T模式
TMOD &= 0x0F; //设置定时器模式
TMOD |= 0x10; //设置定时器模式
TL1 = 0x64; //设置定时初值
TH1 = 0xFF; //设置定时初值
TF1 = 0; //清除TF1标志
TR1 = 1; //定时器1开始计时
ET1 = 1; //T1开中断
}
bit Decode(unsigned char a,unsigned char b)
{
if ((a==1) && (b==3)) return 0;
if ((a==3) && (b==1)) return 1;
return 0;
}
bit RFOK;
unsigned char RFCode[3];
sbit RFin = P3^7;
bit S1,S2,S3;
bit NextS,CurrS;
unsigned char RFc;
unsigned char RFb[50];
void TM1_isr() interrupt 3 //156微秒 @12.000MHz
{
unsigned char i;
TL1 = 0x64;
TH1 = 0x0FF;
S1=S2; // 采样,一个采样单位0.156ms,4α的1/3,保证每个位至少采样2次
S2=S3;
S3=RFin;
i=0; //表决,三局两胜
if (S1) i++;
if (S2) i++;
if (S3) i++;
if (i>1) CurrS=1; else CurrS=0;
if (NextS==CurrS)
RFc++; //计时
else
{ //变位记录宽度
for(i=0;i<50-1;i++) RFb[i]=RFb[i+1]; //串位
if (RFc>80 && RFc < 100) RFc=31; //标记同步头12.48-15.6ms 93*0.156ms=14.5ms
else if (RFc>11) RFc=15; //标记错误位
else if (RFc>6) RFc=3; //标记宽位
else if (RFc<4) RFc=1; //标记窄位
else RFc=15;
RFb[49]=RFc; //记录长度
RFc=0; //清计时
if (RFb[0]==1 && RFb[1]==31) //是否有同步头
{
for(i=2;i<50;i++) //是否有错误位
{
if (RFb[i]==15) break;
}
if (i==50 && RFOK==0) //解码
{
i=0;
if (Decode(RFb[2],RFb[3])) i = B1000_0000;
if (Decode(RFb[4],RFb[5])) i |= B0100_0000;
if (Decode(RFb[6],RFb[8])) i |= B0010_0000;
if (Decode(RFb[8],RFb[9])) i |= B0001_0000;
if (Decode(RFb[10],RFb[11])) i |= B0000_1000;
if (Decode(RFb[12],RFb[13])) i |= B0000_0100;
if (Decode(RFb[14],RFb[15])) i |= B0000_0010;
if (Decode(RFb[16],RFb[17])) i |= B0000_0001;
RFCode[0]=i;
i=0;
if (Decode(RFb[18],RFb[19])) i = B1000_0000;
if (Decode(RFb[20],RFb[21])) i |= B0100_0000;
if (Decode(RFb[22],RFb[23])) i |= B0010_0000;
if (Decode(RFb[24],RFb[25])) i |= B0001_0000;
if (Decode(RFb[26],RFb[27])) i |= B0000_1000;
if (Decode(RFb[28],RFb[29])) i |= B0000_0100;
if (Decode(RFb[30],RFb[31])) i |= B0000_0010;
if (Decode(RFb[32],RFb[33])) i |= B0000_0001;
RFCode[1]=i;
i=0;
if (Decode(RFb[34],RFb[35])) i = B1000_0000;
if (Decode(RFb[36],RFb[37])) i |= B0100_0000;
if (Decode(RFb[38],RFb[39])) i |= B0010_0000;
if (Decode(RFb[40],RFb[41])) i |= B0001_0000;
if (Decode(RFb[42],RFb[43])) i |= B0000_1000;
if (Decode(RFb[44],RFb[45])) i |= B0000_0100;
if (Decode(RFb[46],RFb[47])) i |= B0000_0010;
if (Decode(RFb[48],RFb[49])) i |= B0000_0001;
RFCode[2]=i;
RFOK=1;
}
}
}
NextS=CurrS;
}
RFOK==1 时 RFCode里是遥控器编码
用完RFcode后 RFOK要清零
好理解,占用时间可控,就是有点费内存
遥控器是 PT2262 4.7M
一周热门 更多>