毕业设计单片机液晶显示器多功能显示Word文档格式.docx
《毕业设计单片机液晶显示器多功能显示Word文档格式.docx》由会员分享,可在线阅读,更多相关《毕业设计单片机液晶显示器多功能显示Word文档格式.docx(19页珍藏版)》请在冰豆网上搜索。
3按下KS3可以看到一副图片。
第二章原理介绍
3.1.汉字显示原理
汉字的显示一般采用图形的方式,事先从微机中提取要显示的汉字的点阵码(一般用字模提取软件),每个汉字占32B,分左右两半,各占16B,左边为1、3、5……右边为2、4、6……根据在LCD上开始显示的行列号及每行的列数可找出显示RAM对应的地址,设立光标,送上要显示的汉字的第一字节,光标位置加1,送第二个字节,换行按列对齐,送第三个字节……直到32B显示完就可以LCD上得到一个完整汉字。
跟汉字一样,只不过它的宽和高不再是个定值,而是一个变量,把高先分成8的倍数,然后一行一行扫描,不足的补零。
3.3.1概述
DS1302是DALLAS公司推出的涓流充电时钟芯片内含有一个实时时钟/日历和31字节静态RAM通过简
单的串行接口与单片机进行通信实时时钟/日历电路提供秒分时日日期月年的信息每月的天
数和闰年的天数可自动调整时钟操作可通过AM/PM指示决定采用24或12小时格式DS1302与单片机之
间能简单地采用同步串行的方式进行通信仅需用到三个口线1RES复位2I/O数据线3SCLK
串行时钟时钟/RAM的读/写数据以一个字节或多达31个字节的字符组方式通信DS1302工作时功耗很低保持数据和时钟信息时功率小于1mW
DS1302是由DS1202改进而来增加了以下的特性双电源管脚用于主电源和备份电源供应Vcc1为可
编程涓流充电电源附加七个字节存储器它广泛应用于电话传真便携式仪器以及电池供电的仪器仪表等
产品领域下面将主要的性能指标作一综合
实时时钟具有能计算2100年之前的秒分时日日期星期月年的能力还有闰年调整的能力
318位暂存数据存储RAM
串行I/O口方式使得管脚数量最少
宽范围工作电压2.05.5V
工作电流2.0V时,小于300nA
读/写时钟或RAM数据时有两种传送方式单字节传送和多字节传送字符组方式
8脚DIP封装或可选的8脚SOIC封装根据表面装配
简单3线接口
与TTL兼容Vcc=5V
可选工业级温度范围-40+85
与DS1202兼容
在DS1202基础上增加的特性
对Vcc1有可选的涓流充电能力
双电源管用于主电源和备份电源供应
3.3.2管脚接线
X1X232.768KHz晶振管脚
GND地
RST复位脚
I/O数据输入/输出引脚
SCLK串行时钟
Vcc1,Vcc2电源供电管脚
3.3.4内部寄存器
CH:
时钟停止位寄存器2的第7位12/24小时标志
CH=0振荡器工作允许bit7=1,12小时模式
CH=1振荡器停止bit7=0,24小时模式
WP:
写保护位寄存器2的第5位:
AM/PM定义
WP=0寄存器数据能够写入AP=1下午模式
WP=1寄存器数据不能写入AP=0上午模式
TCS:
涓流充电选择DS:
二极管选择位
TCS=1010使能涓流充电DS=01选择一个二极管
TCS=其它禁止涓流充电DS=10选择两个二极管
DS=00或11,即使TCS=1010,充电功能也被禁止
3.3.4数据寄存器地址
80h秒单元内容为59h
82h分单元内容为59h
84h时单元内容为13h
86h日期单元内容为21h
88h月单元内容为06h
8ch年单元内容为00h
第三章程序
#include"
nokia_5110.h"
bmp_pixel.h"
ds1302.h"
unsignedchargettimebuf[7];
unsignedcharsettimebuf[7];
unsignedchartime1[]={"
am:
:
"
};
unsignedchardate[]={"
20--"
sbitKS1=P0^0;
sbitKS2=P0^1;
sbitKS3=P3^7;
//***********************************
#definedelay_time25767
unsignedchart[4];
unsignedcharx[2];
voiddelay(unsignedintx)
{
unsignedinty,z;
for(y=0;
y<
x;
y++);
for(z=110;
z>
0;
z--);
}
voidshijian(void)
{ds1302int(0x10,0x10,0x5,0x15,0x49,0x01);
LCD_init();
LCD_clear();
while
(1)
{gettimebuf[0]=read_1302(0x81);
time1[6]=(gettimebuf[0])/16+48;
time1[7]=(gettimebuf[0])%16+48;
delay(50);
gettimebuf[1]=read_1302(0x83);
time1[3]=(gettimebuf[1])/16+48;
time1[4]=(gettimebuf[1])%16+48;
gettimebuf[2]=read_1302(0x85);
time1[0]=(gettimebuf[2])/16+48;
time1[1]=(gettimebuf[2])%16+48;
LCD_write_english_string(0,1,time1+0);
delay(50);
LCD_write_english_string(6,1,time1+1);
gettimebuf[3]=read_1302(0x87);
date[8]=(gettimebuf[3])/16+48;
date[9]=(gettimebuf[3])%16+48;
gettimebuf[4]=read_1302(0x89);
date[5]=(gettimebuf[4])/16+48;
date[6]=(gettimebuf[4])%16+48;
gettimebuf[5]=read_1302(0x8d);
date[2]=(gettimebuf[5])/16+48;
date[3]=(gettimebuf[5])%16+48;
LCD_write_english_string(0,0,date+0);
delay(50);
LCD_write_english_string(6,0,date+1);
}
voidhanzi(void)
{LCD_write_chinese_string(0,2,12,3,0,1);
LCD_write_chinese_string(1,4,12,6,3,2);
chinese_string(0,0,30000);
voidmain(void)
unsignedinti;
//初始化液晶
BELL=0;
LCD_LED=1;
while
(1)
{
P0=0xff;
KS3=1;
KS1=0;
i=P0;
switch(i)
{
case0xfa:
delay(100);
if(i==0xfa){LCD_clear();
hanzi();
}break;
case0xf6:
if(i==0xf6){LCD_clear();
shijian();
case0xee:
if(i==0xee){LCD_clear();
LCD_draw_bmp_pixel(0,0,bmp,84,48);
default:
break;
}
delay(100);
}
english_6x8_pixel.h"
write_chinese_string_pixel.h"
move_chinese_string_pixel.h"
/*-----------------------------------------------------------------------
LCD_init:
3310LCD初始化
编写日期:
2009-5-1
最后修改日期:
-----------------------------------------------------------------------*/
voiddelay_1us(void)//1us延时函数
for(i=0;
i<
1000;
i++);
voiddelay_1ms(void)//1ms延时函数
for(i=0;
1140;
voiddelay_nms(unsignedintn)//Nms延时函数
unsignedinti=0;
n;
i++)
delay_1ms();
voidLCD_init(void)
//产生一个让LCD复位的低电平脉冲
LCD_RST=0;
delay_1us();
LCD_RST=1;
//关闭LCD
LCD_CE=0;
//使能LCD
LCD_CE=1;
LCD_write_byte(0x21,0);
//使用扩展命令设置LCD模式
LCD_write_byte(0xc8,0);
//设置偏置电压
LCD_write_byte(0x06,0);
//温度校正
LCD_write_byte(0x13,0);
//1:
48
LCD_write_byte(0x20,0);
//使用基本命令
//清屏
LCD_write_byte(0x0c,0);
//设定显示模式,正常显示
//关闭LCD
LCD_clear:
LCD清屏函数
voidLCD_clear(void)
LCD_write_byte(0x80,0);
i<
504;
i++)
LCD_write_byte(0,1);
LCD_set_XY:
设置LCD坐标函数
输入参数:
X:
0-83
Y:
0-5
voidLCD_set_XY(unsignedcharX,unsignedcharY)
LCD_write_byte(0x40|Y,0);
//column
LCD_write_byte(0x80|X,0);
//row
LCD_write_char:
显示英文字符
c:
显示的字符;
voidLCD_write_char(unsignedcharc)
unsignedcharline;
c-=32;
for(line=0;
line<
6;
line++)
LCD_write_byte(font6x8[c][line],1);
LCD_write_english_String:
英文字符串显示函数
*s:
英文字符串指针;
X、Y:
显示字符串的位置,x0-83,y0-5
2009-5-1
voidLCD_write_english_string(unsignedcharX,unsignedcharY,char*s)
LCD_set_XY(X,Y);
while(*s)
LCD_write_char(*s);
s++;
LCD_write_chinese_string:
在LCD上显示汉字
X、Y:
显示汉字的起始X、Y坐标;
ch_with:
汉字点阵的宽度
num:
显示汉字的个数;
line:
汉字点阵数组中的起始行数
row:
汉字显示的行间距
2009-5-1
测试:
LCD_write_chi(0,0,12,7,0,0);
LCD_write_chi(0,2,12,7,0,0);
LCD_write_chi(0,4,12,7,0,0);
-----------------------------------------------------------------------*/
voidLCD_write_chinese_string(unsignedcharX,unsignedcharY,
unsignedcharch_with,unsignedcharnum,
unsignedcharline,unsignedcharrow)
unsignedchari,n;
//设置初始位置
num;
)
for(n=0;
n<
ch_with*2;
n++)//写一个汉字
{
if(n==ch_with)//写汉字的下半部分
if(i==0)LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
LCD_write_byte(write_chinese[line+i][n],1);
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
LCD_move_chinese_string:
汉字移动
T:
移动速度;
2009-5-2
voidchinese_string(unsignedcharX,unsignedcharY,unsignedcharT)
unsignedchari,n,j=0;
unsignedcharbuffer_h[84]={0};
unsignedcharbuffer_l[84]={0};
130;
buffer_h[83]=move_chinese_string[i/12][j];
buffer_l[83]=move_chinese_string[i/12][j+12];
j++;
if(j==12)j=0;
for(n=0;
83;
n++)
{
buffer_h[n]=buffer_h[n+1];
buffer_l[n]=buffer_l[n+1];
LCD_write_byte(buffer_h[n],1);
LCD_set_XY(X,Y+1);
LCD_write_byte(buffer_l[n],1);
delay_nms(T);
LCD_draw_map:
位图绘制函数
位图绘制的起始X、Y坐标;
*map:
位图点阵数据;
Pix_x:
位图像素(长)
Pix_y:
位图像素(宽)
voidLCD_draw_bmp_pixel(unsignedcharX,unsignedcharY,unsignedchar*map,
unsignedcharPix_x,unsignedcharPix_y)
unsignedinti,n;
unsignedcharrow;
if(Pix_y%8==0)row=Pix_y/8;
//计算位图所占行数
else
row=Pix_y/8+1;
n<
row;
n++)
LCD_set_XY(X,Y);
Pix_x;
LCD_write_byte(map[i+n*Pix_x],1);
Y++;
//换行
LCD_write_byte:
使用SPI接口写数据到LCD
data:
写入的数据;
command:
写数据/命令选择;
voidLCD_write_byte(unsignedchardat,unsignedcharcommand)
unsignedchari;
//PORTB&
=~LCD_CE;
if(command==0)
//PORTB