Functions | |
uns8 | bcd_to_dec (uns8 bcd) |
uns8 | dec_to_bcd (uns8 dec) |
uns8 | rtc_get_config () |
Get the config register from the ds1307. | |
uns8 | rtc_get_date () |
Get the date register from the ds1307. | |
uns8 | rtc_get_day () |
Get the day register from the ds1307. | |
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_seconds () |
Get the decoded seconds register from the ds1307. | |
uns8 | rtc_get_year () |
Get the year register from the ds1307. | |
uns8 | rtc_set_config (uns8 config) |
Set the config register in 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 (uns16 minutes) |
Set the minutes register from the ds1307. | |
void | rtc_set_month (uns8 month) |
Set the month register in the ds1307. | |
void | rtc_set_seconds (uns8 seconds) |
Set the seconds register in the ds1307. | |
void | rtc_set_year (uns16 year) |
Set the year register from the ds1307. | |
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_stop_clock () |
Stop the clock in the ds1307. |
uns8 bcd_to_dec | ( | uns8 | bcd | ) |
uns8 dec_to_bcd | ( | uns8 | dec | ) |
uns8 rtc_get_config | ( | ) |
Returns the config register from 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.
00076 { 00077 return i2c_read_eeprom(ds1307_device, ds1307_control_register); 00078 }
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
00065 { 00066 return bcd_to_dec(i2c_read_eeprom(ds1307_device, ds1307_date_register)); 00067 }
uns8 rtc_get_day | ( | ) |
Returns the day of the week from the ds1307. The result is coverted to decimal from BCD and is ready to use. Range - 1 through 7
00061 { 00062 return bcd_to_dec(i2c_read_eeprom(ds1307_device, ds1307_day_register)); 00063 }
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
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 }
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
00047 { 00048 return bcd_to_dec(i2c_read_eeprom(ds1307_device, ds1307_minutes_register)); 00049 }
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
00069 { 00070 return bcd_to_dec(i2c_read_eeprom(ds1307_device, ds1307_month_register)); 00071 }
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
00057 { 00058 return bcd_to_dec(0b01111111 & i2c_read_eeprom(ds1307_device, ds1307_seconds_register)); 00059 }
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
00072 { 00073 return bcd_to_dec(i2c_read_eeprom(ds1307_device, ds1307_year_register)); 00074 }
uns8 rtc_set_config | ( | uns8 | config | ) |
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.
config | Value to set the config register to |
00080 { 00081 i2c_write_eeprom(ds1307_device, ds1307_control_register, config); 00082 }
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 |
00102 { 00103 i2c_write_eeprom(ds1307_device, ds1307_date_register, dec_to_bcd(date)); 00104 }
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 |
00099 { 00100 i2c_write_eeprom(ds1307_device, ds1307_day_register, dec_to_bcd(day)); 00101 }
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.
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 }
void rtc_set_minutes | ( | uns16 | minutes | ) |
Changes the minutes in the ds1307.
seconds | Value to set minutes to |
00096 { 00097 i2c_write_eeprom(ds1307_device, ds1307_minutes_register, dec_to_bcd(minutes)); 00098 }
void rtc_set_month | ( | uns8 | month | ) |
Set the month register in the m41t81s.
Changes the month in the ds1307.
00115 { 00116 i2c_write_eeprom(ds1307_device, ds1307_month_register, dec_to_bcd(month)); 00117 }
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 |
00106 { 00107 i2c_write_eeprom(ds1307_device, ds1307_seconds_register, (0b10000000 & i2c_read_eeprom(ds1307_device, ds1307_seconds_register)) + dec_to_bcd(seconds)); 00108 }
void rtc_set_year | ( | uns16 | year | ) |
Changes the year in the ds1307.
00093 { 00094 i2c_write_eeprom(ds1307_device, ds1307_year_register, dec_to_bcd(year)); 00095 }
void rtc_setup_io | ( | ) |
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 }
void rtc_start_clock | ( | ) |
Starts the clock in the m41t81s.
Resume time in the ds1307
00089 { 00090 i2c_write_eeprom(ds1307_device, ds1307_seconds_register, 0b01111111 & i2c_read_eeprom(ds1307_device, ds1307_seconds_register)); 00091 }
void rtc_stop_clock | ( | ) |
Stop the clock in the m41t81s.
Pauses time in the ds1307
00085 { 00086 i2c_write_eeprom(ds1307_device, ds1307_seconds_register, 0b10000000 | i2c_read_eeprom(ds1307_device, ds1307_seconds_register)); 00087 }