资源描述:
《51单片机红外遥控格力空调程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、51单片机红外遥控格力空调程序#include#defineucharunsignedchar#defineuintunsignedintsbitkey1=P3^4;//按键控制开机sbitkey2=P3^5;//按键控制关机sbitkey3=P3^6;//按键控制温度+sbitkey4=P3^7;//按键控制温度-sbitout=P1^5;//发送IO口ucharwd1[15]={0x00,0x08,0x04,0x0c,0x02,0x0a,0x06,0x0e,0x01,0x09,
2、0x05,0x0d,0x03,0x0b,0x07};ucharwd2[15]={0x0a,0x06,0x0e,0x01,0x09,0x05,0x0d,0x03,0x0b,0x07,0x0f,0x00,0x08,0x04,0x0c};ucharx=12;//开机28度/************晶振11.0592MHz**************/voiddelay(uintxms){uinti,j;for(i=xms;i>0;i--)//i=xms即延时约xms毫秒for(j=112;j>0;j--)
3、;}voiddelay560us(void)//560us延迟函数{uintj;for(j=63;j>0;j--);}voiddelay4500us(void)//4.5ms延迟函数{uintj;for(j=516;j>0;j--);}voidkhz_2(uintnum)//38KHZ脉冲占空比1:2{for(;num>0;num--){out=~out;}}voidsend0_a(void)//发送0{khz_2(42);//khz_3(21);out=1;delay560us();}voidse
4、nd1_a(void)//发送1{khz_2(42);out=1;delay560us();delay560us();delay560us();}voidleadcode_a(void)//发送引导码{khz_2(690);out=1;delay4500us();}/***************************关机****************************/voidclose(uchara,ucharb,ucharc,uchard){uinti;leadcode_a();se
5、nd1_a();for(i=0;i<7;i++)send0_a();if(a)send1_a();elsesend0_a();if(b)send1_a();elsesend0_a();if(c)send1_a();elsesend0_a();if(d)send1_a();elsesend0_a();send0_a();send0_a();send0_a();send0_a();for(i=0;i<5;i++)send0_a();send1_a();for(i=0;i<6;i++)send0_a();
6、send1_a();send0_a();send1_a();send0_a();send0_a();send1_a();send0_a();khz_2(42);out=1;delay(20);}voidclose1(uchare,ucharf,ucharg,ucharh){uchari;for(i=0;i<13;i++)send0_a();send1_a();send0_a();send0_a();for(i=0;i<12;i++)send0_a();if(e)send1_a();elsesend0
7、_a();if(f)send1_a();elsesend0_a();if(g)send1_a();elsesend0_a();if(h)send0_a();elsesend1_a();khz_2(42);out=1;delay(1000);/*******************************************//****************开机************************/}voidopen(uchara,ucharb,ucharc,uchard){uint
8、i;leadcode_a();send1_a();send0_a();send0_a();send1_a();for(i=0;i<4;i++)send0_a();if(a)send1_a();elsesend0_a();if(b)send1_a();elsesend0_a();if(c)send1_a();elsesend0_a();if(d)send1_a();elsesend0_a();send0_a();send0_a();send0_a();send0_a()