|
紅外遙控智能電風(fēng)扇實(shí)物圖紙程序共享
制作出來(lái)的實(shí)物圖如下:
TIM截圖20190519124806.png (1.13 MB, 下載次數(shù): 45)
下載附件
2019-5-19 12:49 上傳
電路原理圖如下:
TIM截圖20190519124748.png (73.72 KB, 下載次數(shù): 45)
下載附件
2019-5-19 12:49 上傳
單片機(jī)源程序如下:
- //宏定義
- #define uchar unsigned char
- #define uint unsigned int
- //頭函數(shù)
- #include <stc12c5a60s2.h>
- #include <AT24C02.h>
- //溫度傳感器標(biāo)志變量
- uchar flag=1;
- #include <DS18B20.h>
- #include <Ds1302.h>
- #include <Lcd.h>
- #include <Data.h>
- //熱釋電傳感器
- sbit RR=P3^4;
- //是否有人狀態(tài) 鬧鈴狀態(tài) 風(fēng)速狀態(tài)
- uchar R=1,L=1,FS=0;
- //讀取溫度
- uint TT=0;
- //開(kāi)機(jī)時(shí)分秒
- uchar OS=0,OF=0,OM=0;
- //關(guān)機(jī)時(shí)分秒
- uchar ClS=0,ClF=0,ClM=0;
- //模式
- uchar Mode=0;
- //調(diào)整位光標(biāo)
- uchar Modes=0;
- //暫時(shí)保存狀態(tài)
- uchar Modetemp=0;
- //時(shí)間計(jì)算
- #define Imax 14000 //此處為晶振為11.0592時(shí)的取值,
- #define Imin 8000 //如用其它頻率的晶振時(shí),
- #define Inum1 145 //要改變相應(yīng)的取值。
- #define Inum2 700
- #define Inum3 3000
- //解碼變量
- unsigned char Im[4]={0x00,0x00,0x00,0x00};
- //全局變量
- uchar f;
- unsigned long m,Tc;
- uchar IrOK;
- //延時(shí)
- void delayHW(uchar i);
- //PWM脈沖占空比調(diào)節(jié)
- void pwm_set(uchar a);
- //PWM初始化
- void initpwm();
- //外部中斷定時(shí)器0寄存器初始化
- void Init();
- //主函數(shù)
- void main()
- {
- //PWM脈沖
- initpwm();
- //外部中斷定時(shí)器0寄存器初始化
- Init();
- //屏幕初始化
- Init_LCD();
- //時(shí)鐘初始化
- Ds1302_Init();
- //EEPROM初始化
- initeeprom();
- //寫(xiě)
- /* write_add(0x00,L);
- write_add(0x01,OS);
- write_add(0x02,OF);
- write_add(0x03,OM);
- write_add(0x04,ClS);
- write_add(0x05,ClF);
- write_add(0x06,ClM);*/
- //讀
- L=read_add(0x00);
- OS=read_add(0x01);
- OF=read_add(0x02);
- OM=read_add(0x03);
- ClS=read_add(0x04);
- ClF=read_add(0x05);
- ClM=read_add(0x06);
- //發(fā)送溫度轉(zhuǎn)換
- tmpchange();
- //發(fā)送溫度轉(zhuǎn)換
- tmpchange();
- //讀取溫度
- TT=tmp();
- //初始化
- pwm_set(0xff);
- //讀取時(shí)間
- while(1)
- {
- //發(fā)送溫度轉(zhuǎn)換
- tmpchange();
- //讀取溫度
- TT=tmp();
- //讀取人員狀況
- //有人
- if(RR==1)
- {
- R=0;
- }
- //無(wú)人
- else
- {
- R=1;
- }
- //模式處理
- //自動(dòng)開(kāi)機(jī)
- if(Mode==2)
- {
- //有人開(kāi)啟風(fēng)扇
- if(R==1)
- {
- //溫度調(diào)整0檔關(guān)閉
- if(TT<=300)
- {
- pwm_set(0xff);
- FS=0;
- }
- //1檔
- else if(TT>300&&TT<=320)
- {
- pwm_set(50);
- FS=1;
- }
- //2檔
- else if(TT>320&&TT<=340)
- {
- pwm_set(10);
- FS=2;
- }
- //3檔
- else if(TT>340)
- {
- pwm_set(0);
- FS=3;
- }
- }
- //無(wú)人關(guān)閉風(fēng)扇
- else
- {
- pwm_set(0xff);
- FS=0;
- }
- }
- //讀取時(shí)間
- Ds1302_Read_Time();
- //LCD實(shí)時(shí)刷新
- LCD_Write_Time(time_buf1,TT,R,L,FS,Mode);
- //延時(shí)不然芯片會(huì)發(fā)熱
- delay_LCD(50);
- //如果開(kāi)啟定時(shí) 定時(shí)后轉(zhuǎn)為自動(dòng)模式
- if(L==1&&time_buf1[4]==OS&&time_buf1[5]==OF&&time_buf1[6]==OM)
- {
- Mode=2;
- }
- else if(L==3&&time_buf1[0]==OS&&time_buf1[5]==OF&&time_buf1[6]==OM)
- {
- Mode=2;
- }
- else if(L==2&&time_buf1[4]==ClS&&time_buf1[5]==ClF&&time_buf1[6]==ClM)
- {
- Mode=0;
- pwm_set(0xff);
- }
- else if(L==3&&time_buf1[4]==ClS&&time_buf1[5]==ClF&&time_buf1[6]==ClM)
- {
- Mode=0;
- pwm_set(0xff);
- }
- //紅外命令處理
- if(IrOK==1)
- {
- //標(biāo)志變量清空
- IrOK=0;
- //開(kāi)機(jī)關(guān)機(jī)按鍵
- if(Im[2]==0x45)
- {
- //關(guān)機(jī)變開(kāi)機(jī)
- if(Mode==0)
- {
- Mode=1;
- }
- //開(kāi)機(jī)變關(guān)機(jī) 或自動(dòng)變關(guān)機(jī)
- else if(Mode==1||Mode==2)
- {
- Mode=0;
- pwm_set(0xff);
- }
- }
- //自動(dòng)模式/手動(dòng)模式切換
- else if(Im[2]==0x15)
- {
- //手動(dòng)切自動(dòng)
- if(Mode==1)
- {
- Mode=2;
- }
- //自動(dòng)切手動(dòng)
- else if(Mode==2)
- {
- Mode=1;
- }
- }
- //風(fēng)速 手動(dòng)調(diào)節(jié)0檔
- else if(Im[2]==0x16)
- {
- //手動(dòng)模式
- if(Mode==1)
- {
- pwm_set(0xff);
- }
- }
- //風(fēng)速 手動(dòng)調(diào)節(jié)1檔
- else if(Im[2]==0x0c)
- {
- //手動(dòng)模式
- if(Mode==1)
- {
- pwm_set(0x50);
- }
- }
- //風(fēng)速 手動(dòng)調(diào)節(jié)2檔
- else if(Im[2]==0x18)
- {
- //手動(dòng)模式
- if(Mode==1)
- {
- pwm_set(0x10);
- }
- }
- //風(fēng)速 手動(dòng)調(diào)節(jié)3檔
- else if(Im[2]==0x5e)
- {
- //手動(dòng)模式
- if(Mode==1)
- {
- pwm_set(0x00);
- }
- }
- //是否開(kāi)啟鬧鈴
- else if(Im[2]==0x0d)
- {
- L++;
- //開(kāi)啟到關(guān)閉
- if(L==4)
- {
- L=0;
- }
- //////////////////////保存
- //寫(xiě)
- delay_LCD(20);
- write_add(0x00,L);
- }
- //調(diào)整開(kāi)機(jī)時(shí)間
- else if(Im[2]==0x44)
- {
- //屏幕初始化
- Init_LCD_ONTime();
- //時(shí)間調(diào)整
- Modetemp=Mode;
- Mode=4;
- Modes=0;
- //時(shí)間刷新
- LCD_time(OS,OF,OM);
- //開(kāi)啟光標(biāo)
- write_com(0x0F);
- write_com(0x06);
- write_com(0x80+40+11);
-
- //設(shè)置好跳出
- while(Mode==4)
- {
- //紅外命令處理
- if(IrOK==1)
- {
- //標(biāo)志變量清空
- IrOK=0;
- //退出并保存
- if(Im[2]==0x44)
- {
- Mode=Modetemp;
- //保存
- //寫(xiě)
- delay_LCD(20);
- write_add(0x01,OS);
- delay_LCD(20);
- write_add(0x02,OF);
- delay_LCD(20);
- write_add(0x03,OM);
- }
- //左移光標(biāo)
- else if(Im[2]==0x07)
- {
- Modes++;
- if(Modes==3)
- Modes=0;
- }
- //右移光標(biāo)
- else if(Im[2]==0x09)
- {
- Modes--;
- if(Modes==0xff)
- Modes=2;
- }
- //光標(biāo)值+
- else if(Im[2]==0x40)
- {
- //秒++
- if(Modes==0)
- {
- OM++;
- if(OM==60)
- {
- OM=0;
- }
- }
- //分++
- else if(Modes==1)
- {
- OF++;
- if(OF==60)
- {
- OF=0;
- }
- }
- //時(shí)++
- else if(Modes==2)
- {
- OS++;
- if(OS==24)
- {
- OS=0;
- }
- }
- }
- //光標(biāo)值-
- else if(Im[2]==0x19)
- {
- //秒--
- if(Modes==0)
- {
- OM--;
- if(OM==0xff)
- {
- OM=59;
- }
- }
- //分--
- else if(Modes==1)
- {
- OF--;
- if(OF==0xff)
- {
- OF=59;
- }
- }
- //時(shí)--
- else if(Modes==2)
- {
- OS--;
- if(OS==0xff)
- {
- OS=23;
- }
- }
- }
- //時(shí)間刷新
- LCD_time(OS,OF,OM);
- //光標(biāo)設(shè)置
- switch(Modes)
- {
- case 0:
- {
- write_com(0x80+0x40+11);
- break;
- }
- case 1:
- {
- write_com(0x80+0x40+8);
- break;
- }
- case 2:
- {
- write_com(0x80+0x40+5);
- break;
- }
- }//Switch
- }
- }//while end
-
- //屏幕初始化
- Init_LCD();
- }
- //調(diào)整關(guān)機(jī)時(shí)間
- else if(Im[2]==0x43)
- {
- //屏幕初始化
- Init_LCD_OFFTime();
- //時(shí)間調(diào)整
- Modetemp=Mode;
- Mode=5;
- Modes=0;
- //時(shí)間刷新
- LCD_time(ClS,ClF,ClM);
- //開(kāi)啟光標(biāo)
- write_com(0x0F);
- write_com(0x06);
- write_com(0x80+40+11);
-
- //設(shè)置好跳出
- while(Mode==5)
- {
- //紅外命令處理
- if(IrOK==1)
- {
- //標(biāo)志變量清空
- IrOK=0;
- //退出并保存
- if(Im[2]==0x43)
- {
- Mode=Modetemp;
- //保存
- //寫(xiě)
- delay_LCD(20);
- write_add(0x04,ClS);
- delay_LCD(20);
- write_add(0x05,ClF);
- delay_LCD(20);
- write_add(0x06,ClM);
- }
- //左移光標(biāo)
- else if(Im[2]==0x07)
- {
- Modes++;
- if(Modes==3)
- Modes=0;
- }
- //右移光標(biāo)
- else if(Im[2]==0x09)
- {
- Modes--;
- if(Modes==0xff)
- Modes=2;
- }
- //光標(biāo)值+
- else if(Im[2]==0x40)
- {
- //秒++
- if(Modes==0)
- {
- ClM++;
- if(ClM==60)
- {
- ClM=0;
- }
- }
- //分++
- else if(Modes==1)
- {
- ClF++;
- if(ClF==60)
- {
- ClF=0;
- }
- }
- //時(shí)++
- else if(Modes==2)
- {
- ClS++;
- if(ClS==24)
- {
- ClS=0;
- }
- }
- }
- //光標(biāo)值-
- else if(Im[2]==0x19)
- {
- //秒--
- if(Modes==0)
- {
- ClM--;
- if(ClM==0xff)
- {
- ClM=59;
- }
- }
- //分--
- else if(Modes==1)
- {
- ClF--;
- if(ClF==0xff)
- {
- ClF=59;
- }
- }
- //時(shí)--
- else if(Modes==2)
- {
- ClS--;
- if(ClS==0xff)
- {
- ClS=23;
- }
- }
- }
- //時(shí)間刷新
- LCD_time(ClS,ClF,ClM);
- //光標(biāo)設(shè)置
- switch(Modes)
- {
- case 0:
- {
- write_com(0x80+40+11);
- break;
- }
- case 1:
- {
- write_com(0x80+40+8);
- break;
- }
- case 2:
- {
- write_com(0x80+40+5);
- break;
- }
- }//Switch
- }
- }//while end
-
- //屏幕初始化
- Init_LCD();
- }
- //時(shí)間調(diào)整
- else if(Im[2]==0x47)
- {
- //屏幕初始化
- Init_LCD();
- //讀取時(shí)間
- Ds1302_Read_Time();
- //LCD實(shí)時(shí)刷新
- LCD_Write_Time(time_buf1,TT,R,L,FS,Mode);
- //延時(shí)不然芯片會(huì)發(fā)熱
- delay_LCD(50);
- //時(shí)間調(diào)整
- Modetemp=Mode;
- Mode=3;
- Modes=0;
- //開(kāi)啟光標(biāo)
- write_com(0x0F);
- write_com(0x06);
- write_com(0x80+40+7);
- //進(jìn)入調(diào)整
- while(Mode==3)
- {
- //紅外命令處理
- if(IrOK==1)
- {
- //標(biāo)志變量清空
- IrOK=0;
- //跳出調(diào)整
- if(Im[2]==0x47)
- {
- Mode=Modetemp;
- }
- //左移光標(biāo)
- else if(Im[2]==0x07)
- {
- Modes++;
- if(Modes==6)
- Modes=0;
- }
- //右移光標(biāo)
- else if(Im[2]==0x09)
- {
- Modes--;
- if(Modes==0xff)
- Modes=5;
- }
- //光標(biāo)值+
- else if(Im[2]==0x40)
- {
- //秒++
- if(Modes==0)
- {
- time_buf1[6]++;
- if(time_buf1[6]==60)
- {
- time_buf1[6]=0;
- }
- }
- //分++
- else if(Modes==1)
- {
- time_buf1[5]++;
- if(time_buf1[5]==60)
- {
- time_buf1[5]=0;
- }
- }
- //時(shí)++
- else if(Modes==2)
- {
- time_buf1[4]++;
- if(time_buf1[4]==24)
- {
- time_buf1[4]=0;
- }
- }
- //年++
- else if(Modes==3)
- {
- time_buf1[1]++;
- if(time_buf1[1]==99)
- {
- time_buf1[1]=0;
- }
- }
- //月++
- else if(Modes==4)
- {
- time_buf1[2]++;
- if(time_buf1[2]==13)
- {
- time_buf1[2]=1;
- }
- }
- //日++
- else if(Modes==5)
- {
- time_buf1[3]++;
- if(time_buf1[3]==(YDay(time_buf1[1],time_buf1[2])+1))
- {
- time_buf1[3]=1;
- }
- time_buf1[7]=Conver_week(time_buf1[1],time_buf1[2],time_buf1[3]);
- }
- }
- //光標(biāo)值-
- else if(Im[2]==0x19)
- {
- //秒--
- if(Modes==0)
- {
- time_buf1[6]--;
- if(time_buf1[6]==0xff)
- {
- time_buf1[6]=59;
- }
- }
- //分--
- else if(Modes==1)
- {
- time_buf1[5]--;
- if(time_buf1[5]==0xff)
- {
- time_buf1[5]=59;
- }
- }
- //時(shí)--
- else if(Modes==2)
- {
- time_buf1[4]--;
- if(time_buf1[4]==0xff)
- {
- time_buf1[4]=23;
- }
- }
- //年--
- else if(Modes==3)
- {
- time_buf1[1]--;
- if(time_buf1[1]==0xff)
- {
- time_buf1[1]=99;
- }
- }
- //月--
- else if(Modes==4)
- {
- time_buf1[2]--;
- if(time_buf1[2]==0)
- {
- time_buf1[2]=12;
- }
- }
- //日--
- else if(Modes==5)
- {
- time_buf1[3]--;
- if(time_buf1[3]==0)
- {
- time_buf1[3]=YDay(time_buf1[1],time_buf1[2]);
- }
- time_buf1[7]=Conver_week(time_buf1[1],time_buf1[2],time_buf1[3]);
- }
- }
- //LCD實(shí)時(shí)刷新
- LCD_Write_Time(time_buf1,TT,R,L,FS,Mode);
- //光標(biāo)設(shè)置
- switch(Modes)
- {
- case 0:
- {
- write_com(0x80+40+7);
- break;
- }
- case 1:
- {
- write_com(0x80+40+4);
- break;
- }
- case 2:
- {
- write_com(0x80+40+1);
- break;
- }
- case 3:
- {
- write_com(0x80+3);
- break;
- }
- case 4:
- {
- write_com(0x80+6);
- break;
- }
- case 5:
- {
- write_com(0x80+9);
- break;
- }
- }//Switch
- }//if
- }//while
- //屏幕初始化
- Init_LCD();
- //保存時(shí)間
- Ds1302_Write_Time();
- }
- }
- }//while end
- }
- //延時(shí)
- void delayHW(uchar i)
- {
- uchar j,k;
- for(j=i;j>0;j--)
- for(k=125;k>0;k--);
- }
- //外部中斷定時(shí)器0寄存器初始化
- void Init()
- {
- m=0;
- f=0;
- EA=1;//開(kāi)啟總中斷
- IT1=1;//下降沿有效
- EX1=1;//外部中斷1開(kāi)
- TMOD=0x01;//定時(shí)器初始化
- TH0=0;//T0賦初值
- TL0=0;
- TR0=0;//t0開(kāi)始計(jì)時(shí)
- }
- //外部中斷解碼程序_外部中斷1
- void intersvr1(void) interrupt 2 using 1
- {
- TR0=1;
- Tc=TH0*256+TL0/256;//提取中斷時(shí)間間隔時(shí)長(zhǎng)
- TH0=0;
- TL0=0; //定時(shí)中斷重新置零
- if((Tc>Imin)&&(Tc<Imax))
- {
- m=0;
- f=1;
- return;
- } //找到啟始碼
- if(f==1)
- {
- if(Tc>Inum1&&Tc<Inum3)
- {
- Im[m/8]=Im[m/8]>>1|0x80; m++;
- }
- if(Tc>Inum2&&Tc<Inum1)
- {
- Im[m/8]=Im[m/8]>>1; m++; //取碼
- }
- if(m==32)
- {
- m=0;
- f=0;
- if(Im[2]==~Im[3])
- {
- IrOK=1;
- TR0=1;
- delayHW(200);
- }
- else IrOK=0; //取碼完成后判斷讀碼是否正確
- }
- //準(zhǔn)備讀下一碼
- }
- }
- //PWM脈沖初始化
- void initpwm()
- {
- CCON=0;
- CL=0;
- CH=0;
- CMOD=0X00;//設(shè)定Pwm時(shí)鐘頻率11.0592/12
- CCAPM0=0X42;
- PCA_PWM0=0X00;
- CCAP0H=0;
- CCAP0L=0xff;
- CR=1;
- }
- //PWM占空比設(shè)置
- void pwm_set(uchar a)
- {
- CCAP0H=a;
- }
復(fù)制代碼
所有資料51hei提供下載:
程序--原理圖.rar
(2.45 MB, 下載次數(shù): 46)
2019-5-19 12:53 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|