123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "main.h"
- extern int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
- extern int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
- void RTC_Init(void) {
- uint8_t buf[3] = {0};
-
- Flag.I2C_TX_End = 0;
- buf[0] = DS3231_1HZ;
- buf[1] = 0x0;
- user_i2c_write(DS3231_I2C_ADDR, DS3231_ADDR_CONTROL, buf, 2);
- }
- void RTC_ReadAll(rtc_t * data) {
- Flag.I2C_RX_End = 0;
- Flag.I2C_TX_End = 0;
- user_i2c_read(DS3231_I2C_ADDR, DS3231_ADDR_TIME, (uint8_t *)data, DS3231_SIZE_ALL);
- }
- void RTC_WriteTimeCalendar(rtc_t * data) {
- Flag.I2C_TX_End = 0;
- user_i2c_write(DS3231_I2C_ADDR, DS3231_ADDR_TIME, &(data->Sec), (DS3231_SIZE_TIME + DS3231_SIZE_CALENDAR));
- }
- void RTC_WriteTime(rtc_t * data) {
- Flag.I2C_TX_End = 0;
- user_i2c_write(DS3231_I2C_ADDR, DS3231_ADDR_TIME, &(data->Sec), DS3231_SIZE_TIME);
- }
- void RTC_WriteHH(rtc_t * data) {
- Flag.I2C_TX_End = 0;
- user_i2c_write(DS3231_I2C_ADDR, (DS3231_ADDR_TIME + 2), &(data->Hr), 1);
- }
- void RTC_WriteHHMM(rtc_t * data) {
- Flag.I2C_TX_End = 0;
- user_i2c_write(DS3231_I2C_ADDR, (DS3231_ADDR_TIME + 1), &(data->Min), 2);
- }
- void RTC_WriteCalendar(rtc_t * data) {
- Flag.I2C_TX_End = 0;
- user_i2c_write(DS3231_I2C_ADDR, DS3231_ADDR_CALENDAR, &(data->WD), DS3231_SIZE_CALENDAR);
- }
- uint8_t bcd2bin(uint8_t bcd)
- {
- return (10 * (bcd >> 4) + (bcd & 0x0f));
- }
- uint8_t bin2bcd(uint8_t bin)
- {
- return (((bin / 10 ) << 4) | (bin % 10));
- }
|