编译成功了,可是时间无法显示,我测试过了,其他模块没有问题,就是这个模块不知道哪错了。
void DS1302ByteWrite(unsigned char dat)
{
unsigned char mask;
for (mask=0x01; mask!=0; mask<<=1)
{
if ((mask&dat) != 0)
DS1302_IO = 1;
else
DS1302_IO = 0;
DS1302_CK = 1;
}
DS1302_IO = 1;
}
unsigned char DS1302ByteRead()
{
unsigned char mask;
unsigned char dat = 0;
for (mask=0x01; mask!=0; mask<<=1)
{
if (DS1302_IO != 0)
{
dat |= mask;
}
DS1302_CK = 1;
DS1302_CK = 0;
}
return dat;
}
void DS1302SingleWrite(uint8 reg,uint8 dat)
{
DS1302_CE = 1;
DS1302ByteWrite((reg<<1)|0x80);
DS1302ByteWrite(dat);
DS1302_CE = 0;
}
uint8 DS1302SingleRead(uint8 reg)
{
uint8 dat;
DS1302_CE = 1;
DS1302ByteWrite((reg<<1)|0x81);
dat = DS1302ByteRead();
DS1302_CE = 0;
return dat;
}
void DS1302BurstWrite(uint8 *dat)
{
uint8 i;
DS1302_CE = 1;
DS1302ByteWrite(0xBE);
for(i = 0;i < 8;i++)
DS1302ByteWrite(dat
);
DS1302_CE = 0;
}
void DS1302BurstRead(uint8 *dat)
{
uint8 i;
DS1302_CE = 1;
DS1302ByteWrite(0xBF);
for(i = 0;i < 8;i++)
dat = DS1302ByteRead();
DS1302_CE = 0;
}
void InitDS1302()
{
uint8 dat;
struct stime code InintTime = {
0x2017,0x05,0x14,0x11,0x11,0x00,0x07
};
DS1302_CE = 0;
DS1302_CK = 0;
dat = DS1302SingleRead(0);
if((dat&0x80) == 0x80)
{
DS1302SingleWrite(7,0x00);
SetRealTime(&InintTime);
}
}
一周热门 更多>