• Ambiq MicroAMA3B2KKKBR芯片可穿戴产品解决方案开发之RTC时钟


    一 RTC
     
      RTC的英文全称是Real-Time Clock,翻译过来是实时时钟芯片。绝大多数mcu芯片都集成了这个功能。在可穿戴产品中,时间往往是非常重要的因素,怎么让时间保持一直在运行,那就是rtc时钟的功劳了。怎么让rtc超低功耗的运行,这个是其中的难点。
     
    二 源码解析
     
    -AMA3B2KK-KBR的rtc时钟初始化由三个函数组成,如下所示:函数注释比较简答明了,这里不做赘述了。
        //
        // Enable the XT for the RTC.
        //
        am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_XTAL_START, 0);
    
        //
        // Select XT for RTC clock source
        //
        am_hal_rtc_osc_select(AM_HAL_RTC_OSC_XT);
    
        //
        // Enable the RTC.
        //
        am_hal_rtc_osc_enable();
     
    接下来看一下该rtc是怎么获取时间的,从源码中来看,是直接从编译环境的pc机上获取的,假如你把刚编译好的bin文件load进去,这个rtc就会按照这个时间往下走。
        //
        // The RTC is initialized from the date and time strings that are
        // obtained from the compiler at compile time.
        //
        hal_time.ui32Hour = toVal(&__TIME__[0]);
        hal_time.ui32Minute = toVal(&__TIME__[3]);
        hal_time.ui32Second = toVal(&__TIME__[6]);
        hal_time.ui32Hundredths = 00;
        hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + toVal(&__DATE__[9]), mthToIndex(&__DATE__[0]) + 1, toVal(&__DATE__[4]) );
        hal_time.ui32DayOfMonth = toVal(&__DATE__[4]);
        hal_time.ui32Month = mthToIndex(&__DATE__[0]);
        hal_time.ui32Year = toVal(&__DATE__[9]);
        hal_time.ui32Century = 0;
     
    三 效果展示
     
      下面看一下笔者的rtc时钟的日志信息,每间隔1s读取rtc时钟一次,可以看出来,时间走的还挺准的。
     
    四 总结
     
      至此,rtc时钟的功能完善了,再加上显示,一个手表就这样诞生了。
  • 相关阅读:
    hdu 2444(二分图) The Accomodation of Students
    hdu 5532 (LIS) Almost Sorted Array
    hdu 1059 (多重背包) Dividing
    poj 2184(Cow Exhibition)
    hdu 2571 (命运) 那个配图女神
    poj 3624 && hdu 2955(背包入门)
    hdu 1257 && hdu 1789(简单DP或贪心)
    BBS(第一天)项目之 注册功能实现通过forms验证与 前端ajax请求触发查询数据库判断用户是否存在的功能实现
    Django之form模板的使用
    Django之Auth模块 实现登录,退出,自带session 与认证功能的一个重要的模块
  • 原文地址:https://www.cnblogs.com/dylancao/p/16091287.html
Copyright © 2020-2023  润新知