From 3a4bb831be3e14a6627cf2a0109a04c740a48ef5 Mon Sep 17 00:00:00 2001 From: spdis Date: Fri, 30 May 2025 18:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RTC_Module.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 RTC_Module.h 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