研究生
最后登录1970-1-1
在线时间 小时
注册时间2021-8-30
|

楼主 |
发表于 2021-10-17 13:08:43
|
显示全部楼层
对同步算法的再次改动
- //获取RTC的计数值
- temp = RTC_GetCounter();
-
- //同步时间算法,仅实现到了天数同步,如果不开机时长超过30天左右会出现同步出错
- if((temp/3600)>=24)
- {
- DateChanged(year,month,(day+(temp/(3600*24))));
- if(TimeTest(year,month,day) == 1)
- {
- if((year%4==0)&&(month==2))
- {
- DateChanged(year,(month+1),(day-29));
- }
- if(month==2)
- {
- DateChanged(year,(month+1),(day-28));
- }
- if((month==4)||(month==6)||(month==9)||(month==11))
- {
- DateChanged(year,(month+1),(day-30));
- }
- if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
- {
- DateChanged(year,(month+1),(day-31));
- }
- }
- temp -= ((3600*24)*(temp/(3600*24)));
- }
- if(temp<60)
- {
- TimeModificatiopn(hour,minute,sec+temp);
- if(sec>60)
- {
- TimeModificatiopn(hour,(minute+1),(sec-60));
- }
- }
- if(((temp/60)<60) && (temp>=60))
- {
- TimeModificatiopn(hour,(minute+(temp/60)),(sec+(temp%60)));
- if(minute > 60)
- {
- TimeModificatiopn((hour+1),(minute-60),sec);
- }
- }
- if(((temp/3600)<24) && (temp>=3600))
- {
- if((temp%3600)<60)
- {
- TimeModificatiopn((hour+(temp/3600)),minute,(sec+(temp%60)));
- if(hour>=24)
- {
- DateChanged(year,month,(day+1));
- if(TimeTest(year,month,day) == 1)
- {
- if((year%4==0)&&(month==2))
- {
- DateChanged(year,(month+1),(day-29));
- }
- if(month==2)
- {
- DateChanged(year,(month+1),(day-28));
- }
- if((month==4)||(month==6)||(month==9)||(month==11))
- {
- DateChanged(year,(month+1),(day-30));
- }
- if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
- {
- DateChanged(year,(month+1),(day-31));
- }
- }
- TimeModificatiopn((hour-24),minute,sec);
- if(sec>60)
- {
- TimeModificatiopn(hour,(minute+1),(sec-60));
- }
- }
- }
- if((((temp%3600)/60)<60) && ((temp%3600)>=60))
- {
- TimeModificatiopn((hour+(temp/3600)),(minute+((temp%3600)/60)),(sec+(temp%60)));
- if(hour>=24)
- {
- DateChanged(year,month,(day+1));
- if(TimeTest(year,month,day) == 1)
- {
- if((year%4==0)&&(month==2))
- {
- DateChanged(year,(month+1),(day-29));
- }
- if(month==2)
- {
- DateChanged(year,(month+1),(day-28));
- }
- if((month==4)||(month==6)||(month==9)||(month==11))
- {
- DateChanged(year,(month+1),(day-30));
- }
- if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
- {
- DateChanged(year,(month+1),(day-31));
- }
- }
- TimeModificatiopn((hour-24),minute,sec);
- if(minute > 60)
- {
- TimeModificatiopn((hour+1),(minute-60),sec);
- if(sec>60)
- {
- TimeModificatiopn(hour,(minute+1),(sec-60));
- }
- }
- }
- }
- }
复制代码 |
|