Hi Shabana m,
The function below is to convert RTC seconds to date and time. It have been provided by Freescale Japan. Even if the RTC clock is not 32.768kHz but 32kHz, you can use the function by varying the constants by 32/32.768 (=0.9765625) times. That is,
86400 => 84375,
3600 => 3515,
60 => 58, and so on.
If the RTC source clock is LPO (1kHz), the constants conversion would be more simpler.
Can it help you?
Best regards,
Yasuhiko Koumoto.
----[snip]------
typedef struct {
uint32_t Second; /*!< seconds (0 - 59) */
uint32_t Minute; /*!< minutes (0 - 59) */
uint32_t Hour; /*!< hours (0 - 23) */
uint32_t DayOfWeek; /*!< day of week (0-Sunday, .. 6-Saturday) */
uint32_t Day; /*!< day (1 - 31) */
uint32_t Month; /*!< month (1 - 12) */
uint32_t Year; /*!< year */
} LDD_RTC_TTime;
static void RTC1_ConvertSecondsToDateAndTime(LDD_RTC_TTime *TimePtr, uint32_t Seconds)
{
uint32_t x;
uint32_t Days;
Days = Seconds / 86400U; /* Days */
Seconds = Seconds % 86400U; /* Seconds left */
TimePtr->Hour = Seconds / 3600U; /* Hours */
Seconds = Seconds % 3600u; /* Seconds left */
TimePtr->Minute = Seconds / 60U; /* Minutes */
TimePtr->Second = Seconds % 60U; /* Seconds */
TimePtr->DayOfWeek = (Days + 6U) % 7U; /* Day of week */
TimePtr->Year = (4U * (Days / ((4U * 365U) + 1U))) + 2000U; /* Year */
Days = Days % ((4U * 365U) + 1U);
if (Days == ((0U * 365U) + 59U)) { /* 59 */
TimePtr->Day = 29U;
TimePtr->Month = 2U;
return;
} else if (Days > ((0U * 365U) + 59U)) {
Days--;
} else {
}
x = Days / 365U;
TimePtr->Year += x;
Days -= x * 365U;
for (x=1U; x <= 12U; x++) {
if (Days < ULY[x]) {
TimePtr->Month = x;
break;
} else {
Days -= ULY[x];
}
}
TimePtr->Day = Days + 1U;
}
----[snip]------