diff --git a/RTC_Module.h b/RTC_Module.h new file mode 100644 index 0000000..fbde074 --- /dev/null +++ b/RTC_Module.h @@ -0,0 +1,44 @@ +#ifndef RTC_MODULE_H +#define RTC_MODULE_H + +#include +#include + +// RTC通信对象 +extern ThreeWire myWire; +extern RtcDS1302 Rtc; + +// 初始化RTC模块 +void setupRTC() +{ + Rtc.Begin(); + + RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); + + if (!Rtc.IsDateTimeValid()) { + Rtc.SetDateTime(compiled); + } + + if (Rtc.GetIsWriteProtected()) { + Rtc.SetIsWriteProtected(false); + } + + if (!Rtc.GetIsRunning()) { + Rtc.SetIsRunning(true); + } +} + +// 获取当前时间 +RtcDateTime getRTCTime() +{ + return Rtc.GetDateTime(); +} + +// 设置RTC时间 +void setRTCTime(int year, int month, int day, int hour, int minute, int second) +{ + RtcDateTime newTime(year, month, day, hour, minute, second); + Rtc.SetDateTime(newTime); +} + +#endif