//设定文本页首地址子程序
void Text_Home_Address(unsigned char tpage)
{
Write_LCD_Data(0);
Write_LCD_Data(tpage*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;