给初始化里面加一个
w_cmd(0x0f);
去掉那个busy 然后自己写个等待函数试一下
#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=" Hello world! ";
uchar code table1[]=" 2013/8/10 ";
uchar num;
sbit rs=P1^0;
sbit rw=P1^1;
sbit lcden=P2^5;
sbit sd=P2^6;
sbit ds1302=P2^7;
sbit dula=P2^0;
sbit wela=P2^1;
sbit cs88=P2^2;
void delay(uint zz)
{
uint xx,yy;
for (xx=zz;xx>0;xx--)
for(yy=110;yy>0;yy--);
}
void comwrite(uchar com)
{
rs=0;
P0=com;
delay(3);
lcden=1;
delay(5);
lcden=0;
delay(8);
}
void datawrite(uchar dat)
{
rs=1;
P0=dat;
delay(3);
lcden=1;
delay(5);
lcden=0;
delay(8);
}
void initlcd()
{
lcden=1;
rw=0;
comwrite(0x38);//设置1602显示
comwrite(0x0f);//开显示 显示光标 光标闪烁
comwrite(0x06);//光标指针加一
comwrite(0x01);//显示清零
comwrite(0x80);//光标指针初始化
}
void main()
{
wela=0;
dula=0;
cs88=0;
ds1302=0;
sd=0;
initlcd();
comwrite(0x80+0x12);
for(num=0;num<16;num++)
{
datawrite(table[num]);
}
comwrite(0x80+0x40+0x12);
for(num=0;num<16;num++)
{
datawrite(table1[num]);
}
for(num=0;num<18;num++)
{
comwrite(0x18);
delay(200);
}
while(1);
}
这是我今年8月份自己写的 你看看
P0口要加上拉电阻
P0加上拉电阻就可以了