#include "STC89C51RC.H"
sbit DQ = P4^3;
sbit SPK = P1^0;
#include
#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;j<4;j++)//有效字节数设定
{
for(i=0;i<8;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);
}
上一篇:单片机在应力磁测装置中的应用
下一篇:红外遥控解码器设计
推荐阅读最新更新时间:2024-03-16 13:12