代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
This section describes the process of using RTC APIs:
Example:
#include "rtc_if.h"
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
{
if (alarmIndex == RTC_ALARM_INDEX_A) {
/* Process alarm A. */
printf("RTC Alarm A callback function\n\r");
} else if (alarmIndex == RTC_ALARM_INDEX_B) {
/* Process alarm B. */
printf("RTC Alarm B callback function\n\r");
} else {
/* Process the error. */
}
return 0;
}
void RtcTestSample(void)
{
int32_t ret;
struct RtcTime tm;
struct RtcTime alarmTime;
uint32_t freq;
DevHandle handle = NULL;
/* Obtain the RTC device handle. */
handle = RtcOpen();
if (handle == NULL) {
/* Process the error. */
}
/* Register RtcAlarmCallback for alarm A. */
ret = RtcRegisterAlarmCallback(handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
/* Process the error. */
}
/* Set the RTC external crystal frequency. Note that the frequency must be configured in accordance with the requirements specified in the product manual of the in-use component. */
freq = 32768; /* 32768 Hz */
ret = RtcSetFreq(handle, freq);
if (ret != 0) {
/* Process the error. */
}
/* Enable the RTC alarm interrupts. */
ret = RtcAlarmInterruptEnable(handle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
/* Process the error. */
}
/* Set the RTC time to 2020/01/01 00:00:10 .990. */
tm.year = 2020;
tm.month = 01;
tm.day = 01;
tm.hour= 0;
tm.minute = 0;
tm.second = 10;
tm.millisecond = 990;
/* Write the RTC time information. */
ret = RtcWriteTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
}
/* Set the RTC alarm time to 2020/01/01 00:00:30 .100. */
alarmTime.year = 2020;
alarmTime.month = 01;
alarmTime.day = 01;
alarmTime.hour = 0;
alarmTime.minute = 0;
alarmTime.second = 30;
alarmTime.millisecond = 100;
/* Set the alarm time information for RTC_ALARM_INDEX_A. When the specified time is reached, "RTC Alarm A callback function" is printed. */
ret = RtcWriteAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime);
if (ret != 0) {
/* Process the error. */
}
/* Read the RTC real time. */
ret = RtcReadTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
}
sleep(5)
printf("RTC read time:\n\r");
printf("year-month-date-weekday hour:minute:second .millisecond %04u-%02u-%02u-%u %02u:%02u:%02u .%03u",
tm.year, tm.month, tm.day, tm.weekday, tm.hour, tm.minute, tm.second, tm.millisecond);
/* Release the RTC device handle. */
RtcClose(handle);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。