#ifndef __DS1302_H__
#define __DS1302_H__
#define uchar unsigned char
#define uint unsigned int
***it SCL = P1^7;
***it SDA = P2^3;
***it RST = P1^3;
/*******************************
1302释放引脚
*******************************/
extern void RST_1302()
{
SDA = 0;
RST = 0;
SCL = 0;
RST = 1;
}
/**************************
1302写入字节
**************************/
extern void write_byte(uchar byte)
{
static i;
for(i=0;i<8;i++)
{
SDA = byte&0x01;
byte >>= 1;
SCL = 1;
SCL = 0;
}
}
/**************************
1302读出字节
**************************/
extern uchar read_byte()
{
static i,dat;
for(i=0;i<8;i++)
{
dat>>=1;
if( SDA==1)
dat = dat|0x80;
SCL = 1;
SCL = 0;
}
return dat;
}
/***********************************
写入数据
************************************/
extern void write_1302(uchar add,uchar dat)
{
RST_1302();
write_byte(ad6
d);
write_byte(dat);
SDA = 0;
RST = 0;
}
/*******************************
读出数据
*********************************/
extern uchar read_1302(uchar add)
{
static uchar dat;
RST_1302();
write_byte(add);
dat = read_byte();
SDA = 0;
RST = 0;
return dat;
}
/************************************
1302初始化
*************************************/
extern void init_1302()
{
write_1302(0x8e,0x00);
write_1302(0x80,0x58);
write_1302(0x82,0x59);
write_1302(0x84,0x23);
write_1302(0x8e,0x80);
}
#endif