/*---------------------------------------------
/* DS1302 Read Byte
/*-------------------------------------------*/
uint8 ReadByte()
{
uint8 i,tmp = 0x00;
for(i = 0; i < 8 ; i ++)
{
if(io) tmp|=0x80;
sclk = 1 ;
tmp >>= 1;
sclk = 0;
}
return tmp;
}
/*---------------------------------------------
DS1302 WriteByte()
--------------------------------------------*/
void WriteByte(uint8 dat)
{
uint8 i;
for(i = 0; i < 8 ; i ++)
{
io = (bit)(dat & 0x01);
dat >>= 1;
sclk = 1;
sclk = 0;
}
}
/*---------------------------------------------
/* DS1302 SingleRead
/*-------------------------------------------*/
uint8 SingleRead(uint8 addr)
{
uint8 tmp;
cs = 1;
_nop_();
WriteByte(addr);
tmp = ReadByte();
cs = 0;
return tmp;
}
/*----------------------------------------------
/* DS1302 SingleWrite
/---------------------------------------------*/
void SingleWrite(uint8 addr,uint8 dat)
{
cs = 1;
WriteByte(addr);
WriteByte(dat);
cs = 0;
}
SingleRead函數寫入的的地址沒問題,讀出的數據是錯的。
請高手幫忙看一下,哪里錯了?
|