用超声波和lcd做了个测距,但是发现字符有的显示不正确,就写了个lcd单独显示的程序,发现和之前错误的是一样的。
搞不懂是什么原因导致的。
代码和显示图片如下:
#include <reg52.h>
sbit LCDEN=P3^4;
sbit LCDRS=P3^5;
sbit U1=P2^6;
sbit U2=P2^7;
unsigned char code table[]={"Distance:"};
void delayms(unsigned int);
void write_com(unsigned char com)
{
LCDRS=0;
P0=com;
delayms(10);
LCDEN=1;
delayms(10);
LCDEN=0;
}
void write_date(unsigned char date)
{
LCDRS=1;
P0=date;
delayms(10);
LCDEN=1;
delayms(10);
LCDEN=0;
}
void init()
{
U1=0;
U2=0;
LCDEN=0;
write_com(0x38);
write_com(0x0C);
write_com(0x06);
write_com(0x01);
}
void main()
{ unsigned char num;
init();
write_com(0x80);
for(num=0;num<=8;num++)
{
write_date(table[num]);
}
while(1);
}
void delayms(unsigned int ms)
{
unsigned int x,y;
for(x=ms;x>0;x--)
for(y=110;y>0;y--);}
|