帶字庫型12864液晶的簡單使用
這是演示效果,第一行“請您欣賞”上自定義的仿宋字體,下面三行是字庫中自帶的漢字(手機(jī)拍攝的效果不太好)。
下面是我寫的源程序,(由于水平有限,程序?qū)懛赡懿皇亲顑?yōu)的方式,希望高手批評指正):
/*********************************************************
程序:LCD12864自定義顯示字符(最多顯示4個)
內(nèi)容:ASCII碼顯示、自帶字庫顯示(8192個)、自定義顯示字符(4個請您欣賞)。
軟件:keil uVision4
液晶:QYLCD12864HZ1(帶字庫)
學(xué)習(xí)板:HOT-51學(xué)習(xí)板
作者:張家越
整理日期:2011-04-09 17:00
*************************************************************/
#includeAT89X52.h>
#define uchar unsigned char
#define uint unsigned int//定義一下,方便使用
#include"word1.h"
sbit RS=P2^5;
sbit RW=P2^6;
sbit EN=P2^7;//液晶的三個控制端
//sbit PSB=P2^4;//1---8位或4位并口方式;0---串口方式。單片機(jī)上電高電平,選擇的是并口方式
uchar code tab1[]=" LCD12864 ";
uchar code tab2[]="湖北第二師范學(xué)院";
uchar code tab3[]="電子愛好者張家越";
unsigned char code table1[][32] =
{
/*-- 文字: 請 --*/
/*-- 仿宋_GB231212; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
{
0x00,0x40,0x20,0x70,0x13,0xC0,0x10,0x70,0x01,0xC0,0x00,0x7C,0x77,0x80,0x10,0x70,
0x13,0x90,0x12,0x70,0x13,0x90,0x1A,0x70,0x13,0x90,0x02,0x30,0x02,0x10,0x00,0x00,
},
/*-- 文字: 您 --*/
/*-- 仿宋_GB231212; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
{
0x01,0x00,0x09,0x00,0x09,0x38,0x13,0xC8,0x34,0x50,0x51,0x40,0x12,0x50,0x14,0xC8,
0x10,0x40,0x02,0x00,0x21,0x10,0x29,0x08,0x24,0x08,0x42,0x20,0x01,0xE0,0x00,0x00,
},
/*-- 文字: 欣 --*/
/*-- 仿宋_GB231212; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
{
0x00,0x40,0x06,0x40,0x38,0x40,0x20,0x40,0x20,0x7C,0x26,0x88,0x3C,0x80,0x25,0x40,
0x24,0x40,0x24,0x40,0x24,0x40,0x24,0xA0,0x44,0xA0,0x45,0x10,0x82,0x1C,0x00,0x00,
},
/*-- 文字: 賞 --*/
/*-- 仿宋_GB231212; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
{
0x01,0x10,0x09,0x20,0x05,0xFC,0x3E,0x08,0x21,0xC0,0x0E,0x40,0x09,0xC0,0x0E,0x00,
0x00,0xE0,0x0F,0x20,0x09,0x20,0x09,0x20,0x0A,0x20,0x04,0xC0,0x18,0x30,0x00,0x00,
},
} ;
// 漢字表:
// 天道酬勤
void delay(uint i)//延時函數(shù)
{
while(--i);
}
void read_busy()//讀忙標(biāo)志 最高位為1則busy,不能進(jìn)行讀寫操作
{
RS=0;
RW=1;
EN=1;//看時序
while(P0 0x80);
EN=0;
}
void write_LCD_command(uchar value) //寫命令函數(shù)
{
read_busy();//每次讀寫都要進(jìn)行讀忙標(biāo)志
RS=0;
RW=0;
delay(200);
EN=1;//EN從1--0鎖存數(shù)據(jù)
P0=value;
delay(200);
EN=0;
}
void write_LCD_data(uchar value)//寫數(shù)據(jù)函數(shù)
{
read_busy();
RS=1;
RW=0;
delay(200);
EN=1;//EN從1--0鎖存數(shù)據(jù)
P0=value;
delay(200);
EN=0;
}
void init_LCD()//8位并口方式LCD1864初始化函數(shù)
{
delay(4000);//等待時間>40ms
write_LCD_command(0x30);//功能設(shè)定:8位數(shù)據(jù)、基本指令操作
delay(100);//等待時間>100us
write_LCD_command(0x30);//功能設(shè)定:8位數(shù)據(jù)、基本指令操作
delay(37);//等待時間>37us
write_LCD_command(0x0C);//顯示設(shè)定:整體顯示、游標(biāo)關(guān)、不反白
delay(100);// 等待時間>100us
write_LCD_command(0x01);//清屏指令
delay(10000);//等待時間>10ms
write_LCD_command(0x06);//進(jìn)入點設(shè)定:地址指針加1
}
/*=============================================
自定義漢字函數(shù):CGRAM自定義顯示字符
地址顯示編碼
0x400x0000
0x500x0002
0x600x0004
0x700x0006
共可顯示四個自定義字符!
顯示自定義字符前,先要設(shè)定顯示的位置,否則會亂碼
==============================================*/
void CGRAM()
{
uchar i;
write_LCD_command(0x30);//基本指令操作
write_LCD_command(0x40);//設(shè)定CGRAM字符的位置
for(i=0;i16;i++)
{
write_LCD_data(table1[0][i*2]);
write_LCD_data(table1[0][i*2+1]);//送顯示數(shù)據(jù)到CGRAM區(qū)中
}
write_LCD_command(0x50);
for(i=0;i16;i++)
{
write_LCD_data(table1[1][i*2]);
write_LCD_data(table1[1][i*2+1]);
}
write_LCD_command(0x60);
for(i=0;i16;i++)
{
write_LCD_data(table1[2][i*2]);
write_LCD_data(table1[2][i*2+1]);
}
write_LCD_command(0x70);
for(i=0;i16;i++)
{
write_LCD_data(table1[3][i*2]);
write_LCD_data(table1[3][i*2+1]);
}
}
void main()
{
//uchar num;
uchar i;
init_LCD();
write_LCD_command(0x01);
CGRAM();
write_LCD_command(0x82);
write_LCD_data(0x00);
write_LCD_data(0x00);//第一個自定義顯示字符編碼為:0x0000
write_LCD_command(0x83);
write_LCD_data(0x00);
write_LCD_data(0x02);//第一個自定義顯示字符編碼為:0x0002
write_LCD_command(0x84);
write_LCD_data(0x00);
write_LCD_data(0x04);//第一個自定義顯示字符編碼為:0x0004
write_LCD_command(0x85);
write_LCD_data(0x00);
write_LCD_data(0x06);//第一個自定義顯示字符編碼為:0x0006
delay(5000);
write_LCD_command(0x90);
//write_LCD_command(0x00);
for(i=0;i16;i++)
{
write_LCD_data(tab1[i]);
delay(5000);
}
write_LCD_command(0x88);
//write_LCD_command(0x00);
for(i=0;i16;i++)
{
write_LCD_data(tab2[i]);
delay(5000);
}
write_LCD_command(0x98);
//write_LCD_command(0x00);
for(i=0;i16;i++)
{
write_LCD_data(tab3[i]);
delay(5000);
}
while(1);
}
如果覺得我空間里面不夠詳細(xì)可以參看大海橡樹的空間:http://hi.baidu.com/echoas(里面寫的比較好)
12864圖片顯示我將在“12864使用方法(二)”中給出.。
感謝大家閱讀指教。
評論