求帮忙!关于51单片机1602液晶显示屏无法动态显示变量的问题!
时间:10-02
整理:3721RD
点击:
需要实现的功能是实时显示倒车距离value值,可是怎么都调不出来,一直显示DISTANCE=000cm,table2[]怎么就不起作用呢?
刚学单片机,有些地方自己实在捉摸不透,麻烦各位大神帮我看一下是什么原因~~
程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="WARNING!";
uchar code table1[]="DISTANCE=";
uchar table2[];
uchar code table3[]="cm";
sbit lcden=P3^4;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar num;
uint value;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80+0x13);
}
void main()
{
init();
for(num=0;num<10;num++)
{
write_data(table[num]);
delay(20);
}
write_com(0x80+0x51);
for(num=0;num<9;num++)
{
write_data(table1[num]);
delay(20);
}
value=110; //假设倒车距离value值为110
table2[0]=value/100;
table2[1]=(value/10)%10;
table2[2]=value%10;
write_com(0x80+0x5A);
for(num=0;num<3;num++)
{
write_data(0x30+table2[num]);
delay(20);
}
write_com(0x80+0x5D);
for(num=0;num<2;num++)
{
write_data(table3[num]);
delay(20);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(100);
}
while(1);
}
刚学单片机,有些地方自己实在捉摸不透,麻烦各位大神帮我看一下是什么原因~~
程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="WARNING!";
uchar code table1[]="DISTANCE=";
uchar table2[];
uchar code table3[]="cm";
sbit lcden=P3^4;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar num;
uint value;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80+0x13);
}
void main()
{
init();
for(num=0;num<10;num++)
{
write_data(table[num]);
delay(20);
}
write_com(0x80+0x51);
for(num=0;num<9;num++)
{
write_data(table1[num]);
delay(20);
}
value=110; //假设倒车距离value值为110
table2[0]=value/100;
table2[1]=(value/10)%10;
table2[2]=value%10;
write_com(0x80+0x5A);
for(num=0;num<3;num++)
{
write_data(0x30+table2[num]);
delay(20);
}
write_com(0x80+0x5D);
for(num=0;num<2;num++)
{
write_data(table3[num]);
delay(20);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(100);
}
while(1);
}
table2能这样定义?