版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Mega16單片機(jī)程序 interface.h/*移植時(shí)要實(shí)現(xiàn)以下函數(shù):LcdClrScrn(); /清屏ShowARROW(SysSclt); /在某一行顯示箭頭DisShowARROW(SysSclt); /在某一行不顯示箭頭ShowLine(0, "Copy Right"); /在某一行顯示字符串uchar
2、 GetKey(); /按鍵檢測函數(shù)。 返回Key_Up Key_Down Key_Right Key_Left*/#ifndef _INTERFACE_H_#define _INTERFACE_H_ #include "KEY.h" /extern void Interface(void); #define &
3、#160; GOTO_CHILD 0XFC#define FROM_FATHER 0XFC #define GOTO_FATHER 0XFD /之前設(shè)置為0xff 不對,有問題,子界面返回時(shí),不刷新#define FROM_CHILD 0XFD /# #define INT8U unsigned char INT8U Key;
4、0; /系統(tǒng)按鍵.INT8U KeyDir = FROM_FATHER; /用來各個(gè)界面之間的切換時(shí)傳遞參數(shù)./=/系統(tǒng)界面函數(shù)聲明區(qū).(一定要聲明!) 有幾個(gè)不同的界面就有幾個(gè)函數(shù)void UI_Idle(void);void UI_Help(void);void UI_Time();void UI_Temperature();void UI_Play();void UI_Set();void (*pUI)()=UI_Idle; /界面指針初始化為IDLE函數(shù). 函數(shù)指針 &
5、#160; /pUI();為當(dāng)前while()大循環(huán)下執(zhí)行的函數(shù)#define UI_GOTO(index) pUI=(index); #define UI_GOTO_CHILD(index) pUI=(index); KeyDir=GOTO_CHILD;#define UI_GOTO_FATHER(index) pUI=(index); Key
6、Dir=GOTO_FATHER;/=/以下是各個(gè)界面的函數(shù)實(shí)現(xiàn).每個(gè)函數(shù)都要在上面聲明!/空閑狀態(tài)下的循環(huán).void UI_Idle()static INT8U SysSclt=0; /當(dāng)前選中的是哪一項(xiàng)switch(Key) /進(jìn)入菜單. case FROM_FATHER: case FROM_CHILD: /case GOTO_FATHER: LcdClrScrn();
7、60; / 0 1 2 3 4 #define IDLE_MENU_MAX 4 ShowLine(0,"1.Temperature"); ShowLine(1,"2.Time"); ShowLine(2,"3.Play Games"); ShowLine(3,"4.
8、Set "); ShowLine(4,"5.Help"); ShowLine(7," select"); ShowARROW(SysSclt); break; /箭頭上移 case Key_Up: DisShowARRO
9、W(SysSclt); if(SysSclt=0)SysSclt=IDLE_MENU_MAX; else SysSclt-; ShowARROW(SysSclt); break; /箭頭下移 case Key_Down: DisShowARROW(SysSclt); S
10、ysSclt+; if(SysSclt>IDLE_MENU_MAX)SysSclt=0; ShowARROW(SysSclt); break; /確定 進(jìn)入 子項(xiàng) case Key_Right: if(SysSclt = 0) /Temperature UI_GOTO_CHILD(UI_Temper
11、ature); /KeyDir = GOTO_CHILD; break; if(SysSclt = 1) /Time UI_GOTO_CHILD(UI_Time); /KeyDir =
12、GOTO_CHILD; break; if(SysSclt = 2) /Time UI_GOTO_CHILD(UI_Play); /KeyDir = GOTO_CHILD; &
13、#160; break; if(SysSclt = 3) /Time UI_GOTO_CHILD(UI_Set); /KeyDir = GOTO_CHILD; break;
14、 if(SysSclt = 4) /help UI_GOTO_CHILD(UI_Help); /KeyDir = GOTO_CHILD; break; defa
15、ult:break;/switchvoid UI_Temperature()switch(Key) /進(jìn)入菜單. case FROM_FATHER: /case FROM_CHILD: LcdClrScrn(); ShowLine(0, "The"); ShowLine(2, "Temperature"); ShowLine(4, "
16、;is 27"); /改天加DS18B20實(shí)際測一個(gè) ShowLine(7, "back"); break; case Key_Left: UI_GOTO_FATHER(UI_Idle); break; default:break;/switch
17、void UI_Time()switch(Key) /進(jìn)入菜單. case FROM_FATHER: /case FROM_CHILD: LcdClrScrn(); ShowLine(0, "The Time is "); ShowLine(2, "09-12-24"); ShowLine(4, "0:01 ");
18、0; ShowLine(7, "back"); break; case Key_Left: UI_GOTO_FATHER(UI_Idle); break; default:break;/switch void UI_Play()switch(Key) /進(jìn)入
19、菜單. case FROM_FATHER: /case FROM_CHILD: LcdClrScrn(); ShowLine(0, "YOU get to "); ShowLine(1, "go back to"); ShowLine(2, "STUDY"); ShowLine(4, "Made dy
20、 LYQ"); ShowLine(7, "back"); break; case Key_Left: UI_GOTO_FATHER(UI_Idle); break; default:break;/switchvoid UI_Set()switch(Key)
21、/進(jìn)入菜單. case FROM_FATHER: /case FROM_CHILD: LcdClrScrn(); ShowLine(0, "Nothing NOW"); ShowLine(7, "back"); break; case Key_Left:
22、60; UI_GOTO_FATHER(UI_Idle); break; default:break;/switchvoid UI_Help()switch(Key) /進(jìn)入菜單. case FROM_FATHER: /case FROM_CHILD: LcdClrScrn(); ShowLine(0, "Copy
23、 Right"); ShowLine(2, "I love China"); ShowLine(4, "Made dy LYQ"); ShowLine(7, "back"); break; case Key_Left: UI_GOTO_FATHER(UI_Idle)
24、; break; default:break;/switch /系統(tǒng)的大循環(huán).void Interface(void)/=/以下為按鍵的處理.Key = GetKey(); if(KeyDir!=0) /KeyDir=GOTO_CHILD or KeyDir=GOTO_FATHER; /建立一種傳遞信息的變量. &
25、#160; Key = KeyDir; KeyDir = 0; /=/以下為界面的相互調(diào)用pUI();#endif =#ifndef _KEY_H_#define _KEY_H_#define Key_Up 0x11#define Key_Down 0x12#define Key_Left 0x13#define Key_Right 0x14/
26、uchar Key_Scan();void delay_ms(unsigned int t)unsigned int i,j;for(i=0;i<t;i+) for(j=0;j<1141;j+);unsigned char Key_Scan()unsigned char key;DDRA|=0X0f; /輸出PORTA|=0Xff; /上拉DDRA&=0X0f; /輸入if(PINA=0xfe) delay_ms(10); if(PINA=0xfe)
27、60; while(PINA=0xfe); /等待松手 return Key_Up; if(PINA=0xfd) delay_ms(10); if(PINA=0xfd) while(PINA=0xfd); return Key_Down; if(PINA=0xfb) delay_ms(10);&
28、#160; if(PINA=0xfb) while(PINA=0xfb); return Key_Left; if(PINA=0xf7) delay_ms(10); if(PINA=0xf7) while(PINA=0xf7); return Key_Right; return 0;/沒有鍵按下
29、返回0unsigned char GetKey()return Key_Scan();#endif =#-=#ifndef _PG12864_H_#define _PG12864_H_#include <iom16v.h>#define uchar unsigned char#define uint unsigned int#define WR_L() PORTD&=(1)#define WR_H() PORTD|=(1)#define RD_L() PORTD&=(1<<1)#define RD_H() PORTD|=(1<<1)#defi
30、ne CE_L() PORTD&=(1<<2)#define CE_H() PORTD|=(1<<2)#define CD_L() PORTD&=(1<<3)#define CD_H() PORTD|=(1<<3)#define RST_L() PORTD&=(1<<4)#define RST_H() PORTD|=(1<<4)void delay(uint t);uchar read_status()uchar status;DDRB=0;/端口b置為輸入RD_L();WR_H();CE_L();
31、CD_H();status=PINB;return status;void check_status()uchar s;DDRB=0XFF;/端口b置為輸出while(s&0x03)!=0x03) s=read_status();/等待位1,2置為。命令讀寫準(zhǔn)備好。數(shù)據(jù)讀寫準(zhǔn)備好/void init_txt_12864();void write_data(uchar data);void write_cmd1(uchar cmd);void write_cmd2(uchar data,uchar cmd);void write_cmd3(uchar data1,
32、uchar data2,uchar cmd);/uchar read_status();/void clear_screen();void display_char(uchar x,uchar y,uchar ch);/void init_graphic_12864();/void display_HZ(uchar x,uchar y,uchar *hz); /x 0-3 y 0-7/void display_string(uchar x,uchar y,uchar *s);/*int main()
33、 uchar i,j=0; init_txt_12864(); display_string(0,0,ch); delay(100); clear_screen(); init_graphic_12864();
34、 for(i=0;i<15;i+) if(i>=8) display_HZ(1,i-8,HZ2i); else display_HZ(0,i,HZ2i); while(1);/調(diào)整文本區(qū)首地址,可以實(shí)現(xiàn)移屏;/i+;/ write_cmd3(i+,0,0x40);/文本區(qū)首地址;/ delay(10000);/*/#include <pg12864.h>/處在
35、x y處顯示漢字hzvoid display_HZ(uchar x,uchar y,uchar *hz)/x 0-3 y 0-7uchar i,j=0;for(i=0;i<16;i+) write_cmd3(j/2)<<4)|(y*2),x,0x24);/地址指針設(shè)置.低地址,高地址,命令 write_cmd2(hzj+,0xc0); write_cmd2(hzj+,0xc0); /處在x y處顯示c
36、hvoid display_char(uchar x,uchar y, uchar ch)/x 0-7 y 0-15write_cmd3(x*2)<<4)+y),0x00,0x24);/地址指針位置write_cmd2(ch-32,0xc0);/t6963c字符表與ASCII差32void display_string(uchar x,uchar y, uchar *s)uchar i=0;while(*s) display_char( x, y+(i+),*s);
37、; s+; if(i>=16) x+; i=0; void delay(uint t)uint i,j;for(i=0;i<t;i+) for(j=0;j<1141;j+);void init_txt_12864()/初始化端口DDRD=0XFF;DDRB=0XFF;PORTB=0XFF;/液晶復(fù)位RST_L();delay(1);RST_L();/所有控制引腳置高WR_H();RD_H();CE
38、_H();CD_H();RST_H();/初始化指令check_status();write_cmd3(0x01,0x00,0x21);/光標(biāo)指針設(shè)置check_status();write_cmd3(0x00,0x00,0x40);/文本區(qū)首地址check_status();/加上下面2行代碼,只顯示4行?而不是8行!/write_cmd3(16,0x00,0x41);/文本區(qū)寬度。字節(jié)數(shù)/行&&&&&/check_status();write_cmd1(0x80);/顯示方式設(shè)置,正常顯示check_status();write_cmd1(0x94)
39、;/。顯示狀態(tài)設(shè)置 1 0 1 0 N3 N2 N1 N0 文本顯示,光標(biāo)不顯示,不閃爍/write_cmd1(0x98);/圖形方式顯示,不顯示字母,只打點(diǎn)check_status();write_cmd1(0xa1);/光標(biāo)形狀設(shè)置1 0 1 0 0 N2 N1 N0void init_graphic_12864()/初始化端口DDRD=0XFF;DDRB=0XFF;PORTB=0XFF;/液晶復(fù)位RST_L();delay(1);RST_L();/所有控制引腳置高WR_H();RD_H();CE_H();CD_H();RST_H();/初始化指令check_sta
40、tus();write_cmd3(0x01,0x00,0x21);/光標(biāo)指針設(shè)置check_status();write_cmd3(0x00,0x00,0x42);/圖形區(qū)首地址check_status();write_cmd3(16,0x00,0x43);/圖形區(qū)寬度check_status();write_cmd1(0x80);/顯示方式設(shè)置,正常顯示check_status();/write_cmd1(0x94);/。顯示狀態(tài)設(shè)置 1 0 1 0 N3 N2 N1 N0 文本顯示,光標(biāo)不顯示,不閃爍write_cmd1(0x98);/圖形方式顯示,不顯示字母,只打
41、點(diǎn)check_status();write_cmd1(0xa0);/光標(biāo)形狀設(shè)置1 0 1 0 0 N2 N1 N0void clear_screen()uint i;write_cmd3(0x00,0x00,0x24);/地址指針設(shè)置check_status();write_cmd1(0xb0);/數(shù)據(jù)自動(dòng)寫,每寫一次,地址指針自動(dòng)加一check_status();for(i=0;i<8192;i+) check_status(); write_data(0X00);check_status();write_cmd1(0xb2);/數(shù)據(jù)自
42、動(dòng)寫結(jié)束void write_data(uchar data)RD_H();CD_L();CE_L();WR_L();PORTB=data;asm("nop");/delay(1);WR_H();CE_H();CD_H();void write_cmd1(uchar cmd)RD_H();CD_H();CE_L();WR_L();PORTB=cmd;asm("nop");/delay(1);/須延時(shí)80ns左右WR_H();CE_H();CD_L();/先送參數(shù),再送指令void write_cmd2(uchar data,uchar cmd)check
43、_status();write_data(data);check_status();write_cmd1(cmd);void write_cmd3(uchar data1,uchar data2,uchar cmd)check_status();write_data(data1);check_status();write_data(data2);check_status();write_cmd1(cmd);/#pragma data:codeuchar HZ432=0x00,0xF8,0x3F,0x90,0x12,0x10,0x09,0x20,0x3F,0xFE,0x22,0x02,0x42,
44、0x00,0x3F,0xFC,0x04,0x00,0x07,0xF0,0x0C,0x20,0x0B,0x40,0x10,0xC0,0x63,0x30,0x8C,0x0E,0x30,0x04,/*"愛",0*/0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02,/*"我",1*/0x01,0x
45、00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,/*"中",2*/0x08,0x80,0x0C,0x88,0x10,0x9C,0x30,0xE0,0x53,0x80,0x90,0x84,0x10,0x84,0x10,0x7C,0x11,0x00,0x01,0x00,0x7F,0xFE,0x01,0x00,0x01,0x0
46、0,0x01,0x00,0x01,0x00,0x01,0x00/*"華",3*/;uchar HZ232=0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x7F,0xFC,0x20,0x04,0x00,0x00,/*"山",0*/0x02,0x00,0x02,0x00,0x7F,0xFC,0x04,0x00,0x08,0x80,0x08,0x8
47、0,0x10,0x80,0x1F,0xF8,0x00,0x80,0x08,0xA0,0x0C,0x90,0x18,0x88,0x10,0x8C,0x22,0x84,0x01,0x80,0x00,0x80,/*"東",1*/0x08,0x00,0x0B,0xFE,0x48,0x20,0x48,0x20,0x4B,0xFE,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x52,0x22,0x52,0x2A,0x12,0x24,0x20,0x20,0x40,0x20,0x80,0x20,0x00,0x20,/*"師",2*/
48、0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x60,0x40,0x00,0x31,0xF8,0x91,0x08,0x61,0x08,0x49,0x08,0x09,0x38,0x11,0x10,0xE1,0x00,0x21,0x04,0x21,0x04,0x20,0xFC,0x20,0x00,/*"范",3*/0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80,0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,0
49、x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04,/*"大",4*/0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,/*"學(xué)",5*/0x10,0x80,0x10,0x80,0x50,0x80,0x51,0xFC,0x7D,0x54,0x52,0x54,0x94,0x94,0x14,0x94,0x19,0x24,0x32,0x24,0xD4,0x44,0x10,0x84,0x11,0x04,0x12,0x04,0x14,0x28,0x00,0x10,/*"物",6*/0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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ǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 一的變調(diào)練習(xí)題
- 二零二五年度重型吊車安全責(zé)任及運(yùn)輸合同3篇
- 壓瘡的預(yù)防及護(hù)理課件
- 射箭游戲-數(shù)學(xué)
- 2024年浙江宇翔職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測試歷年參考題庫含答案解析
- 2024年濟(jì)源職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測試歷年參考題庫含答案解析
- 《科幻小說賞析與寫作》 課件 -第三章 “太空歌劇”的探索與開拓-《2001太空漫游》
- 2024年河南工業(yè)貿(mào)易職業(yè)學(xué)院高職單招職業(yè)技能測驗(yàn)歷年參考題庫(頻考版)含答案解析
- 二零二五年租賃權(quán)轉(zhuǎn)讓及配套設(shè)備協(xié)議范本3篇
- 2024年滄州職業(yè)技術(shù)學(xué)院高職單招語文歷年參考題庫含答案解析
- 2023年重癥醫(yī)學(xué)科護(hù)理工作計(jì)劃
- 人教版八年級上冊地理全冊單元測試卷(含期中期末試卷及答案)
- 年會(huì)抽獎(jiǎng)券可編輯模板
- 感染性疾病標(biāo)志物及快速診斷課件(PPT 134頁)
- YC∕T 273-2014 卷煙包裝設(shè)計(jì)要求
- 2022年煤礦地面消防應(yīng)急預(yù)案范文
- 高中化學(xué)必修二第三章第一節(jié)認(rèn)識(shí)有機(jī)化合物課件
- 水上拋石護(hù)坡施工方案
- 4PL的供應(yīng)鏈整合及其對區(qū)域發(fā)展的借鑒意義
- 物料提升機(jī)基礎(chǔ)方案
- 840dsl常用參數(shù)
評論
0/150
提交評論