版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、TFT液晶显示时钟程序说明:该程序文件中包含三个.c文件和三个.h文件,方便读者理解程序的层次性和关联性。该程序的功能是利用51单片机实现逻辑控制,在液晶显示屏上显示动态时钟。1. shizhong.c (实际上是主程序):#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"/*函数名: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; /放置命令数据TFT_DATAPORTL = cmdL; /放置命令数据TFT_WR = 0; /写入时序TFT_WR = 1;TFT_CS = 1; /关闭片选/*函数名:TFT_WriteCmdData*输 入:cmd, dat*输 出:*功 能:写命令, 写数据。*/ 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; /选择发送数据TFT_DATAPORTH = datH; /放置命令数据TFT_DATAPORTL = datL; /放置命令数据TFT_WR = 0; /写入时序TFT_WR = 1;TFT_CS = 1; /关闭片选/*函数名: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);/*函数名:TFT_SetWindow*输 入:xStart, yStart, xEnd, yEnd*输 出:*功 能:设置要操作的窗口。*/ 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); /*函数名:GUI_Clearcreen*输 入:backColor*输 出:*功 能:清屏并涂上颜色。*/ void TFT_ClearScreen(uint color) uint i, j;TFT_Set
18、Window(0, 0, TFT_XMAX, TFT_YMAX); /作用区域 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>/-重定义关键词-/#ifndef uchar#define uchar unsigned char#endif#ifndef uint#define uint unsigned int#endif/-定义使用的IO口-/sb
19、it TFT_RST = P33; /复位sbit TFT_CS = P32; /片选sbit TFT_RS = P27; /数据命令选择端sbit TFT_WR = P26; /读写控制sbit TFT_RD = P25; /读写控制#define TFT_DATAPORTH P1 /放置高8位数据#define TFT_DATAPORTL P0/-定义屏的大小-/#define TFT_XMAX (uchar)175)/设置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 /定义颜色的宏/- 声明全局函数 -/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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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; 此字体下对应的点阵为:宽x高=12x24 -*/*- 宽度不是8的倍数,现调整为:宽度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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大学学术中心宣传部工作计划学校工作计划
- hr个人年度工作计划范文
- 2024银行金融行业员工工作计划
- 2024职高教师学期工作计划范文
- 血透室护理工作计划范本血透室年度工作计划
- 2024学校采购工作计划学校工作计划
- 2024教师个人进修计划范文
- 2024学年度小学语文人教版五年级教学计划
- 团委书记个人工作计划模板
- 小学常识组教研计划
- 三年级下册口算天天100题(A4打印版)
- 妇产科学之异常分娩护理课件
- 肺腺癌护理查房
- 设备部常用维修工具使用课件
- 重大事故隐患检查表
- 公路工程资料整理
- 顶管工程施工中的施工质量控制
- 广东省广州市白云区2023-2024学年九年级上学期期末化学试题
- 《美术的主要分类》课件
- 《晶体缺陷》课件
- 2024年内蒙古包钢集团招聘笔试参考题库含答案解析
评论
0/150
提交评论