版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、TFT液晶顯示時(shí)鐘程序說(shuō)明:該程序文件中包含三個(gè).c文件和三個(gè).h文件,方便讀者理解程序的層次性和關(guān)聯(lián)性。該程序的功能是利用51單片機(jī)實(shí)現(xiàn)邏輯控制,在液晶顯示屏上顯示動(dòng)態(tài)時(shí)鐘。1. shizhong.c (實(shí)際上是主程序):#include "REG51.H"#include "gui.h"unsigned char count;#define key P1sbit K=P20;unsigned char a;unsigned char b;unsigned char c;unsigned char d;unsigned char e;unsigned
2、char f;unsigned char g;unsigned char sw;unsigned char h1=0;unsigned char h2=0;unsigned char h3=0;unsigned int q;void Keyboard() unsigned int k;key=0xf0;if(key!=0xf0)for(q=0;q<800;q+);if(key!=0xf0)key=0x0f;switch(key)case(0x0e): k=0; break;case(0x0d): k=4; break;case(0x0b): k=8; break;case(0x07):
3、k=12; break;key=0xf0;switch(key)case(0xe0): k=k; break;case(0xd0): k=k+1; break;case(0xb0): k=k+2; break;case(0x70): k=k+3; break;while(key!=0xf0);switch(k)case 0: f+; P0=0x01; if(f=3) f=0; break;case 1: e+; P0=0x02;if(f<2)if(e=10) e=0; if(f=2)if(e=4)e=0; break;case 2: d+; P0=0x04;if(d=6) d=0; br
4、eak;case 3: c+; P0=0x08;if(c=10) c=0; break;case 4: b+; P0=0x10;if(b=6) b=0; break;case 5: a+; P0=0x20;if(a=10) a=0; break;case 6: sw=0;break;case 7: sw=1; break;void jishu() K=1; if(K=0) for(q=0;q<800;q+);if(K=0) h1+; if(h1=10) h1=0; h2+;if(h2=10)h2=0;h3+; while(K=0); GUI_WriteASCII(0, 50, h3, R
5、ED, WHITE); GUI_WriteASCII(16, 50, h2, RED, WHITE); GUI_WriteASCII(32, 50, h1, RED, WHITE);void main (void)TFT_Init(); TFT_ClearScreen(BLACK);EA=1;ET1=1;TMOD=0x10;TH1=15536/256;TL1=15536%256;TR1=1;a=0;b=0;c=0;d=0;e=0;f=0;g=10;count=0;sw=1;GUI_WriteASCII(0, 50, 0, RED, WHITE);GUI_WriteASCII(16, 50, 0
6、, RED, WHITE);GUI_WriteASCII(32, 50, 0, RED, WHITE);while(1)while(sw)TR1=1;jishu();if(count>=20)count=0;a+;if(a=10)a=0;b+;if(b=6)b=0;c+;if(c=10)c=0;d+;if(d=6)d=0;e+;if(f<2&&e=10)e=0;f+;if(f=2&&e=4)f=0;e=0;GUI_WriteASCII(0, 0, f, RED, WHITE);GUI_WriteASCII(16, 0, e, RED, WHITE);
7、GUI_WriteASCII(32, 0, g, RED, WHITE);GUI_WriteASCII(48, 0, d, RED, WHITE);GUI_WriteASCII(64, 0, c, RED, WHITE);GUI_WriteASCII(80, 0, g, RED, WHITE); GUI_WriteASCII(96, 0, b, RED, WHITE);GUI_WriteASCII(112,0, a, RED, WHITE); Keyboard(); Keyboard();GUI_WriteASCII(0, 0, f, RED, WHITE);GUI_WriteASCII(16
8、, 0, e, RED, WHITE);GUI_WriteASCII(32, 0, g, RED, WHITE);GUI_WriteASCII(48, 0, d, RED, WHITE);GUI_WriteASCII(64, 0, c, RED, WHITE);GUI_WriteASCII(80, 0, g, RED, WHITE); GUI_WriteASCII(96, 0, b, RED, WHITE);GUI_WriteASCII(112,0, a, RED, WHITE);TR1=0; void Time1(void) interrupt 3count+;TH1=15536/256;T
9、L1=15536%256;2. gui.c :#include"gui.h"#include"charcode.h"#ifdef USE_ASCIIvoid GUI_WriteASCII(uchar x, uchar y, uchar p, uint wordColor, uint backColor)uchar j, wordByte,wordNum;uint color;wordNum = p;TFT_SetWindow(x,y,x+15, y+23);for (wordByte=0; wordByte<48; wordByte+)color
10、= ASCII16x24wordNumwordByte;for (j=0; j<8; j+) if (color&0x80) = 0x80)TFT_WriteData(wordColor); elseTFT_WriteData(backColor); color <<= 1;#endif3. driver.c :#include "driver.h"/*函數(shù)名:TFT_WriteCmd*輸 入:cmd*輸 出:*功 能:寫命令。*/ void TFT_WriteCmd(uint cmd)uchar cmdH, cmdL;cmdH = cmd >
11、;> 8;cmdL = cmd & 0x00FF;TFT_WR = 1; /初始化WRTFT_CS = 0; /打開片選TFT_RD = 1; /選擇寫TFT_RS = 0; /選擇命令TFT_DATAPORTH = cmdH; /放置命令數(shù)據(jù)TFT_DATAPORTL = cmdL; /放置命令數(shù)據(jù)TFT_WR = 0; /寫入時(shí)序TFT_WR = 1;TFT_CS = 1; /關(guān)閉片選/*函數(shù)名:TFT_WriteCmdData*輸 入:cmd, dat*輸 出:*功 能:寫命令, 寫數(shù)據(jù)。*/ void TFT_WriteData(uint dat) uchar datH,
12、 datL;datH = dat >> 8;datL = dat & 0x00FF;TFT_WR = 1; /初始化WRTFT_CS = 0; /打開片選TFT_RD = 1; /選擇寫TFT_RS = 1; /選擇發(fā)送數(shù)據(jù)TFT_DATAPORTH = datH; /放置命令數(shù)據(jù)TFT_DATAPORTL = datL; /放置命令數(shù)據(jù)TFT_WR = 0; /寫入時(shí)序TFT_WR = 1;TFT_CS = 1; /關(guān)閉片選/*函數(shù)名:TFT_Init*輸 入:*輸 出:*功 能:初始化TFT。*/ void TFT_Init(void)uint i;TFT_RST =
13、1;for(i=500; i>0; i-);TFT_RST = 0;for(i=500; i>0; i-);TFT_RST = 1;for(i=5000; i>0; i-);TFT_CS = 0;TFT_WriteCmd(0x11);TFT_WriteCmd(0xc5);TFT_WriteData(0xc5);TFT_WriteCmd(0xf0);TFT_WriteData(0x5a);TFT_WriteCmd(0xf2);TFT_WriteData(0x01);TFT_WriteCmd(0xe0);TFT_WriteData(0x00);TFT_WriteData(0x01
14、);TFT_WriteData(0x06);TFT_WriteData(0x2e);TFT_WriteData(0x2b);TFT_WriteData(0x0b);TFT_WriteData(0x1a);TFT_WriteData(0x02);TFT_WriteData(0x06);TFT_WriteData(0x05);TFT_WriteData(0x0c);TFT_WriteData(0x0d);TFT_WriteData(0x00);TFT_WriteData(0x05);TFT_WriteData(0x02);TFT_WriteData(0x05);TFT_WriteCmd(0xe1)
15、;TFT_WriteData(0x06);TFT_WriteData(0x23);TFT_WriteData(0x25);TFT_WriteData(0x0f);TFT_WriteData(0x0a);TFT_WriteData(0x04);TFT_WriteData(0x02);TFT_WriteData(0x1a);TFT_WriteData(0x05);TFT_WriteData(0x03);TFT_WriteData(0x06);TFT_WriteData(0x01);TFT_WriteData(0x0c);TFT_WriteData(0x0b);TFT_WriteData(0x05)
16、;TFT_WriteData(0x05);TFT_WriteCmd(0x3a);TFT_WriteData(0x05); TFT_WriteCmd(0x36); TFT_WriteData(0xC8);TFT_WriteCmd(0x29);/*函數(shù)名:TFT_SetWindow*輸 入:xStart, yStart, xEnd, yEnd*輸 出:*功 能:設(shè)置要操作的窗口。*/ void TFT_SetWindow(uchar xStart, uchar yStart, uchar xEnd, uchar yEnd) TFT_WriteCmd(0x2A); TFT_WriteData(0x0
17、0); TFT_WriteData(xStart); TFT_WriteData(0x00); TFT_WriteData(xEnd); TFT_WriteCmd(0x2b); TFT_WriteData(0x00); TFT_WriteData(yStart); TFT_WriteData(0x00); TFT_WriteData(yEnd); TFT_WriteCmd(0x2c); /*函數(shù)名:GUI_Clearcreen*輸 入:backColor*輸 出:*功 能:清屏并涂上顏色。*/ void TFT_ClearScreen(uint color) uint i, j;TFT_Set
18、Window(0, 0, TFT_XMAX, TFT_YMAX); /作用區(qū)域 for(i=0; i<=TFT_XMAX; i+)for (j=0; j<=TFT_YMAX; j+)TFT_WriteData(color);4. driver.h#ifndef _DRIVER_H#define _DRIVER_H#include <reg51.h>/-重定義關(guān)鍵詞-/#ifndef uchar#define uchar unsigned char#endif#ifndef uint#define uint unsigned int#endif/-定義使用的IO口-/sb
19、it TFT_RST = P33; /復(fù)位sbit TFT_CS = P32; /片選sbit TFT_RS = P27; /數(shù)據(jù)命令選擇端sbit TFT_WR = P26; /讀寫控制sbit TFT_RD = P25; /讀寫控制#define TFT_DATAPORTH P1 /放置高8位數(shù)據(jù)#define TFT_DATAPORTL P0/-定義屏的大小-/#define TFT_XMAX (uchar)175)/設(shè)置TFT屏的大小#define TFT_YMAX (uchar)219)/-定義顏色的宏-/#define WHITE 0xFFFF#define BLACK 0x000
20、0#define BLUE 0x001F#define RED 0xF800#define MAGENTA 0xF81F#define GREEN 0x07E0#define CYAN 0x7FFF#define YELLOW 0xFFE0 /定義顏色的宏/- 聲明全局函數(shù) -/void TFT_WriteCmd(uint cmd);void TFT_WriteData(uint dat);void TFT_Init(void);void TFT_SetWindow(uchar xStart, uchar yStart, uchar xEnd, uchar yEnd);void TFT_Cle
21、arScreen(uint color);#endif5.gui.h#ifndef _GUI_H_#define _GUI_H_#include"driver.h"#define USE_ASCIIvoid GUI_WriteASCII(uchar x, uchar y, uchar p, uint wordColor, uint backColor);#endif6.charcode.h#ifndef _CHARCODE_H#define _CHARCODE_H#ifdef USE_ASCIIconst unsigned char code ASCII16x241148
22、= /*- 文字: 0 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x19,0x80,0x30,0xC0,0x30,0xC0,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x30,0xC0,0x30,0xC0,0x19,0x80,0x0F,0x00,0x00,0x00,
23、0x00,0x00,0x00,0x00,/*- 文字: 1 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x06,0x00,0x3E,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x
24、3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,/*- 文字: 2 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x21,0x80,0x40,0xC0,0x60,0xC0,0x60,0xC0,0x00,0xC0,0x01,0x80,0x01,0x80,0x03,0x00,0x04,0x00,0x08,0x00,0x10,0x40,0x20,0x40,0x40
25、,0x40,0x7F,0xC0,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,/*- 文字: 3 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x23,0x00,0x61,0x80,0x61,0x80,0x61,0x80,0x01,0x80,0x03,0x00,0x0E,0x00,0x01,0x80,0x00,0x80,0x00,0xC0,0x60,0
26、xC0,0x60,0xC0,0x60,0xC0,0x21,0x80,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ,/*- 文字: 4 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x80,0x03,0x80,0x03,0x80,0x05,0x80,0x09,0x80,0x09,0x80,0x11,0x80,0x21,0x80,0x21,0x80,0x41,0
27、x80,0x7F,0xE0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, ,/*- 文字: 5 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xC0,0x3F,0xC0,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x2F,0x00,0x31,0
28、x80,0x20,0xC0,0x00,0xC0,0x00,0xC0,0x60,0xC0,0x60,0xC0,0x41,0x80,0x21,0x80,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ,/*- 文字: 6 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x18,0xC0,0x30,0xC0,0x30,0x00,0x20,0x00,0x60,0
29、x00,0x67,0x80,0x68,0xC0,0x70,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x20,0x60,0x30,0x40,0x18,0xC0,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ,/*- 文字: 7 -*/*- 宋體18; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x24 -*/*- 寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=16x24 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xE0,0x3F,0xE0,0x30,0x40,0x20,0x80,0x20,0x80,0x00,0x80,0x01,0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 掛面合同買賣合同范例
- 二手車無(wú)手續(xù)轉(zhuǎn)讓合同范例
- 弟弟贍養(yǎng)姐姐合同范例
- 小食堂勞務(wù)合同范例
- 粘結(jié)砂漿采購(gòu)合同范例
- 口紅買賣合同范例
- 私人建房施工合同范例
- 混凝土商貿(mào)公司合同范例
- 加工鑄造用工合同范例
- 湖北省十堰市張灣區(qū)東風(fēng)高中2025屆高考沖刺模擬數(shù)學(xué)試題含解析
- 三年級(jí)上冊(cè)道德與法治第5課《走近我們的老師》教案教學(xué)設(shè)計(jì)(第一課時(shí))
- 《管理學(xué)-原理與方法》歷年考試真題試題庫(kù)(含答案)
- 機(jī)電安全風(fēng)險(xiǎn)辨識(shí)評(píng)估分級(jí)管控清單
- 夫妻股權(quán)轉(zhuǎn)讓合同協(xié)議書
- 2024-2025學(xué)年粵教版信息技術(shù)必修一《1.2數(shù)據(jù)編碼》教學(xué)設(shè)計(jì)
- 部編版道德與法治二年級(jí)上冊(cè)全單元教案
- 2023年度學(xué)校食堂食品從業(yè)人員考核試題(附答案)
- 媽媽課堂系列醫(yī)生講課文檔
- 新教材高中英語(yǔ)UNIT6NURTURINGNATURE單元復(fù)習(xí)與提升課件外研版選擇性必修第一冊(cè)
- 2024年新華社招考應(yīng)屆高校畢業(yè)生(高頻重點(diǎn)提升專題訓(xùn)練)共500題附帶答案詳解
- 日常消防安全巡檢記錄表
評(píng)論
0/150
提交評(píng)論