m41t81s.h File Reference

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

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


Define Documentation

#define __m41t81s_h   defined
#define m41t81s_alarm_date_reg   0x0B

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

#define m41t81s_alarm_hour_reg   0x0C

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

#define m41t81s_alarm_min_reg   0x0D

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

#define m41t81s_alarm_month_reg   0x0A

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

#define m41t81s_alarm_seconds_reg   0x0E

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

#define m41t81s_calibration_reg   0x08

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

#define m41t81s_date_reg   0x05

m41t81s date in month register

#define m41t81s_device_addr   0xD0

The m41t81s device address

#define m41t81s_dow_reg   0x04

m41t81s day of week register

#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)

#define m41t81s_hours_reg   0x03

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

#define m41t81s_minutes_reg   0x02

m41t81s minutes register

#define m41t81s_month_reg   0x06

m41t81s month register

#define m41t81s_part_seconds_reg   0x00

m41t81s tenths and hundreths of seconds register

#define m41t81s_reserved1_reg   0x10

m41t81s reserved register

#define m41t81s_reserved2_reg   0x11

m41t81s reserved register

#define m41t81s_reserved3_reg   0x12

m41t81s reserved register

#define m41t81s_seconds_reg   0x01

m41t81s seconds register (D7=ST)

#define m41t81s_sqw_reg   0x13

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

#define m41t81s_watchdog_reg   0x09

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

#define m41t81s_year_reg   0x07

m41t81s year register

 
#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

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

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

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

00050                      {
00051 
00052 // Always assume it's in 24 hour mode
00053 
00054     return bcd_to_dec(0b00111111 & i2c_read_eeprom(ds1307_device, ds1307_hours_register));
00055 }       

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

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

Here is the call graph for this function:

uns8 rtc_get_register ( uns8  reg  ) 

00078                                  {
00079     return i2c_read_eeprom(m41t81s_device_addr, reg);
00080 }

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

00057                        {
00058     return bcd_to_dec(0b01111111 & i2c_read_eeprom(ds1307_device, ds1307_seconds_register));
00059 }

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

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

00080                                   {
00081     i2c_write_eeprom(ds1307_device, ds1307_control_register, config);
00082 }

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

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

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.

00110                                {
00111     // by doing this we clear the 12/24 flag, making it 24 hour mode
00112         i2c_write_eeprom(ds1307_device, ds1307_hours_register, dec_to_bcd(hours));
00113 }

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

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.

Here is the call graph for this function:

void rtc_set_register ( uns8  reg,
uns8  data 
)

00082                                             {
00083     i2c_write_eeprom(m41t81s_device_addr, reg, data);
00084 }

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

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.

00125                                  {
00126     
00127     freq = freq << 4;
00128     rtc_set_register(m41t81s_sqw_reg, freq);
00129 }

Here is the call graph for this function:

void rtc_set_year ( uns8  year  ) 

Changes the year in the m41t81s.

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

00119                     {
00120     i2c_setup_io();
00121 }

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

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);

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

Here is the call graph for this function:

void rtc_stop_sqw_output (  ) 

Stops square wave output

00136                            {
00137 
00138     rtc_set_register(m41t81s_alarm_month_reg, 0b10111111 | rtc_get_register(m41t81s_alarm_month_reg));
00139 
00140 }

Here is the call graph for this function:


Generated on Fri Aug 19 09:07:09 2011 for Pic Pack Library by  doxygen 1.6.1