奇怪的是用protues仿真可以正常显示,但下到单片机却不行,是乱码, 下面是程序 请问该怎么解决
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^6;
//rw接地
sbit leden=P2^7;
void delay(uint x) //延时
{
int a,b;
for(a=x;a>0;a--)
for(b=300;b>0;b--);
}
void write_ml(uchar ml) //写命令
{
P0=ml;
rs=0;
leden=0;
delay(10);
leden=1;
delay(10);
leden=0;
delay(10);
}
void write_date(uchar date) //写数据
{
P0=date;
rs=1;
leden=0;
delay(50);
leden=1;
delay(50);
leden=0;
delay(50);
}
void init() //初始化
{
write_ml(0x38);
delay(20);
write_ml(0x38);
delay(20);
write_ml(0x38);
delay(20);
write_ml(0x0c);
delay(20);
write_ml(0x0c);
delay(20);
write_ml(0x06);
delay(20);
write_ml(0x01);
delay(20);
}
void main()
{
delay(50);
init();
write_ml(0x80);
delay(50);
write_date(0x41); //显示A
delay(50);
write_date(0x42);
while(1);
} |