pdf-icon

RTC

RTC相关函数使用前请使用M5.begin()进行初始化

RTC_Time & RTC_Date 结构体

typedef struct RTC_Time {
    int8_t hour;
    int8_t min;
    int8_t sec;
    RTC_Time() : hour(), min(), sec() {}
    RTC_Time(int8_t h, int8_t m, int8_t s) : hour(h), min(m), sec(s) {}
} rtc_time_t;

typedef struct RTC_Date {
    int8_t week;
    int8_t mon;
    int8_t day;
    int16_t year;
    RTC_Date() : week(), mon(), day(), year() {}
    RTC_Date(int8_t w, int8_t m, int8_t d, int16_t y)
        : week(w), mon(m), day(d), year(y) {}
} rtc_date_t;

Begin()

功能说明:

初始化RTC

RTC相关函数使用前请使用M5.RTC.begin()进行初始化

函数原型:

void begin()

setTime()

功能说明:

设置结构体变量时间

函数原型:

void setTime(const rtc_time_t *time)

案例程序:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_time_t RTCtime;

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCtime.hour = 00;
    RTCtime.min  = 00;
    RTCtime.sec  = 00;
    M5.RTC.setTime(&RTCtime);
}

void loop() {}

getTime()

功能说明:

获取结构体时间

函数原型:

void getTime(rtc_time_t *time)

案例程序:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

rtc_time_t RTCtime;
char timeStrbuff[64];

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCtime.hour = 00;
    RTCtime.min  = 00;
    RTCtime.sec  = 00;
    M5.RTC.setTime(&RTCtime);
}

void loop() {
    M5.RTC.getTime(&RTCtime);
    sprintf(timeStrbuff, "%02d:%02d:%02d", RTCtime.hour, RTCtime.min,
            RTCtime.sec);
    canvas.drawString(timeStrbuff, 0, 0);
    canvas.pushCanvas(200, 200, UPDATE_MODE_DU4);
    delay(2000);
}

setDate()

功能说明:

设置结构体变量日期

函数原型:

void setDate(const rtc_date_t *date)

案例程序:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_date_t RTCDate;

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCDate.year = 2020;
    RTCDate.mon  = 11;
    RTCDate.day  = 27;
    M5.RTC.setDate(&RTCDate);
}

void loop() {}

getDate()

功能说明:

获取结构体变量日期

函数原型:

void getDate(rtc_date_t *date)

案例程序:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_date_t RTCDate;
char timeStrbuff[64];

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCDate.year = 2020;
    RTCDate.mon  = 11;
    RTCDate.day  = 27;
    M5.RTC.setDate(&RTCDate);
}

void loop() {
    M5.RTC.getDate(&RTCDate);
    sprintf(timeStrbuff, "%02d:%02d:%02d", RTCDate.year, RTCDate.mon,
            RTCDate.day);
    canvas.drawString(timeStrbuff, 0, 0);
    canvas.pushCanvas(150, 200, UPDATE_MODE_DU4);
    delay(10000);
}

SetAlarmIRQ()

功能说明:

设置中断时钟

函数原型:

int SetAlarmIRQ(int afterSeconds)

int setAlarmIRQ(const rtc_time_t &time)

int setAlarmIRQ(const rtc_date_t &date, const rtc_time_t &time)

案例程序:

#include <M5Core2.h>

RTC_TimeTypeDef TimeStruct;
void setup() {
  M5.begin();
  M5.Lcd.println("RTC SetAlarmIQR");
  TimeStruct.Hours   = 18;
  TimeStruct.Minutes = 56;
  TimeStruct.Seconds = 10;
  M5.Rtc.SetTime(&TimeStruct);
}

void loop() {
  M5.update();
  M5.Rtc.GetTime(&TimeStruct);
  M5.Lcd.setCursor(0, 15);
  M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
  if(M5.BtnA.wasPressed()){
    M5.Lcd.println("M5Core2 Will Close, Restore After 5 seconds ");
    delay(2000);
    M5.Rtc.clearIRQ();
    M5.Rtc.SetAlarmIRQ(5);
    delay(10);
    M5.Axp.PowerOff();
  }
}

clearIRQ()

功能说明:

清除中断请求

函数原型:

void clearIRQ()

disableIRQ()

功能说明:

关闭中断请求

函数原型:

void disableIRQ()

On This Page