本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
这是我自己写的红外接收解码,但是解码不成功,解出来的不是红外码,下面是程序,小弟在这里谢过了
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit BEEP = P1^5;
sbit irin=P3^3;
uchar tap[33];
uchar tep[4];
uchar time0,kaishi,irok,num;
uchar code table[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uchar i)
{
uchar x,y;
for(x=i;x>0;x--)
for(y=200;y>0;y--);
}
void timeinit()
{
TMOD = 0x20;
TH1=0X00;
TL1=0X00;
// ET1=1;
EA=1;
// TR1=1;
}
void int1init()
{
irin=1;
IT1=1;
EX1=1;
EA=1;
}
void beep()
{
unsigned char i;
for (i=0;i<100;i++)
{
delay(255);
BEEP=!BEEP; //BEEP取反
}
//BEEP=1; //关闭蜂鸣器
}
void jiema()
{
uchar i,j,k,l;
l=1;
if(irok==1)
{
EX1=0;
for(i=0;i<4;i++)
{
for(j=8;j>0;j--)
{
k=k>>1;
if(tap[l]>6)
{
k=k|0x80;
}
l++;
}
tep[i]=k;
}
}
kaishi=0;
EX1=1;
l=1;
}
void xianshi()
{
P2=0x00;
P0=table[tep[0]/16];
delay(5);
P2=0x01;
P0=table[tep[0]%16];
delay(5);
P2=0x02;
P0=table[tep[1]/16];
delay(5);
P2=0x03;
P0=table[tep[1]%16];
delay(5);
P2=0x04;
P0=table[tep[2]/16];
delay(5);
P2=0x05;
P0=table[tep[2]%16];
delay(5);
P2=0x06;
P0=table[tep[3]/16];
delay(5);
P2=0x07;
P0=table[tep[3]%16];
delay(5);
}
void main()
{
timeinit();
int1init();
while(1)
{
xianshi();
jiema();
}
}
void time() interrupt 3
{
TH1=0X00;
TL1=0X00;
time0++;
}
void ir() interrupt 2
{
TR1=1;
// ET0=1;
if(kaishi==1)
{
if(time0>=40)
{
num=0;
time0=0;
}
tap[num]=time0;
time0=0;
num++;
if(num==33)
{
num=0;
TR1=0;
irok=1;
}
}
else
{
kaishi=1;
time0=0;
}
} |