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. |
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
00066 { 00067 return bcd_to_dec(i2c_read_eeprom(m41t81s_device_addr, m41t81s_date_reg)); 00068 }
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
00062 { 00063 return bcd_to_dec(i2c_read_eeprom(m41t81s_device_addr, m41t81s_dow_reg)); 00064 }
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 }
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
00048 { 00049 return bcd_to_dec(i2c_read_eeprom(m41t81s_device_addr, m41t81s_minutes_reg)); 00050 }
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
00070 { 00071 return bcd_to_dec(i2c_read_eeprom(m41t81s_device_addr, m41t81s_month_reg)); 00072 }
uns8 rtc_get_register | ( | uns8 | reg | ) |
00078 { 00079 return i2c_read_eeprom(m41t81s_device_addr, reg); 00080 }
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 }
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
00074 { 00075 return bcd_to_dec(i2c_read_eeprom(m41t81s_device_addr, m41t81s_year_reg)); 00076 }
void rtc_set_date | ( | uns8 | date | ) |
Set the date register from the m41t81s.
Changes the date in the ds1307.
seconds | Value to set date to |
00107 { 00108 i2c_write_eeprom(m41t81s_device_addr, m41t81s_date_reg, dec_to_bcd(date)); 00109 }
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.
seconds | Value to set day to |
00104 { 00105 i2c_write_eeprom(m41t81s_device_addr, m41t81s_dow_reg, dec_to_bcd(day)); 00106 }
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 }
void rtc_set_minutes | ( | uns8 | minutes | ) |
Changes the minutes in the m41t81s.
seconds | Value to set minutes to |
00101 { 00102 i2c_write_eeprom(m41t81s_device_addr, m41t81s_minutes_reg, dec_to_bcd(minutes)); 00103 }
void rtc_set_month | ( | uns8 | month | ) |
Set the month register in the m41t81s.
Changes the month in the ds1307.
00121 { 00122 i2c_write_eeprom(m41t81s_device_addr, m41t81s_month_reg , dec_to_bcd(month)); 00123 }
void rtc_set_register | ( | uns8 | reg, | |
uns8 | data | |||
) |
00082 { 00083 i2c_write_eeprom(m41t81s_device_addr, reg, data); 00084 }
void rtc_set_seconds | ( | uns8 | seconds | ) |
Set the seconds register in the m41t81s.
Changes the seconds in the ds1307.
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 }
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 }
void rtc_set_year | ( | uns8 | year | ) |
Changes the year in the m41t81s.
00098 { 00099 i2c_write_eeprom(m41t81s_device_addr, m41t81s_year_reg, dec_to_bcd(year)); 00100 }
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 }
void rtc_start_clock | ( | ) |
Starts the clock in the m41t81s.
Resume time in the ds1307
00091 { 00092 00093 i2c_write_eeprom(m41t81s_device_addr, m41t81s_alarm_hour_reg, 0b10111111 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_alarm_hour_reg)); //HT 00094 i2c_write_eeprom(m41t81s_device_addr, m41t81s_seconds_reg, 0b01111111 & i2c_read_eeprom(m41t81s_device_addr, m41t81s_seconds_reg)); //ST 00095 00096 }
void rtc_start_sqw_output | ( | ) |
Outputs desired frequency on the SQW output pin. To set the frequency, see rtc_set_sqw_freq(uns8 freq);
00131 { 00132 00133 rtc_set_register(m41t81s_alarm_month_reg, 0b01000000 | rtc_get_register(m41t81s_alarm_month_reg)); 00134 }
void rtc_stop_clock | ( | ) |
Stop the clock in the m41t81s.
Pauses time in the ds1307
00087 { 00088 i2c_write_eeprom(m41t81s_device_addr, m41t81s_seconds_reg, 0b10000000 | i2c_read_eeprom(m41t81s_device_addr, m41t81s_seconds_reg)); 00089 }
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 }