/** * @brief Sets the RTC Date(DD/MM/YYYY) * @param DD,MM,YYYY * @retval : None */ void set_time(rtc_t *time) { /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( time->Month == 4 || time->Month == 6 || time->Month == 9 || time->Month == 11) && time->mDay == 31) || (time->Month == 2 && (time->mDay > 29)) || (time->Month == 2 && time->mDay == 29 && (CheckLeap(time->Year)==0))) { DEBUGF("INCORRECT DATE...\n"); } else { s_DateStructVar.Year = time->Year; s_DateStructVar.Month = time->Month; s_DateStructVar.mDay = time->mDay; s_DateStructVar.wDay = WeekDay(time->Year, time->Month, time->mDay); s_DateStructVar.Hour = time->Hour; s_DateStructVar.Minute = time->Minute; s_DateStructVar.Second = time->Second; WRITE_BKP_CLOCK_YEAR(time->Year); WRITE_BKP_CLOCK_MONTH(time->Month); WRITE_BKP_CLOCK_MDAY(time->mDay); WRITE_BKP_CLOCK_WDAY(s_DateStructVar.wDay); WRITE_BKP_CLOCK_TIME( (time->Hour * 60 + time->Minute) * 60 + time->Second); SummerTimeCorrection(); } }
void set_alarm(rtc_t *alarm){ /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( alarm->Month == 4 || alarm->Month == 6 || alarm->Month == 9 || alarm->Month == 11) && alarm->mDay == 31) || (alarm->Month == 2 && ( alarm->mDay > 29)) || (alarm->Month == 2 && alarm->mDay == 29 && (CheckLeap(alarm->Year)==0))) { DEBUGF("INCORRECT DATE...\n"); } else { s_AlarmDateStructVar.Year = alarm->Year; s_AlarmDateStructVar.Month = alarm->Month; s_AlarmDateStructVar.mDay = alarm->mDay; s_AlarmDateStructVar.Hour = alarm->Hour; s_AlarmDateStructVar.Minute = alarm->Minute; s_AlarmDateStructVar.mode = alarm->mode; WRITE_BKP_ALARM_YEAR(alarm->Year); WRITE_BKP_ALARM_MONTH(alarm->Month); WRITE_BKP_ALARM_MDAY(alarm->mDay); WRITE_BKP_ALARM_TIME((alarm->Hour * 60 + alarm->Minute) * 60 ); WRITE_BKP_ALARM_MODE(alarm->mode); } }
/** * @brief Sets the RTC Date(DD/MM/YYYY) * @param DD,MM,YYYY * @retval : None */ void SetDate(uint8_t Day, uint8_t Month, uint16_t Year) { uint32_t DateTimer; RightLeftIntExtOnOffConfig(DISABLE); UpDownIntOnOffConfig(DISABLE); /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( Month==4 || Month==6 || Month==9 || Month==11) && Day ==31) \ || (Month==2 && Day==31)|| (Month==2 && Day==30)|| \ (Month==2 && Day==29 && (CheckLeap(Year)==0))) { LCD_Clear(Red); LCD_SetBackColor(Red); LCD_DisplayString(Line3,Column2,"INCORRECT DATE"); LCD_DisplayString(Line6,Column1,"PLEASE RECONFIGURE"); DateTimer=RTC_GetCounter(); while((RTC_GetCounter()-DateTimer)<2) { } } /* if date entered is correct then set the date*/ else { if(AlarmDate==0) { BKP_WriteBackupRegister(BKP_DR2,Month); BKP_WriteBackupRegister(BKP_DR3,Day); BKP_WriteBackupRegister(BKP_DR4,Year); DisplayDateFlag=1; } else { s_AlarmDateStructVar.Day = Day; s_AlarmDateStructVar.Month = Month; s_AlarmDateStructVar.Year = Year; BKP_WriteBackupRegister(BKP_DR8,Month); BKP_WriteBackupRegister(BKP_DR9,Day); BKP_WriteBackupRegister(BKP_DR10,Year); AlarmDate=0; } } }
/******************************************************************************* * Function Name : SetDate * Description : Sets the RTC Date(DD/MM/YYYY) * Input : DD,MM,YYYY * Output : None * Return : None *******************************************************************************/ void SetDate(u8 u8_Day, u8 u8_Month, u16 u16_Year) { u32 u32_DateTimer; //RightLeftIntExtOnOffConfig(DISABLE); //UpDownIntOnOffConfig(DISABLE); /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( u8_Month==4 || u8_Month==6 || u8_Month==9 || u8_Month==11) && u8_Day ==31) \ || (u8_Month==2 && u8_Day==31)|| (u8_Month==2 && u8_Day==30)|| \ (u8_Month==2 && u8_Day==29 && (CheckLeap(u16_Year)==0))) { u32_DateTimer=RTC_GetCounter(); while((RTC_GetCounter()-u32_DateTimer)<2) { } } /* if date entered is correct then set the date*/ else { if(u8_AlarmDate==0) { s_DateStructVar.u16_Year = u16_Year; s_DateStructVar.u8_Month = u8_Month; s_DateStructVar.u8_Day = u8_Day; BKP_WriteBackupRegister(BKP_DR2,u8_Month); BKP_WriteBackupRegister(BKP_DR3,u8_Day); BKP_WriteBackupRegister(BKP_DR4,u16_Year); u8_DisplayDateFlag=1; } else { s_AlarmDateStructVar.u8_Day = u8_Day; s_AlarmDateStructVar.u8_Month = u8_Month; s_AlarmDateStructVar.u16_Year = u16_Year; BKP_WriteBackupRegister(BKP_DR8,u8_Month); BKP_WriteBackupRegister(BKP_DR9,u8_Day); BKP_WriteBackupRegister(BKP_DR10,u16_Year); u8_AlarmDate=0; } } }
main() { int year,month,startDay,days,yes_no;//年,月,该月第一天星期几,该月有多少天,是否是闰年 printf("input the year and month<YYYY-MM>:"); scanf("%d-%d",&year,&month); printf(" %d年-%d月\n",year,month);//打印标题YYYY-MM /*调用函数*/ yes_no=CheckLeap ( year); startDay=GetWeekDay (year,month,yes_no); days=GetMonthDay (year,month,yes_no);//值传递和处理 PrintMonthCalender (startDay,days); system("pause"); return 0; }
/** * @brief Sets the RTC Date(DD/MM/YYYY) * @param DD,MM,YYYY * @retval : None */ static void SetDate(uint8_t Day, uint8_t Month, uint8_t Year) { uint32_t DateTimer; /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( Month==4 || Month==6 || Month==9 || Month==11) && Day ==31) \ || (Month==2 && Day==31)|| (Month==2 && Day==30)|| \ (Month==2 && Day==29 && (CheckLeap(Year)==0))) { DateTimer=RTC_GetCounter(); while((RTC_GetCounter()-DateTimer)<2) { } } /* if date entered is correct then set the date*/ else { BKP_ModifyBackupRegister(BKP_DR3,Day | (Month << 8)); BKP_ModifyBackupRegister(BKP_DR5,Year); } }
void DateUpdate(void) { s_DateStructVar.Day=BKP_ReadBackupRegister(BKP_DR2); s_DateStructVar.Month=BKP_ReadBackupRegister(BKP_DR3); s_DateStructVar.Year=BKP_ReadBackupRegister(BKP_DR4); if(s_DateStructVar.Month == 1 || s_DateStructVar.Month == 3 || \ s_DateStructVar.Month == 5 || s_DateStructVar.Month == 7 ||\ s_DateStructVar.Month == 8 || s_DateStructVar.Month == 10 \ || s_DateStructVar.Month == 12) { if(s_DateStructVar.Day < 31) { s_DateStructVar.Day++; } /* Date structure member: s_DateStructVar.Day = 31 */ else { if(s_DateStructVar.Month != 12) { s_DateStructVar.Month++; s_DateStructVar.Day = 1; } /* Date structure member: s_DateStructVar.Day = 31 & s_DateStructVar.Month =12 */ else { s_DateStructVar.Month = 1; s_DateStructVar.Day = 1; s_DateStructVar.Year++; } } } else if(s_DateStructVar.Month == 4 || s_DateStructVar.Month == 6 \ || s_DateStructVar.Month == 9 ||s_DateStructVar.Month == 11) { if(s_DateStructVar.Day < 30) { s_DateStructVar.Day++; } /* Date structure member: s_DateStructVar.Day = 30 */ else { s_DateStructVar.Month++; s_DateStructVar.Day = 1; } } else if(s_DateStructVar.Month == 2) { if(s_DateStructVar.Day < 28) { s_DateStructVar.Day++; } else if(s_DateStructVar.Day == 28) { /* Leap Year Correction */ if(CheckLeap(s_DateStructVar.Year)) { s_DateStructVar.Day++; } else { s_DateStructVar.Month++; s_DateStructVar.Day = 1; } } else if(s_DateStructVar.Day == 29) { s_DateStructVar.Month++; s_DateStructVar.Day = 1; } } BKP_WriteBackupRegister(BKP_DR2,s_DateStructVar.Day); BKP_WriteBackupRegister(BKP_DR3,s_DateStructVar.Month); BKP_WriteBackupRegister(BKP_DR4,s_DateStructVar.Year); }
/** * @brief Updates the Date (This function is called when 1 Day has elapsed * @param None * @retval :None */ void DateUpdate(void) { s_DateStructVar.Month = READ_BKP_CLOCK_MONTH(); s_DateStructVar.Year = READ_BKP_CLOCK_YEAR(); s_DateStructVar.mDay = READ_BKP_CLOCK_MDAY(); s_DateStructVar.wDay = READ_BKP_CLOCK_WDAY(); if(s_DateStructVar.Month == 1 || s_DateStructVar.Month == 3 || s_DateStructVar.Month == 5 || s_DateStructVar.Month == 7 || s_DateStructVar.Month == 8 || s_DateStructVar.Month == 10 || s_DateStructVar.Month == 12) { if(s_DateStructVar.mDay < 31) { s_DateStructVar.mDay++; } /* Date structure member: s_DateStructVar.Day = 31 */ else { if(s_DateStructVar.Month != 12) { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } /* Date structure member: s_DateStructVar.Day = 31 & s_DateStructVar.Month =12 */ else { s_DateStructVar.Month = 1; s_DateStructVar.mDay = 1; s_DateStructVar.Year++; } } } else if(s_DateStructVar.Month == 4 || s_DateStructVar.Month == 6 || s_DateStructVar.Month == 9 ||s_DateStructVar.Month == 11) { if(s_DateStructVar.mDay < 30) { s_DateStructVar.mDay++; } /* Date structure member: s_DateStructVar.Day = 30 */ else { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } else if(s_DateStructVar.Month == 2) { if(s_DateStructVar.mDay < 28) { s_DateStructVar.mDay++; } else if(s_DateStructVar.mDay == 28) { /* Leap Year Correction */ if(CheckLeap(s_DateStructVar.Year)) { s_DateStructVar.mDay++; } else { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } else if(s_DateStructVar.mDay == 29) { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } s_DateStructVar.mDay = WeekDay(s_DateStructVar.Year , s_DateStructVar.Month , s_DateStructVar.mDay); WRITE_BKP_CLOCK_YEAR(s_DateStructVar.Year); WRITE_BKP_CLOCK_MONTH(s_DateStructVar.Month); WRITE_BKP_CLOCK_MDAY(s_DateStructVar.mDay); WRITE_BKP_CLOCK_WDAY(s_DateStructVar.wDay); }