#include<reg52.h>
#include<intrins.h>
typedef unsigned char unit8;
sbit RST=P3^3;
sbit SDA=P3^4;
sbit CLK=P3^5;
unit8 write_address[7] ={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};//写入时间地址
unit8 read_address[7] ={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};//读取时间地址
unit8 set_time[7] ={0x00,0x00,0x01,0x02,0x03,0x04,0x05};//设定时间7个字节,年两个字节,年月日时分秒
unit8 time[7];
void Delay1ms()
{
unit8 i, j;
_nop_();
_nop_();
i = 22;
j = 128;
do
{
while (--j);
} while (--i);
}
void Delay(int i)
{
for(;i>0;i--)
{
Delay1ms();
}
}
void Ds_prepar()//起始时序
{
RST=0;
CLK=0;
RST=1;
}
void Send_byte(unit8 d)//发送一个字节数据
{
unit8 i;
for(i=0;i<8;i++)
{
SDA=d & 0x01;
CLK=1;
CLK=0;
d>>=1;
}
}
unit8 Receive_byte()
{
unit8 i,receive_data=0;
for(i=0;i<8;i++)
{
receive_data>>=1;