解码思路:
红外线经一体化接受头解码放到后送到单片机的外部中断0,单片机设置外部中断下降沿触发,T0和T1为16位定时器,T0在系统启动后定时5ms.T1在外部中断0启动后开始定时,初值为0,每次在INT0中断后先读T1计数值,并重设初值为0,而且判断T1的计数值,
- //Fosc=11.0592MHz
- //statesforandvariablesIRdataprocessing
- typedefenum{
- IR_idle,
- IR_waitstart,
- IR_getaddr,
- IR_getaddrinv,
- IR_getdata,
- IR_getdatainv
- }_IRstate
- _IRstateIRstate=IR_idle
- unsignedcharIRaddr=0xff
- unsignedchar_IRaddr=0xff
- unsignedcharIRdata=0xff
- unsignedchar_IRdata=0xff
- unsignedcharIR_repeat=0
- unsignedcharIR_ready=0
- unsignedcharIR_poweron=0
- //bitir_done=0
- //timeconstants
- unsignedintIRtimer=0//IRtimeout
- //cpu初始化
- voidcpu_init(void)
- {
- TMOD=0X11//T0andT1十六位定时
- TH0=0xee//fosc=11.0592M,timer=5ms
- TL0=0x00
- TR0=1//runtimer0
- TF0=0
- ET0=1//enabletmr0overflowinterrupt
- IT0=1//int0edgesensitive
- EX0=1//enable"int0"
- EA=1//globalinteruptenable
- }
- //T0中断
- voidtmrint()interrupt1
- {
- TH0=0xee
- TL0=0x00
- if(IRtimer)//IR接收超时
- --IRtimer//
- else
- {
- IRstate=IR_idle
- //IR_poweron=0
- }
- }
- //Fosc=11.0592MHz
- #definemsec_12p50x2d00
- #definemsec_150x3600
- #definemsec_90x2066
- //#definemsec_90x1066
- #definemsec_2p50x900
- #definemsec_0p90x33d
- #definemsec_1p680x610
- //voidIRint()interrupt0(void)
- //WhentheIRreceivepingoeslowandinterruptisgenerated
- //IRiscollectedbystartingtimer2inthefirstfallingedgeofthepin
- //thenoneveryotherfallingedge,thetimervalueissavedandthetimerrestarted.
- //thecapturedtimeisthenusedtogettheIRdata
- //a"startofdata"is13.5Msec,a"1"is2.25Msec,a"0"is1.12msecanda"repeat"is11.25msec.
- //thecounterincrementsat1.085Usec
- //Iallowafairlylargetolerancetotimejitterbuttherearenofalsetriggersseen.
- voidIRint()interrupt0
- {
- staticunsignedcharbits
- unsignedshorttime
- switch(IRstate)
- {
- caseIR_idle:
- TL1=0
- TH1=0
- TR1=1
- IRstate=IR_waitstart
- IRtimer=26
- break
- caseIR_waitstart://P2_4=!P2_4
- TR1=0
- time=TH1
- time=(time<<8)+TL1
- TL1=0
- TH1=0
- TR1=1
- if((time>msec_12p5)&&(time
- {
- IRaddr=0
- _IRaddr=0
- IRdata=0
- _IRdata=0
- bits=1
- IRstate=IR_getaddr
- }
- elseif((time>msec_9)&&(time
- {
- IR_repeat=2
- IRstate=IR_idle
- }
- else
- {//toshort,baddatajustgotoidle
- IRstate=IR_idle
- }
- break
- caseIR_getaddr://P2_4=!P2_4
- TR1=0
- time=TH1
- time=(time<<8)+TL1
- TL1=0
- TH1=0
- TR1=1
- if((time>msec_2p5)||(time
2.5msecorshorterthan.9Msecbaddata,gotoidle - {
- IRstate=IR_idle
- break
- }
- if(time>msec_1p68)//greaterthan1.68Msecisa1
- {
- IRaddr|=bits
- }
- bits=bits<<1
- if(!bits)
- {
- IRstate=IR_getaddrinv
- bits=1
- }
- break
- caseIR_getaddrinv://P2_4=!P2_4
- TR1=0
- time=TH1
- time=(time<<8)+TL1
- TL1=0
- TH1=0
- TR1=1
- if((time>msec_2p5)||(time
2.5msecorshorterthan.9Msecbaddata,gotoidle - {
- IRstate=IR_idle
- break
- }
- if(time>msec_1p68)//greaterthan1.68Msecisa1
- {
- _IRaddr|=bits
- }
- bits=bits<<1
- if(!bits)
- {
- IRstate=IR_getdata
- bits=1
- }
- break
- caseIR_getdata:
- TR1=0
- time=TH1
- time=(time<<8)+TL1
- TL1=0
- TH1=0
- TR1=1
- if((time>msec_2p5)||(time
2.5msecorshorterthan.9Msecbaddata,gotoidle - {
- IRstate=IR_idle
- break
- }
- if(time>msec_1p68)//greaterthan1.68Msecisa1
- {
- IRdata|=bits
- }
- bits=bits<<1
- if(!bits)
- {
- IRstate=IR_getdatainv
- bits=1
- }
- break
- caseIR_getdatainv:
- TR1=0
- time=TH1
- time=(time<<8)+TL1
- TL1=0
- TH1=0
- TR1=1
- if((time>msec_2p5)||(time
2.5msecorshorterthan.9Msecbaddata,gotoidle - {
- IRstate=IR_idle
- break
- }
- if(time>msec_1p68)//greaterthan1.68Msecisa1
- {
- _IRdata|=bits
- }
- bits=bits<<1
- if(!bits)//wehaveitall,nowwemakesureitisaNECcodefromtheCHSIRtransmitter
- {//makesureaddress,~addressarecorrect,da
ta,~dataarecorrectandaddressis0. - IR_ready=((IRaddr^_IRaddr)==0xff)&&((IRdata^_IRdata)==0xff)&&(IRaddr==0)
- if(IR_ready)
- {
- IRstate=IR_idle
- }
- }
- break
- default:
- IRstate=IR_idle
- break
- }
- }
- voidmain(void)
- {
- cpu_init()
- while(1)
- {
- if(IR_ready)
- {
- IR_ready=0
- switch(IRdata)
- {
- case0x45://1
- //yourcode
- break
- case0x44://3
- //yourcode
- break
- case0x43://4
- //yourcode
- break
- case0x08://prev
- //yourcode
- break
- case0x5a://next
- //yourcode
- break
- default:
- break
- &n bsp}
- }
- }
- }
上一篇:超低功耗低测量频率数据采集记录系统的设计
下一篇:89C51引脚图及功能
推荐阅读最新更新时间:2024-03-16 15:16
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- 微灵医疗李骁健:脑机接口技术正在开启意识与AI融合的新纪元
- USB Type-C® 和 USB Power Delivery:专为扩展功率范围和电池供电型系统而设计
- 景昱医疗耿东:脑机接口DBS治疗技术已实现国产替代
- 首都医科大学王长明:针对癫痫的数字疗法已进入使用阶段
- 非常见问题解答第223期:如何在没有软启动方程的情况下测量和确定软启动时序?
- 兆易创新GD25/55全系列车规级SPI NOR Flash荣获ISO 26262 ASIL D功能安全认证证书
- 新型IsoVu™ 隔离电流探头:为电流测量带来全新维度
- 英飞凌推出简化电机控制开发的ModusToolbox™电机套件
- 意法半导体IO-Link执行器电路板为工业监控和设备厂商带来一站式参考设计
- Melexis采用无磁芯技术缩小电流感测装置尺寸