微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > C语言写的红外遥控解码程序

C语言写的红外遥控解码程序

时间:11-06 来源:互联网 点击:

#include "STC89C51RC.H"

sbit DQ = P4^3;
sbit SPK = P1^0;


#include absacc.h>

#define seg1 XBYTE[0xffec]
#define seg2 XBYTE[0xffed]
#define seg3 XBYTE[0xffee]
#define seg4 XBYTE[0xffef]
unsigned char IRMcode[4];

unsigned char code ledmap[]=//共阴LED数码管译码表
{
0x3f,0x06,0x5b,0x4f,0x66,//0,1,2,3,4,
0x6d,0x7d,0x07,0x7f,0x6f,//5,6,7,8,9,
0x77,0x7C,0x39,0x5E,0x79,//A,b,C,d,E,
0x71,//F,
};

void delay(unsigned int);

void main()
{
EA = 1;
EX2 = 1;
while(1)
{

if (IRMcode[2]==~IRMcode[3]){
seg1 = ~ledmap[IRMcode[2]/100];
seg2 = ~ledmap[IRMcode[2]/10%10];
seg3 = ~ledmap[IRMcode[2]%10];
seg4 = 0xff;//熄灭
}
}
}

void Sound(void)
{
SPK = 0;
delay(10000);
SPK = 1;
}

void IRMint(void) interrupt 6 using 2
{
unsigned char count;
unsigned int count1;
unsigned char i,j;
EA = 0;
count = 9;
while(--count)
{
delay(100);//440us
if(DQ){EA = 1;return;}
}
while(DQ==0);//通过引导码余下的低电平
//以上完成引导码4.5ms的低电平检测

count = 9;
count1 = 0;
while(--count)
{
delay(100);//440us
if(DQ==0){EA = 1;return;}
}
while(DQ==1)//通过引导码余下的高电平
{
if(count1++>1000) {
P1=0x55;EA = 1;return;}
}
//以上完成引导码4.5ms的高电平检测

count1 = 0;
for(j=0;j4;j++)//有效字节数设定
{
for(i=0;i8;i++)//字节bit数
{
while(DQ==0);//通过编码低电平
delay(200);//延时判断编码高电平维持长度
IRMcode[j]=1;
if(DQ)IRMcode[j]|=0x01;
while(DQ==1){//通过编码余下的高电平
if(count1++>2000){EA = 1;return;}
}
}
}

Sound();
EA = 1;
}

//通用延时函数
//22.1184,10 = 48.4 us (5us+43.4)
//22.1184,100 = 439 us (43.4*10+5)
//22.1184,1000 = 4345 us(43.4*100+5)
//22.1184,10000 = 43450 us(43.45*1000+5)
void delay(unsigned int t)
{
while(--t);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top