单片机与液晶显示器的接口应用介绍
*0x02);
Write_LCD_Cmd(0x40); }
//设定图形页首地址子程序
void Graph_Home_Address(unsigned char gpage)
{
gpage+= 2;
Write_LCD_Data(0);
Write_LCD_Data(gpage*0x10);
Write_LCD_Cmd(0x42); }
//设定文本页地址子程序
void Text_Address(unsigned char x, unsigned char y)
{
extern unsigned char textpage;
unsigned int xy;
xy=y*32+x+textpage*0x0200;
Write_LCD_Data(xy&0xff);
Write_LCD_Data(xy/256);
Write_LCD_Cmd(0x24);
}
//设定图形页地址子程序
void Graph_Address(unsigned char x,
unsigned char y)
{
extern unsigned char graphpage; unsigned int xy;
graphpage+=2;
xy=y*32+x+graphpage*0x1000;
Write_LCD_Data(xy&0xff);
Write_LCD_Data(xy/256);
Write_LCD_Cmd(0x24);
}
//初始化子程序
void Init_LCD(void)
{
Write_LCD_Cmd(0x90);
Write_LCD_Data(0x20);
Write_LCD_Data(0x00);
Write_LCD_Cmd(0x41);
Write_LCD_Data(0x20);
Write_LCD_Data(0x00);
Write_LCD_Cmd(0x43);
Write_LCD_Cmd(0x89);
Write_LCD_Cmd(0xa1);
Write_LCD_Data(0x0F);
Write_LCD_Data(0x00);
Write_LCD_Cmd(0x22);
Write_LCD_Cmd(0x9c);
}
3 汉字、字符和图形的显示程序
通过调用前面编写的驱动、初始化和清屏程序就可以方便的实现汉字、字符和图形的显示。本文以汉字显示为例介绍显示程序的编制。汉字既可以以文本方式显示也可以以图形方式显示。以文本方式显示时,每次开机都要先把汉字字模写进液晶显示模块的CGRAM,浪费了时间,而且由于CGRAM的容量只有2kb,显示的汉字有限,所以一般用图形方式显示汉字。以图形方式显示时先把汉字字模写在Flash存储器中,显示时再从Flash存储器中取出来,这样不用每次开机时都写汉字字模,节约时间,而且显示的汉字数量多。下面给出以图形方式显示汉字的通用子程序。汉字字模存储在Flash存储器中。
void put_hanzi (char c)
{
unsigned char kk=c;
unsigned int order;
unsigned int aaa;
static unsigned char previous=0x00;
if(previous==0) previous=c;
else
{
order=((unsigned int)
(previous-0xa1)*94+kk-0xa1);
previous=order%8;
aaa=32*previous;
order=order/8;
SCON=0;
SBUF=concode[0x52];
kk=order/128;
while(!TI);
SCON=0;
SBUF=concode[kk]; kk=order%128;
kk<<=1;
while(!TI);
SCON=0;
SBUF=concode[kk]; kk=aaa%256;
while(!TI);
SCON=0;
SBUF=concode[kk]; for(kk=0;kk<4;kk++)
{
while(!TI);
SCON=0;
SBUF=concode[0xff]; }
while(!TI);
SCON=0x10;
for (kk=0;kk<16;kk++)
{
Graph_Address(x,y*8+kk);
while(!RI);
previous=SBUF;
SCON=0x10;
write_lcd(concode[previous]);
ctrl(0xc0);
while(!RI);
previous=SBUF;
SCON=0x10;
write_lcd(concode[
- RS232、RS485和RS422介绍与比较(12-14)
- ARM处理器模式介绍和模式切换(11-28)
- EZ-USB FX2单片机CY7C68013的特性介绍(10-15)
- MCS-51单片机的中央处理器CPU介绍(05-13)
- PIC12F683微控制器实验板介绍(11-10)
- 详细介绍用51单片机解密任何红外遥控器(10-23)