S32K144之SDK版:RTC时钟应用

一、RTC概述

  1. 背景

  2. 定义

实时时钟的缩写是RTC(Real_Time Clock)。RTC 是集成电路,通常称为

  1. 本质

一个32位的计数器,只能向上计数(输入频率低的定时器,可以记录很久的时间,有电子的,可以MCU掉电继续记录时间)

  1. 应用场景

日历:记录一个时间(年月日,时分秒)

闹钟:设定特定时间进入中断(处理特定事情:软件复位,软件唤醒,退出待机...)

RTC_Second(秒中断)

RTC_Overflow(溢出事件/时间无效)

RTC_Alarm(闹钟中断)

二、RTC应用

模块配置

初始化

void RTC_Init(void)
{
    /* Initialize RTC instance
     *  - See RTC configuration component for options
     */
    RTC_DRV_Init(RTCTIMER1, &rtcTimer1_Config0);
    /* Set the time and date */
    RTC_DRV_SetTimeDate(RTCTIMER1, &rtcTimer1_StartTime0);
    /* Start the RTC counter */
    RTC_DRV_StartCounter(RTCTIMER1);
}

测试代码

void RTC_Get_CurrentTime(uint16_t year,uint16_t month,uint16_t day,uint16_t hour,uint16_t minutes,uint8_t seconds)
{
    rtc_timedate_t tempTime = {0};

    RTC_DRV_GetCurrentTimeDate(RTCTIMER1, &tempTime);

    year = tempTime.year;
    month = tempTime.month;
    day = tempTime.day;
    hour = tempTime.hour;
    minutes = tempTime.minutes;
    seconds = tempTime.seconds;
}

void RTC_Set_CurrentTime(uint16_t year,uint16_t month,uint16_t day,uint16_t hour,uint16_t minutes,uint8_t seconds)
{
    rtc_timedate_t tempTime = {0};

    tempTime.year = year;
    tempTime.month = month;
    tempTime.day = day;
    tempTime.hour = hour;
    tempTime.minutes = minutes;
    tempTime.seconds = seconds;

    RTC_DRV_StopCounter(RTCTIMER1);
    RTC_DRV_SetTimeDate(RTCTIMER1, &tempTime);
    RTC_DRV_StartCounter(RTCTIMER1);
}

void RTC_test(void)
{
    ///放在周期中跑,看打印时间
    rtc_timedate_t tempTime;
    RTC_DRV_GetCurrentTimeDate(RTCTIMER1, &tempTime);
    u1_Printf("Current time:%d/%d/%d    %d:%d:%d \r\n",tempTime.year,tempTime.month,tempTime.day,tempTime.hour,tempTime.minutes,tempTime.seconds);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值