上传文件至 /
This commit is contained in:
parent
8f306d1955
commit
3a4bb831be
44
RTC_Module.h
Normal file
44
RTC_Module.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef RTC_MODULE_H
|
||||
#define RTC_MODULE_H
|
||||
|
||||
#include <RtcDS1302.h>
|
||||
#include <ThreeWire.h>
|
||||
|
||||
// RTC通信对象
|
||||
extern ThreeWire myWire;
|
||||
extern RtcDS1302<ThreeWire> 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
|
Loading…
x
Reference in New Issue
Block a user