液晶显示了很多“?” 这是怎么回事啊、。
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit clk=P1^0;
sbit io=P1^1;
sbit rst=P1^2;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
//uint i;
uchar code table[]={0x10,0x04,0x05,0x07,
0x10,0x10,0x10,0x00};
uchar curtime[7]={0x0,0x0,0x0,0x0,0x0,
0x0,0x0};
uchar shi[7]={0x0,0x0,0x0,0x0,0x0,0x0,0x0};
uchar ge[7]={0x0,0x0,0x0,0x0,0x0,0x0,0x0};
void delay(uchar x)
{
uchar t;
while(x--)
for(t=0;t<110;t++);
}
void writeb(uchar data1302)
{
uchar i;
ACC=data1302;
for(i=8;i>0;i--)
{
io=ACC0;
clk=1;
clk=0;
ACC=ACC>>1;
}
}
uchar readb(void)
{
uchar i;
for(i=8;i>0;i--)
{
ACC=ACC>>1;
ACC7=io;
clk=1;
clk=0;
}
return(ACC);
}
void init1302()
{
rst=0;clk=0;rst=1;
}
void w1302(uchar addr1302,uchar data1302)
{
init1302();
writeb(addr1302);
writeb(data1302);
clk=1;rst=0;
}
uchar r1302(uchar addr1302)
{
uchar data1302;
init1302();
writeb(addr1302);
data1302=readb();
clk=1;rst=0;
return (data1302);
}
void burstw1302t()
{
uchar i;
w1302(0x8e,0x00);
init1302();
writeb(0xbe);
for(i=8;i>0;i--)
{
writeb(table[i]);
}
clk=0;rst=0;
w1302(0x8e,0x80);
}
void gettime1302()
{ uchar i;
uchar addr=0x81;
for(i=0;i<7;i++)
{
curtime[i]=r1302(addr);
addr+=2;
shi[i]=curtime[i]/16;
ge[i]=curtime[i]%16;
}
}
void write_commond(uchar commond)
{
rs=0;
P0=commond;
delay(5);
e=1;
delay(5);
e=0;
}
void write_date(uchar Date)
{
rs=1;
rw=0;
e=0;
P0=Date;
delay(5);
e=1;
delay(5);
e=0;
}
void init()
{
e=0;
rw=0;
write_commond(0x38);//16*2
write_commond(0x0c);//开显示,光标
write_commond(0x06);
write_commond(0x01);
}
void disp()
{ uchar i,j;
write_commond(0x80);//第一行
for(i=0;i<4;i++)
{
write_date(shi[i]+'0');
write_date(ge[i]+'0');
}
write_commond(0x80+0x40);//第二行
for(j=4;j<8;j++)
{
write_date(shi[j]+'0');
write_date(ge[j]+'0');
}
delay(10);
}
void main()
{
init(); //液晶复位初始化
burstw1302t();
while(1)
{
gettime1302();
disp();
}
} |