DS1302头文件
#ifndef _DS1302_H
#define _DS1302_H
#include <STC15F2K60S2.H>
#include <intrins.h>#define u8 unsigned char
#define u16 unsigned int
sbit SDA=P2^3;
sbit SCK=P1^7;
sbit RST=P1^3;
extern char time[];
void ds1302_write();
void ds1302_read();
#endif
DS1302驱动
#include "DS1302.H"
char time[]={0x50,0x59,0x23};
void Write_Ds1302_Byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
SCK=0;
SDA=temp&0x01;
temp>>=1;
SCK=1;
}
}
void Write_Ds1302( unsigned char address,unsigned char dat )
{
RST=0;
_nop_();
SCK=0;
_nop_();
RST=1;
_nop_();
Write_Ds1302_Byte(address);
Write_Ds1302_Byte(dat);
RST=0;
}
unsigned char Read_Ds1302 ( unsigned char address )
{
unsigned char i,temp=0x00;
RST&