|
@@ -27,14 +27,13 @@ void DS3231_Init(void (*Callback)()) {
|
|
|
IO_Rtc.rise(Callback);
|
|
|
}
|
|
|
|
|
|
-void DS3231_SetTime(int Second, int Minute, int Hour, bool PM) {
|
|
|
+void DS3231_SetTime(int Second, int Minute, int Hour) {
|
|
|
DS3231_REGS regs = {0};
|
|
|
|
|
|
regs.Second.Value = DecimalToBCD(Second);
|
|
|
regs.Minute.Value = DecimalToBCD(Minute);
|
|
|
regs.Hour.Value = DecimalToBCD(Hour);
|
|
|
- regs.Hour.nAM = PM;
|
|
|
- regs.Hour.n24 = 1;
|
|
|
+ regs.Hour.n24 = 0;
|
|
|
|
|
|
I2C_Write(DS3231_ADDR, FIELD_OFFSET(DS3231_REGS, Second),
|
|
|
regs.AS_BYTE + FIELD_OFFSET(DS3231_REGS, Second),
|
|
@@ -66,3 +65,27 @@ void DS3231_GetTime(int *Second, int *Minute, int *Hour) {
|
|
|
*Minute = BCDToDecimal(regs.Minute.Value);
|
|
|
*Hour = BCDToDecimal(regs.Hour.Value);
|
|
|
}
|
|
|
+
|
|
|
+void DS3231_GetDate(int *Day, int *Date, int *Month, int *Year) {
|
|
|
+ DS3231_REGS regs = {0};
|
|
|
+
|
|
|
+ I2C_Read(DS3231_ADDR, FIELD_OFFSET(DS3231_REGS, Day),
|
|
|
+ regs.AS_BYTE + FIELD_OFFSET(DS3231_REGS, Day),
|
|
|
+ FIELD_SIZE_THROUGH(DS3231_REGS, Day, Year));
|
|
|
+
|
|
|
+ *Day = BCDToDecimal(regs.Day.Value);
|
|
|
+ *Date = BCDToDecimal(regs.Date.Value);
|
|
|
+ *Month = BCDToDecimal(regs.Month.Value);
|
|
|
+ *Year = BCDToDecimal(regs.Year.Value);
|
|
|
+}
|
|
|
+
|
|
|
+bool IsDst(int Day, int Date, int Month, int Hour_24) {
|
|
|
+
|
|
|
+ if (Month < 3 || Month > 11) return false;
|
|
|
+
|
|
|
+ if (Month > 3 && Month < 11) return true;
|
|
|
+
|
|
|
+ if (Month == 3) return ((Date - Day) >= 8) && (Hour_24 >= 2);
|
|
|
+
|
|
|
+ return ((Date - Day) <= 0) && (Hour_24 < 2);
|
|
|
+}
|