大佬们,是这样的,我正在学习时钟芯片的使用,然后到这读取秒数时,读不出来,总是乱码,我感觉我的初始化,读秒没什么问题啊。请大家帮忙看看,谢谢了
这是程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]=" 2018-6-12 THU";
uchar code table[]=" 00:00:00";
sbit lcden=P1^2;
sbit lcdrs=P1^3;
sbit D1=P1^1;
sbit dscs=P1^7;
sbit dsas=P1^6;
sbit dsrw=P1^5;
sbit dsds=P1^4;
sbit dairq=P3^2;
uchar num;
int miao,fen,shi;
void init();
void disylay();
void set_time();
uchar read_ds(uchar add);
void write_sfm(uchar add,uchar date);
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;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
lcdrs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
lcden=0;
num=0;
set_time();
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table1[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table[num]);
delay(5);
}
}
void main()
{
init();
while(1)
{
disylay();
}
}
void disylay()
{
miao=read_ds(0);
fen=read_ds(2);
shi=read_ds(4);
write_sfm(10,miao);
write_sfm(7,fen);
write_sfm(4,shi);
}
void write_ds(uchar add,uchar date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P2=add;
dsas=0;
dsrw=0;
P2=date;
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P2=add;
dsas=0;
dsds=0;
P2=0xff;
ds_date=P2;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void set_time()
{
write_ds(4,01);
write_ds(2,10);
//write_ds(0,10);
}
此帖出自
小平头技术问答
一周热门 更多>