stm32_ota/SYSTEM/RTC/rtc.c

519 lines
21 KiB
C
Raw Permalink Normal View History

2023-12-15 06:28:06 +00:00
#include "rtc.h"
#include "syslib.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_bkp.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_it.h"
#include "sysport.h"
/********************************************************************************
* @file rtc.c
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief <EFBFBD>STM32<EFBFBD>ڲ<EFBFBD>rtc<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
*******************************************************************************/
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
RTCFP rtcSecFp = NULL ; //RTC<54><43><EFBFBD>жϻص<CFBB><D8B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
RTCFP rtcAlrFp = NULL ; //RTC<54><43><EFBFBD><EFBFBD><EFBFBD>жϻص<CFBB><D8B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
const uint8_t weekTable[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>
const uint8_t monTable[12] ={31,28,31,30,31,30,31,31,30,31,30,31}; //ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ڱ<EFBFBD>
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD>ⲿʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
Calendar_u uCalendar ; //Calendar_u<5F><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>uCalendar<61><72><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>¼ʵʱʱ<CAB1><CAB1>
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>RTCFP Rtc_RegHookCallback(uint16_t rtcIt, RTCFP pCallback)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>rtc<EFBFBD>жϻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rtcSecFp<EFBFBD><EFBFBD><EFBFBD>жϻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rtcAlrFp<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* Rtc_RegHookCallback<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>rtcSecFp\rtcAlrFpָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 rtcIt RTC_IT_SEC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_IT_ALR
* @param2 pCallback RTCFP<EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 pCallback RTCFP<EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
*************************************************************************************************/
RTCFP Rtc_RegHookCallback(uint16_t rtcIt, RTCFP pCallback)
{
if( RTC_IT_SEC == rtcIt ) //<2F><><EFBFBD>жϻص<CFBB><D8B5><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
{
if( rtcSecFp == NULL )
rtcSecFp = pCallback ;
else
SysErr("Rtc SecTi Callback repeat reg!") ;
}
else if( RTC_IT_ALR == rtcIt)
{
if( rtcAlrFp == NULL )
rtcAlrFp = pCallback ;
else
SysErr("Rtc AlrTi Callback repeat reg!") ;
}
else
{
SysErr("Rtc_RegHookCallback Failed!") ;
}
return pCallback ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void Rtc_Hook(uint16_t rtcIt)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD>ж<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD>õĹ<EFBFBD><EFBFBD>Ӻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>е<EFBFBD><EFBFBD>жϻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD>ٺٺ١<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>RTC_IT<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 rtcIt RTC_IT_SEC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_IT_ALR
*************************************************************************************************/
void Rtc_Hook(uint16_t rtcIt)
{
switch(rtcIt)
{
case RTC_IT_SEC:
if( rtcSecFp != NULL)
rtcSecFp() ;
break ;
case RTC_IT_ALR: if( rtcAlrFp != NULL) rtcAlrFp() ; break ;
default: break ;
}
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void RTC_IRQHandler(void)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTCʱ<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ÿ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
*************************************************************************************************/
void RTC_IRQHandler(void)
{
if ( RTC_GetITStatus(RTC_IT_SEC) != RESET )//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
RTC_ClearITPendingBit(RTC_IT_SEC); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
RTC_WaitForLastTask() ;
SysLog("RTC_IT_SEC!") ;
Rtc_Hook(RTC_IT_SEC) ;
}
if( RTC_GetITStatus(RTC_IT_ALR)!= RESET ) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
RTC_ClearITPendingBit(RTC_IT_ALR); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
RTC_WaitForLastTask() ;
SysLog("RTC_IT_ALR!") ;
Rtc_Hook(RTC_IT_ALR) ;
}
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void RTCAlarm_IRQHandler(void)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC->ALRֵʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϡ<EFBFBD> ע<EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EXTI_Line17<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵģ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
*************************************************************************************************/
void RTCAlarm_IRQHandler(void)
{
if( RTC_GetITStatus(RTC_IT_ALR)!= RESET ) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
EXTI_ClearITPendingBit(EXTI_Line17);
RTC_ClearITPendingBit(RTC_IT_ALR); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
RTC_WaitForLastTask() ;
//SysLog("RTC_IT_ALR!") ;
Rtc_Hook(RTC_IT_ALR) ;
}
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void Rtc_Sec_Callback(void)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTC<EFBFBD><EFBFBD><EFBFBD>жϻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************************************************************/
void Rtc_Sec_Callback(void)
{
RTC_Get(&uCalendar); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void RTC_NVIC_Config(IntPriority_e ePriority)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTCʱ<EFBFBD><EFBFBD><EFBFBD>жϺ<EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 ePriority IntPriority_eö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD>ʾRTC<EFBFBD>жϵ<EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
*************************************************************************************************/
void RTC_NVIC_Config(IntPriority_e ePriority)
{
NVIC_InitTypeDef NVIC_InitStructure ;
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn ; //RTC<54>ж<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ePriority ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ; //ʹ<>ܸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>ж<EFBFBD>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>NVIC_InitStruct<63><74>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NVIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
// NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn ; //RTCAlarm<72>ж<EFBFBD>
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ePriority ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
// NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>NVIC_InitStruct<63><74>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NVIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult RTC_Init(IntPriority_e ePriority)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 ePriority IntPriority_eö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD>ʾRTC<EFBFBD>жϵ<EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RunResult: <EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>LSEʧЧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LSI<EFBFBD><EFBFBD>ΪRTCʱ<EFBFBD>ӣ<EFBFBD>LSIƵ<EFBFBD><EFBFBD>Ư<EFBFBD>ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************************************************************/
RunResult RTC_Init(IntPriority_e ePriority)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2>ǵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
uint32_t lsTimeOut = 0 ;
uCalendar.sCalendar.spacing = 0x20 ; uCalendar.sCalendar.dash1 = uCalendar.sCalendar.dash2 = '-' ; uCalendar.sCalendar.colon1 = uCalendar.sCalendar.colon2 = ':' ;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE ) ; //ʹ<><CAB9>PWR<57><52>BKP<4B><50><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE) ; //ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD><EBBFAA>AFIOʱ<4F><CAB1>
PWR_BackupAccessCmd(ENABLE); //ʹ<>ܺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (BKP_ReadBackupRegister(BKP_DR1) != 0x5050) //<2F><>ָ<EFBFBD><D6B8><EFBFBD>ĺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
{
BKP_DeInit(); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysLog("BKP_DeInit!") ;
RCC_LSEConfig(RCC_LSE_ON); //<2F><><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD>پ<EFBFBD><D9BE><EFBFBD>(LSE),ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>پ<EFBFBD><D9BE><EFBFBD>
RTC_EnterConfigMode() ; //RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CNT\ALR\PRL
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while ( (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (lsTimeOut < 0x00FFFFFF)) //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>RCC<43><43>־λ<D6BE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>پ<EFBFBD><D9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 72M<32><4D>Ƶ<EFBFBD>´<EFBFBD><C2B4>ŵȴ<C5B5>2.8S
{
lsTimeOut++;
//Wait_For_Nms(10) ;
}
if( lsTimeOut < 0x00FFFFF0 ) //LSE<53><45><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
{
RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE ) ; //<2F><><EFBFBD><EFBFBD>RTCʱ<43><CAB1>(RTCCLK),ѡ<><D1A1>LSE<53><45>ΪRTCʱ<43><CAB1>
lsTimeOut = 1 ;
}
else
{
lsTimeOut = 0 ;
RCC_LSICmd(ENABLE) ; //<2F><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>LSIʱ<49><CAB1>
while ( (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) && (lsTimeOut < 0x00FFFFFF)) //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>RCC<43><43>־λ<D6BE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>پ<EFBFBD><D9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
lsTimeOut++;
//Wait_For_Nms(10) ;
}
if( lsTimeOut < 0x00FFFFF0 ) //<2F>ڲ<EFBFBD>LSIʱ<49><CAB1>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
RCC_RTCCLKConfig( RCC_RTCCLKSource_LSI ) ; //<2F><><EFBFBD><EFBFBD>RTCʱ<43><CAB1>(RTCCLK),ѡ<><D1A1>LSI<53><49>ΪRTCʱ<43><CAB1>
SysErr("") ; //LSEʧЧ,LEI<45><49>ΪRTCʱ<43>ӣ<EFBFBD>
lsTimeOut = 0 ;
}
else
{
SysErr("") ; //LSE+LSI<53><49>ʧЧ<CAA7><D0A7>
return (RUNERR) ; //<2F><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>ʧ<EFBFBD><CAA7>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
RCC_RTCCLKCmd(ENABLE) ; //ʹ<><CAB9>RTCʱ<43><CAB1>
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( lsTimeOut == 0 )
{
RTC_SetPrescaler(40000); //<2F><><EFBFBD><EFBFBD>RTCԤ<43><D4A4>Ƶ<EFBFBD><C6B5>ֵ LSI
}
else
{
RTC_SetPrescaler(32767); //<2F><><EFBFBD><EFBFBD>RTCԤ<43><D4A4>Ƶ<EFBFBD><C6B5>ֵ LSE
}
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//RTC_Set((Calendar_u *)"2018-01-21 09:00:00") ;
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_ExitConfigMode(); //<2F>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ģʽ
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BKP_WriteBackupRegister( BKP_DR1, 0x5050 ) ; //<2F><>ָ<EFBFBD><D6B8><EFBFBD>ĺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else//<2F>Ѿ<EFBFBD><D1BE><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>RTC<54><43><EFBFBD>ڼ<EFBFBD><DABC>󱸷<EFBFBD><F3B1B8B7><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>жϵ<D0B6>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
{
//RTC_WaitForSynchro() ; //RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȴ<EFBFBD>
RTC_WaitForLastTask() ; //RTCд<43><D0B4><EFBFBD><EFBFBD>ǰ<EFBFBD>ȴ<EFBFBD>
RTC_ITConfig( RTC_IT_SEC, ENABLE ) ; //ʹ<><CAB9>RTC<54><43><EFBFBD>ж<EFBFBD>
}
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_ITConfig(RTC_IT_SEC, ENABLE); //ʹ<><CAB9>RTC<54><43><EFBFBD>ж<EFBFBD>
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_ITConfig(RTC_IT_ALR, ENABLE); //ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4>ϴζ<CFB4>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// EXTI_InitTypeDef EXTI_InitStructure; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>EXTI<54><49>17<31>жϲ<D0B6><CFB2><EFBFBD><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>RTCAlarm_IRQHandler<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>RTCȫ<43><C8AB><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ
// EXTI_ClearITPendingBit( EXTI_Line17 );
// EXTI_InitStructure.EXTI_Line = EXTI_Line17 ;
// EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>RTCAlarm_IRQHandler
// EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling ;
// EXTI_InitStructure.EXTI_LineCmd = ENABLE;
// EXTI_Init( &EXTI_InitStructure ); //EXTI<54>ж<EFBFBD><D0B6><EFBFBD>17ΪRTC<54><43><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
PWR_BackupAccessCmd(DISABLE); //<2F><>ֹ<EFBFBD>󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_NVIC_Config(ePriority) ; //RCT<43>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_Get(&uCalendar); //<2F><><EFBFBD><EFBFBD>uCalendarʱ<72><CAB1>
Rtc_RegHookCallback(RTC_IT_SEC, Rtc_Sec_Callback) ; //ע<><D7A2>RTC<54><43><EFBFBD>жϻص<CFBB><D8B5><EFBFBD><EFBFBD><EFBFBD>
return (RUNOK) ; //ok
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult RTC_Get(Calendar_u *getCalendar)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 *getCalendar: ָ<EFBFBD><EFBFBD>Calendar_u<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param RunResult<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD>.
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTC_Get(&uCalendar) ;
*************************************************************************************************/
RunResult RTC_Get(Calendar_u *getCalendar)
{
static uint16_t daycnt = 0 ; //static<69><63><EFBFBD><EFBFBD> <20><>ֻ֤<D6A4>иı<D0B8><C4B1><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u32 timecount = 0, temp = 0 ;
uint16_t temp1 = 0 ;
vu8 hour, min, sec, w_month, w_date, week;
vu16 w_year;
RTC_WaitForSynchro() ; //RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȴ<EFBFBD>
timecount = RTC_GetCounter() ;
temp = timecount/86400 ; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>)
if( daycnt != temp ) //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>˲Ż<CBB2>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
daycnt = temp;
temp1 = 1970; //<2F><>1970<37>ʼ
while( temp >= 365 )
{
if( CheckLeepYear(temp1) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if( temp >= 366 )
temp -= 366 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else
{
temp1++ ;
break ;
}
}
else
temp -= 365 ; //ƽ<><C6BD>
temp1++ ;
}
w_year = temp1 ; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
getCalendar->sCalendar.w_year[0] = w_year/1000+'0' ;
getCalendar->sCalendar.w_year[1] = (w_year%1000)/100+'0' ;
getCalendar->sCalendar.w_year[2] = ((w_year%1000)%100)/10 + '0' ;
getCalendar->sCalendar.w_year[3] = w_year%10 + '0' ;
temp1 = 0 ;
while( temp >= 28 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
{
if( CheckLeepYear(w_year)&&temp1==1 )//<2F><><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/2<>·<EFBFBD>
{
if( temp >= 29 )
temp -= 29 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else
break ;
}
else
{
if( temp >= monTable[temp1] )
temp -= monTable[temp1] ;//ƽ<><C6BD>
else
break ;
}
temp1++ ;
}
w_month = temp1+1 ; //<2F>õ<EFBFBD><C3B5>·<EFBFBD>
w_date = temp+1 ; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
getCalendar->sCalendar.w_month[0] = w_month/10+'0' ;
getCalendar->sCalendar.w_month[1] = w_month%10+'0' ;
getCalendar->sCalendar.w_date[0] = w_date/10+'0' ;
getCalendar->sCalendar.w_date[1] = w_date%10+'0' ;
}
temp = timecount%86400 ; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
hour = temp/3600 ; //Сʱ
min = (temp%3600)/60 ; //<2F><><EFBFBD><EFBFBD>
sec = (temp%3600)%60 ; //<2F><><EFBFBD><EFBFBD>
getCalendar->sCalendar.hour[0] = hour/10+'0' ;
getCalendar->sCalendar.hour[1] = hour%10+'0' ;
getCalendar->sCalendar.min[0] = min/10+'0' ;
getCalendar->sCalendar.min[1] = min%10+'0' ;
getCalendar->sCalendar.sec[0] = sec/10+'0' ;
getCalendar->sCalendar.sec[1] = sec%10+'0' ;
week = RTC_Get_Week( w_year, w_month, w_date ) ; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
return (RUNOK) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> uint8_t RTC_Set(Calendar_u *setCalendar)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD>ǰʱ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param *setCalendar<EFBFBD><EFBFBD>Calendar_u<EFBFBD><EFBFBD><EFBFBD>͹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param uint8_t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:0,<EFBFBD>ɹ<EFBFBD>;<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************************************************************/
RunResult RTC_Set(Calendar_u *setCalendar) //
{
u16 t = 0 ;
u32 seccount = 0 ; //<2F>洢setCalendar<61><72><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ʼ<EFBFBD><CABC>RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t syear = (setCalendar->bytes[0]-'0')*1000+(setCalendar->bytes[1]-'0')*100+(setCalendar->bytes[2]-'0')*10+(setCalendar->bytes[3]-'0') ;
uint8_t smon = (setCalendar->bytes[5]-'0')*10 +(setCalendar->bytes[6]-'0') ;
uint8_t sday = (setCalendar->bytes[8]-'0')*10 +(setCalendar->bytes[9]-'0') ;
uint8_t hour = (setCalendar->bytes[11]-'0')*10 +(setCalendar->bytes[12]-'0') ;
uint8_t min = (setCalendar->bytes[14]-'0')*10 +(setCalendar->bytes[15]-'0') ;
uint8_t sec = (setCalendar->bytes[17]-'0')*10 +(setCalendar->bytes[18]-'0');
if( syear<1970 || syear>2099 )
return (RUNERR);
for( t = 1970; t < syear; t++ ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(CheckLeepYear(t))
seccount += 31622400; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else
seccount += 31536000; //ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
smon -= 1;
for( t=0; t<smon; t++ ) //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
seccount += (u32)monTable[t]*86400; //<2F>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(CheckLeepYear(syear)&&t==1)
seccount += 86400; //<2F><><EFBFBD><EFBFBD>2<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
seccount += (u32)(sday-1)*86400 ; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += (u32)hour*3600 ; //Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += (u32)min*60 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += sec ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>ȥ
PWR_BackupAccessCmd( ENABLE ) ; //ʹ<><CAB9>RTC<54>ͺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_EnterConfigMode() ; //<2F><><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD>ģʽ CNT\ALR\PRL
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_SetCounter( seccount ) ; //<2F><><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
RTC_WaitForLastTask() ; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_ExitConfigMode() ; //<2F>˳<EFBFBD>RTC<54><43><EFBFBD><EFBFBD>ģʽ
RTC_WaitForLastTask() ; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return (RUNOK) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> uint8_t RTC_Alarm_Set(uint16_t syear,uint8_t smon,uint8_t sday,uint8_t hour,uint8_t min,uint8_t sec)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param *setCalendar<EFBFBD><EFBFBD>Calendar_u<EFBFBD><EFBFBD><EFBFBD>͹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param uint8_t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:0,<EFBFBD>ɹ<EFBFBD>;<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1970~2099<EFBFBD><EFBFBD>Ϊ<EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************************************************************/
RunResult RTC_Alarm_Set(Calendar_u *setCalendar)
{
u16 t = 0 ;
u32 seccount = 0 ;
uint16_t syear = (setCalendar->bytes[0]-'0')*1000+(setCalendar->bytes[1]-'0')*100+(setCalendar->bytes[2]-'0')*10+(setCalendar->bytes[3]-'0') ;
uint8_t smon = (setCalendar->bytes[5]-'0')*10 +(setCalendar->bytes[6]-'0') ;
uint8_t sday = (setCalendar->bytes[8]-'0')*10 +(setCalendar->bytes[9]-'0') ;
uint8_t hour = (setCalendar->bytes[11]-'0')*10 +(setCalendar->bytes[12]-'0') ;
uint8_t min = (setCalendar->bytes[14]-'0')*10 +(setCalendar->bytes[15]-'0') ;
uint8_t sec = (setCalendar->bytes[17]-'0')*10 +(setCalendar->bytes[18]-'0');
if( syear<1970 || syear>2099 )
return (RUNERR) ;
for( t=1970; t<syear; t++ ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(CheckLeepYear(t))
seccount += 31622400 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else
seccount += 31536000 ; //ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
smon -= 1;
for( t=0; t<smon; t++ ) //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
seccount += (u32)monTable[t]*86400 ; //<2F>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(CheckLeepYear(syear)&& (t==1) )
seccount += 86400 ; //<2F><><EFBFBD><EFBFBD>2<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
seccount += (u32)(sday-1)*86400 ; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += (u32)hour*3600 ; //Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += (u32)min*60; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
seccount += sec; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>ȥ
PWR_BackupAccessCmd( ENABLE ) ; //ʹ<>ܺ󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_EnterConfigMode() ; //RTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CNT\ALR\PRL
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_SetAlarm(seccount);
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_ExitConfigMode(); //RTC<54>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD> CNT\ALR\PRL
RTC_WaitForLastTask(); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζ<EFBFBD>RTC<54>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PWR_BackupAccessCmd(DISABLE); //<2F><>ֹ<EFBFBD>󱸼Ĵ<F3B1B8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return (RUNOK);
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> uint8_t CheckLeepYear(uint16_t year)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>year<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param uint16_t year<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param uint8_t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@arg 1: yearΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @arg 0: yearΪƽ<EFBFBD><EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>·<EFBFBD> 1 2 3 4 5 6 7 8 9 10 11 12
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 31 29 31 30 31 30 31 31 30 31 30 31
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 31 28 31 30 31 30 31 31 30 31 30 31
*************************************************************************************************/
uint8_t CheckLeepYear(uint16_t year)
{
if( year%4 == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD>
{
if( year%100 == 0 )
{
if( year%400 == 0 )
return 1 ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>00<30><30>β,<2C><>Ҫ<EFBFBD>ܱ<EFBFBD>400<30><30><EFBFBD><EFBFBD>
else
return 0 ;
}
else
return 1 ;
}
else
return 0 ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> Ruint8_t RTC_Get_Week(uint16_t year, uint8_t month, uint8_t day)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 year: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param2 mon: <EFBFBD>·<EFBFBD>
* @param3 day: <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 uint8_t: <EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD>
* @param RunResult<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD>.
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵõ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1901-2099<EFBFBD><EFBFBD>)
*************************************************************************************************/
uint8_t RTC_Get_Week(uint16_t year, uint8_t month, uint8_t day)
{
uint16_t temp2 ;
uint8_t yearH, yearL ;
yearH = year/100 ;
yearL = year%100 ;
if ( yearH>19 ) // <20><><EFBFBD><EFBFBD>Ϊ21<32><31><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100
yearL+=100;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>1900<30><30>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>
temp2 = yearL+yearL/4 ;
temp2 = temp2%7 ;
temp2 = temp2+day+weekTable[month-1] ;
if ( yearL%4==0&&month<3 )
temp2--;
return(temp2%7) ;
}