MicroPython STM32F4 RTC功能使用介绍

📓RTC属于mpy模块中的类

>>> from pyb import RTC
>>> help(RTC)
object <class 'RTC'&gt; is of type type
  init -- <function>
  info -- <function>
  datetime -- <function>
  wakeup -- <function>
  calibration -- <function>

📝RTC测试代码

from pyb import RTC
import time
# 定义星期数组
weekdays = ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
rtc = RTC()
rtc.datetime((2023, 11, 28, 2, 21, 10, 15, 0)) # set a specific date and time

if __name__ == '__main__':   
    while True:
        # Get the current time from the RTC
        current_time = rtc.datetime()
        print(current_time) # get date and time
        time.sleep(1)
        year, month, day,weekday, hour, minute, second,  yearday = rtc.datetime()
        # 获取星期对应数组成员
        weekday_name = weekdays[weekday]
        print("当前时间:{}-{}-{} {}:{}:{} Week:{}".format(year, month, day, hour, minute, second,weekday_name))


在这里插入图片描述

原文地址:https://blog.csdn.net/weixin_42880082/article/details/134677014

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_49639.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注