1、51单片机格力空调遥控器1.1151单片机格力空调遥控器2.2.#include 3.#include 4.#define uchar unsigned char5.#define uint unsigned int6.#define enTransmitt flag=17.#define disTransmitt flag=O8.sfr T2M0D = 0XC9;9.bit flag=0;10.sbit IR38k =P2A3; / 红外发射管11.sbit key1=P1A1;12.sbit key2=P1A3;13.sbit key3=P1A5;14.sbit key4=PM7;15.s
2、bit key5=P1A0;16.sbit key6=P1A4;17.uchar KeyScan();18.uint count=0,set_count=0;19.uchar fengliang_value=0;20.uchar key_value=0;21.uchar wendu_value=0;22.uchar mode_value=0;23.uchar switch_value=0;24.uchar zhuanye_value=0;25.uchar codeZhuanye5=0x39,0x04,0x00,0x50,0x02,0x79,0x04,0x00,0x50,0x02;/手动,自动转
3、页(20度,冷气)26.ucharcode fengliang5=0x28,0x08,0x00,0x50,0x02,0x19,0x08,0x00,0x50,0x02,29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.uchar code mode5=0x58,0x00,0x00,0x50,0x02,0x59,0x04,0x00,0x50,0x02,0x5a,0x04,0x00,0x50,0x02,0x5b,0x04,0x00,0x50,0x02; / 自动,冷气,除湿,送风/*uch
4、arcode on_or_off5= 0x40,0x00,0x00,0x50,0x02,0x48,0x00,0x00,0x50,0x02 ; */uchar code on_or_off5=0x39,0x08,0x00,0x50,0x02,0x31,0x08,0x00,0x50,0x02,0x59,0x08,0x00,0x50,0x02,0x51,0x08,0x00,0x50,0x02,0x79,0x08,0x00,0x50,0x02,0x71,0x08,0x00,0x50,0x02,; / 开机,关机uchar code wendu5=0x59,0x00,0x00,0x50,0x02,0x5
5、9,0x01,0x00,0x50,0x02,0x59,0x02,0x00,0x50,0x02,0x59,0x03,0x00,0x50,0x02,0x59,0x04,0x00,0x50,0x02,0x59,0x05,0x00,0x50,0x02,0x59,0x06,0x00,0x50,0x02,0x59,0x07,0x00,0x50,0x02,0x59,0x08,0x00,0x50,0x02,0x59,0x09,0x00,0x50,0x02,0x59,0x0a,0x00,0x50,0x02,0x59,0x0b,0x00,0x50,0x02,0x59,0x0c,0x00,0x50,0x02,0x5
6、9,0x0d,0x00,0x50,0x02,0x59,0x0e,0x00,0x50,0x02; / 温度值void send_precode(unsigned int s_cnt_1,unsigned int s_cnt_2);void send_8bit_code(uchar value);void send_4bit_code(uchar value);void send_final_code();void ir_out1() / 启动和关闭57.send_precode(180,90);58.send_8bit_code(on_or_offswitch_value0);59.send_8
7、bit_code(on_or_offswitch_value1);60.send_8bit_code(on_or_offswitch_value2);61.send_8bit_code(on_or_offswitch_value3);62.send_4bit_code(on_or_offswitch_value4);63.send_final_code();64./ key_value=0;65.switch_value+;66.if(switch_value=6) switch_value=0; 67.67.68.void ir_out2() /wendu-69.71.70.send_pre
8、code(180,90);71.send_8bit_code(wenduwendu_value0);72.send_8bit_code(wenduwendu_value1);73.send_8bit_code(wenduwendu_value2);74.send_8bit_code(wenduwendu_value3);75.send_4bit_code(wenduwendu_value4);76.send_final_code();77.wendu_value-;78.if(wendu_value=0) wendu_value=15;81.79.80.void ir_out3() wendu
9、+81.82.send_precode(180,90);83.send_8bit_code(wenduwendu_value0);84.send_8bit_code(wenduwendu_value1);85.send_8bit_code(wenduwendu_value2);86.send_8bit_code(wenduwendu_value3);87.send_4bit_code(wenduwendu_value4);88.send_final_code();89.wendu_value+;90.if(wendu_value=15) wendu_value=O;91.92.void ir_
10、out4()/mode choose93.94.send_precode(180,90);95.send_8bit_code(modemode_value0);96.send_8bit_code(modemode_value1);97.send_8bit_code(modemode_value2);98.send_8bit_code(modemode_value3);99.send_4bit_code(modemode_value4);100.send_final_code();101.mode_value+;102.if(mode_value=4)103. mode_value=0;107.
11、104.105.void ir_out5() / 转叶106.107.send_precode(180,90);108.send_8bit_code(zhuanyezhuanye_value0);109.send_8bit_code(zhuanyezhuanye_value1);110.send_8bit_code(zhuanyezhuanye_value2);111.send_8bit_code(zhuanyezhuanye_value3);112.send_4bit_code(zhuanyezhuanye_value4);113.send_final_code();114.zhuanye_
12、value+;115.if(zhuanye_value=2) zhuanye_value=0;void ir_out6() / 风量send_precode(180,90);send_8bit_code(fengliangfengliang_value0);send_8bit_code(fengliangfengliang_value1);send_8bit_code(fengliangfengliang_value2);send_8bit_code(fengliangfengliang_value3);send_4bit_code(fengliangfengliang_value4);sen
13、d_final_code();fengliang_value+;if(fengliang_value=3) fengliang_value=0;/=void delayms(unsigned char ms)unsigned char i;while(ms-)for(i=0;i8; /output frequency is 38KHz154.RCAP2L=(65536-11059/38/4)&0 xff;155.156.void TransmittPulse()157.158.enTransmitt;159./ ir=0;160.TR0=1;161.TR2=1;162.163.void Tra
14、nsmittLow()164.165./ir=1;166.TR0=1;167.disTransmitt;168.TR2=0;169.IR38k=1;170.171.void endTransmitt()172.173./ir=0;174.TR0=0;175.TR2=0;176.IR38k=1; /JIEZHI177.178.void send_logic0(unsigned int s_cnt_1,unsigned int s_cnt_2)179.180.set_count=s_cnt_1;/181.TransmittPulse();182.count =0;184.while(countse
15、t_count)185.;186.endTransmitt();187.ir=1;188.set_count=s_cnt_2;/11;189./ir=1;190.count =0;191.TransmittLow();192.192.while(countset_count)193.;194.endTransmitt();195.196.void send_logic1(unsigned int s_cnt_1,unsigned int s_cnt_2)197.198.set_count=s_cnt_1;/199.TransmittPulse();201.200.count =0;203.20
16、1.while(countset_count)202.;203.endTransmitt();204./ir=1;205./=206.set_count=s_cnt_2;/32;207./ir=1;208.count =0;212.209.TransmittLow();214.210.while(countset_count)216.217.218.219.220.221.222.223.224.225.226.227.228.229.230.231.232.233.234.235.236.237.238.239.240.241.242.243.244.245.246.247.endTrans
17、mitt();void send_precode(unsigned int s_cnt_1,unsigned int s_cnt_2)set_count =s_cnt_1;/180; 9MSTransmittPulse(); /start send pulsecount =0;while(countset_count);endTransmitt();set_count =s_cnt_2;/90;/4.5MScount =0;TransmittLow();while(countset_count);endTransmitt();void send_final_code()set_count=28
18、;/count =0;TransmittPulse();while(countset_count)endTransmitt();void send_8bit_code(uchar value)248.249.250.251.252.253.254.255.256.257.258.259.260.261.262.263.264.265.266.267.268.269.270.271.272.273.274.275.276.277.278.279.uchar i,temp;temp=value;for(i=0;i1;void send_4bit_code(uchar value)uchar i,t
19、emp;temp=value;for(i=0;i1;/=主函数=void main()TimerInit();while(1)key_value=KeyScan();switch(key_value)case 1:ir_out1();delayms(200);break; /280.281.282.283.284.285.286.287.288.289.290.291.292.293.294.295.296.297.298.299.300.301.302.303.304.305.306.307.308.309.310.311.case 2:ir_out2();delayms(200);brea
20、k; / 温度-case 3:ir_out3();delayms(200);break; / 温度 +.case 4:ir_out4();delayms(200);break; / 模式选择case 5:ir_out5();delayms(200);break; / 转叶设置case 6:ir_out6();delayms(200);break;default:ir=1;break;void timer0(void) interrupt 1TH0=0XfF;TL0=221; 50uscount+;if(flag)TR2=1; IR38k=0;else TR2=0;/IR38k=1;unsign
21、ed char KeyScan()/* 第一列扫描 */if(key1=0)delayms(20);if(key1=0)return 1;312.while(!key1);313.314.if(key2=0)315.316.delayms(20);317.if(key2=0)318.319.return 2;320.321.while(!key2);322.323.324.if(key3=0)325.326.delayms(20);327.if(key3=0)328.329.return 3;330.331.while(!key3);332.333.if(key4=0)334.335.delayms(20);336.if(key4=0)337.338.return 4;339.340.while(!key4);341.342.if(key5=0)344.delayms(20);345.if(key5=0)346.347.return 5;348.349.while(!key5);350.351.if(key6=0)352.353.delayms(20);354.if(key6=0)355.356.return 6;357.358.while(!key6);359.360.return 0 ;361.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1