文档详情

keil_c51红外遥控解码程序.pdf

发布:2016-01-29约8.48千字共7页下载文档
文本预览下载声明
keil c51 keil c51 kkeeiill cc5511红外遥控解码程序 本keil c51程序适用uPC1621/uPC1622及兼容的红外遥控器芯片,占用外部中断0和定时器1,以中断方式 解码,节省系统资源,以查询方式检测遥控信号是否有效. 解码思路: 红外线经一体化接受头解码放到后送到单片机的外部中断0,单片机设置外部中断下降沿触发,T0和T1 为16位定时器,T0在系统启动后定时5ms.T1在外部中断0启动后开始定时,初值为0,每次在INT0中断后先读 T1计数值,并重设初值为0,而且判断T1的计数值, 代码 //Fosc=11.0592MHz // states for and variables IR dataprocessing ; typedef enum{ IR_idle, IR_waitstart, IR_getaddr, IR_getaddrinv, IR_getdata, IR_getdatainv }_IRstate; _IRstate IRstate = IR_idle; unsigned char IRaddr=0xff; unsigned char _IRaddr=0xff; unsigned char IRdata=0xff; unsigned char _IRdata=0xff; unsigned char IR_repeat=0; unsigned char IR_ready=0; unsigned char IR_poweron=0; //bit ir_done=0; // timeconstants unsigned int IRtimer=0; // IR timeout //cpu初始化 void cpu_init(void) { TMOD=0X11;//T0 andT1 十六位定时 TH0=0xee; //fosc=11.0592M,timer=5ms TL0=0x00; TR0=1; // run timer0; TF0=0; ET0=1; // enable tmr 0 overflow interrupt IT0=1; // int0 edgesensitive EX0=1;// enable int0 EA=1; // global interupt enable } //T0中断 void tmrint() interrupt 1 { TH0=0xee; TL0=0x00; if(IRtimer) //IR 接收超时 --IRtimer; // else { IRstate=IR_idle; // IR_poweron=0; } } //Fosc=11.0592MHz #define msec_12p5 0x2d00 #define msec_15 0x3600 #define msec_9 0x2066 //#define msec_9 0x1066 #define msec_2p5 0x900 #define msec_0p9 0x33d #define msec_1p68 0x610 //void IRint() interrupt 0(void) //When the IR receive pin goes low and interrupt is generated // IR is collectedby starting timer2 inthe firstfalling edgeof the pin // thenon every other falling edge, the timervalue
显示全部
相似文档