struct SYSTEMTIME {
u16 wYear; ///‹ › 1601 && ‹ 30827
u16 wMonth; ///‹ January = 1, February = 2, and so on.
u16 wDayOfWeek; ///‹ Sunday = 0, Monday = 1, and so on
u16 wDay; ///‹ Current day of the month
u16 wHour; ///‹ Current hour
u16 wMinute; ///‹ Current minute
u16 wSecond; ///‹ Current second
u16 wMilliseconds; ///‹ Current millisecond
} ;
static SYSTEMTIME SysTyme;
void RTCInit()
{
/* Disable RTC interrupt */
NVIC_DisableIRQ(RTC_IRQn);
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(RTC_IRQn, ((0x01‹‹3)|0x01));
/* Enable rtc (starts increase the tick counter and second counter register) */
RTC_ResetClockTickCounter(LPC_RTC);
RTC_Cmd(LPC_RTC, ENABLE);
RTC_CalibCounterCmd(LPC_RTC, DISABLE);
/* Set current time for RTC */
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 6);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 10);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 5);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2012);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 22);
/* Set ALARM time for second */
RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);
/* Set the CIIR for second counter interrupt*/
RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
/* Set the AMR for 10s match alarm interrupt */
RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
/* Enable RTC interrupt */
NVIC_EnableIRQ(RTC_IRQn);
}
SYSTEMTIME RTCGetTime()
{
SYSTEMTIME LocalTime;
LocalTime.wSecond = LPC_RTC-›SEC;
LocalTime.wMinute = LPC_RTC-›MIN;
LocalTime.wHour = LPC_RTC-›HOUR;
LocalTime.wDay = LPC_RTC-›DOM;
LocalTime.wDayOfWeek = LPC_RTC-›DOW;
//LocalTime.RTC_Yday = LPC_RTC-›DOY;
LocalTime.wMonth = LPC_RTC-›MONTH;
LocalTime.wYear = LPC_RTC-›YEAR;
return ( LocalTime );
}
void RTC_IRQHandler()
{
LPC_RTC-›ILR |= ILR_RTCCIF;
}
int main()
{
RTCInit();
while(1)
{
for(int i = 0; i ‹ 10000; i++)
asm("nop");
SysTyme = RTCGetTime();
}
return 0;
} |