请问刚开始00000的时候按减一按键,屏幕显示乱码该如何解决?
2. 按键加到一百会显示“1:0” 一百一十是“1;0”十位没有显示正确该如何解决?
单片机源程序如下:
#include <REGX52.H>
typedef unsigned char uchar;
typedef unsigned int uint;
uchar code table[] = {"Welcome!"};
uchar code ren[] = {"RenShu:"};
uchar code dat[2];
sbit RS = P2^6; //RS?
sbit RW = P2^5;
sbit EN = P2^7; //EN?
sbit du=P1^6;
sbit we=P1^7;
sbit k1=P3^2;
sbit k2=P3^3;
uint num,i,c;
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
void Read_Busy()
{
uchar busy;
P0 = 0xff;
RS = 0;
RW = 1;
do
{
EN = 1;
busy = P0;
EN = 0;
}while(busy & 0x80);
}
void Write_Cmd(uchar cmd)
{
Read_Busy();//???
RS = 0;
RW = 0;
P0 = cmd;
EN = 1;
EN = 0;
}
void Write_Dat(uchar dat)
{
Read_Busy();
RS = 1;
RW = 0;
P0 = dat;
EN = 1;
EN = 0;
}
void Init_LCD1602()
{
du=0;
we=0;
EN=0;
Write_Cmd(0x38);
Write_Cmd(0x0c);
Write_Cmd(0x06);
Write_Cmd(0x01);
}
void key()
{
if(k1==0)
{
delay(5);
if(k1==0)
{
c++;
}
while(!k1);
}
if(k2==0)
{
delay(5);
if(k2==0)
{
c--;
}
while(!k2);
}
}
void main()
{
Init_LCD1602();//1602???
c=0;
while(1)
{
Write_Cmd(0x80 | 0x00);//????
for(num=0;num<8;num++)
{
Write_Dat(table[num]);
delay(5);
}
Write_Cmd(0x80 | 0x40);//????
for(i=0;i<7;i++)
{
Write_Dat(ren[ i]);
delay(5);
}
Write_Cmd(0x80 | 0x48);
key();
Write_Dat(c/10000+0x30);
Write_Dat(c/1000+0x30);
Write_Dat(c/100+0x30);
Write_Dat(c/10+0x30);
Write_Dat(c%10+0x30);
}
}
|