51单片机的12864液晶字符显现,选用液晶的并行接法
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define LCD_data P0 //界说数据口
sbit LCD_RS=P3^5; //数据指令挑选端,高电平为写数据,低电平写指令
sbit LCD_RW=P3^6;//读写操控端,高电平读信息,低电平写信息
sbit LCD_EN=P3^7; // 使能端
sbit LCD_PSB=P3^4; //拉高 ,挑选并行
//单片机特别功用位声明
uchar code dis1[]={“名字:浩泉”};
uchar code dis2[]={“性别:男”};
uchar code dis3[]={“卡号:050817”};
uchar code dis4[]={“www.szu.edu.cn”};
void delay_1ms(uint x) //延时函数1ms
{
uint i,j;
for(j=0;j
}
void write_cmd(uchar cmd) //写指令函数,请参阅12864液晶手册
{
LCD_RS=0; //低电平,写入指令
LCD_RW=0;
P0=cmd; // 赋值
delay_1ms(5);
LCD_EN=1;//使能端拉高送入指令
delay_1ms(5);
LCD_EN=0;
}
void write_date(uchar date) //写数据
{
LCD_RS=1;
LCD_RW=0;
P0=date;
delay_1ms(5);
LCD_EN=1; //使能端拉高送入数据
delay_1ms(5);
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 lcd_init() //液晶初始化函数
{
LCD_PSB=1; // 并行挑选,请参阅液晶指令表
write_cmd(0x01);
delay_1ms(5);
write_cmd(0x30);
delay_1ms(5);
write_cmd(0x0C);
delay_1ms(5);
write_cmd(0x06);
delay_1ms(5);
}
main()
{
uchar i;
lcd_init();
lcd_pose(0,0); //液晶榜首行榜首列的榜首个字符显现
i=0;
while(dis1[i]!=/0)//查询没有到字符串结尾
{
write_date(dis1[i]); //写入字符
i++;
}
lcd_pose(1,0);//第2行
i=0;
while(dis2[i]!=/0)
{
write_date(dis2[i]);
i++;
}
lcd_pose(2,0); //第3行
i=0;
while(dis3[i]!=/0)
{
write_date(dis3[i]);
i++;
}
lcd_pose(3,0); //第4行
i=0;
while(dis4[i]!=/0)
{
write_date(dis4[i]);
i++;
}
while(1);
}