STM32L151内部RTC时钟
Fclk=32768/[(PREdiv_S+1)*(PREdiv_A+1)]
void RTC_Config(void)
{
RTC_InitTypeDef RTC_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
PWR_RTCAccessCmd(ENABLE);
#if defined RTC_CLOCK_SOURCE_LSI
RTC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#elif defined RTC_CLOCK_SOURCE_LSE
RTC_LSEConfig(RCC_LSE_ON);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else #error Please select the RTC Clock Source inside the main.c file
#endif
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStruct.RTC_AsynchPrediv = 0x7F;
RTC_InitStruct.RTC_SynchPrediv = 0xFF;
RTC_Init(&RTC_InitStruct);
}
void RTC_TimeRegulate(void)
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_TimeStruct.RTC_Hours = 23;
RTC_TimeStruct.RTC_Minutes = 59;
RTC_TimeStruct.RTC_Seconds = 59;
RTC_TimeStruct.RTC_H12 = RTC_H12_AM;
RTC_SetTime(RTC_Format_BIN,&RTC_TImeStruct);
RTC_DateStruct.RTC_Year = 12;
RTC_DateStruct.RTC_Date = 31;
RTC_DateStruct.RTC_Month = 12;
RTC_DateStruct.RTC_WeekDay = 1;
RTC_SetDate(RTC_Format_BIN,&RTC_DateStruct);
}
void RTC_TimeShow(unsigned char *pDate)
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_GetTime(RTC_Format_BIN,&RTC_TImeStruct);
RTC_GetDate(RTC_Format_BIN,&RTC_DateStruct);
pDate[0] = RTC_TimeStruct.RTC_Hours;
pDate[1] = RTC_TimeStruct.RTC_Minutes;
pDate[2] = RTC_TimeStruct.RTC_Seconds ;
pDate[3] = RTC_DateStruct.RTC_Year;
pDate[4] = RTC_DateStruct.RTC_Date;
pDate[5] = RTC_DateStruct.RTC_Month ;
pDate[6] = RTC_DateStruct.RTC_WeekDay ;
}
STM32L151内部RTC时 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)