forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-06-05 cf4d12fd8322cbb350dd3bc5af8c748e8790ac64
Function/EXTERN_RTC/extern_rtc.c
@@ -4,15 +4,14 @@
#include "gpio.h"
#include "system_general_para.h"
//__IO CALENDAR_TIME_T calendar_g = {0};
__IO sClockBCD sys_clockBCD_g = {0x24,1,1,0,0,0};
//__IO CALENDAR_TIME_T calendar_test_g = {0};
void RTC_GPIO_Init(void)
{
   I2c_Scl_Gpio_Init();
   
   InputtIO(EXT_RTC_INT_PORT,EXT_RTC_INT_PIN,IN_PULLUP);
   InputtIO(EXT_RTC_INT_PORT,EXT_RTC_INT_PIN,IN_NORMAL);
}
@@ -29,12 +28,31 @@
   minDec = BCD_2_DECIMAL(TimeBCD.min);
   secDec = BCD_2_DECIMAL(TimeBCD.sec);
   
   if((yearDec>99)||(yearDec<20)||(monthDec>12)||(monthDec==0)||(dayDec>31)||(dayDec==0)||(hourDec>23)||(minDec>59)||(secDec>59))
   if((yearDec>YEAR_DEC_MAX)||(yearDec<20)||(monthDec>12)||(monthDec==0)||(dayDec>31)||(dayDec==0)||(hourDec>23)||(minDec>59)||(secDec>59))
   {
      //ËÑË÷ʱ¼äÎÞЧ
      //ʱ¼äÎÞЧ
      return FAIL;
   }else
   {
      switch(monthDec)
      {
         case 4:
         case 6:
         case 9:
         case 11:
            if(dayDec>30)
               return FAIL;
         case 2:
            if(((yearDec&0x3) != 0) && (dayDec>28)){
               return FAIL;
            }
            else if(((yearDec&0x3) == 0) && (dayDec > 29)){
               return FAIL;
            }
            break;
         default:
            break;
      }
      return PASS;
   }
}
@@ -102,7 +120,7 @@
//ÉèÖÃÍⲿRTCʱ¼ä 
//²ÎÊý£ºBCD¸ñʽ
void Set_Extern_Rtc_Time(uint16_t year,uint8_t month,uint8_t day,uint8_t week,uint8_t hour,uint8_t min,uint8_t sec)
ErrorStatus Set_Extern_Rtc_Time(uint16_t year,uint8_t month,uint8_t day,uint8_t week,uint8_t hour,uint8_t min,uint8_t sec)
{
   uint8_t rtc_time[7] = {0,0,0,0,1,1,0x15};
   sClockBCD   calendar_l;
@@ -124,7 +142,10 @@
      rtc_time[5] = month;
      rtc_time[6] = year;
      R8025T_Write(0,rtc_time,7);
      return PASS;
   }
   return FAIL;
}
//»ñÈ¡ÍⲿRTCʱ¼ä
@@ -157,7 +178,33 @@
      return PASS;
   }else
   {
      return FAIL;
      //ÔÙ¶ÁÒ»´Î
      R8025T_Read(0,rtc_time,7);
      calendar_l.year = rtc_time[6];
      calendar_l.month = rtc_time[5];
      calendar_l.day = rtc_time[4];
      calendar_l.hour = rtc_time[2];
      calendar_l.min = rtc_time[1];
      calendar_l.sec = rtc_time[0];
      if(TimeEffectJudgm(calendar_l)==PASS) //¶ÁÈ¡µÄʱ¼äÕýÈ·²Å²Ù×÷Ö¸Õë
      {
         calendar_p->sec = rtc_time[0];
         calendar_p->min = rtc_time[1];
         calendar_p->hour = rtc_time[2];
         calendar_p->day = rtc_time[4];
         calendar_p->month = rtc_time[5];
         calendar_p->year = rtc_time[6];
   #ifdef RS232_PRINTF
      printf("EX_RTC_TIME = %X-%02X-%02X-%02X-%02X-%02X \r\n",calendar_p->year,calendar_p->month,calendar_p->day,
                                                                                             calendar_p->hour,calendar_p->minute,calendar_p->second);
   #endif
         return PASS;
      }else
      {
         return FAIL;
      }
   }
}