|
分享一個自己做的單片機(jī)設(shè)計
智能風(fēng)扇控制系統(tǒng)仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
功能非常多多,帶三擋風(fēng)速調(diào)節(jié),還有正常,睡眠,自然3個模式,是按鍵控制的。
單片機(jī)風(fēng)扇源程序如下:
- //數(shù)碼管低電平有效
- #include <reg51.h>
- #include <absacc.h>
- #include <ctype.h>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- #include "set.h"
- #include "myinit.h"
- #include "function.h"
- uint signal;
- uint q; //用于DS18B20 j秒讀取一次數(shù)據(jù)
- uchar code a[]={ //定義數(shù)組,用于數(shù)碼管顯示
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x40
- };
- /*******************************************************************************/
- uchar TH=50,TL=10; //定義溫度上下限
- uchar t[2]={20,20},*pt; //用來存放溫度值,測溫程序就是通過這個數(shù)組與主函數(shù)通信的
- uchar TempBuffer1[9]={0x2b,0x31,0x32,0x32,0x2e,0x30,0x30,0x43,'\0'};
- //顯示實時溫度,上電時顯示+125.00C
- uchar TempBuffer0[17]={0x54,0x48,0x3a,0x2b,0x31,0x32,0x35,0x20,
- 0x54,0x4c,0x3a,0x2b,0x31,0x32,0x34,0x43,'\0'};
- //顯示溫度上下限,上電時顯示TH:+125 TL:+124C
- uchar code dotcode[4]={0,25,50,75};
- /*******************************************************************************/
- void main()
- {
- // unsigned char TH=50,TL=10; //定義溫度上下限
- init_timer(); //初始化
- init(); //初始化
- pt=ReadTemperature(TH,TL,0x3f); //上限溫度-22,下限-24,分辨率10位,也就是0.25C
- //讀取溫度,溫度值存放在一個兩個字節(jié)的數(shù)組
- covert1(); //將溫度轉(zhuǎn)換為LCD顯示的據(jù)數(shù)
- while(1) //等待啟動
- {
- scan();
- if(flag_modle==1)
- {
- led_normal=1;
- led_style=1;
- break;
- }
- }
- close_motor=1; //打開電機(jī)電源
- while(1) //啟動后進(jìn)入循環(huán)掃面狀態(tài)
- {
- scan();
- switch(flag_modle)
- {
- case 1:
- choice_speed();
- break;
- case 2:
- choice_modle();
- flag_modle=1;
- break;
- case 3:
- stop_operation();
- break;
- }
- /* if(q>60) //3S讀取一次溫度
- {
- pt=ReadTemperature(TH,TL,0x3f); //上限溫度-22,下限-24,分辨率10位,也就是0.25C
- //讀取溫度,溫度值存放在一個兩個字節(jié)的數(shù)組
- covert1();
- } */
- }
- }
- //中斷函數(shù)
- void timer0() interrupt 1
- {
- if(i>=20) //定時1S
- {
- i=0;
- time--;
- if(time<=0)
- time=0;
- }
- if(q>20) //定時3S,3S測一次溫度
- {
- q=0;
- pt=ReadTemperature(TH,TL,0x3f);
- covert1();
- }
- if((t[1]>TH)|(t[1]<TL)) //溫度 TL<t[1]<TH 時,關(guān)閉電機(jī)
- {
- close_motor=0; //關(guān)閉電機(jī)電源
- init(); //初始化
- }
- else
- close_motor=1; //打開電機(jī)電源
- i++,q++;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- }
復(fù)制代碼- #include "function.h"
- #include "set.h"
- //按鍵掃描函數(shù)
- void scan(void)
- {
- if(speed==1)//風(fēng)速
- {
- delay(10);
- if(speed==1)
- {
- while(speed);
- flag_modle=1; //模式標(biāo)志位
- flag_speed++;
- signal=1; //按鍵信號標(biāo)志,用于選擇模式
- if(flag_speed>4)
- flag_speed=1;
- }
- }
- if(style==1)//模式
- {
- delay(10);
- if(style==1)
- {
- while(style);
- flag_modle=2; //模式標(biāo)志位
- flag_style++;
- signal=1; //按鍵信號標(biāo)志,用于選擇模式
- if(flag_style>3)
- flag_style=1;
- }
- }
- if(stop==1)//停止
- {
- delay(10);
- if(stop==1)
- {
- while(stop);
- flag_modle=3; //模式標(biāo)志位
- signal=1; //按鍵信號標(biāo)志,用于選擇模式
- }
- }
- }
復(fù)制代碼
調(diào)試中的代碼與Proteus7.8版本的仿真下載(代碼存在一些Keil版本兼容性問題):
STC89C51_風(fēng)扇控制系統(tǒng).zip
(433.14 KB, 下載次數(shù): 284)
2018-4-19 12:52 上傳
點(diǎn)擊文件名下載附件
最終代碼下載:經(jīng)過2樓提醒后 修復(fù)某些Keil會編譯錯誤的問題
修復(fù)后的代碼.7z
(37.51 KB, 下載次數(shù): 77)
2022-11-11 05:05 上傳
點(diǎn)擊文件名下載附件
|
評分
-
查看全部評分
|