【電氣設(shè)計(jì)自動(dòng)化論文】自動(dòng)溫控制電風(fēng)扇系統(tǒng)設(shè)計(jì)
【電氣設(shè)計(jì)自動(dòng)化論文】自動(dòng)溫控制電風(fēng)扇系統(tǒng)設(shè)計(jì),電氣設(shè)計(jì),自動(dòng)化,論文,自動(dòng),溫控,電風(fēng)扇,系統(tǒng),設(shè)計(jì)
數(shù)字溫度傳感器模塊和顯示子模塊程序:#include //調(diào)用單片機(jī)頭文件#define uchar unsigned char //無符號字符型 宏定義 變量范圍0~255#define uint unsigned int //無符號整型 宏定義 變量范圍 0~65535#include “eeprom52.h“//數(shù)碼管段選定義 0 1 2 3 4 5 6 7 8 9uchar code smg_du[]={0x28,0xee,0x42,0x52,0xe5,0xa8,0x41,0xe7,0x20,0xa0,0x60,0x25,0x39,0x26,0x31,0x71,0xff}; //斷碼//數(shù)碼管位選定義uchar code smg_we[]={0xef,0xdf,0xbf,0x7f};uchar dis_smg[8] = {0x28,0xee,0x32,0xa2,0xe4,0x92,0x82,0xf8};uchar smg_i = 3; //顯示數(shù)碼管的個(gè)位數(shù)sbit dq = P2^4; //18b20 IO口的定義bit flag_lj_en; //按鍵連加使能bit flag_lj_3_en; //按鍵連 3次連加后使能 加的數(shù)就越大了 uchar key_time,key_value; //用做連加的中間變量bit key_500ms ;sbit pwm = P2^3; uchar f_pwm_l ; //越小越暗uint temperature ; //bit flag_300ms ;uchar menu_1; //菜單設(shè)計(jì)的變量uint t_high = 300,t_low = 100; //溫度上下限報(bào)警值 /***********************1ms延時(shí)函數(shù)*****************************/void delay_1ms(uint q){uint i,j;for(i=0;i= smg_i)i = 0;P1 = 0xff; //消隱 P3 = smg_we[i]; //位選P1 = dis_smg[i]; //段選}/******************把數(shù)據(jù)保存到單片機(jī)內(nèi)部 eepom中******************/void write_eeprom(){SectorErase(0x2000);byte_write(0x2000, t_high % 256);byte_write(0x2001, t_high / 256);byte_write(0x2002, t_low % 256);byte_write(0x2003, t_low / 256);byte_write(0x2055, a_a);}/******************把數(shù)據(jù)從單片機(jī)內(nèi)部 eepom中讀出來*****************/void read_eeprom(){t_high = byte_read(0x2001);t_high = 1;}}/*************讀取 18b20內(nèi)的數(shù)據(jù)***************/uchar read_18b20(){uchar i,value;for(i=0;i= 1; //讀數(shù)據(jù)是低位開始dq = 1; //釋放總線if(dq == 1) //開始讀寫數(shù)據(jù) value |= 0x80;delay_uint(5); //60us 讀一個(gè)時(shí)間隙最少要保持 60us的時(shí)間}return value; //返回?cái)?shù)據(jù)}/*************讀取溫度的值 讀出來的是小數(shù)***************/uint read_temp(){uint value;uchar low; //在讀取溫度的時(shí)候如果中斷的太頻繁了,就應(yīng)該把中斷給關(guān)了,否則會(huì)影響到 18b20的時(shí)序init_18b20(); //初始化 18b20EA = 0;write_18b20(0xcc); //跳過 64位 ROMwrite_18b20(0x44); //啟動(dòng)一次溫度轉(zhuǎn)換命令EA = 1;delay_uint(50); //500usinit_18b20(); //初始化 18b20EA = 0;write_18b20(0xcc); //跳過 64位 ROMwrite_18b20(0xbe); //發(fā)出讀取暫存器命令low = read_18b20(); //讀溫度低字節(jié)value = read_18b20(); //讀溫度高字節(jié)EA = 1;value = 3){menu_1 = 0;smg_i = 3; //數(shù)碼管顯示 3位}}if(menu_1 == 1) //設(shè)置高溫報(bào)警{smg_i = 4; //數(shù)碼管顯示 4位if(key_can == 2){if(flag_lj_3_en == 0)t_high ++ ; //按鍵按下未松開自動(dòng)加三次t_high += 10; //按鍵按下未松開自動(dòng)加三次之后每次自動(dòng)加 10if(t_high 990)t_high = 990;}if(key_can == 3){if(flag_lj_3_en == 0)t_high -- ; //按鍵按下未松開自動(dòng)減三次else t_high -= 10; //按鍵按下未松開自動(dòng)減三次之后每次自動(dòng)減10if(t_high = t_high)t_low = t_high - 1;}if(key_can == 3){if(flag_lj_3_en == 0)t_low -- ; //按鍵按下未松開自動(dòng)減三次else t_low -= 10; //按鍵按下未松開自動(dòng)加三次之后每次自動(dòng)加 10if(t_low = t_high) //風(fēng)扇全開{TR1 = 1;pwm = 0;}else if((temperature = t_low)) //風(fēng)扇緩慢{f_pwm_l = 60; TR1 = 1;}else if(temperature = 150){value = 0; flag_300ms = 1;}if(flag_lj_en == 1) //按下按鍵使能{key_time ++;if(key_time = 250) //500ms{key_time = 0;key_500ms = 1; //500mskey_value ++;if(key_value 3){key_value = 10;flag_lj_3_en = 1; //3次后 1.5秒連加大些}}}}/*******************定時(shí)器 1用做單片機(jī)模擬 PWM 調(diào)節(jié)***********************/void Timer1() interrupt 3 //調(diào)用定時(shí)器 1{static uchar value_l;TH1=0xfe; // 定時(shí) 10ms中斷一次TL1=0x0c; //500usif(pwm==1){value_l+=3;if(value_l f_pwm_l) //高電平{value_l=0;if(f_pwm_l != 0) pwm=0; }}else{value_l+=3;if(value_l 100 - f_pwm_l) //低電平{value_l=0;pwm=1;}
收藏