libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
PCF8523 Class Reference

Interface to the PCF8523 Real Time Clock (RTC). More...

#include <pcf8523.h>

Public Member Functions

 PCF8523 ()
 Create a PCF8523 instance. More...
 
bool Init (I2C *newbus)
 Initialize a PCF8523 instance. More...
 
bool GetStatus ()
 Test to see if the device is present and readable. More...
 
bool SetClock (const int year, const int month, const int day, const int hour, const int minute, const int second, const int weekday=0)
 Sets the time on the RTC. More...
 
bool GetClock (int &year, int &month, int &day, int &hour, int &minute, int &second, int &weekday)
 Get the current time from the RTC chip. More...
 
bool GetClock (int &year, int &month, int &day, int &hour, int &minute, int &second)
 Get the current time from the RTC chip. More...
 

Detailed Description

Interface to the PCF8523 Real Time Clock (RTC).

Hardware connections: The PCF8523 should be connected to an I2C bus. If you want the clock to keep ticking after power is removed, make sure to attach a battery to the batt pin. The SQW pin can optionally be connected. At this time, this class does not use that pin for any purpose.

Possible improvements:

Author
SRLM

Constructor & Destructor Documentation

PCF8523::PCF8523 ( )
inline

Create a PCF8523 instance.

Member Function Documentation

bool PCF8523::GetClock ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  weekday 
)
inline

Get the current time from the RTC chip.

Note that the parameters are passed by reference.

Parameters
yearThe current year, in the range 0 to 99.
monthThe current month, in the range 1 to 12.
dayThe current day, in the range 1 to 31.
hourThe current hour, in the range 0 to 23.
minuteThe current second, in the range 0 to 59.
secondThe current second, in the range 0 to 59.
weekdayThe current weekday, in the range 0 to 6.
Returns
true if the RTC chip was successfully read, and false otherwise.

Here is the call graph for this function:

bool PCF8523::GetClock ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second 
)
inline

Get the current time from the RTC chip.

Note that the parameters are passed by reference.

Parameters
yearThe current year, in the range 0 to 99.
monthThe current month, in the range 1 to 12.
dayThe current day, in the range 1 to 31.
hourThe current hour, in the range 0 to 23.
minuteThe current second, in the range 0 to 59.
secondThe current second, in the range 0 to 59.
Returns
true if the RTC chip was successfully read, and false otherwise.

Here is the call graph for this function:

bool PCF8523::GetStatus ( void  )
inline

Test to see if the device is present and readable.

Sends a ping on the i2c bus.

Returns
present (true) or missing (false).

Here is the call graph for this function:

bool PCF8523::Init ( I2C newbus)
inline

Initialize a PCF8523 instance.

Set the control registers of the device:

  • CONTROL_1 (set to 0b10000000):
    • Set to 12.5pF capacitor (matches crystal)
    • 0 (no functionality)
    • Set to RTC time circuits running
    • No software reset
    • 24 Hour mode
    • second interrupt disabled
    • alrarm interrupt disabled
    • no correction input generated
  • CONTROL_2 (set to 0b00000000):
    • 0 (no functionality on write)
    • 0 (no functionality on write)
    • 0 (no functionality on write)
    • 0 (no functionality on write)
    • 0 (no functionality on write)
    • Disable watchdog timer A interrupt.
    • Disable countdown timer A interrupt.
    • Disable countdown timer B interrupt.
  • CONTROL_3 (set to 0b00000000):
    • Battery switch over (standard mode), battery low detection enabled
    • 0 (no functionality)
    • Reset battery switchover interrupt (whether set or not)
    • 0 (no functionality on write)
    • Set to no interrupt when battery switch over flag is set
    • Set to no interrupt when battery low flag is set
Parameters
newbusThe i2c bus to use.
Returns
true if successfully initialized, false otherwise

Here is the call graph for this function:

bool PCF8523::SetClock ( const int  year,
const int  month,
const int  day,
const int  hour,
const int  minute,
const int  second,
const int  weekday = 0 
)
inline

Sets the time on the RTC.

The various limits (ie, month less than 12) are not checked.

If the RTC chip has a battery backup, then the time will persist across power cycles.

Parameters
yearThe year to set, in the range 0 to 99.
monthThe month to set, in the range 1 to 12.
dayThe day to set, in the range 1 to 31.
hourThe hour to set, in the range 0 to 23.
minuteThe minute to set, in the range 0 to 59.
secondThe second to set, in the range 0 to 59.
weekdayThe weekday to set, in the range of 0 to 6. You can set and interpret this anyway that you want: it's simply incremented when the day changes.
Returns
true if the clock was successfully set, false otherwise.

Here is the call graph for this function:


The documentation for this class was generated from the following file: