DS1302显示乱码,不间断跳出85
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uchar unsigned char
sbit rs=P2^6;
sbit rw=P2^5;
sbit lcde=P2^7;
sbit sclk=P3^6;
sbit dsio=P3^4;
sbit ce=P3^5;
sbit ACC_7=ACC^7;
uchar zhou,shi,fen,miao,ri,yue,nian;
uchar code table[]=" 20 - - 01";
uchar code table1[]=" : : ";
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //写控制指令
{
rs=0;
rw=0;
lcde=0;
P0=com;
delay(5);
lcde=1;
delay(5);
lcde=0;
}
void write_data(uchar date) //写数据指令
{
rs=1;
rw=0;
lcde=0;
P0=date;
delay(5);
lcde=1;
delay(5);
lcde=0;
}
void init() //初始化程序
{
uchar i;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(i=0;i<14;i++)
{
write_data(table);
}
write_com(0x80+0x40);
for(i=0;i<10;i++)
{
write_data(table1);
}
}
void write_ds1302(uchar addr,uchar date)
{
uchar i,temp;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=addr;
dsio=temp&0x01;
addr>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
sclk=0;
temp=date;
dsio=temp&0x01;
date>>=1;
sclk=1;
}
ce=0;
}
uchar read_ds1302(uchar addr)
{
uchar i,temp,dat1,dat2;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=addr;
dsio=temp&0x01;
addr>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
ACC_7=dsio;
sclk=1;
ACC>>=1;
sclk=0;
}
ce=0;
dat1=ACC;
dat2=dat1/16;
dat1=dat1%16;
dat1=dat2*10+dat1;
return (dat1);
}
void init_ds1302()
{
write_ds1302(0x8e,0x00);
write_ds1302(0x80,0x55);
write_ds1302(0x82,0x29);
write_ds1302(0x84,0x15);
write_ds1302(0x86,0x24);
write_ds1302(0x88,0x06);
write_ds1302(0x8a,0x01);
write_ds1302(0x8c,0x13);
write_ds1302(0x8e,0x80);
}
void write_sfm(uchar add,uchar date) //哪个地址显示数据
{
uchar ge,shi;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void write_nyr(uchar add,uchar date) //哪个地址显示数据
{
uchar ge,shi;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void display()
{
write_ds1302(0x8e,0x00);
miao=read_ds1302(0x81);
write_sfm(8,miao);
fen=read_ds1302(0x83);
write_sfm(5,fen);
shi=read_ds1302(0x85);
write_sfm(2,shi);
ri=read_ds1302(0x87);
write_nyr(10,ri);
yue=read_ds1302(0x89);
write_nyr(7,yue);
zhou=read_ds1302(0x8b);
write_nyr(14,zhou);
nian=read_ds1302(0x81);
write_nyr(4,nian);
write_ds1302(0x8e,0x80);
}
void main()
{
init();
init_ds1302();
while(1)
{
display();
}
}
如题,时分秒年月日都显示85?求大神指教
#define uchar unsigned char
sbit rs=P2^6;
sbit rw=P2^5;
sbit lcde=P2^7;
sbit sclk=P3^6;
sbit dsio=P3^4;
sbit ce=P3^5;
sbit ACC_7=ACC^7;
uchar zhou,shi,fen,miao,ri,yue,nian;
uchar code table[]=" 20 - - 01";
uchar code table1[]=" : : ";
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //写控制指令
{
rs=0;
rw=0;
lcde=0;
P0=com;
delay(5);
lcde=1;
delay(5);
lcde=0;
}
void write_data(uchar date) //写数据指令
{
rs=1;
rw=0;
lcde=0;
P0=date;
delay(5);
lcde=1;
delay(5);
lcde=0;
}
void init() //初始化程序
{
uchar i;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(i=0;i<14;i++)
{
write_data(table);
}
write_com(0x80+0x40);
for(i=0;i<10;i++)
{
write_data(table1);
}
}
void write_ds1302(uchar addr,uchar date)
{
uchar i,temp;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=addr;
dsio=temp&0x01;
addr>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
sclk=0;
temp=date;
dsio=temp&0x01;
date>>=1;
sclk=1;
}
ce=0;
}
uchar read_ds1302(uchar addr)
{
uchar i,temp,dat1,dat2;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=addr;
dsio=temp&0x01;
addr>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
ACC_7=dsio;
sclk=1;
ACC>>=1;
sclk=0;
}
ce=0;
dat1=ACC;
dat2=dat1/16;
dat1=dat1%16;
dat1=dat2*10+dat1;
return (dat1);
}
void init_ds1302()
{
write_ds1302(0x8e,0x00);
write_ds1302(0x80,0x55);
write_ds1302(0x82,0x29);
write_ds1302(0x84,0x15);
write_ds1302(0x86,0x24);
write_ds1302(0x88,0x06);
write_ds1302(0x8a,0x01);
write_ds1302(0x8c,0x13);
write_ds1302(0x8e,0x80);
}
void write_sfm(uchar add,uchar date) //哪个地址显示数据
{
uchar ge,shi;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void write_nyr(uchar add,uchar date) //哪个地址显示数据
{
uchar ge,shi;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void display()
{
write_ds1302(0x8e,0x00);
miao=read_ds1302(0x81);
write_sfm(8,miao);
fen=read_ds1302(0x83);
write_sfm(5,fen);
shi=read_ds1302(0x85);
write_sfm(2,shi);
ri=read_ds1302(0x87);
write_nyr(10,ri);
yue=read_ds1302(0x89);
write_nyr(7,yue);
zhou=read_ds1302(0x8b);
write_nyr(14,zhou);
nian=read_ds1302(0x81);
write_nyr(4,nian);
write_ds1302(0x8e,0x80);
}
void main()
{
init();
init_ds1302();
while(1)
{
display();
}
}
如题,时分秒年月日都显示85?求大神指教
试一下显示刷新间隔调大一点试一下。