51单片机红外遥控格力空调程序.docx
- 文档编号:2224952
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:14
- 大小:27.01KB
51单片机红外遥控格力空调程序.docx
《51单片机红外遥控格力空调程序.docx》由会员分享,可在线阅读,更多相关《51单片机红外遥控格力空调程序.docx(14页珍藏版)》请在冰豆网上搜索。
51单片机红外遥控格力空调程序
51单片机红外遥控格力空调程序
51单片机红外遥控格力空调程序
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitkey1=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,
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;
{
khz_2(42);
//khz_3(21);
out=1;
delay560us();
}
voidsend1_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();
send1_a();
for(i=0;i<7;i++)
send0_a();
if(a)
send1_a();
else
send0_a();
if(b)
send1_a();
else
send0_a();
if(c)
send1_a();
else
send0_a();
if(d)
send1_a();
else
send0_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();
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();
else
send0_a();
if(f)
send1_a();
else
send0_a();
if(g)
send1_a();
else
send0_a();
if(h)
send0_a();
else
send1_a();
khz_2(42);
out=1;
delay(1000);
/*******************************************/
/****************开机************************/
}
voidopen(uchara,ucharb,ucharc,uchard)
{
uinti;
leadcode_a();
send1_a();
send0_a();
send0_a();
send1_a();
for(i=0;i<4;i++)
send0_a();
if(a)
send1_a();
else
send0_a();
if(b)
send1_a();
else
send0_a();
if(c)
send1_a();
else
send0_a();
if(d)
send1_a();
else
send0_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();
send1_a();
send0_a();
send1_a();
send0_a();
send0_a();
send1_a();
send0_a();
khz_2(42);
out=1;
delay(20);
}
voidopen1(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();
else
send0_a();
if(f)
send1_a();
else
send0_a();
if(g)
send1_a();
else
send0_a();
if(h)
send1_a();
else
send0_a();
khz_2(42);
out=1;
delay(1000);
}
voidkeyscan()
{
uchara,b,c,d,e,f,g,h;
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!
key1);
if(wd1[x]&0x08)
a=1;
else
a=0;
if(wd1[x]&0x04)
b=1;
else
b=0;
if(wd1[x]&0x02)
c=1;
else
c=0;
if(wd1[x]&0x01)
d=1;
else
d=0;
if(wd2[x]&0x08)
e=1;
else
e=0;
if(wd2[x]&0x04)
f=1;
else
f=0;
if(wd2[x]&0x02)
g=1;
else
g=0;
if(wd2[x]&0x01)
h=1;
else
h=0;
open(a,b,c,d);
open1(e,f,g,h);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!
key2);
if((wd1[x]&0x08))
a=1;
else
a=0;
if((wd1[x]&0x04))
b=1;
else
b=0;
if((wd1[x]&0x02))
c=1;
else
c=0;
if((wd1[x]&0x01))
d=1;
else
d=0;
if((wd2[x]&0x08))
e=1;
else
e=0;
if((wd2[x]&0x04))
f=1;
else
f=0;
if((wd2[x]&0x02))
g=1;
else
g=0;
if((wd2[x]&0x01))
h=1;
else
h=0;
close(a,b,c,d);
close1(e,f,g,h);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!
key1);
x++;
if((wd1[x]&0x08))
a=1;
else
a=0;
if((wd1[x]&0x04))
b=1;
else
b=0;
if((wd1[x]&0x02))
c=1;
else
c=0;
if((wd1[x]&0x01))
d=1;
else
d=0;
if((wd2[x]&0x08))
e=1;
else
e=0;
if((wd2[x]&0x04))
f=1;
else
f=0;
if((wd2[x]&0x02))
g=1;
else
g=0;
if((wd2[x]&0x01))
h=1;
else
h=0;
open(a,b,c,d);
open1(e,f,g,h);
}
}
if(key4==0)
{
delay(10);
if(key4==0)
{
while(!
key1);
x--;
if((wd1[x]&0x08))
a=1;
else
a=0;
if((wd1[x]&0x04))
b=1;
else
b=0;
if((wd1[x]&0x02))
c=1;
else
c=0;
if((wd1[x]&0x01))
d=1;
else
d=0;
if((wd2[x]&0x08))
e=1;
else
e=0;
if((wd2[x]&0x04))
f=1;
else
f=0;
if((wd2[x]&0x02))
g=1;
else
g=0;
if((wd2[x]&0x01))
h=1;
else
h=0;
open(a,b,c,d);
open1(e,f,g,h);
}
}
}
voidinit()
{
key1=1;
key2=1;
key3=1;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 51 单片机 红外 遥控 空调 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)