#include <otRTC.h>
#include <otSerial.h>
#include <otTimer.h>
#include <otPrintfLite.h>
FAST_CODE_1 void rtcCallBack(void)
{
printf("Yawn ... uhm, uhm, sleep over ...\n");
}
void setup()
{
UartEnableSignals(UART0);
UartSetBaud(UART0, 115200);
setStdout(UART0);
RtcOn();
RtcSetInterruptService(rtcCallBack);
RtcSetDate(2020, 2, 19);
RtcSetTime(0, 0, 0);
}
void loop()
{
U16 val, loopCnt = 0;
U8 h, m, s;
int yy, mm, dd, min = 1;
while(1)
{
RtcGetTime(&h, &m, &s);
RtcGetDate(&yy, &mm, &dd);
printf("[%5d][%4d/%02d/%02d :: %02d:%02d:%02d] Countdown example:\n", loopCnt, yy, mm, dd, h, m, s);
RtcSetCountDown(10);
while(val = RtcGetCountDown())
{
printf("%5u\r", val);
DelayMs(500);
}
RtcSetCountDown(10);
RtcInterruptEnable(Rtc_Stopwatch, true);
RtcGetTime(&h, &m, &s);
printf("[%5d][%4d/%02d/%02d :: %02d:%02d:%02d] Now I do a little sleep but in 10 seconds I wake up .... ", loopCnt, yy, mm, dd, h, m, s);
DelayMs(5);
SLEEP;
RtcInterruptEnable(Rtc_Stopwatch, false);
RtcGetTime(&h, &m, &s);
printf("[%5d][%4d/%02d/%02d :: %02d:%02d:%02d] I'll take a little longer sleep, but I'll be back soon ... ", loopCnt, yy, mm, dd, h, m, s);
RtcInterruptEnable(Rtc_Alarm, true);
RtcSetAlarm(0, min, 0);
min++;
SLEEP;
RtcInterruptEnable(Rtc_Alarm, false);
loopCnt++;
}
}