本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
//红外解码程序,下降沿触发
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar ma[8]={0,0,0,0,0,0,0,0};
//uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0X66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar shuzu[4]={0x00,0x00,0x00,0x00};
sbit irjk=P3^2;
void irdecode();
void delay140us(void) ;
void delay882us(void) ;
void shuxian();
void int0() interrupt 0
{
EX0=0;
while(irjk);
delay882us();
if(irjk==1)
{
EX0=1;
return;
}
else if(irjk==0)
{
EX0=0;
irdecode();
shuxian();
delay882us();
}
EX0=1;
}
void irdecode()
{
uchar i=0,j=0,d=0;
while(!irjk);
while(irjk);
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
while(!irjk);
while(irjk)
{
delay140us();
d++;
if(d>=30)
{
EX0=1;
return;
}
}
shuzu[i]>>=1;
if(d>8) shuzu[i]=shuzu[i]|0x80;
d=0;
}
}
EX0=1;
}
void shuxian()
{
ma[0]=shuzu[0]/16;
ma[1]=shuzu[0]%16;
ma[2]=shuzu[1]/16;
ma[3]=shuzu[1]%16;
ma[4]=shuzu[2]/16;
ma[5]=shuzu[2]%16;
ma[6]=shuzu[3]/16;
ma[7]=shuzu[3]%16;
}
void main()
{
EA=1;
EX0=1;
while(1)
{
uchar i=0;
for(i=0;i<8;i++)
{
P0=table[ma[i]];
P2=table1[i];
delay882us();
}
}
}
void delay882us(void) //误差 0us
{
unsigned char a,b;
for(b=3;b>0;b--)
for(a=145;a>0;a--);
}
void delay140us(void) //误差 0us
{
unsigned char a,b;
for(b=1;b>0;b--)
for(a=67;a>0;a--);
}
|