单片机之LCD显示原理Word格式.docx

上传人:b****5 文档编号:19950606 上传时间:2023-01-12 格式:DOCX 页数:10 大小:388.40KB
下载 相关 举报
单片机之LCD显示原理Word格式.docx_第1页
第1页 / 共10页
单片机之LCD显示原理Word格式.docx_第2页
第2页 / 共10页
单片机之LCD显示原理Word格式.docx_第3页
第3页 / 共10页
单片机之LCD显示原理Word格式.docx_第4页
第4页 / 共10页
单片机之LCD显示原理Word格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

单片机之LCD显示原理Word格式.docx

《单片机之LCD显示原理Word格式.docx》由会员分享,可在线阅读,更多相关《单片机之LCD显示原理Word格式.docx(10页珍藏版)》请在冰豆网上搜索。

单片机之LCD显示原理Word格式.docx

具体电路图:

接口说明:

运行:

用户自定义字符的应用:

我们从CGROM表上可以看到,在表的最左边是一列可以允许用户自定义的CGRAM,从上往下看着是16个,实际只有8个字节可用。

它的字符码是00000000-00000111这8个地址,表的下面还有8个字节,但因为这个CGRAM的字符码规定0-2位为地址,3位无效,4-7全为零。

因此CGRAM的字符码只有最后三位能用也就是8个字节了。

等效为0000X111,X为无效位,最后三位为000-111共8个。

如果我们要想显示这8个用户自定义的字符,操作方法和显示CGROM的一样,先设置DDRAM位置,再向DDRAM写入字符码,例如“A”就是41H。

现在我们要显示CGRAM的第一个自定义字符,就向DDRAM写入00000000B(00H),如果要显示第8个就写入00000111(08H),简单吧!

好!

现在我们来看怎么向这八个自定义字符写入字模。

有个设置CGRAM地址的指令大家还记得吗?

赶快再找出来看看。

 

从这个指令可以看出指令数据的高2位已固定是01,只有后面的6位是地址数据,而这6位中的高3位就表示这八个自定义字符,最后的3位就是字模数据的八个地址了。

例如第一个自定义字符的字模地址为01000000-01000111八个地址。

我们向这8个字节写入字模数据,让它能显示出“℃”

地址:

01000000  数据:

00010000 

图示:

○○○■○○○○

   01000001     00000110 

○○○○○■■○

   01000010     00001001 

○○○○■○○■

   01000011     00001000 

○○○○■○○○

   01000100     00001000 

   01000101     00001001 

   01000110     00000110 

   01000111     00000000 

○○○○○○○○

下面我们写一段程序让这8个自定义字符显示出一个心的图案:

#include<

reg51.h>

unsignedchartable1[]={0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,

0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,

0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,

0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,

0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,

0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,

0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,

0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00};

//心图案

unsignedchartable[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00};

//字符℃

#define 

CLEARSCREEN 

LCD_write_command(0x01)

/**************定义接口************************/

LCDIO 

P2

sbitLCD1602_RS=P3^0;

sbitLCD1602_RW=P3^1;

sbitLCD1602_EN=P3^2;

/**************定义函数************************/

voidLCD_write_command(unsignedcharcommand);

//写入指令函数

voidLCD_write_dat(unsignedchardat);

//写入数据函数

voidLCD_set_xy(unsignedcharx,unsignedchary);

//设置显示位置函数

voidLCD_dsp_char(unsignedx,unsignedchary,unsignedchardat);

//显示一个字符函数

voidLCD_dsp_string(unsignedcharX,unsignedcharY,unsignedchar*s);

//显示字符串函数

voidLCD_init(void);

//初始化函数

voiddelay_nms(unsignedintn);

//延时函数

/********************************************/

/************初始化函数****************/

voidLCD_init(void)

{

CLEARSCREEN;

//clearscreen

LCD_write_command(0x38);

//set8bitdatatransmissionmode

LCD_write_command(0x0c);

//opendisplay(enablelcddisplay)

LCD_write_command(0x80);

//setlcdfirstdisplayaddress

//clearscreen

}

/****************************************************/

/**************写指令函数********************************/ 

voidLCD_write_command(unsignedcharcommand)

{

LCDIO=command;

LCD1602_RS=0;

LCD1602_RW=0;

LCD1602_EN=0;

LCD1602_EN=1;

delay_nms(10);

/***************************************************/

/****************写数据函数************************/

voidLCD_write_dat(unsignedchardat)

LCDIO=dat;

LCD1602_RS=1;

LCD1602_RW=0;

LCD1602_EN=0;

delay_nms

(1);

LCD1602_EN=1;

/***************设置显示位置**************************/

voidLCD_set_xy(unsignedcharx,unsignedchary)

unsignedcharaddress;

if(y==1)

address=0x80+x;

else

address=0xc0+x;

LCD_write_command(address);

/****************显示一个字符**********************/

voidLCD_dsp_char(unsignedx,unsignedchary,unsignedchardat)

LCD_set_xy(x,y);

LCD_write_dat(dat);

/**********************************************/

/***************显示字符串函数***************/

voidLCD_dsp_string(unsignedcharX,unsignedcharY,unsignedchar*s)

LCD_set_xy(X,Y);

while(*s) 

{

LCD_write_dat(*s);

s++;

}

/***********************************************/

/**********延时**********************/

voiddelay_nms(unsignedintn) 

unsignedinti=0,j=0;

for(i=n;

i>

0;

i--)

for(j=0;

j<

10;

j++);

/**************************************/

/***********主函数**************/

voidmain(void)

unsignedchari,j,k,tmp;

LCD_init();

delay_nms(100);

tmp=0x40;

//设置CGRAM地址的格式字

k=0;

for(j=0;

8;

j++)

for(i=0;

i<

i++)

LCD_write_command(tmp+i);

//设置自定义字符的CGRAM地址 

delay_nms

(2);

LCD_write_dat(table1[k]);

//向CGRAM写入自定义字符表的数据

k++;

tmp=tmp+8;

LCD_dsp_string(1,1,"

LCDTEST 

"

);

//在第一行第一列显示“LCDTEST”

LCD_dsp_string(1,2,"

SUCCESSFUL 

//在第二行第一列显示“SUCCESSFUL”

for(i=0;

4;

LCD_dsp_char(12+i,1,i);

//在第一行第12列位置显示心图案的上半部

delay_nms

(1);

for(i=4;

LCD_dsp_char(12+i-4,2,i);

在第二行第12列位置显示心图案的下半部

while

(1);

/********************************************************************/

实际效果如图:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 建筑土木

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1