unsigned char Ds1302_Read_Byte(unsigned char addr)
{
unsigned char i;
unsigned char temp=0x00;
RST_SET;
//写入目标地址:addr
addr = addr | 0x01;//最低位置高
for (i = 0; i < 8; i ++)
{
if (addr & 0x01)
{
IO_SET;
}
else
{
IO_CLR;
}
SCK_SET;
SCK_CLR;
addr = addr >> 1;
}
//输出数据:temp
for (i = 0; i < 8; i ++)
{
if (IO_R)
{
temp |= 0x80;
}
else
{
temp &= 0x7F;
}
SCK_SET;
SCK_CLR;
temp = temp >> 1;
}
RST_CLR; //停止DS1302总线
return temp;
}
和
unsigned char i;
unsigned char temp=0x00;
RST_SET;
//写入目标地址:addr
addr = addr | 0x01;//最低位置高
for (i = 0; i < 8; i ++)
{
if (addr & 0x01)
{
IO_SET;
}
else
{
IO_CLR;
}
SCK_SET;
SCK_CLR;
addr = addr >> 1;
}
//输出数据:temp
for (i = 0; i < 8; i ++)
{
temp = temp >> 1;
if (IO_R)
{
temp |= 0x80;
}
else
{
temp &= 0x7F;
}
SCK_SET;
SCK_CLR;
}
RST_CLR; //停止DS1302总线
return temp;
}
仅仅是temp = temp >> 1;先后的问题 为什么结果会不一样?? |