Fireduino/rtc

来自Firefly wiki
跳转至: 导航搜索

RTC -- HYM5863

HYM8563 is a low power CMOS real-time clock / calendar chip, which provides a programmable clock output, interrupt output and a brown-out detector, all of the address and data are communication with a serial I2C bus interface. The maximum bus speed of 400Kbit / s, each read and write data, built-in word address register is automatically incremented.

Fireduino RTC

Fireduino RTC use external devices for the I2C interface HYM5863, articulated in Wire1 Interface

Fireduino RTCTime Struct

//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)

   Description
        Get RTCTime 
   Syntax
        RTC.getTime(&time);
   Parameter
        RTCTime type point
   Returns 
        None   

setTime(RTCTime *time)

   Description 
         Set RTCTime 
   Syntax
         RTC.setTime(&time);
   Parameter 
         RTCTime type point
   Returns 
         None

Fireduino RTC Example

#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();
}