//该程序可以将遥控码通过1602液晶显示出来 //不要的朋友可以将其部分删除即可
  //版权所有比尔单片机  //更多资料详见Http://www.brmcu.com //著作:billxiong //E-mail:billxiong008@163.com //QQ:417152902
  #include <reg51.h> #include "1602lcd.h"
  #define c(x) (x*110592/120000) 
  sbit Ir_Pin=P3^2;         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 main(void) {  Init1602();  IntSys();  ShowMessage(1,1,13,"www.brmcu.com");  ShowMessage(0,2,5,"code:");  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(temp<c(8500) || temp>c(9500)) continue;//引导脉冲低电平9000    temp=Ir_Get_High();    if(temp<c(4000) || temp>c(5000)) continue;//引导脉冲高电平4500    for(i=0;i<4;i++) //4个字节    {     for(j=0;j<8;j++) //每个字节8位     {      temp=Ir_Get_Low();      if(temp<c(200) || temp>c(800)) goto restart;      temp=Ir_Get_High();      if(temp<c(200) || temp>c(2000)) goto restart;      Ir_Buf>>=1;      if(temp>c(1120)) Ir_Buf|=0x80;     }    }    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); }
 
 
   |