求助红外遥控解码的C程序问题 求教高手
上面是数码管部分的电路图,4位共阴极数码管接P2,晶振用的是11.0592M的,从网上找来一个程序改了一下,但试了试好像有问题,想请教论坛高人程序要怎么修改,或者重新写的话,要怎么写
测试用的程序如下:
#include <reg51.h>
#define c(x) (x*110592)
sbit Ir_Pin=P3^3;
unsigned char code Led_Tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code Led_Sel[]={0xE,0xD,0xB,0x7};
unsigned char Led_Buf[4];
char Led_Index;
unsigned char Ir_Buf[4];
timer0() interrupt 1 using 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
P0=0xff;
P2=Led_Sel[Led_Index];
P0=Led_Tab[Led_Buf[Led_Index]];
if(++Led_Index>3) Led_Index=0;
}
unsigned int Ir_Get_Low()
{
TL1=0;
TH1=0;
TR1=1;
while(!Ir_Pin && (TH1&0x80)==0);
TR1=0;
return TH1*256+TL1;
}
unsigned int Ir_Get_High()
{
TL1=0;
TH1=0;
TR1=1;
while(Ir_Pin && (TH1&0x80)==0);
TR1=0;
return TH1*256+TL1;
}
main()
{
unsigned int temp;
char i,j;
Led_Index=1;
TMOD=0x11;
TL0=(65536-1000)%256;
TH0=(65536-1000)/256;
EA=1;
ET0=1;
TR0=1;
Led_Buf[0]=0;
Led_Buf[1]=0;
Led_Buf[2]=0;
Led_Buf[3]=0;
do{
restart:
while(Ir_Pin);
temp=Ir_Get_Low();
if(temp<c(8500) || temp>c(9500)) continue;
temp=Ir_Get_High();
if(temp<c(4000) || temp>c(5000)) continue;
for(i=0;i<4;i++)
for(j=0;j<8;j++)
{
temp=Ir_Get_Low();
if(temp<c(200) || temp>c(800)) goto restart;
temp=Ir_Get_High();
if(temp<c(200) || temp>c(2000)) goto restart;
Ir_Buf>>=1;
if(temp>c(1120)) Ir_Buf|=0x80;
}
Led_Buf[0]=Ir_Buf[2]&0xf;
Led_Buf[1]=(Ir_Buf[2]/16)&0xf;
Led_Buf[2]=Ir_Buf[3]&0xf;
Led_Buf[3]=(Ir_Buf[3]/16)&0xf;
}while(1);
}
还请各位高手给些指点!
谢谢分享。