代码拉取完成,页面将自动刷新
同步操作将从 casy/Calendar_LCD12864 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*******************************************************************************
* Function Name : USART_Scanf
* Description : Gets numeric values from the hyperterminal.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u32 USART_Scanf(u32 value)
{
u32 index = 0;
u32 tmp[4] = {0, 0};
u32 Num;
if (value==2136)
Num = 4;
else
Num = 2;
while(index < Num)
{
/* Loop until RXNE = 1 */
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
{
}
tmp[index++] = (USART_ReceiveData(USART1));
if((tmp[index - 1] < 0x30) || (tmp[index - 1] > 0x39))
{
printf("\n\rPlease enter valid number between 0 and 9");
index--;
}
}
/* Calculate the Corresponding value */
if (value!=2136)
index = ((tmp[0] - 0x30) * 10) + (tmp[1] - 0x30);
else
index = ((tmp[0] - 0x30) * 1000) + ((tmp[1] - 0x30) * 100) + ((tmp[2] - 0x30) * 10) + (tmp[3] - 0x30);
/* Checks */
if(index > value)
{
printf("\n\rPlease enter valid number between 0 and %d", value);
return 0xFF;
}
return index;
}
void Time_Display(u32 TimeVar)
{
#if 1
u32 TY = 0, TM = 1, TD = 0;
s32 Num4Y,NumY, OffSec, Off4Y = 0;
u32 i;
s32 NumDay, OffDay;
#endif
u32 THH = 0, TMM = 0, TSS = 0;
#if 0
/* Compute hours */
THH = TimeVar/3600;
/* Compute minutes */
TMM = (TimeVar % 3600)/60;
/* Compute seconds */
TSS = (TimeVar % 3600)% 60;
#endif
#if 1
{
Num4Y = TimeVar/SecsPerFourYear;
OffSec = TimeVar%SecsPerFourYear;
i=1;
while(OffSec > Year_Secs_Accu[i++])
Off4Y++;
/* Numer of Complete Year */
NumY = Num4Y*4 + Off4Y;
/* 2000,2001,...~2000+NumY-1 complete year before, so this year is 2000+NumY*/
TY = 2000+NumY;
OffSec = OffSec - Year_Secs_Accu[i-2];
/* Month (TBD with OffSec)*/
i=0;
if(TY%4)
{// common year
while(OffSec > Month_Secs_Accu_C[i++]);
TM = i-1;
OffSec = OffSec - Month_Secs_Accu_C[i-2];
}
else
{// leap year
while(OffSec > Month_Secs_Accu_L[i++]);
TM = i-1;
OffSec = OffSec - Month_Secs_Accu_L[i-2];
}
/* Date (TBD with OffSec) */
NumDay = OffSec/SecsPerDay;
OffSec = OffSec%SecsPerDay;
TD = NumDay+1;
/* Compute hours */
THH = OffSec/3600;
/* Compute minutes */
TMM = (OffSec % 3600)/60;
/* Compute seconds */
TSS = (OffSec % 3600)% 60;
}
#endif
printf("Date: %0.4d-%0.2d-%0.2d Time: %0.2d:%0.2d:%0.2d\r",TY, TM, TD,THH, TMM, TSS);
}
static u32 Time_Regulate(void)
{
#if 1
u32 Tmp_Year=0xFFFF, Tmp_Month=0xFF, Tmp_Date=0xFF;
u32 LeapY, ComY, TotSeconds, TotDays;
#endif
u32 Tmp_HH = 0xFF, Tmp_MM = 0xFF, Tmp_SS = 0xFF;
printf("\r\n=================Time Settings==================================");
#if 1
printf("\r\n Please Set Year");
while(Tmp_Year == 0xFFFF)
{
/*32-bit counter at Second Unit--> 4*1024*1024(s) --> 49710(day) --> 136(year)*/
Tmp_Year = USART_Scanf(2136);
}
printf(": %d", Tmp_Year);
printf("\r\n Please Set Month");
while(Tmp_Month == 0xFF)
{
Tmp_Month = USART_Scanf(12);
}
printf(": %d", Tmp_Month);
printf("\r\n Please Set Date");
while(Tmp_Date == 0xFF)
{
Tmp_Date = USART_Scanf(31);
}
printf(": %d", Tmp_Date);
#endif
printf("\r\n Please Set Hours");
while(Tmp_HH == 0xFF)
{
Tmp_HH = USART_Scanf(23);
}
printf(": %d", Tmp_HH);
printf("\r\n Please Set Minutes");
while(Tmp_MM == 0xFF)
{
Tmp_MM = USART_Scanf(59);
}
printf(": %d", Tmp_MM);;
printf("\r\n Please Set Seconds");
while(Tmp_SS == 0xFF)
{
Tmp_SS = USART_Scanf(59);
}
printf(": %d", Tmp_SS);
#if 1
{
/* change Year-Month-Data-Hour-Minute-Seconds into X(Second) to set RTC->CNTR */
if(Tmp_Year==2000)
LeapY = 0;
else
LeapY = (Tmp_Year - 2000 -1)/4 +1;
ComY = (Tmp_Year - 2000)-(LeapY);
if (Tmp_Year%4)
//common year
TotDays = LeapY*366 + ComY*365 + Month_Days_Accu_C[Tmp_Month-1] + (Tmp_Date-1);
else
//leap year
TotDays = LeapY*366 + ComY*365 + Month_Days_Accu_L[Tmp_Month-1] + (Tmp_Date-1);
TotSeconds = TotDays*SecsPerDay + (Tmp_HH*3600 + Tmp_MM*60 + Tmp_SS);
}
#endif
/* Return the value to store in RTC counter register */
//return((Tmp_HH*3600 + Tmp_MM*60 + Tmp_SS));
return TotSeconds;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。