m41t81s.c File Reference

Include dependency graph for m41t81s.c:

Functions

uns8 bcd_to_dec (uns8 bcd)
uns8 dec_to_bcd (uns8 dec)
uns8 rtc_get_date ()
 Get the date register from the ds1307.
uns8 rtc_get_dow ()
 Get the day register from the m41t81s.
uns8 rtc_get_hours ()
 Get the decoded hours register from the ds1307.
uns8 rtc_get_minutes ()
 Get the decoded minutes register from the ds1307.
uns8 rtc_get_month ()
 Get the month register from the ds1307.
uns8 rtc_get_register (uns8 reg)
uns8 rtc_get_seconds ()
 Get the decoded seconds register from the ds1307.
uns8 rtc_get_year ()
 Get the year register from the ds1307.
void rtc_set_date (uns8 date)
 Set the date register from the ds1307.
void rtc_set_day (uns8 day)
 Set the day of the week register from the ds1307.
void rtc_set_hours (uns8 hours)
 Set the hours register in the ds1307.
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 ds1307.
void rtc_set_register (uns8 reg, uns8 data)
void rtc_set_seconds (uns8 seconds)
 Set the seconds register in the ds1307.
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 ds1307.
void rtc_start_clock ()
 Starts the clock in the ds1307.
void rtc_start_sqw_output ()
 Start pulsing on square wave output pin.
void rtc_stop_clock ()
 Stop the clock in the ds1307.
void rtc_stop_sqw_output ()
 Stop pulsing on square wave output pin.

Function Documentation

uns8 bcd_to_dec ( uns8  bcd  ) 

00040                           {
00041     return (bcd & 0b00001111) + ((bcd >> 4) * 10);
00042 }

uns8 dec_to_bcd ( uns8  dec  ) 

00044                           {
00045     return ((dec / 10) << 4) + (dec % 10);
00046 }

uns8 rtc_get_date (  ) 

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

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

00051                      {
00052 
00053     // m41t81s is always in 24 hour mode
00054 
00055     return bcd_to_dec(0b00111111 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_hours_reg));
00056 }       

Here is the call graph for this function:

uns8 rtc_get_minutes (  ) 

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

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

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

00058                        {
00059     return bcd_to_dec(0b01111111 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_seconds_reg));
00060 }

Here is the call graph for this function:

uns8 rtc_get_year (  ) 

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:

void rtc_set_date ( uns8  date  ) 

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  ) 

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  ) 

Set the hours register in the m41t81s.

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

00116                                {
00117     // preserve the century / century enable bits
00118     i2c_write_eeprom(m41t81s_device_addr, m41t81s_hours_reg, (0b11000000 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_hours_reg)) | dec_to_bcd(hours));
00119 }

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  ) 

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  ) 

Set the seconds register in the m41t81s.

Changes the seconds in the ds1307.

Parameters:
seconds Value to set seconds to

00111                                    {
00112     // preserve the stop bit
00113     i2c_write_eeprom(m41t81s_device_addr, m41t81s_seconds_reg, (0b10000000 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_seconds_reg)) | dec_to_bcd(seconds));
00114 }

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

Setup ports and pins for use in the m41t81s.

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

00143                     {
00144     i2c_setup_io();
00145 }

Here is the call graph for this function:

void 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 (  ) 

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:02 2011 for Pic Pack Library by  doxygen 1.6.1