pcf8563外部RTC驅(qū)動(dòng)程序基于STM32F10x
#define uchar unsigned char
#endif
#define SEC
#define MIN
#define HOUR
#define DAY
#define WEEK
#define MONTH
#define YEAR
#define read_ADD 0xA3 //寫器件地址
#define write_ADD 0xA2 //讀器件地址
tm timer_8563;
// char ResetTime[ResetTime_Len];
#define PCF8563_SCK_High()
#define PCF8563_SCK_Low()
#define PCF8563_DATA_High() {
#define PCF8563_DATA_Low()
#define PCF8563_DATA_In()
#define PCF8563_DATA_Sta()
void Delay_8563()
{
int i=100;
while(i--);
}
void Start()
{
PCF8563_DATA_High();
PCF8563_SCK_High();
Delay_8563();
PCF8563_DATA_Low();
Delay_8563();
PCF8563_SCK_Low();
}
void Stop()
{
PCF8563_DATA_Low();
PCF8563_SCK_Low();
Delay_8563();
PCF8563_SCK_High();
Delay_8563();
PCF8563_DATA_High();
Delay_8563();
}
void WriteACK(uchar ack)
{
if(ack)
{
PCF8563_SCK_High();
}
else
{
PCF8563_SCK_Low();
}
Delay_8563();
PCF8563_SCK_High();
Delay_8563();
PCF8563_SCK_Low();
}
void WaitACK()
{
uchar errtime=20;
PCF8563_DATA_High();
Delay_8563();
PCF8563_SCK_High();
Delay_8563();
PCF8563_DATA_In();
while(PCF8563_DATA_Sta())
{
errtime--;
if(!errtime) Stop();
}
PCF8563_SCK_Low();
Delay_8563();
}
void writebyte(uchar wdata)
{
uchar i;
for(i=0;i<8;i++)
{
if(wdata&0x80)
{
PCF8563_DATA_High();
}
else
{
PCF8563_DATA_Low();
}
wdata<<=1;
PCF8563_SCK_High();
Delay_8563();
PCF8563_SCK_Low();
}
WaitACK();
}
uchar Readbyte()
{
uchar i,bytedata;
PCF8563_DATA_High();
for(i=0;i<8;i++)
{
PCF8563_SCK_High();
bytedata<<=1;
PCF8563_DATA_In();
if(PCF8563_DATA_Sta())
bytedata|=0x01;
else
bytedata|=0x00;
PCF8563_SCK_Low();
Delay_8563();
}
return(bytedata);
}
void writeData(uchar address,uchar mdata)
{
Start();
writebyte(0xa2);
writebyte(address);
writebyte(mdata);
Stop();
}
uchar ReadData(uchar address)
{
uchar rdata;
Start();
writebyte(0xa2);
writebyte(address);
Start();
writebyte(0xa3);
rdata=Readbyte();
WriteACK(1);
Stop();
return(rdata);
}
void ReadData1(uchar address,uchar count,uchar * buff)
{
uchar i;
Start();
writebyte(0xa2);
writebyte(address);
Start();
writebyte(0xa3);
for(i=0;i
{
buff[i]=Readbyte();
if(i
}
WriteACK(1);
Stop();
}
void P8563_set_time(u8 year,u8 month,u8 day,u8 hour,u8 min,u8 sec,u8 week)
{
}
void P8563_get_time()
{
}
void P8563_init(void)
{
}
評(píng)論