MD_D1307 Real Time Clock Library
1.3
Library to control DS1307 real time clock
|
#include <MD_DS1307.h>
Public Member Functions | |
MD_DS1307 () | |
MD_DS1307 (int sda, int scl) | |
Methods for object and hardware control. | |
void | control (uint8_t item, uint8_t value) |
uint8_t | status (uint8_t item) |
Methods for RTC operations | |
void | readTime (void) |
void | writeTime (void) |
void | now (void) |
boolean | isRunning (void) |
Miscellaneous methods | |
uint8_t | readRAM (uint8_t addr, uint8_t *buf, uint8_t len) |
uint8_t | writeRAM (uint8_t addr, uint8_t *buf, uint8_t len) |
uint8_t | calcDoW (uint16_t yyyy, uint8_t mm, uint8_t dd) |
Public Attributes | |
Public variables for reading and writing time data | |
uint16_t | yyyy |
Year including the century. | |
uint8_t | mm |
Month (1-12) | |
uint8_t | dd |
Date of the month (1-31) | |
uint8_t | h |
Hour of the day (1-12) or (0-23) depending on the am/pm or 24h mode setting. | |
uint8_t | m |
Minutes past the hour (0-59) | |
uint8_t | s |
Seconds past the minute (0-59) | |
uint8_t | dow |
Day of the week (1-7). Sequential number; day coding depends on the application and zero is an undefined value. | |
uint8_t | pm |
Non-zero if 12 hour clock mode and PM, always zero for 24 hour clock. Check the time and if < 12 then check this indicator. | |
Core object for the MD_DS1307 library
MD_DS1307::MD_DS1307 | ( | ) |
Class Constructor
Instantiate a new instance of the class. One instance of the class is created in the libraries as the RTC object.
MD_DS1307::MD_DS1307 | ( | int | sda, |
int | scl | ||
) |
Overloaded Class Constructor (ESP8266 only)
Provides a way to assign custom SCL and SDA pins if the architecture supports them.
sda | Pin number for the SDA signal |
scl | Pin number for the SCL signal |
uint8_t MD_DS1307::calcDoW | ( | uint16_t | yyyy, |
uint8_t | mm, | ||
uint8_t | dd | ||
) |
Calculate day of week for a given date
Given the specified date, calculate the day of week.
yyyy | year for specified date. yyyy must be > 1752. |
mm | month for the specified date where mm is in the range [1..12], 1 = January. |
dd | date for the specified date in the range [1..31], where 1 = first day of the month. |
void MD_DS1307::control | ( | uint8_t | item, |
uint8_t | value | ||
) |
Set the control status of the specified parameter to the specified value.
The device has a number of control parameters that can be set through this method. The type of control action required is passed through the mode parameter and should be one of the defined control actions. The value that needs to be supplied on the control action required is one of the defined status values. Not all combinations of item and value are valid.
item | one of the defined code request values. |
value | value as one of the defined code status values. |
boolean MD_DS1307::isRunning | ( | void | ) |
Compatibility function - Check if RTC is running
Wrapper for a HALT status check
void MD_DS1307::now | ( | void | ) |
Compatibility function - Read the current time
Wrapper to read the current time.
uint8_t MD_DS1307::readRAM | ( | uint8_t | addr, |
uint8_t * | buf, | ||
uint8_t | len | ||
) |
Read the raw RTC clock data
Read len bytes from the RTC clock starting at addr as raw data into the buffer supplied. The size of the buffer should be at least MAX_BUF bytes long (defined in the library cpp file).
Read address starts at 0.
addr | starting address for the read. |
buf | address of the receiving byte buffer. |
len | number of bytes to read. |
void MD_DS1307::readTime | ( | void | ) |
Read the current time into the interface registers
Query the RTC for the current time and load that into the library interface registers (yyyy, mm, dd, h, m, s, dow, pm) from which the data can be accessed.
uint8_t MD_DS1307::status | ( | uint8_t | item | ) |
Obtain the current setting for the specified parameter.
Any of the parameters that can be set from the control() method can be queried using this method. The code status value returned will be one of the defined values for the control() method for each specific code request parameter.
item | one of the defined control request values. |
uint8_t MD_DS1307::writeRAM | ( | uint8_t | addr, |
uint8_t * | buf, | ||
uint8_t | len | ||
) |
Write the raw RTC clock data
Write len bytes of data in the buffer supplied to the RTC clock starting at addr. The size of the buffer should be at least len bytes long.
Write address starts at 8 (first 7 bytes are for clock registers).
addr | starting address for the write. |
buf | address of the data buffer. |
len | number of bytes to write. |
void MD_DS1307::writeTime | ( | void | ) |
Write the current time from the interface registers
Write the data in the interface registers (yyyy, mm, dd, h, m, s, dow, pm) as the current time in the RTC.