Обновление
This commit is contained in:
parent
495bb1220f
commit
97eec3849b
|
|
@ -78,7 +78,7 @@ static bool RTC_CheckTimeDate(const RTC_TimeDate * const pTimeDate)
|
||||||
}
|
}
|
||||||
return bCheckReturn;
|
return bCheckReturn;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
static void RTC_TimeDate_To_Second(RTC_TimeDate * const pTimeDate, uint32_t u32Second)
|
static void RTC_TimeDate_To_Second(RTC_TimeDate * const pTimeDate, uint32_t u32Second)
|
||||||
{
|
{
|
||||||
uint32_t u32CountDays;
|
uint32_t u32CountDays;
|
||||||
|
|
@ -122,6 +122,7 @@ static void RTC_TimeDate_To_Second(RTC_TimeDate * const pTimeDate, uint32_t u32S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint32_t RTC_Second_To_TimeDate(const RTC_TimeDate * const pTimeDate)
|
static uint32_t RTC_Second_To_TimeDate(const RTC_TimeDate * const pTimeDate)
|
||||||
{
|
{
|
||||||
uint32_t u32Second;
|
uint32_t u32Second;
|
||||||
|
|
@ -151,6 +152,78 @@ static uint32_t RTC_Second_To_TimeDate(const RTC_TimeDate * const pTimeDate)
|
||||||
|
|
||||||
return u32Second;
|
return u32Second;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
static void RTC_TimeDate_To_Second(RTC_TimeDate * const pTimeDate, uint32_t u32Second)
|
||||||
|
{
|
||||||
|
uint32_t u32CountDays;
|
||||||
|
uint32_t u32TempCount;
|
||||||
|
|
||||||
|
u32CountDays = u32Second / SECONDS_DAY;
|
||||||
|
u32TempCount = u32Second % SECONDS_DAY;
|
||||||
|
|
||||||
|
pTimeDate->u8Hour = (uint8_t)(u32TempCount / SECONDS_HOUR);
|
||||||
|
u32TempCount = u32TempCount % SECONDS_HOUR;
|
||||||
|
|
||||||
|
pTimeDate->u8Minute = (uint8_t)(u32TempCount / SECONDS_MINUTE);
|
||||||
|
pTimeDate->u8Second = (uint8_t)(u32TempCount % SECONDS_MINUTE);
|
||||||
|
|
||||||
|
pTimeDate->u16Year = (uint16_t)START_YEAR;
|
||||||
|
|
||||||
|
// Вычисляем год
|
||||||
|
uint32_t u32DaysInYear = DAYS_COM_YEAR;
|
||||||
|
while (u32CountDays >= u32DaysInYear)
|
||||||
|
{
|
||||||
|
pTimeDate->u16Year++;
|
||||||
|
u32CountDays -= u32DaysInYear;
|
||||||
|
u32DaysInYear = RTC_IsLeapYear(pTimeDate->u16Year) ? DAYS_LEAP_YEAR : DAYS_COM_YEAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// u32CountDays теперь содержит день года (0-364/365)
|
||||||
|
// Преобразуем в месяц и день
|
||||||
|
const uint8_t* pMonthDays = RTC_IsLeapYear(pTimeDate->u16Year) ? LeapYear : ComYear;
|
||||||
|
uint32_t u32DayOfYear = u32CountDays + 1; // День года (1-366)
|
||||||
|
|
||||||
|
for (uint8_t u8TempMonth = 1; u8TempMonth <= 12; u8TempMonth++)
|
||||||
|
{
|
||||||
|
uint32_t u32DaysInMonth = pMonthDays[u8TempMonth];
|
||||||
|
if (u32DayOfYear <= u32DaysInMonth)
|
||||||
|
{
|
||||||
|
pTimeDate->u8Month = u8TempMonth;
|
||||||
|
pTimeDate->u8Day = (uint8_t)u32DayOfYear;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32DayOfYear -= u32DaysInMonth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t RTC_Second_To_TimeDate(const RTC_TimeDate * const pTimeDate)
|
||||||
|
{
|
||||||
|
uint32_t u32Second = 0;
|
||||||
|
|
||||||
|
// Считаем дни за полные годы с 1970
|
||||||
|
for (uint16_t u16Year = START_YEAR; u16Year < pTimeDate->u16Year; u16Year++)
|
||||||
|
{
|
||||||
|
u32Second += RTC_IsLeapYear(u16Year) ? DAYS_LEAP_YEAR * SECONDS_DAY : DAYS_COM_YEAR * SECONDS_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Считаем дни за полные месяцы в текущем году
|
||||||
|
const uint8_t* pMonthDays = RTC_IsLeapYear(pTimeDate->u16Year) ? LeapYear : ComYear;
|
||||||
|
for (uint8_t u8Month = 1; u8Month < pTimeDate->u8Month; u8Month++)
|
||||||
|
{
|
||||||
|
u32Second += pMonthDays[u8Month] * SECONDS_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Считаем дни, часы, минуты, секунды
|
||||||
|
u32Second += ((uint32_t)(pTimeDate->u8Day - 1) * SECONDS_DAY) +
|
||||||
|
((uint32_t)pTimeDate->u8Hour * SECONDS_HOUR) +
|
||||||
|
((uint32_t)pTimeDate->u8Minute * SECONDS_MINUTE) +
|
||||||
|
((uint32_t)pTimeDate->u8Second);
|
||||||
|
|
||||||
|
return u32Second;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set time and date
|
* @brief Set time and date
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue