Fireduino 开源创意平台 立即购买

拥有双核Cortex-M3处理器,集成高质量音频Codec和WiFi模组,拥有良好的IOT扩展性能,完美兼容Arduino IDE和Arduino标准接口,并支持FireBlock图形化编程软件,是一款首选的编程启蒙教学平台,更是一款开源的创意原型平台。

RTC

更新时间:2017-08-08 阅读:1427

RTC -- HYM5863

HYM8563是一款低功耗CMOS实时时钟/日历芯片,它提供一个可编程的时钟输出,一个中断输出和一个掉电检测器,所有的地址和数据都通过I2C总线接口串行传递。最大总线速度为400Kbit/s,每次读写数据后,内嵌的字地址寄存器会自动递增。

Fireduino RTC

Fireduino RTC 使用外接设备为I2C 接口的HYM5863,挂接在Wire1 接口

Fireduino RTCTime 相关结构体

//datetimeInfo struct
typedef struct
{
    unsigned short year;//year (1900 ~ 2099)
    unsigned char  mon;//month,begin from 1 to 12
    unsigned char  week;//week (0:Sunday 1:Monday ... 6:Saturday)
    unsigned char  day;//day,begin from 1 to 31
    unsigned char  hour;//hour,24-hour
    unsigned char  min;//minute
    unsigned char  sec;//second
}RTCTime;

Fireduino RTC API

getTime(RTCTime *time)

   说明
        获取RTCTime 
   语法
        RTC.getTime(&time);
   参数
        RTCTime 类型指针
   返回
        无   

setTime(RTCTime *time)

   说明
         设置RTCTime 
   语法
         RTC.setTime(&time);
   参数
         RTCTime 类型指针
   返回
         无

Fireduino RTC 示例程序

#include "Arduino.h"
#include "Wire.h"
#include "RTC.h"
RTCTime time;
void setup(void)
{
	Serial.begin(115200);
	Serial.print("\r\n FireDuino Setup ...\r\n");
	time.year  = 2016;//year (1900 ~ 2099)
	time.mon   = 3;//month,begin from 1 to 12
	time.week  = 1 ;//week (0:Sunday 1:Monday ... 6:Saturday)
	time.day   = 14;//day,begin from 1 to 31
	time.hour  = 23;//hour,24-hour
	time.min   = 59;//minute
	time.sec   = 50;//second
	Wire1.begin();
	RTC.setTime(&time);
}
void loop(void)
{
	delay(100);
	RTC.getTime(&time);
	Serial.println();
	Serial.print("Y:");
	Serial.print(time.year,DEC);
	Serial.print(" M:");
	Serial.print(time.mon,DEC);
	Serial.print(" W:");
	Serial.print(time.week,DEC);
	Serial.print(" d:");
	Serial.print(time.day,DEC);
	Serial.print(" h:");
	Serial.print(time.hour,DEC);
	Serial.print(" m:");
	Serial.print(time.min,DEC);
	Serial.print(" s:");
	Serial.print(time.sec,DEC);
	Serial.println();
}