123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include "Ds1302.h"
- #include "string.h"
- #include "gpio.h"
- #include "stdio.h"
- #include "ac780x_rtc.h"
- #include "ac780x.h"
- DateTime g_dateTime;
- /**
- * RTCCallBackFunc
- *
- * @param[in] wparam: reserved
- * @param[in] lparam: reserved
- * @return 0: success, other: error value
- *
- * @brief 中断回调函数
- * 改变LED输出,使得LED闪烁
- */
- void RTCCallBackFunc(void *device, uint32_t wpara, uint32_t lpara)
- {
-
- if (wpara & RTC_SC_RPIF_Msk) //预分频中断
- {
-
- }
- if (wpara & RTC_SC_RTIF_Msk) //RTC溢出中断
- {
- //printf("g_timer0Cnt:%d \r\n", g_timer0Cnt);
- DS1302_UpdateTime();
- }
-
- }
- /**
- * RTC_Timeout1s
- *
- * @param[in] none
- * @return none
- *
- * @brief 配置RTC计时1S,时钟源为Bus clock
- */
- void RTC_Timeout1s(void)
- {
- uint32_t tmpMod = 239999;
- uint32_t tmpPrescalerValue = 99; //(99+1)*(239999+1)/24000000 = 1s
- RTC_ConfigType RTCConfig;
-
- memset(&RTCConfig,0,sizeof(RTCConfig));
- RTCConfig.clockSource = RTC_CLOCK_APB; //时钟源选择:0:Bus clk (demo板上总线时钟为24M);
- //1: LSI 32KHz; 2: External OSC; 3:Internal 8M;
- RTCConfig.periodValue = tmpMod;
- RTCConfig.psrInterruptEn = DISABLE;
- RTCConfig.rtcInterruptEn = ENABLE;
- RTCConfig.psrValue = tmpPrescalerValue; //time = (pre+1)*(mod+1)/clk
- RTCConfig.rtcOutEn = DISABLE;
- RTCConfig.callBack = RTCCallBackFunc;
- RTC_Init(&RTCConfig); //配置RTC
- }
- void DS1302_Init(void)
- {
- g_dateTime.year = 24;
- g_dateTime.month = 7;
- g_dateTime.day = 5;
- g_dateTime.hour = 15;
- g_dateTime.minute = 0;
- g_dateTime.second = 0;
-
- RTC_Timeout1s();
-
- }
- uint8_t Ds1302_ReadReg(uint8_t _address)
- {
-
- return 0;
- }
- void DS1302_SetTime(DateTime* pDateTime)
- {
- }
- void DS1302_UpdateTime()
- {
- g_dateTime.second++;
- if(g_dateTime.second >= 60){
- g_dateTime.second=0;
- g_dateTime.minute++;
- if(g_dateTime.minute >= 60){
- g_dateTime.minute=0;
- g_dateTime.hour++;
- if(g_dateTime.hour>= 24){
- g_dateTime.hour=0;
- g_dateTime.day++;
- }
- }
- }
-
- //if(g_dateTime.day>= 3){
- //
- //}
- }
- void DS1302_PrintDateTime()
- {
-
- printf("DS1302 DateTime:[%d][%d][%d] \r\n", g_dateTime.hour, g_dateTime.minute, g_dateTime.second);
- }
- void DS1302_DeInit(void)
- {
- }
|