still wip

This commit is contained in:
2025-12-22 23:02:29 +01:00
parent 627acef32c
commit a48ef9d5e0
60 changed files with 6993 additions and 4939 deletions

View File

@@ -48,6 +48,43 @@ uint8_t Is_Leap_Year (u16 year) {
return 0;
}
static uint8_t month_from_str(const char *m) {
static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
for (uint8_t i = 0; i < 12; i++) {
if (m[0] == months[i*3] &&
m[1] == months[i*3 + 1] &&
m[2] == months[i*3 + 2])
return i + 1; // 1¨C12
}
return 0; // should never happen
}
void RTC_Set_From_BuildTime(void) {
const char *date = __DATE__;
const char *time = __TIME__;
uint16_t year =
(date[7] - '0') * 1000 +
(date[8] - '0') * 100 +
(date[9] - '0') * 10 +
(date[10] - '0');
uint8_t month = month_from_str(date);
uint8_t day =
(date[4] == ' ' ? 0 : (date[4] - '0') * 10) +
(date[5] - '0');
uint8_t hour =
(time[0] - '0') * 10 + (time[1] - '0');
uint8_t min =
(time[3] - '0') * 10 + (time[4] - '0');
uint8_t sec =
(time[6] - '0') * 10 + (time[7] - '0');
RTC_Set(year, month, day, hour, min, sec);
}
/*********************************************************************
* @fn RTC_Set
*
@@ -244,7 +281,8 @@ uint8_t RTC_Init (void) {
RTC_EnterConfigMode();
RTC_SetPrescaler (32767);
RTC_WaitForLastTask();
RTC_Set (2025, 9, 7, 11, 33, 30); /* Setup Time */
//RTC_Set (2025, 9, 7, 11, 33, 30); /* Setup Time */
RTC_Set_From_BuildTime();
RTC_ExitConfigMode();
BKP_WriteBackupRegister (BKP_DR1, 0XA1A1);