下午没事,就搜了一些12864的参考程序,然后结合自己前一阶段卖家给的12864说明书,写了一个简单的显示程序,在此把代码附上。其实这款LCD功能很强大,本身带有字库,而且可以显示图形,改天再写个显示图形的程序供大家参考。此程序可以直接下载开发板
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^0;
sbit wela=P2^1;
sbit rs = P1^2;
sbit rw = P1^3;
sbit LCD_EN = P1^4;
sbit PSB = P1^1;
uchar code table[]="0123456789";
uchar code table1[]="欢迎进入:";
uchar code table2[]="张福利的新浪博客";
uchar code table3[]="blog.sina.com.cn";
uchar code table4[]="/xxmutouren ";
void write_12864com(uchar com);
void write_12864dat(uchar dat);
void delay_ms(uint z);
void main()
{
uchar num;
dula=0;
wela=0;
PSB=1;
write_12864com(0x30);
write_12864com(0x0e);
write_12864com(0x01);
write_12864com(0x80);
for(num=0;num<10;num++)
{
write_12864dat(table1[num]);
delay_ms(1);
}
write_12864com(0x90);
for(num=0;num<16;num++)
{
write_12864dat(table2[num]);
delay_ms(1);
}
write_12864com(0x88);
for(num=0;num<16;num++)
{
write_12864dat(table3[num]);
delay_ms(1);
}
write_12864com(0x98);
for(num=0;num<11;num++)
{
write_12864dat(table4[num]);
delay_ms(1);
}
while(1);
}
void write_12864com(uchar com)
{
rs = 0;
rw = 0;
LCD_EN = 0;
P0 = com;
delay_ms(5);
LCD_EN = 1;
delay_ms(5);
LCD_EN = 0;
}
void write_12864dat(uchar dat)
{
rs = 1;
rw = 0;
LCD_EN=0;
P0 = dat;
delay_ms(5);
LCD_EN = 1;
delay_ms(5);
LCD_EN = 0;
}
void display(void)
{
uchar i;
//uchar a;
//a = 0x10;
write_12864com(0x80);
delay_ms(5);
for(i=0;i<16;i++)
{
write_12864dat(table1[i]);
delay_ms(5);
//a++;
}
}
void delay_ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}