单片机学习板上用的是16个管脚的12864,按照20个管脚的datasheet写了一段程序,但12864不起作用,是程序写的不对,还是datasheet不对,找不到16个管脚的datasheet,以下是我写的程序:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis1[]={"welcome"};
uchar code dis2[]={"2016-08-11"};
sbit lcde=P2^7; // 使能,下降沿写数据,为1的时候读数据
sbit rd=P2^6; //rd=0 指令,rd=1 数据
sbit wr=P2^5; //wr=0 往lcd写,wr=1 读lcd
uchar busy,j;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rd=0;
wr=0;
lcde=0;
delay(10);
P0=com;
delay(10);
lcde=1;
delay(10);
lcde=0;
delay(10);
}
void write_date(uchar date)
{
rd=1;
wr=0;
lcde=0;
delay(10);
P0=date;
delay(10);
lcde=1;
delay(10);
lcde=0;
delay(10);
}
uchar lcd_busy()
{
uchar busy;
rd=0;
wr=1;
lcde=1;
delay(1);
lcde=0;
busy=P0&0x80; //P0.7为BF位,得到BF位
return busy;
}
void init()
{
// delay(10);
// write_com(0x38); //数据总线为8位,显示2行
delay(10);
write_com(0x0c); //显示功能开,无光标,不闪烁
delay(10);
write_com(0x06); //写入后光标右移,屏幕不动
delay(10);
write_com(0x01); //清屏
delay(10);
}
void lcd_disp_pos(uchar x,y) //显示位置函数
{
uchar address;
switch(x)
{
case 1:address=0x80+y;
break;
case 2:address=0x90+y;
break;
case 3:address=0x88+y;
break;
case 4:address=0x98+y;
break;
}
delay(5);
write_com(address);
}
void main()
{
init();
delay(10);
lcd_disp_pos(1,2);
j=0;
while(dis1[j]!='\0')
{
delay(10);
write_date(dis1[j]);
j++;
}
lcd_disp_pos(2,2);
j=0;
while(dis2[j]!='\0')
{
delay(10);
write_date(dis2[j]);
j++;
}
} |