液晶12864漢字顯示程序及顯示順序正常的C語言程序
液晶12864顯示漢字程序,經(jīng)過調(diào)試發(fā)現(xiàn),兩個(gè)漢字行中間隔一行,為了達(dá)到不隔行的目的,我拆分開來,這樣分4行分別顯示,就達(dá)到了,代碼雖然多,但簡單,可以通過復(fù)制粘貼達(dá)到效果。
以下為行行正確顯示漢字的C程序,想顯示什么,改掉那些初始字就可以了。
#include
#include
#include
#include
sbit RS=P2^4;
sbit WRD=P2^5;
sbit E=P2^6;
sbit PSB=P2^1;
sbit RES=P2^3;
void TransferData(char data1,bit DI);
void delayms(unsigned int n);
void delay(unsigned int m);
void lcd_mesg(unsigned char code *addr1);
void lcd_mesg2(unsigned char code *addr1);
void lcd_mesg3(unsigned char code *addr1);
void lcd_mesg4(unsigned char code *addr1);
//漢字定義,8個(gè)漢字或是16個(gè)字符,一行。
unsigned char code IC_DAT[]={
"我我我我我我我我"};
unsigned char code IC_DAT2[]={
"是是是是是是是是"};
unsigned char code IC_DAT3[]={
"中中中中中中中中"};
unsigned char code IC_DAT4[]={
"國國國國國國國國"};
unsigned char code IC_DAT5[]={
"人人人人人人人人"};
unsigned char code IC_DAT6[]={
"當(dāng)當(dāng)當(dāng)當(dāng)當(dāng)當(dāng)當(dāng)當(dāng)"};
unsigned char code IC_DAT7[]={
"自自自自自自自自"};
unsigned char code IC_DAT8[]={
"強(qiáng)強(qiáng)強(qiáng)強(qiáng)強(qiáng)強(qiáng)強(qiáng)強(qiáng)"};
//程序要初始化,即液晶12864要初始化。
void initinal(void)
{
delay(40);
PSB=1; //并口工作模式
delay(1);
RES=0; //復(fù)位
delay(1);
RES=1; //復(fù)位置高
delay(10);
TransferData(0x30,0);
delay(100);
TransferData(0x30,0);
delay(37);
TransferData(0x08,0);
delay(100);
TransferData(0x10,0);
delay(100);
TransferData(0x0C,0);
delay(100);
TransferData(0x01,0);
delay(10);
TransferData(0x06,0);
delay(100);
}
void main(void) //分兩屏顯示漢字。
{
while(1)
{
initinal();//調(diào)用LCD字庫初始化程序
delay(100);
lcd_mesg(IC_DAT);
lcd_mesg2(IC_DAT2);
lcd_mesg3(IC_DAT3);
lcd_mesg4(IC_DAT4);
delayms(240);
delayms(240);
initinal();
delay(100);
lcd_mesg(IC_DAT5);
lcd_mesg2(IC_DAT6);
lcd_mesg3(IC_DAT7);
lcd_mesg4(IC_DAT8);
delayms(240);
delayms(240);
}
}
//顯示時(shí),由于地址不同,顯示所在行不同,這里分別列出四行的地址。
void lcd_mesg(unsigned char code *addr1)
{
unsigned char i;
//第一行
TransferData(0x80,0);
delay(100);
for(i=0;i<16;i++)
{
TransferData(*addr1,1);
addr1++;
}
}
void lcd_mesg2(unsigned char code *addr1)
{
unsigned char i;
//第一行
TransferData(0x90,0);
delay(100);
for(i=0;i<16;i++)
{
TransferData(*addr1,1);
addr1++;
}
}
void lcd_mesg3(unsigned char code *addr1)
{
unsigned char i;
//第一行
TransferData(0x88,0);
delay(100);
for(i=0;i<16;i++)
{
TransferData(*addr1,1);
addr1++;
}
}
void lcd_mesg4(unsigned char code *addr1)
{
unsigned char i;
//顯示一行
TransferData(0x98,0);
delay(100);
for(i=0;i<16;i++)
{
TransferData(*addr1,1);
addr1++;
}
}
void TransferData(char data1,bit DI) //傳送數(shù)據(jù)或是命令,當(dāng)DI=0時(shí),傳送命令,當(dāng)DI=1時(shí),傳送數(shù)據(jù)
{
WRD=0;
RS=DI;
delay(1);
P0=data1;
E=1;
delay(1);
E=0;
}
void delayms(unsigned int n)
{
unsigned int i,j;
for(i=0;i
}
void delay(unsigned int m)
{
unsigned int i,j;
for(i=0;i
}
以上程序在AT89s52單片機(jī)+帶字庫12864液晶上調(diào)試OK。