LTlib LaurTec Library  4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
MCP7940.c File Reference
#include "MCP7940.h"

Go to the source code of this file.

Functions

void RTCC_initialize (unsigned int baud_rate_KHz)
 
void RTCC_start_oscillator (void)
 
signed char RTCC_set_seconds (unsigned char seconds)
 
unsigned char RTCC_get_seconds (void)
 
signed char RTCC_set_minutes (unsigned char minutes)
 
unsigned char RTCC_get_minutes (void)
 
signed char RTCC_set_hours (unsigned char hours)
 
unsigned char RTCC_get_hours (void)
 
unsigned char * RTCC_get_time_seconds (void)
 
unsigned char * RTCC_get_time (void)
 
signed char RTCC_set_days (unsigned char days)
 
unsigned char RTCC_get_days (void)
 
signed char RTCC_set_months (unsigned char months)
 
unsigned char RTCC_get_months (void)
 
signed char RTCC_set_years (unsigned char years)
 
unsigned char RTCC_get_years (void)
 
unsigned char * RTCC_get_date (void)
 
signed char RTCC_set_seconds_alarm (unsigned char seconds, unsigned char alarm_enable)
 
signed char RTCC_set_minutes_alarm (unsigned char minutes, unsigned char alarm_enable)
 
signed char RTCC_set_hours_alarm (unsigned char hours, unsigned char alarm_enable)
 
signed char RTCC_set_days_alarm (unsigned char days, unsigned char alarm_enable)
 
signed char RTCC_enable_alarm_interrupt (void)
 
signed char RTCC_disable_alarm_interrupt (void)
 
unsigned char RTCC_is_alarm_ON (void)
 
signed char RTCC_increment_minutes (void)
 
signed char RTCC_increment_hours (void)
 
signed char RTCC_increment_years (void)
 
signed char RTCC_increment_months (void)
 
signed char RTCC_increment_days (void)
 

Function Documentation

signed char RTCC_disable_alarm_interrupt ( void  )

This function disable the interrupt pin functionality.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision

Definition at line 408 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_CONFIGURATION_REG_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_enable_alarm_interrupt ( void  )

This function enables the interrupt pin functionality.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision

Definition at line 394 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_CONFIGURATION_REG_ADDR, and RTCC_WRITE_ADD.

unsigned char* RTCC_get_date ( void  )

This function reads the Date from the RTC. The Format DD/MM/YY

Returns
Date that is read back, as ASCII string terminated with /0

Definition at line 288 of file MCP7940.c.

References RTCC_get_days(), RTCC_get_months(), and RTCC_get_years().

unsigned char RTCC_get_days ( void  )

This function reads the day from the RTC.

Returns
Days that are read back, in BCD format (eg. 12 is 0x12 or 0b00010010).
Note
Days are in BCD format.

Definition at line 230 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_DAYS_ADDR, and RTCC_WRITE_ADD.

unsigned char RTCC_get_hours ( void  )

This function reads the hours from the RTC.

Returns
Hours that are read back, in BCD format (eg. 12 is 0x12 or 0b00010010).
Note
Hours are in BCD format.

Definition at line 146 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_HOURS_ADDR, and RTCC_WRITE_ADD.

unsigned char RTCC_get_minutes ( void  )

This function reads the minutes from the RTC.

Returns
Minutes that are read back, in BCD format (eg. 22 min. is 0x22 or 0b00100010).
Note
Seconds are in BCD format.

Definition at line 123 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_MINUTES_ADDR, and RTCC_WRITE_ADD.

unsigned char RTCC_get_months ( void  )

This function reads the months from the RTC.

Returns
Months that are read back, in BCD format (eg. 12 is 0x12 or 0b00010010).
Note
Months are in BCD format.

Definition at line 254 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_MONTHS_ADDR, and RTCC_WRITE_ADD.

unsigned char RTCC_get_seconds ( void  )

This function reads the second from the RTC.

Returns
Second that are read back, in BCD format (eg. 22 sec. is 0x22 or 0b00100010).
Note
Seconds are in BCD format.

Definition at line 96 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_SECONDS_ADDR, and RTCC_WRITE_ADD.

unsigned char* RTCC_get_time ( void  )

This function reads the time from the RTC. The format is HH:MM (without seconds)

Returns
Time that is read back, as ASCII string terminated with /0

Definition at line 193 of file MCP7940.c.

References RTCC_get_hours(), and RTCC_get_minutes().

unsigned char* RTCC_get_time_seconds ( void  )

This function reads the time from the RTC. The format is HH:MM.ss

Returns
Time that is read back, as ASCII string terminated with /0

Definition at line 160 of file MCP7940.c.

References RTCC_get_hours(), RTCC_get_minutes(), and RTCC_get_seconds().

unsigned char RTCC_get_years ( void  )

This function reads the Year from the RTC.

Returns
Year that is read back, in BCD format (eg. 12 is 0x12 or 0b00010010 represents 2012).
Note
Year are in BCD format. 2012 is read as 0x12.

Definition at line 277 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, RTCC_WRITE_ADD, and RTCC_YEARS_ADDR.

signed char RTCC_increment_days ( void  )

This function increments the Days inside the RTCC.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
The function automatically checks the overflow.

Definition at line 598 of file MCP7940.c.

References RTCC_get_days(), RTCC_MAX_DAYS, and RTCC_set_days().

signed char RTCC_increment_hours ( void  )

This function increments the hours inside the RTCC.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
The function automatically checks the overflow.

Definition at line 494 of file MCP7940.c.

References RTCC_get_hours(), RTCC_MAX_HOURS, and RTCC_set_hours().

signed char RTCC_increment_minutes ( void  )

This function increments the minutes inside the RTCC.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
The function automatically checks the overflow and automatically increments the hours.

Definition at line 459 of file MCP7940.c.

References RTCC_get_minutes(), RTCC_MAX_MINUTES, and RTCC_set_minutes().

signed char RTCC_increment_months ( void  )

This function increments the Months inside the RTCC.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
The function automatically checks the overflow.

Definition at line 564 of file MCP7940.c.

References RTCC_get_months(), RTCC_MAX_MONTHS, and RTCC_set_months().

signed char RTCC_increment_years ( void  )

This function increments the Years inside the RTCC.

Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
The function automatically checks the overflow.

Definition at line 529 of file MCP7940.c.

References RTCC_get_years(), RTCC_MAX_YEARS, and RTCC_set_years().

void RTCC_initialize ( unsigned int  baud_rate_KHz)

This function initialize the I2C module accordingly to the clock and baud rate.

Parameters
baud_rate_KHzBaud rate expressed in KHz
Returns
Note
If other devices are connected on the I2C bus the baud rate would be changed by the function. Among several calls from different device initializations, only the last one will be reflected in the I2C module configuration.

Definition at line 60 of file MCP7940.c.

References I2C_MASTER, MCP7940_I2C_baud_rate, MCP7940_I2C_open, and RTCC_start_oscillator().

unsigned char RTCC_is_alarm_ON ( void  )

This function checks if the Alarm id ON using polling method.

Returns
status Alarm status 1: ON 0:OFF
Note
If the alarm is on, AF flag is automatically cleaned.

Definition at line 423 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_ALARM_CONTROL_REG_1_ADDR, RTCC_ALARM_CONTROL_REG_2_ADDR, RTCC_CONFIGURATION_REG_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_days ( unsigned char  days)

This function writes the days in the RTC.

Parameters
daysDay to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Days are in BCD format. Decimal format won't work!

Definition at line 221 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_DAYS_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_days_alarm ( unsigned char  days,
unsigned char  alarm_enable 
)

This function writes the Days for the alarm, in the RTC.

Parameters
daysDays to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
alarmEnableEnable the alarm or not (for matching) [ENABLE_ON , ENABLE_OFF]
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Days are in BCD format. Decimal format won't work!
Note
Use the constants ENABLE_ON and ENABLE_OFF

Definition at line 375 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_ALARM_CONTROL_REG_1_ADDR, RTCC_DAYS_ALARM_ADDR, RTCC_ENABLE_ON, and RTCC_WRITE_ADD.

signed char RTCC_set_hours ( unsigned char  hours)

This function writes the hours in the RTC.

Parameters
hoursHours to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Hours are in BCD format. Decimal format won't work!

Definition at line 137 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_HOURS_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_hours_alarm ( unsigned char  hours,
unsigned char  alarm_enable 
)

This function writes the hours for the alarm, in the RTC.

Parameters
hoursHours to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
alarmEnableEnable the alarm or not (for matching) [ENABLE_ON , ENABLE_OFF]
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Hours are in BCD format. Decimal format won't work!
Note
Use the constants ENABLE_ON and ENABLE_OFF

Definition at line 357 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_ALARM_CONTROL_REG_1_ADDR, RTCC_ENABLE_ON, RTCC_HOURS_ALARM_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_minutes ( unsigned char  minutes)

This function writes the seconds in the RTC.

Parameters
minutesMinutes to be written, as 2 digits BCD format (eg. 22 min. is 0x22 or 0b00100010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Minutes are in BCD format. Decimal format won't work!

Definition at line 113 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_MINUTES_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_minutes_alarm ( unsigned char  minutes,
unsigned char  alarm_enable 
)

This function writes the minutes for the alarm, in the RTC.

Parameters
minutesMinutes to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
alarmEnableEnable the alarm or not (for matching) [ENABLE_ON , ENABLE_OFF]
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Minutes are in BCD format. Decimal format won't work!
Note
Use the constants ENABLE_ON and ENABLE_OFF

Definition at line 340 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_ALARM_CONTROL_REG_1_ADDR, RTCC_ENABLE_ON, RTCC_MINUTES_ALARM_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_months ( unsigned char  months)

This function writes the moths in the RTC.

Parameters
monthsMonths to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Months are in BCD format. Decimal format won't work!

Definition at line 244 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_MONTHS_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_seconds ( unsigned char  seconds)

This function writes the seconds in the RTC.

Parameters
secondsSeconds to be written, as 2 digits BCD format (eg. 22 sec. is 0x22 or 0b00100010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Seconds are in BCD format. Decimal format won't work!

Definition at line 84 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_SECONDS_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_seconds_alarm ( unsigned char  seconds,
unsigned char  alarm_enable 
)

This function writes the seconds for the alarm, in the RTC.

Parameters
secondsSeconds to be written, as 2 digits BCD format (eg. 12 is 0x12 or 0b00010010).
alarmEnableEnable the alarm or not (for matching) [ENABLE_ON , ENABLE_OFF]
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Seconds are in BCD format. Decimal format won't work!
Note
Use the constants ENABLE_ON and ENABLE_OFF

Definition at line 322 of file MCP7940.c.

References MCP7940_I2C_read_byte_from_external_device, MCP7940_I2C_write_byte_to_external_device, RTCC_ALARM_CONTROL_REG_1_ADDR, RTCC_ENABLE_ON, RTCC_SECONDS_ALARM_ADDR, and RTCC_WRITE_ADD.

signed char RTCC_set_years ( unsigned char  years)

This function writes the Year in the RTC.

Parameters
yearsYear to be written, as 2 digits BCD format (eg. 2012 is only 0x12 or 0b00010010).
Returns
status 0: The info has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
Years are in BCD format. Decimal format won't work!
Note
2012 is written as 12.

Definition at line 268 of file MCP7940.c.

References MCP7940_I2C_write_byte_to_external_device, RTCC_WRITE_ADD, and RTCC_YEARS_ADDR.

void RTCC_start_oscillator ( void  )

This function enable the internal 32KHz buffer to let the external crystal oscillate.

Parameters
void
Returns

Definition at line 71 of file MCP7940.c.

References delay_ms(), and RTCC_set_seconds().