先出现00,01,然后乱码,08,09,十位数一直为0,不增加
单片机源程序如下:
#include <STC12C5A60S2.H>
#include "intrins.h"
#include "DS1302.h"
#include "12864.h"
unsigned char test[3];
unsigned char dat;
void DS1302_Init(void)
{
DS1302_RST=0;
DS1302_SCLK=0;
}
void DS1302_WriteByte(unsigned char Command,Data)
{
unsigned char i;
DS1302_RST=1;
for(i=0;i<8;i++)
{
DS1302_IO=Command&(0x01<<i);
DS1302_SCLK=1;
DS1302_SCLK=0;
}
for(i=0;i<8;i++)
{
DS1302_IO=Data&(0x01<<i);
DS1302_SCLK=1;
DS1302_SCLK=0;
}
DS1302_RST=0;
}
unsigned char DS1302_ReadByte(unsigned char Command)
{
unsigned char i,Data=0x00;
Command|=0x01;
DS1302_RST=1;
for(i=0;i<8;i++)
{
DS1302_IO=Command&(0x01<<i);
DS1302_SCLK=0;
DS1302_SCLK=1;
}
for(i=0;i<8;i++)
{
DS1302_SCLK=1;
DS1302_SCLK=0;
if(DS1302_IO){Data|=(0x01<<i);}
}
DS1302_RST=0;
DS1302_IO=0;
return Data;
}
void SetTime ()
{
DS1302_WriteByte(0x8E,0x00);
DS1302_WriteByte(0x80,0x10);
DS1302_WriteByte(0x8E,0x80);
}
void ReadTime()
{
dat = DS1302_ReadByte(0x81) ; //读取秒
test[0] = dat / 16*10 + '0';
test[1] = dat % 16 + '0';
DisplayListNum(3,1,&test,2); //数据显示
}
|