液晶顯示電冰箱溫度控制器_第1頁
液晶顯示電冰箱溫度控制器_第2頁
液晶顯示電冰箱溫度控制器_第3頁
液晶顯示電冰箱溫度控制器_第4頁
液晶顯示電冰箱溫度控制器_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、液晶顯示電冰箱溫控器源程序#include / 器件配置文件#include sbit LCM_RS=P33; /引腳定義sbit LCM_RW=P34; /引腳定義sbit LCM_EN=P35; /引腳定義sbit OUT=P36; /控制繼電器sbit TSOR=P37; /溫度測(cè)試端#define Busy 0x80 /常量定義#define uchar unsigned char#define uint unsigned int#define DATAPORT P1 #define reset( WDT=0x1e;WDT=0xe1;/看門狗啟動(dòng)/復(fù)位宏定義sfr WDT=0xa6;/

2、看門狗寄存器定義bit ON_OFF;bit outflag;/=uchar temp1,temp2;uchar cnt;uchar deda,sec; /時(shí)間變量char min,hour;char set,T;uchar data buff10;uchar ReadStatusLCM(void;/讀數(shù)據(jù)到MCU子函數(shù)聲明uchar code str0="- : : - "/待顯字符串uchar code str1="SET: C SA: . C"uchar code str2=" "/待顯空字符串/=函數(shù)聲明=void fun0(

3、void;void fun1(void;void fun2(void;void fun3(void;void set_adj(void;void inc_key(void;void dec_key(void;void key(void;void gettempTS(void;void initTS(void;uchar readBTS(void;void writeBTS(uchar byte;void resetTS(void;bit readTS(void;void write1TS(void;void write0TS(void;void delay15us(void;void dela

4、y60us(void;/*延時(shí)K*1mS,12.000MHz*void delay(uint k/函數(shù)名為delay的延時(shí)子函數(shù)。定義k為無符號(hào)整型變量 /delay函數(shù)開始uint i,j; /定義i、j為無符號(hào)整型變量for(i=0;i /for循環(huán)語句開始for(j=0;j<60;j+ / for循環(huán)語句開始;reset( /兩個(gè)for循環(huán)體 /delay函數(shù)結(jié)束/*-寫指令到LCM子函數(shù)-*/void WriteCommandLCM(uchar WCLCM, uchar BusyC /*函數(shù)名為WriteCommandLCM 的寫指令到LCM子函數(shù)。定義WCLCM、BusyC 為

5、無符號(hào)字符型變量*/ /WriteCommandLCM函數(shù)開始if(BusyCReadStatusLCM(; /*若BusyC為"1",則調(diào)用ReadStatusLCM子函數(shù)進(jìn)行忙檢測(cè)*/DATAPORT=WCLCM; /將變量WCLCM中的指令傳送至P1口LCM_RS=0; /選中指令寄存器LCM_RW=0; /寫模式LCM_EN=0; /置LCM_EN端為低電平LCM_EN=0; /置LCM_EN端為低電平,延時(shí)一會(huì)兒LCM_EN=1; /置LCM_EN端為高電平,寫入使能 / WriteCommandLCM函數(shù)結(jié)束/*-寫數(shù)據(jù)到LCM子函數(shù)-*/void WriteD

6、ataLCM(uchar WDLCM /*函數(shù)名為WriteDataLCM 的寫數(shù)據(jù)到LCM子函數(shù)。定義WDLCM 為無符號(hào)字符型變量*/ / WriteDataLCM函數(shù)開始ReadStatusLCM(; /調(diào)用ReadStatusLCM子函數(shù)檢測(cè)忙信號(hào)DATAPORT=WDLCM; /將變量WDLCM中數(shù)據(jù)傳送至P1口LCM_RS=1; /選中數(shù)據(jù)寄存器LCM_RW=0; /寫模式LCM_EN=0; /置LCM_EN端為低電平LCM_EN=0; /置LCM_EN端為低電平,延時(shí)一會(huì)兒LCM_EN=1; /置LCM_EN端為高電平,寫入使能 / WriteDataLCM函數(shù)結(jié)束/*-讀數(shù)據(jù)到

7、MCU子函數(shù)-*/*uchar ReadDataLCM(void /函數(shù)名為ReadDataLCM的讀數(shù)據(jù)到MCU子函數(shù) / ReadDataLCM函數(shù)開始LCM_RS=1; /選中數(shù)據(jù)寄存器LCM_RW=1; /讀模式LCM_EN=0; /置LCM_EN端為低電平LCM_EN=0; /置LCM_EN端為低電平,延時(shí)一會(huì)兒LCM_EN=1; /置LCM_EN端為高電平,讀使能return(DATAPORT; /返回P1口的內(nèi)容*/ / ReadDataLCM函數(shù)結(jié)束/*-讀狀態(tài)到MCU子函數(shù)-*/uchar ReadStatusLCM(void /函數(shù)名為ReadStatusLCM的讀狀態(tài)到M

8、CU子函數(shù) /ReadStatusLCM函數(shù)開始DATAPORT=0xFF; /置P1口為全1LCM_RS=0; /選中指令寄存器LCM_RW=1; /讀模式LCM_EN=0; /置LCM_EN端為低電平LCM_EN=0; /置LCM_EN端為低電平,延時(shí)一會(huì)兒LCM_EN=1; /置LCM_EN端為高電平,讀使能while(P1&Busy; /*檢測(cè)忙信號(hào)。當(dāng)P1口內(nèi)容與Busy(80H)相與后不為零時(shí),程序原地踏步*/return(DATAPORT; /返回P1口的內(nèi)容 / ReadStatusLCM函數(shù)結(jié)束/*-LCM初始化子函數(shù)-*/void InitLcd( /函數(shù)名為Ini

9、tLcd 的LCM初始化子函數(shù) / InitLcd函數(shù)開始WriteCommandLCM(0x38,1;/8位數(shù)據(jù)傳送,2行顯示,5*7字形,檢測(cè)忙信號(hào)WriteCommandLCM(0x08,1;/關(guān)閉顯示,檢測(cè)忙信號(hào)WriteCommandLCM(0x01,1;/清屏,檢測(cè)忙信號(hào)WriteCommandLCM(0x06,1;/顯示光標(biāo)右移設(shè)置,檢測(cè)忙信號(hào)WriteCommandLCM(0x0c,1;/顯示屏打開,光標(biāo)不顯示、不閃爍,檢測(cè)忙信號(hào) / InitLcd函數(shù)結(jié)束/*-顯示指定座標(biāo)的一個(gè)字符子函數(shù)-*/*顯示指定座標(biāo)的一個(gè)字符(X=015,Y=01)子函數(shù),函數(shù)名為DisplayOn

10、eChar,定義X、Y、DData為無符號(hào)字符型變量*/void DisplayOneChar(uchar X,uchar Y,uchar DData / DisplayOneChar 函數(shù)開始Y&=1; /Y的變化范圍01X&=15; / X的變化范圍015if(YX|=0x40; /若Y為1(顯示第二行),地址碼+0x40X|=0x80; /指令碼為地址碼+0x80WriteCommandLCM(X,0; /將指令X寫入LCM,忽略忙信號(hào)檢測(cè)WriteDataLCM(DData; /再將數(shù)據(jù)Ddata寫入LCM / DisplayOneChar 函數(shù)結(jié)束/*-顯示指定座標(biāo)的

11、一串字符子函數(shù)-*/*顯示指定座標(biāo)的一串字符(X=015,Y=01)子函數(shù),函數(shù)名為DisplayListChar ,定義X、Y為無符號(hào)字符型變量,DData 為指向code區(qū)的無符號(hào)字符型指針變量*/void DisplayListChar(uchar X,uchar Y,uchar code *DData / DisplayListChar 函數(shù)開始uchar ListLength=0; /定義ListLength 為無符號(hào)字符型變量,并賦初值為0Y&=0x1; / Y的變化范圍01X&=0xF; / X的變化范圍015while(X<=15 /X<=15時(shí)進(jìn)入

12、while語句循環(huán) /while語句開始DisplayOneChar(X,Y,DDataListLength;/顯示單個(gè)字符ListLength+; /數(shù)組指針遞增X+; /X軸座標(biāo)遞增 /while語句結(jié)束 /DisplayListChar 函數(shù)結(jié)束/=void init_timer0(void /定時(shí)器T0初始化TMOD=0x01;TH0=-(50235/256;TL0=-(50235%256;TR0=1;ET0=1;EA=1;/=void time_zd0(void interrupt 1 using 1 /定時(shí)器T0中斷子函數(shù)TH0=-(50235/256;TL0=-(50235%25

13、6;deda+;cnt+;if(deda>=20sec+;deda=0;if(sec>=60min+;sec=0;if(min>=60hour+;min=0;if(hour>=24hour=0;if(cnt>=6cnt=0;key(; /掃描鍵盤/=void fun0(void /液晶顯示子函數(shù)0WriteCommandLCM(0x0c,1;/顯示屏打開,光標(biāo)不顯示、不閃爍,檢測(cè)忙信號(hào)DisplayListChar(0,0,str0;DisplayListChar(0,1,str1;/=DisplayOneChar(3,0,hour/10+0x30;Display

14、OneChar(4,0,hour%10+0x30;/=DisplayOneChar(6,0,min/10+0x30;DisplayOneChar(7,0,min%10+0x30;/=DisplayOneChar(9,0,sec/10+0x30;DisplayOneChar(10,0,sec%10+0x30;/=DisplayOneChar(4,1,T/10+0x30;DisplayOneChar(5,1,T%10+0x30;/=DisplayOneChar(11,1,temp1/10+0x30;DisplayOneChar(12,1,temp1%10+0x30;DisplayOneChar(1

15、4,1,temp2+0x30;/=if(ON_OFF=0DisplayOneChar(14,0,0x4f;DisplayOneChar(15,0,0x46;elseDisplayOneChar(14,0,0x4f;DisplayOneChar(15,0,0x4e;if(outflag=1DisplayOneChar(0,0,0x7c;else DisplayOneChar(0,0,0xef;/=/*/void fun1(void /液晶顯示子函數(shù)1WriteCommandLCM(0x0c,1;/顯示屏打開,光標(biāo)不顯示、不閃爍,檢測(cè)忙信號(hào)DisplayListChar(0,0,str0;Disp

16、layListChar(0,1,str1;/=DisplayOneChar(6,0,min/10+0x30;DisplayOneChar(7,0,min%10+0x30;/=DisplayOneChar(9,0,sec/10+0x30;DisplayOneChar(10,0,sec%10+0x30;/=DisplayOneChar(4,1,T/10+0x30;DisplayOneChar(5,1,T%10+0x30;/=DisplayOneChar(11,1,temp1/10+0x30;DisplayOneChar(12,1,temp1%10+0x30;DisplayOneChar(14,1,

17、temp2+0x30;/=WriteCommandLCM(0x0f,1;/顯示屏打開,光標(biāo)顯示、閃爍,檢測(cè)忙信號(hào)DisplayOneChar(3,0,hour/10+0x30;DisplayOneChar(4,0,hour%10+0x30;/*/void fun2(void /液晶顯示子函數(shù)2WriteCommandLCM(0x0c,1;/顯示屏打開,光標(biāo)不顯示、不閃爍,檢測(cè)忙信號(hào)DisplayListChar(0,0,str0;DisplayListChar(0,1,str1;/=DisplayOneChar(3,0,hour/10+0x30;DisplayOneChar(4,0,hour%

18、10+0x30;/=DisplayOneChar(9,0,sec/10+0x30;DisplayOneChar(10,0,sec%10+0x30;/=DisplayOneChar(4,1,T/10+0x30;DisplayOneChar(5,1,T%10+0x30;/=DisplayOneChar(11,1,temp1/10+0x30;DisplayOneChar(12,1,temp1%10+0x30;DisplayOneChar(14,1,temp2+0x30;/=WriteCommandLCM(0x0f,1;/顯示屏打開,光標(biāo)顯示、閃爍,檢測(cè)忙信號(hào)DisplayOneChar(6,0,mi

19、n/10+0x30;DisplayOneChar(7,0,min%10+0x30;/*/void fun3(void /液晶顯示子函數(shù)3WriteCommandLCM(0x0c,1;/顯示屏打開,光標(biāo)不顯示、不閃爍,檢測(cè)忙信號(hào)DisplayListChar(0,0,str0;DisplayListChar(0,1,str1;/=DisplayOneChar(3,0,hour/10+0x30;DisplayOneChar(4,0,hour%10+0x30;/=DisplayOneChar(6,0,min/10+0x30;DisplayOneChar(7,0,min%10+0x30;/=Displ

20、ayOneChar(9,0,sec/10+0x30;DisplayOneChar(10,0,sec%10+0x30;/=DisplayOneChar(11,1,temp1/10+0x30;DisplayOneChar(12,1,temp1%10+0x30;DisplayOneChar(14,1,temp2+0x30;/=WriteCommandLCM(0x0f,1;/顯示屏打開,光標(biāo)顯示、閃爍,檢測(cè)忙信號(hào)DisplayOneChar(4,1,T/10+0x30;DisplayOneChar(5,1,T%10+0x30;/*/void key(void /掃描鍵盤uchar xx;P2=0xff

21、;if(P2!=0xffdelay(10;if(P2!=0xffxx=P2;switch(xxcase 0xfe:set_adj(;break;case 0xfd:inc_key(;break;case 0xfb:dec_key(;break;case 0xf7:ON_OFF=!ON_OFF;break;default:break;/*/void set_adj(void /設(shè)定工作模式子函數(shù)if(cnt=5set+;if(set>=4set=0;/*/void inc_key(void /按鍵加法子函數(shù)if(cnt=5switch(setcase 0:if(P2=0xf7ON_OFF=

22、!ON_OFF;break;case 1:hour+;if(hour>=23hour=23;break;case 2:min+;if(min>=59min=59;break;case 3:T+;if(T>=99T=99; break;default:break;/*/void dec_key(void /按鍵減法子函數(shù)if(cnt=5switch(setcase 0:if(P2=0xf7ON_OFF=!ON_OFF;break;case 1:hour-;if(hour<=0hour=0;break;case 2:min-;if(min<=0min=0;break;

23、case 3:T-;if(T<=1T=1;break;default:break;/*/*/void delay15us(void /延時(shí)15微秒子函數(shù)uchar i;for(i=0;i<4;i+;/*void delay60us(void 延時(shí)60微秒子函數(shù)uchar i;for(i=0;i<15;i+;/*void write0TS(void /write bit0TSOR=1;TSOR=0;delay15us(;delay15us(;delay15us(;delay15us(;TSOR=1;_nop_(;_nop_(;/*void write1TS(void /writ

24、e bit1TSOR=1;TSOR=0;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;TSOR=1;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;delay15us(;delay15us(;delay15us(;/*bit readTS(void /read databitbit b;TSOR=1;TSOR=0;_nop_(;_nop_(;_nop_(;_nop_(;TSOR=1;_nop_(;_nop_(;_nop_(;_nop_(;_nop_(;b=TSOR;delay15us(;del

25、ay15us(;delay15us(;_nop_(;_nop_(;return b;/*void resetTS(void /reset databituchar i;TSOR=1;TSOR=0;for(i=0;i<8;i+delay60us(;TSOR=1;while(TSOR;for(i=0;i<8;i+delay60us(;/*void writeBTS(uchar byte /write one byteuchar i;for(i=0;i<8;i+if(byte&0x01write1TS(;elsewrite0TS(;byte=byte>>1;/*uchar readBTS(void /read one byteuchar i,j;bit b;j=0;for(i=0;i<8;i+b=readTS

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論