电子大神的日记本,供应链专家的功夫茶盘,在这里记录、分享与共鸣。

登录以开始

红外遥控解码 的代码

红外遥控解码

           日期: 2008-06-22             发表人: 比尔盖茨熊         文章来源:本站原创,如有转载请注明出处

include <reg51.h>

include <intrins.h>

include "1602lcd.h"

define c(x) (x*110592/120000)

sbit Ir_Pin=P3^2;
sbit BZO="P0"^4;
unsigned char Ir_Buf[4]; //Save decode result

code const uchar NumCode[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

unsigned int Ir_Get_Low(void);
unsigned int Ir_Get_High(void);
void IR_Process(void);
void IntSys(void);
void BzOut(void);

void main(void)
{
Init1602();
IntSys();
ShowMessage(1,1,13,"www.brmcu.com");
ShowMessage(0,2,5,"code:");
BzOut();
while(1)
{
IR_Process();
}
}

void IntSys(void)
{
TMOD=0x21;
EA=1;
ET0=1;
TR0=0;
}

unsigned int Ir_Get_Low(void)
{
TL0=0;
TH0=0;
TR0=1;
while(!Ir_Pin && (TH0&0x80)==0);
TR0=0;
return TH0*256+TL0;
}

unsigned int Ir_Get_High(void)
{
TL0=0;
TH0=0;
TR0=1;
while(Ir_Pin && (TH0&0x80)==0);
TR0=0;
return TH0*256+TL0;
}

void IR_Process(void)
{
unsigned int temp;
char i,j;
do{
restart:
while(Ir_Pin);
temp=Ir_Get_Low();
if(tempc(9500)) continue;//引导脉冲低电平9000
temp=Ir_Get_High();
if(tempc(5000)) continue;//引导脉冲高电平4500
for(i=0;i<4;i++) //4个字节
{
for(j=0;j<8;j++) //每个字节8位
{
temp=Ir_Get_Low();
if(tempc(800)) goto restart;
temp=Ir_Get_High();
if(tempc(2000)) goto restart;
Ir_Buf[i]>>=1;
if(temp>c(1120)) Ir_Buf[i]|=0x80;
}
}
BzOut();
ShowMessage(5,2,1,&NumCode[Ir_Buf[0]>>4]);
ShowMessage(6,2,1,&NumCode[Ir_Buf[0]&0xF]);
ShowMessage(8,2,1,&NumCode[Ir_Buf[1]>>4]);
ShowMessage(9,2,1,&NumCode[Ir_Buf[1]&0xF]);
ShowMessage(11,2,1,&NumCode[Ir_Buf[2]>>4]);
ShowMessage(12,2,1,&NumCode[Ir_Buf[2]&0xF]);
ShowMessage(14,2,1,&NumCode[Ir_Buf[3]>>4]);
ShowMessage(15,2,1,&NumCode[Ir_Buf[3]&0xF]);
}while(1);
}

void BzOut(void)
{
uchar i,j;
for(i=0;i<100;i++)
{
BZO=!BZO;
for(j=0;j<40;j++)
{nop();nop();}
}
BZO=1;
}

博主
dzebmvlz1910
dzebmvlz1910's Blog
dzebmvlz1910
点击跳转