取得当前系统时间的方法是直接访问RTC芯片。
RTC芯片可以通过0x70和0x71端口直接访问。0x70是选址寄存器,0x71是数据寄存器。
Addr Function
==== =========================================
** clock/calendar
00 current second for real-time clock
01 alarm second
02 current minute
03 alarm minute
04 current hour
05 alarm hour
06 current day of week (1=Sunday)
07 current date of month
08 current month
09 current year (final two digits; eg, 93)
==== =========================================
** clock/calendar
00 current second for real-time clock
01 alarm second
02 current minute
03 alarm minute
04 current hour
05 alarm hour
06 current day of week (1=Sunday)
07 current date of month
08 current month
09 current year (final two digits; eg, 93)
rtc.h源代码如下所示
#ifndef _RTC_H_
#define _RTC_H_
#define RTC_REG_ADDR 0x70 //寻址寄存器
#define RTC_REG_VALUE 0x71 //内容