MD_D1307 Real Time Clock Library  1.3
Library to control DS1307 real time clock
Software Overview

Using the Library

The library has a simple interface to the RTC hardware implemented through:

  • a set of time (h, m, s and dow) and date (yyyy, mm, dd) variables. All data to and from the RTC passes through these. Clock or alarm time data is read or written to these interface registers before the appropriate methods are invoke to act on that data.
  • control() and status() methods to set and query the functionality of the RTC.

The Control and Status Methods

The control() and status() methods are the main interface to action setting parameters or status values. The parameters used for each are similar, but not symmetrical, due to the way the hardware is implemented. The table below highlights the combinations of valid parameters for the control() method and whether a parameter can be changed by user code.

The status() method will return the current value from the parameter nominated and is guaranteed to be in the valid set.

Function R W Write value ------------------—
DS1307_CLOCK_HALT Y Y DS1307_ON, DS1307_OFF
DS1307_SQW_RUN Y Y DS1307_ON, DS1307_OFF
DS3231_SQW_TYPE_ON Y Y DS1307_SQW_1HZ, DS1307_SQW_4KHZ, DS1307_SQW_8KHZ, DS1307_SQW_32KHZ
DS1307_SQW_TYPE_OFF Y Y DS1307_SQW_HIGH, DS1307_SQW_LOW
DS1307_12H Y Y DS1307_ON, DS1307_OFF

Working with the Current Time

Reading the current time from the clock is a call to the readTime() method. The current date and time is then available in the interface registers.

Writing the current time is a sequence of writing to the interface registers followed by a call to the writeTime() method.

The DS1307_LCD_Time example has examples of the different ways of interacting with the RTC.