#include<reg51.h>
#define wei P0
#define duan P1
sbit ird=P3^2;
signed int
timelong;
unsigned int z;
unsigned char quke,b,k,yonghuma_l,yonghuma_h,anjianma_z,anjianma_f;
unsigned char code zifuku[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void delay(unsigned int z){
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);}
void main(){
IT0=1;
EX0=1;
EA=1;
TMOD=1;
TH0=0;
TL0=0;
wei=0x00;
duan=0xff;
quke=0x00;
b=0;
while(1){
while(ird); //判断接收头是否有输入
while((timelong-2000)&&(2500-timelong)<1); //检测是否引导码到来
for(k=32;k>0;k--){
while(ird==0); // 让循环跟中断同步进行 并且防止
while(ird==1); // 引导码的timelong代入
while(ird==0); // 下面的for循环
quke=quke>>1;
if((timelong-2000)&&(2500-timelong)>0){ //解码1
quke=quke|0x80;
}
if((timelong-850)&&(1375-timelong)>0) { //解码0
quke=quke|0x00;
}
if(k==24){yonghuma_l=quke;}
if(k==16){yonghuma_h=quke;}
if(k==8){anjianma_z=quke;}
if(k==0){anjianma_f=quke;}
}
while((timelong-20000)<0){ //如果没有引导码 就一直显示解码值
wei=0x80;
duan=zifuku[anjianma_z/16];
delay(1);
duan=0xff;
wei=0x40;
duan=zifuku[anjianma_z%16];
delay(1);
duan=0xff;
}
}
}
void zd ()interrupt 0{
unsigned char a;
if(a>0){
TR0=0;
timelong=TH0*256+TL0;
TH0=0;
TL0=0;
TR0=1;
}
else{TR0=1;
a++;
}
}
NEC 红外解码
一周热门 更多>