资源描述:
《c语言写的红外遥控解码程序.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、c语言写的红外遥控解码程序#include"STC89C51RC.H"sbitDQ=P4^3;sbitSPK=P1^0;#include#defineseg1XBYTE[0xffec]#defineseg2XBYTE[0xffed]#defineseg3XBYTE[0xffee]#defineseg4XBYTE[0xffef]unsignedcharIRMcode[4];unsignedcharcodeledmap[]= //共阴LED数码管译码表{ 0x3f,0x06,0x5b,0x4f,0x66, //0,1,2,3,4, 0x6d
2、,0x7d,0x07,0x7f,0x6f, //5,6,7,8,9, 0x77,0x7C,0x39,0x5E,0x79, //A,b,C,d,E, 0x71, //F,};voiddelay(unsignedint);voidmain(){ EA=1; EX2=1; while(1) { if(IRMcode[2]==~IRMcode[3]){ seg1=~ledmap[IRMcode[2]/100]; seg2=~ledmap[IRMcode[2]/10%10]; seg3=~ledmap[IRMcode[2]%10
3、]; seg4=0xff;//熄灭 } }}voidSound(void){ SPK=0; delay(10000); SPK=1;}voidIRMint(void)interrupt6 using2{ unsignedcharcount; unsignedintcount1; unsignedchari,j; EA=0; count=9; while(--count) { delay(100);//440us if(DQ){EA=1;return;} } while(DQ==0);//通过引导码余下的低电平 //以上完成引导码4.5ms的低
4、电平检测 count=9; count1=0; while(--count) { delay(100);//440us if(DQ==0){EA=1;return;} } while(DQ==1)//通过引导码余下的高电平 { if(count1++>1000){ P1=0x55;EA=1;return;} } //以上完成引导码4.5ms的高电平检测 count1=0; for(j=0;j<4;j++)//有效字节数设定 { for(i=0;i<8;i++)//字节bit数 { while(DQ==0);//通过编码低电平 del
5、ay(200);//延时判断编码高电平维持长度 IRMcode[j]<<=1; if(DQ)IRMcode[j]
6、=0x01; while(DQ==1){//通过编码余下的高电平 if(count1++>2000){EA=1;return;} } } } Sound(); EA=1;}//通用延时函数//22.1184,10=48.4us(5us+43.4)//22.1184,100=439us(43.4*10+5)//22.1184,1000=4345us(43.4*100+5)//22.1184,10000=43450u
7、s(43.45*1000+5)voiddelay(unsignedintt){ while(--t); }