#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(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; } } 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; }
|
|
文章评论(0条评论)
登录后参与讨论