m41t81s.h File Reference

Routines for communicating with the m41t81s real time clock. More...

#include "i2c.h"
#include "pic_utils.h"
Include dependency graph for m41t81s.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __m41t81s_h   defined
#define m41t81s_alarm_date_reg   0x0B
#define m41t81s_alarm_hour_reg   0x0C
#define m41t81s_alarm_min_reg   0x0D
#define m41t81s_alarm_month_reg   0x0A
#define m41t81s_alarm_seconds_reg   0x0E
#define m41t81s_calibration_reg   0x08
#define m41t81s_date_reg   0x05
#define m41t81s_device_addr   0xD0
#define m41t81s_dow_reg   0x04
#define m41t81s_flags_reg   0x0F
#define m41t81s_hours_reg   0x03
#define m41t81s_minutes_reg   0x02
#define m41t81s_month_reg   0x06
#define m41t81s_part_seconds_reg   0x00
#define m41t81s_reserved1_reg   0x10
#define m41t81s_reserved2_reg   0x11
#define m41t81s_reserved3_reg   0x12
#define m41t81s_seconds_reg   0x01
#define m41t81s_sqw_reg   0x13
#define m41t81s_watchdog_reg   0x09
#define m41t81s_year_reg   0x07
#define rtc_setup()   rtc_setup_io()
#define rtc_sqw_freq_1024Hz   0b00000101
#define rtc_sqw_freq_128Hz   0b00001000
#define rtc_sqw_freq_16Hz   0b00001011
#define rtc_sqw_freq_1Hz   0b00001111
#define rtc_sqw_freq_2048Hz   0b00000100
#define rtc_sqw_freq_256Hz   0b00000111
#define rtc_sqw_freq_2Hz   0b00001110
#define rtc_sqw_freq_32768Hz   0b00000001
#define rtc_sqw_freq_32Hz   0b00001010
#define rtc_sqw_freq_4096Hz   0b00000011
#define rtc_sqw_freq_4Hz   0b00001101
#define rtc_sqw_freq_512Hz   0b00000110
#define rtc_sqw_freq_64Hz   0b00001001
#define rtc_sqw_freq_8192Hz   0b00000010
#define rtc_sqw_freq_8Hz   0b00001100

Functions

uns8 rtc_get_date ()
 Get the date register from the m41t81s.
uns8 rtc_get_dow ()
 Get the day register from the m41t81s.
uns8 rtc_get_hours ()
 Get the decoded hours register from the m41t81s.
uns8 rtc_get_minutes ()
 Get the decoded minutes register from the m41t81s.
uns8 rtc_get_month ()
 Get the month register from the m41t81s.
uns8 rtc_get_register (uns8 reg)
uns8 rtc_get_seconds ()
 Get the decoded seconds register from the m41t81s.
uns8 rtc_get_year ()
 Get the year register from the m41t81s.
uns8 rtc_set_config (uns8 config)
 Set the config register in the m41t81s.
void rtc_set_date (uns8 date)
 Set the date register from the m41t81s.
void rtc_set_day (uns8 day)
 Set the day of the week register from the m41t81s.
void rtc_set_hours (uns8 hours)
 Set the hours register in the m41t81s.
void rtc_set_minutes (uns8 minutes)
 Set the minutes register from the m41t81s.
void rtc_set_month (uns8 month)
 Set the month register in the m41t81s.
void rtc_set_register (uns8 reg, uns8 data)
void rtc_set_seconds (uns8 seconds)
 Set the seconds register in the m41t81s.
void rtc_set_sqw_freq (uns8 freq)
 Set the frequence of the square wave output pin.
void rtc_set_year (uns8 year)
 Set the year register from the m41t81s.
void rtc_setup_io ()
 Setup ports and pins for use in the m41t81s.
void rtc_start_clock ()
 Starts the clock in the m41t81s.
void rtc_start_sqw_output ()
 Start pulsing on square wave output pin.
void rtc_stop_clock ()
 Stop the clock in the m41t81s.
void rtc_stop_sqw_output ()
 Stop pulsing on square wave output pin.

Detailed Description

Definition in file m41t81s.h.


Define Documentation

#define __m41t81s_h   defined

Definition at line 44 of file m41t81s.h.

#define m41t81s_alarm_date_reg   0x0B

m41t81s alarm date register (D7=RPT4, D6=RPT5, D5-D4=ABE, D4=AL 10M, D3-D0=Alarm month)

Definition at line 95 of file m41t81s.h.

#define m41t81s_alarm_hour_reg   0x0C

m41t81s alarm hour register (D7=RPT3, D6=HT, D5-D4=Alarm 10 Hour, D3-D0=Alarm Hour)

Definition at line 97 of file m41t81s.h.

Referenced by rtc_start_clock().

#define m41t81s_alarm_min_reg   0x0D

m41t81s alarm min register (D7=RPT2, D6-D4=Alarm 10 Minutes, D3-D0=Alarm Minutes)

Definition at line 99 of file m41t81s.h.

#define m41t81s_alarm_month_reg   0x0A

m41t81s alarm month register (D7=AFE, D6=SQWE, D5=ABE, D4=AL 10M, D3-D0=Alarm month)

Definition at line 93 of file m41t81s.h.

Referenced by rtc_start_sqw_output(), and rtc_stop_sqw_output().

#define m41t81s_alarm_seconds_reg   0x0E

m41t81s alarm seconds register (D7=RPT1, D6-D4=Alarm 10 Seconds, D3-D0=Alarm Seconds)

Definition at line 101 of file m41t81s.h.

#define m41t81s_calibration_reg   0x08

m41t81s calibration register (D7=OUT, D6=FT, D5=S D4-D0=Calibration)

Definition at line 89 of file m41t81s.h.

#define m41t81s_date_reg   0x05

m41t81s date in month register

Definition at line 83 of file m41t81s.h.

Referenced by rtc_get_date(), and rtc_set_date().

#define m41t81s_device_addr   0xD0
#define m41t81s_dow_reg   0x04

m41t81s day of week register

Definition at line 81 of file m41t81s.h.

Referenced by rtc_get_dow(), and rtc_set_day().

#define m41t81s_flags_reg   0x0F

m41t81s flags register (D7=WDF, D6=AF, D5=0, D4=BL, D3=0, D2=OF, D1=0, D0=0 -D4=Alarm 10 Seconds, D3-D0=Alarm Seconds)

Definition at line 103 of file m41t81s.h.

#define m41t81s_hours_reg   0x03

m41t81s hours register (D7=CEB, D6=CB)

Definition at line 79 of file m41t81s.h.

Referenced by rtc_get_hours(), and rtc_set_hours().

#define m41t81s_minutes_reg   0x02

m41t81s minutes register

Definition at line 77 of file m41t81s.h.

Referenced by rtc_get_minutes(), and rtc_set_minutes().

#define m41t81s_month_reg   0x06

m41t81s month register

Definition at line 85 of file m41t81s.h.

Referenced by rtc_get_month(), and rtc_set_month().

#define m41t81s_part_seconds_reg   0x00

m41t81s tenths and hundreths of seconds register

Definition at line 73 of file m41t81s.h.

#define m41t81s_reserved1_reg   0x10

m41t81s reserved register

Definition at line 105 of file m41t81s.h.

#define m41t81s_reserved2_reg   0x11

m41t81s reserved register

Definition at line 107 of file m41t81s.h.

#define m41t81s_reserved3_reg   0x12

m41t81s reserved register

Definition at line 109 of file m41t81s.h.

#define m41t81s_seconds_reg   0x01

m41t81s seconds register (D7=ST)

Definition at line 75 of file m41t81s.h.

Referenced by rtc_get_seconds(), rtc_set_seconds(), rtc_start_clock(), and rtc_stop_clock().

#define m41t81s_sqw_reg   0x13

m41t81s SQW register (D7-D4=RS3-RS0)

Definition at line 111 of file m41t81s.h.

Referenced by rtc_set_sqw_freq().

#define m41t81s_watchdog_reg   0x09

m41t81s watchdog register (D7=OFIE, D6-D2=BMB, D1-D0=RB

Definition at line 91 of file m41t81s.h.

#define m41t81s_year_reg   0x07

m41t81s year register

Definition at line 87 of file m41t81s.h.

Referenced by rtc_get_year(), and rtc_set_year().

 
#define rtc_setup (  )     rtc_setup_io()

Definition at line 356 of file m41t81s.h.

#define rtc_sqw_freq_1024Hz   0b00000101

Definition at line 56 of file m41t81s.h.

#define rtc_sqw_freq_128Hz   0b00001000

Definition at line 59 of file m41t81s.h.

#define rtc_sqw_freq_16Hz   0b00001011

Definition at line 62 of file m41t81s.h.

#define rtc_sqw_freq_1Hz   0b00001111

Definition at line 66 of file m41t81s.h.

#define rtc_sqw_freq_2048Hz   0b00000100

Definition at line 55 of file m41t81s.h.

#define rtc_sqw_freq_256Hz   0b00000111

Definition at line 58 of file m41t81s.h.

#define rtc_sqw_freq_2Hz   0b00001110

Definition at line 65 of file m41t81s.h.

#define rtc_sqw_freq_32768Hz   0b00000001

Definition at line 51 of file m41t81s.h.

#define rtc_sqw_freq_32Hz   0b00001010

Definition at line 61 of file m41t81s.h.

#define rtc_sqw_freq_4096Hz   0b00000011

Definition at line 54 of file m41t81s.h.

#define rtc_sqw_freq_4Hz   0b00001101

Definition at line 64 of file m41t81s.h.

#define rtc_sqw_freq_512Hz   0b00000110

Definition at line 57 of file m41t81s.h.

#define rtc_sqw_freq_64Hz   0b00001001

Definition at line 60 of file m41t81s.h.

#define rtc_sqw_freq_8192Hz   0b00000010

Definition at line 53 of file m41t81s.h.

#define rtc_sqw_freq_8Hz   0b00001100

Definition at line 63 of file m41t81s.h.


Function Documentation

uns8 rtc_get_date (  ) 

Returns the date in month from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range 1 through 28/29/30/31 depending on month

Get the date register from the m41t81s.

Returns the date in month from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range 1 through 28/29/30/31 depending on month

Definition at line 65 of file ds1307.c.

References bcd_to_dec(), ds1307_date_register, ds1307_device, i2c_read_eeprom(), m41t81s_date_reg, and m41t81s_device_addr.

Here is the call graph for this function:

uns8 rtc_get_dow (  ) 

Returns the day of the week from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range - 1 through 7

Definition at line 62 of file m41t81s.c.

References bcd_to_dec(), i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_dow_reg.

Here is the call graph for this function:

uns8 rtc_get_hours (  ) 

Returns hour from the m41t81s. The result is coverted to decimal from BCD and is ready to use. These routines assume the m41t81s is running in 24 hour mode. Range - 0 through 23

Get the decoded hours register from the m41t81s.

Returns hour from the ds1307. The result is coverted to decimal from BCD and is ready to use. These routines assume the ds1307 is running in 24 hour mode. Range - 0 through 23

Definition at line 50 of file ds1307.c.

References bcd_to_dec(), ds1307_device, ds1307_hours_register, i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_hours_reg.

Here is the call graph for this function:

uns8 rtc_get_minutes (  ) 

Returns the number of minutes past the hour from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range - 0 through 59

Get the decoded minutes register from the m41t81s.

Returns the number of minutes past the hour from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range - 0 through 59

Definition at line 47 of file ds1307.c.

References bcd_to_dec(), ds1307_device, ds1307_minutes_register, i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_minutes_reg.

Here is the call graph for this function:

uns8 rtc_get_month (  ) 

Returns the month of the year from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range 1 through 12

Get the month register from the m41t81s.

Returns the month of the year from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range 1 through 12

Definition at line 69 of file ds1307.c.

References bcd_to_dec(), ds1307_device, ds1307_month_register, i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_month_reg.

Here is the call graph for this function:

uns8 rtc_get_register ( uns8  reg  ) 

Definition at line 78 of file m41t81s.c.

References i2c_read_eeprom(), and m41t81s_device_addr.

Referenced by rtc_start_sqw_output(), and rtc_stop_sqw_output().

Here is the call graph for this function:

Here is the caller graph for this function:

uns8 rtc_get_seconds (  ) 

Returns seconds from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range - 0 through 59

Get the decoded seconds register from the m41t81s.

Returns seconds from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range - 0 through 59

Definition at line 57 of file ds1307.c.

References bcd_to_dec(), ds1307_device, ds1307_seconds_register, i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_seconds_reg.

Here is the call graph for this function:

uns8 rtc_get_year (  ) 

Returns the year from the m41t81s. The result is coverted to decimal from BCD and is ready to use. Range 0 through 99

Get the year register from the m41t81s.

Returns the year from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range 0 through 99

Definition at line 72 of file ds1307.c.

References bcd_to_dec(), ds1307_device, ds1307_year_register, i2c_read_eeprom(), m41t81s_device_addr, and m41t81s_year_reg.

Here is the call graph for this function:

uns8 rtc_set_config ( uns8  config  ) 
Parameters:
config Value to set the config register to

Set the config register in the m41t81s.

Sets the config register in the ds1307.

Bit 7 - Out - Value on SQWE pin if not outputting square wave Bit 6 - 0 Bit 5 - 0 Bit 4 - SQWE - Enable square wave output Bit 3 - 0 Bit 2 - 0 Bit 1 - RS1 Bit 0 - RS0

RS1/0 determin the speed of the square wave output. Set to 0/0 for 1 Hz.

Parameters:
config Value to set the config register to

Definition at line 80 of file ds1307.c.

References ds1307_control_register, ds1307_device, and i2c_write_eeprom().

Here is the call graph for this function:

void rtc_set_date ( uns8  date  ) 

Changes the date in the m41t81s.

Parameters:
seconds Value to set date to

Set the date register from the m41t81s.

Changes the date in the ds1307.

Parameters:
seconds Value to set date to

Definition at line 102 of file ds1307.c.

References dec_to_bcd(), ds1307_date_register, ds1307_device, i2c_write_eeprom(), m41t81s_date_reg, and m41t81s_device_addr.

Here is the call graph for this function:

void rtc_set_day ( uns8  day  ) 

Changes the day of the week in the m41t81s.

Parameters:
seconds Value to set day to

Set the day of the week register from the m41t81s.

Changes the day of the week in the ds1307.

Parameters:
seconds Value to set day to

Definition at line 99 of file ds1307.c.

References dec_to_bcd(), ds1307_day_register, ds1307_device, i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_dow_reg.

Here is the call graph for this function:

void rtc_set_hours ( uns8  hours  ) 

Changes the hours in the m41t81s. Forces the m41t81s into 24 hour mode.

Set the hours register in the m41t81s.

Changes the hours in the ds1307. Forces the ds1307 into 24 hour mode.

Definition at line 110 of file ds1307.c.

References dec_to_bcd(), ds1307_device, ds1307_hours_register, i2c_read_eeprom(), i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_hours_reg.

Here is the call graph for this function:

void rtc_set_minutes ( uns8  minutes  ) 

Changes the minutes in the m41t81s.

Parameters:
seconds Value to set minutes to

Definition at line 101 of file m41t81s.c.

References dec_to_bcd(), i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_minutes_reg.

Here is the call graph for this function:

void rtc_set_month ( uns8  month  ) 

Changes the month in the m41t81s.

Set the month register in the m41t81s.

Changes the month in the ds1307.

Definition at line 115 of file ds1307.c.

References dec_to_bcd(), ds1307_device, ds1307_month_register, i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_month_reg.

Here is the call graph for this function:

void rtc_set_register ( uns8  reg,
uns8  data 
)

Definition at line 82 of file m41t81s.c.

References i2c_write_eeprom(), and m41t81s_device_addr.

Referenced by rtc_set_sqw_freq(), rtc_start_sqw_output(), and rtc_stop_sqw_output().

Here is the call graph for this function:

Here is the caller graph for this function:

void rtc_set_seconds ( uns8  seconds  ) 

Changes the seconds in the m41t81s.

Parameters:
seconds Value to set seconds to

Set the seconds register in the m41t81s.

Changes the seconds in the ds1307.

Parameters:
seconds Value to set seconds to

Definition at line 106 of file ds1307.c.

References dec_to_bcd(), ds1307_device, ds1307_seconds_register, i2c_read_eeprom(), i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_seconds_reg.

Here is the call graph for this function:

void rtc_set_sqw_freq ( uns8  freq  ) 

Use one of the following self explanitory defines:

rtc_sqw_freq_32768Hz rtc_sqw_freq_8192Hz rtc_sqw_freq_4096Hz rtc_sqw_freq_2048Hz rtc_sqw_freq_1024Hz rtc_sqw_freq_512Hz rtc_sqw_freq_256Hz rtc_sqw_freq_128Hz rtc_sqw_freq_64Hz rtc_sqw_freq_32Hz rtc_sqw_freq_16Hz rtc_sqw_freq_8Hz rtc_sqw_freq_4Hz rtc_sqw_freq_2Hz rtc_sqw_freq_1Hz

Note that on the m41t81s 18384Hz is not available.

Definition at line 125 of file m41t81s.c.

References m41t81s_sqw_reg, and rtc_set_register().

Here is the call graph for this function:

void rtc_set_year ( uns8  year  ) 

Changes the year in the m41t81s.

Definition at line 98 of file m41t81s.c.

References dec_to_bcd(), i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_year_reg.

Here is the call graph for this function:

void rtc_setup_io (  ) 

Calls i2c_setup() to configure ports and pins ready for use

Setup ports and pins for use in the m41t81s.

Calls i2c_setup() to configure ports and pins ready for use

Definition at line 119 of file ds1307.c.

References i2c_setup_io().

Here is the call graph for this function:

void rtc_start_clock (  ) 

Resume time in the m41t81s. Also resumes the paused time that happens upon non-battery backup start up (which allows you to read the time before "resuming" so you know how long the clock has been running on battery back up).

If you want to do this, read the time etc before calling rtc_start_clock();

Starts the clock in the m41t81s.

Resume time in the ds1307

Definition at line 89 of file ds1307.c.

References ds1307_device, ds1307_seconds_register, i2c_read_eeprom(), i2c_write_eeprom(), m41t81s_alarm_hour_reg, m41t81s_device_addr, and m41t81s_seconds_reg.

Here is the call graph for this function:

void rtc_start_sqw_output (  ) 

Outputs desired frequency on the SQW output pin. To set the frequency, see rtc_set_sqw_freq(uns8 freq);

Definition at line 131 of file m41t81s.c.

References m41t81s_alarm_month_reg, rtc_get_register(), and rtc_set_register().

Here is the call graph for this function:

void rtc_stop_clock (  ) 

Pauses time in the m41t81s

Stop the clock in the m41t81s.

Pauses time in the ds1307

Definition at line 85 of file ds1307.c.

References ds1307_device, ds1307_seconds_register, i2c_read_eeprom(), i2c_write_eeprom(), m41t81s_device_addr, and m41t81s_seconds_reg.

Here is the call graph for this function:

void rtc_stop_sqw_output (  ) 

Stops square wave output

Definition at line 136 of file m41t81s.c.

References m41t81s_alarm_month_reg, rtc_get_register(), and rtc_set_register().

Here is the call graph for this function:


Generated on Wed Dec 8 13:47:26 2010 for Pic Pack by  doxygen 1.6.1