有一个单片机c程序,可能出问题了,求修改,用液晶,1602显示动态值,AD为0804八位的,显示0-100,具体程序 通过调节输入电压,显示0-100
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="WENDU:";
uchar code table1[]="SHEZHI:";
uchar code table2[]={'0','1','2','3','4','5','6','7','8','9','0'};
sbit lcden=P3^4;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
sbit wr=P3^6;
sbit rd=P3^7;
uchar num,A1,A2,A3;
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);
}
void start()
{
wr=1;
delay(20);
wr=0;
delay(20);
wr=1;
}
void main()
{
float adval,B;
while(1)
{init();
start();
delay(1000);
P1=0xff;
rd=1;
delay(10);
rd=0;
adval=P1;
rd=1;
B=adval*20/51;
num=B;
A1=num/100;
A2=num%100/10;
A3=num%10;
for(num=0;num<6;num++)
{
write_data(table[num]);
delay(20);
}
//
write_com(1);
write_com(0x80+0x40);
for(num=0;num<7;num++)
{
write_data(table1[num]);
delay(20);
}
write_com(0x80+0x48);
for(num=0;num<1;num++)
{
write_data(table2[A1]);
delay(20);
}
write_com(0x80+0x49);
for(num=0;num<1;num++)
{
write_data(table2[A2]);
delay(20);
}
write_com(0x80+0x50);
for(num=0;num<1;num++)
{
write_data(table2[A3]);
delay(20);
}
delay(1000);
}
} |