單片機與液晶顯示器的接口及應用
本文引用地址:http://m.butianyuan.cn/article/170790.htm
//設定圖形頁地址子程序
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(xy0xff);
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 漢字、字符和圖形的顯示程序
通過調用前面編寫的驅動、初始化和清屏程序就可以方便的實現(xiàn)漢字、字符和圖形的顯示。本文以漢字顯示為例介紹顯示程序的編制。漢字既可以以文本方式顯示也可以以圖形方式顯示。以文本方式顯示時,每次開機都要先把漢字字模寫進液晶顯示模塊的CGRAM,浪費了時間,而且由于CGRAM的容量只有2kb,顯示的漢字有限,所以一般用圖形方式顯示漢字。以圖形方式顯示時先把漢字字模寫在Flash存儲器中,顯示時再從Flash存儲器中取出來,這樣不用每次開機時都寫漢字字模,節(jié)約時間,而且顯示的漢字數(shù)量多。下面給出以圖形方式顯示漢字的通用子程序。漢字字模存儲在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];
評論