add read minutes, hours, day, date, month, and year from RTC IC
This commit is contained in:
parent
dc9ddc76a7
commit
3cc04f7499
|
@ -128,3 +128,65 @@ uint8_t rtc_read_seconds(void)
|
|||
to_return = ((data[0]&0x70)>>4)*10+(data[0]&0x0f); // convert BCD coding into seconds
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_minutes(void)
|
||||
{
|
||||
uint8_t to_return = 0; // minutes to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(1, data, LENGTH(data)); // read a single byte to test
|
||||
to_return = (data[0]>>4)*10+(data[0]&0x0f); // convert BCD coding into minutes
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_hours(void)
|
||||
{
|
||||
uint8_t to_return = 0; // hours to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(2, data, LENGTH(data)); // read a single byte to test
|
||||
if (data[0]&0x40) { // 12 hour mode
|
||||
if (data[0]&0x02) { // PM
|
||||
to_return += 12; // add the 12 hours
|
||||
}
|
||||
to_return += ((data[0]&0x10)>>4)*10; // convert BCD coding into hours (first digit)
|
||||
} else {
|
||||
to_return = ((data[0]&0x30)>>4)*10; // convert BCD coding into hours (first digit)
|
||||
}
|
||||
to_return += (data[0]&0x0f); // convert BCD coding into hours (second digit)
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_day(void)
|
||||
{
|
||||
uint8_t to_return = 0; // day to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(3, data, LENGTH(data)); // read a single byte to test
|
||||
to_return = (data[0]&0x07); // convert BCD coding into days
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_date(void)
|
||||
{
|
||||
uint8_t to_return = 0; // date to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(4, data, LENGTH(data)); // read a single byte to test
|
||||
to_return = ((data[0]&0x30)>>4)*10+(data[0]&0x0f); // convert BCD coding into date
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_month(void)
|
||||
{
|
||||
uint8_t to_return = 0; // month to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(5, data, LENGTH(data)); // read a single byte to test
|
||||
to_return = ((data[0]&0x10)>>4)*10+(data[0]&0x0f); // convert BCD coding into month
|
||||
return to_return;
|
||||
}
|
||||
|
||||
uint8_t rtc_read_year(void)
|
||||
{
|
||||
uint8_t to_return = 0; // seconds to return
|
||||
uint8_t data[1] = {0}; // to read data from I2C
|
||||
rtc_read_memory(6, data, LENGTH(data)); // read a single byte to test
|
||||
to_return = ((data[0]&0xf0)>>4)*10+(data[0]&0x0f); // convert BCD coding into year
|
||||
return to_return;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @date 2016
|
||||
* @brief this library handles communication with the I2C RTC IC Maxim DS1307
|
||||
* @todo control register and user RAM are not handled
|
||||
* peripherals used: I2C @ref rtc_ds1307_i2c
|
||||
*/
|
||||
#pragma once
|
||||
|
@ -28,3 +29,27 @@ void rtc_setup(void);
|
|||
* @return the number of seconds of the current time
|
||||
*/
|
||||
uint8_t rtc_read_seconds(void);
|
||||
/** @brief read minutes (0-59) from RTC IC
|
||||
* @return the number of minutes of the current time
|
||||
*/
|
||||
uint8_t rtc_read_minutes(void);
|
||||
/** @brief read hours (0-23) from RTC IC
|
||||
* @return the number of hours of the current time
|
||||
*/
|
||||
uint8_t rtc_read_hours(void);
|
||||
/** @brief read day (1-7) from RTC IC
|
||||
* @return the day of the current time, 1 being Sunday
|
||||
*/
|
||||
uint8_t rtc_read_day(void);
|
||||
/** @brief read date (1-31) from RTC IC
|
||||
* @return the date (day of the month) of the current time
|
||||
*/
|
||||
uint8_t rtc_read_date(void);
|
||||
/** @brief read month (1-12) from RTC IC
|
||||
* @return the month of the current time
|
||||
*/
|
||||
uint8_t rtc_read_month(void);
|
||||
/** @brief read year (00-99) from RTC IC
|
||||
* @return the year of the current time
|
||||
*/
|
||||
uint8_t rtc_read_year(void);
|
||||
|
|
Loading…
Reference in New Issue