发下我的程序,大家 看看哪有错误
#define uchar unsigned char
#define unit unsigned int
#define write_second 0x80
#define write_minute 0x82
#define write_hour 0x84
#define read_second 0x83
#define read_minute 0x85
#define read_hour 0x8e
sbit SCLK=P3^3;
sbit SDA=P3^4;
sbit RST=P3^5;
uchar hour=23;minute=59;second=58;
void delay1(uchar x)
{
uchar i;
while(x--)
for(i=0;i<110;i++);
}
void DS1302WriteByte(uchar dat)
{
uchar i;
for(i=0;i<8;i++
{
SDA=dat&0x01
delay1(2);
SCLK=1
delay1(2);
dat>>=1;
SCLK=0;
}
}
uchar DS1302ReadByte()
{
uchar i,dat;
delay1(2);
for(i=0;i<8;i++)
{
dat>>=1;
if(SDA==1
dat|=0x80;
delay1(2);
SCLK=0;
delay1(2);
}
return dat;
}
/*每次发起数据传输之前,要复位ds1302*/
void resetds1302(void)
{
RST=0;
SCLK=0;
RST=1;
}
/*写数据前清除写保护*/
void cleards1302wp(void)
{
resetds1302();
RST=1;
DS1302WriteByte(0X8E);
DS1302WriteByte(0);
SDA=0;
RST=0;
}
/*写完数据设置写保护*/
void setds1302wp(void)
{
resetds1302();
RST=1;
DS1302WriteByte(0X8E);
DS1302WriteByte(0X80);
SDA=0;
RST=0;
}
uchar DS1302Read(uchar addr)
{
uchar tmp=0;
resetds1302();
RST=1;
DS1302WriteByte(addr);
tmp=DS1302ReadByte();
SDA=0;
RST=0;
return tmp;
}
void DS1302Write(uchar addr,uchar dat)
{
resetds1302;
RST=1;
DS1302WriteByte(addr);
DS1302WriteByte(dat);
SDA=0;
RST=0;
}
void set_time(uchar addr,uchar time)
{
uchar tmp;
tmp=time/10;
time=time%10;
time=time+tmp*16;
cleards1302wp();
DS1302Write(addr,time);
setds1302wp();
}
void read_time(uchar addr,uchar time)
{
time=DS1302Read(addr);
}
void dispalytime(uchar addr,uchar time)
{
uchar shi,ge;
shi=time/16;
ge=time%16;
com(addr);
dat(0x30+shi);
dat(0x30+ge);
}
void main()
{
set_time(write_hour,hour);
set_time(write_minute,minute);
set_time(write_second,second);
while(1)
{
read_time(read_hour,hour);
dispalytime(0x90,hour);
read_time(read_minute,minute);
dispalytime(0x92,minute);
read_time(read_second,second);
dispalytime(0x94,second);
}
}
com(),dat() 是12864 显示所需子函数. 硬件上一开始显示初始值,完后马上显示17 : 3; : 3:
这算是乱码吗?且时间不变化,
硬件上没有在晶振处加电容 谁有能用的程序给一份 但是大多数都是这样的吧
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
抖动延时多久?一般延时10ms.
一周热门 更多>