确定12864有中文字库
单片机源程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis1[]={"姓名: 我爱你"};
uchar code dis2[]={"性别: 男"};
uchar code dis3[]={"工号: 119137"};
uchar code dis4[]={"www.szu.edu.cn"};
sbit LCD_RS=P0^7;
sbit LCD_RW=P0^6;
sbit LCD_EN=P0^5;
sbit LCD_PSB=P0^4;
sbit LCD_RST=P0^3;
void delay_1ms(uint x) //1ms延迟函数
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<148;i++);
}
void write_cmd(uchar cmd)//发送命令
{
LCD_RW=0;
LCD_RS=0;
P2=cmd;
delay_1ms(1);
LCD_EN=1;
delay_1ms(1);
LCD_EN=0;
}
void write_data(uchar a)//发送数据
{
LCD_RW=0;
LCD_RS=1;
LCD_EN=0;
P2=a;
delay_1ms(1);
LCD_EN=1;
delay_1ms(1);
LCD_EN=0;
}
void lcd_pose(uchar X,uchar Y)//定位坐标
{
uchar S,pose;
switch (X)
{
case 0:
S=0x80; //液晶第一行显示
break;
case 1:
S=0x90; //第二行显示
break;
case 2: //第三行显示
S=0x88;
break;
case 3: //第四行显示
S=0x98;
break;
}
pose=S+Y;
write_cmd(pose);
}
void LCD12864_Init()
{
//首先对LCD进行复位
LCD_RST=0;
delay_1ms(1);
LCD_RST=1;
delay_1ms(1);
LCD_PSB=1;
delay_1ms(1);
/* 开始初始化的步骤 */
write_cmd(0x30);
delay_1ms(1);
// write_cmd(0x08);
delay_1ms(1);
write_cmd(0x01);
delay_1ms(1);
write_cmd(0x06);
delay_1ms(1);
write_cmd(0x0c);
}
void write_zifu(uchar *p) //循环发送数组数据
{
while(*p!='\0')
{
write_data(*p);
p++;
delay_1ms(5);
}
}
void main()
{
LCD12864_Init();
{
lcd_pose(0,0);
write_zifu(dis1);
lcd_pose(1,0);
write_zifu(dis2);
lcd_pose(2,0);
write_zifu(dis3);
lcd_pose(3,0);
write_zifu(dis4);
}
while(1);
}
|