RTC时间设置思路
进入时间设置,不进行RTC时间读取
通过按键设置时间相关参数,按键确认,将更改后的时间写入
未进行参数
进行参数设置是时,就会出现错乱
/************模式2下按下按键,进行时间日期设置,再次按下进行时间写入****************/
if(2 == MODE)
{
key3_Sure++;
Key_Rig_1=1;
if(1==Key2_Flag&&1==key3_Sure)
{
// RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
// Nian=RTC_DateStruct.RTC_Year;
// Yuan=RTC_DateStruct.RTC_Month;
// Ri=RTC_DateStruct.RTC_Date;
RCC_RTCCLKCmd(DISABLE ); //ê1ÄüRTCê±Öó
}
if(2==Key2_Flag&&1==key3_Sure)
{
// RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
// Shi=RTC_TimeStruct.RTC_Hours;
// Fen=RTC_TimeStruct.RTC_Minutes;
// Miao=RTC_TimeStruct.RTC_Seconds;
RCC_RTCCLKCmd(DISABLE );
}
if(1!=Key2_Flag&&key3_Sure>=2){key3_Sure=0;Key_Rig_1=0; RCC_RTCCLKCmd(ENABLE );RTC_Set_Date(Nian,Yuan,Ri,2);}
if(2!=Key2_Flag&&key3_Sure>=2){key3_Sure=0;Key_Rig_1=0; RCC_RTCCLKCmd(ENABLE );RTC_Set_Time(Shi,Fen,Miao,RTC_H12_AM); }
if(((1!=Key2_Flag)||(2!=Key2_Flag))&&key3_Sure>=2){key3_Sure=0;Key_Rig_1=0;} ////½çÃæ2ÿò»à¸è·èÏ
}
/**************时间修改函数****************************/
if(1==key3_Sure && 2 == MODE &&2==Key2_Flag) //½çÃæ2ê±¼äéèÖÃ
{
Temp_SW=Shi/10; //24
Temp_W=Shi%10;
Temp_Q=Fen/10; //60
Temp_B=Fen%10;
Temp_S=Miao/10; //60
Temp_G=Miao%10;
switch(Key_Rig_1)
{
case 1: //
Temp_SW++; if(Temp_SW>=3) Temp_SW=0;
break;
case 2: //
Temp_W++; if((0==Temp_SW&&Temp_W>=10)||(1==Temp_SW&&Temp_W>=10)){ Temp_W=0;}
if(2==Temp_SW&&Temp_W>=4){ Temp_W=0;} //á½ÖÖÇé¿öShi 24
break;
case 3: //
Temp_Q++; if(Temp_Q>=6) Temp_Q=0;
break;
case 4: //
Temp_B++; if(Temp_B>=10) Temp_B=0;
break;
case 5: //
Temp_S++; if(Temp_S>=6) Temp_S=0;
break;
case 6: //
Temp_G++; if(Temp_G>=10) Temp_G=0;
break;
default:
break;
}
Shi=Temp_SW*10+Temp_W;
Fen=Temp_Q*10+Temp_B;
Miao=Temp_S*10+Temp_G;
}
[mw_shl_code=applescript,true]/**********************"èÕÆúéèÖÃ"***********************/
if(((1!=Key2_Flag)||(2!=Key2_Flag))&&0==key3_Sure) //ê±¼äèÕÆúéèÖÃ
{
RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
}
Nian=RTC_DateStruct.RTC_Year;
Yuan=RTC_DateStruct.RTC_Month;
Ri=RTC_DateStruct.RTC_Date;
Gui_DrawFont_GBK32(198,44, RED,GRAY0,"-");
Gui_DrawFont_GBK32(198+54,44, RED,GRAY0,"-");
/**********************"ê±¼äéèÖÃ"**********************/
Shi=RTC_TimeStruct.RTC_Hours;
Fen=RTC_TimeStruct.RTC_Minutes;
Miao=RTC_TimeStruct.RTC_Seconds;
Gui_DrawFont_GBK32(198,84, RED,GRAY0,"-");
Gui_DrawFont_GBK32(198+54,84, RED,GRAY0,"-");
if(1==Key2_Flag)
{
switch (Key_Rig_1)
{
case 1: //
sprintf((char*)tbuf,"%d",Nian/10);
Gui_DrawFont_GBK32(162,44, YELLOW,GRAY0,tbuf);
break;
case 2: //
sprintf((char*)tbuf,"%d",Nian%10);
Gui_DrawFont_GBK32(162+18,44, YELLOW,GRAY0,tbuf);
break;
case 3: //
sprintf((char*)tbuf,"%d",Yuan/10);
Gui_DrawFont_GBK32(162+18*3,44, YELLOW,GRAY0,tbuf);
break;
case 4: //
sprintf((char*)tbuf,"%d",Yuan%10);
Gui_DrawFont_GBK32(162+18*4,44, YELLOW,GRAY0,tbuf);
break;
case 5: //
sprintf((char*)tbuf,"%d",Ri/10);
Gui_DrawFont_GBK32(162+18*6,44, YELLOW,GRAY0,tbuf);
break;
case 6: //
sprintf((char*)tbuf,"%d",Ri%10);
Gui_DrawFont_GBK32(162+18*7,44, YELLOW,GRAY0,tbuf);
break;
default:
break;
}
}
if(1!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Nian/10); Gui_DrawFont_GBK32(162,44, RED,GRAY0,tbuf); }
if(2!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Nian%10); Gui_DrawFont_GBK32(162+18,44, RED,GRAY0,tbuf);}
if(3!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Yuan/10); Gui_DrawFont_GBK32(162+18*3,44, RED,GRAY0,tbuf);}
if(4!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Yuan%10); Gui_DrawFont_GBK32(162+18*4,44, RED,GRAY0,tbuf);}
if(5!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Ri/10); Gui_DrawFont_GBK32(162+18*6,44, RED,GRAY0,tbuf);}
if(5!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Ri%10); Gui_DrawFont_GBK32(162+18*7,44, RED,GRAY0,tbuf);}
if(2==Key2_Flag)
{
switch (Key_Rig_1)
{
case 1: //
sprintf((char*)tbuf,"%d",Shi/10);
Gui_DrawFont_GBK32(162,84, YELLOW,GRAY0,tbuf);
break;
case 2: //
sprintf((char*)tbuf,"%d",Shi%10);
Gui_DrawFont_GBK32(162+18,84, YELLOW,GRAY0,tbuf);
break;
case 3: //
sprintf((char*)tbuf,"%d",Fen /10);
Gui_DrawFont_GBK32(162+18*3,84, YELLOW,GRAY0,tbuf);
break;
case 4: //
sprintf((char*)tbuf,"%d",Fen %10);
Gui_DrawFont_GBK32(162+18*4,84, YELLOW,GRAY0,tbuf);
break;
case 5: //
sprintf((char*)tbuf,"%d",Miao /10);
Gui_DrawFont_GBK32(162+18*6,84, YELLOW,GRAY0,tbuf);
break;
case 6: //
sprintf((char*)tbuf,"%d",Miao%10);
Gui_DrawFont_GBK32(162+18*7,84, YELLOW,GRAY0,tbuf);
break;
default:
break;
}
}
if(1!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Shi/10); Gui_DrawFont_GBK32(162,84, RED,GRAY0,tbuf); }
if(2!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Shi%10); Gui_DrawFont_GBK32(162+18,84, RED,GRAY0,tbuf);}
if(3!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Fen/10); Gui_DrawFont_GBK32(162+18*3,84, RED,GRAY0,tbuf);}
if(4!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Fen%10); Gui_DrawFont_GBK32(162+18*4,84, RED,GRAY0,tbuf);}
if(5!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Miao/10); Gui_DrawFont_GBK32(162+18*6,84, RED,GRAY0,tbuf);}
if(5!=Key_Rig_1) {sprintf((char*)tbuf,"%d",Miao%10); Gui_DrawFont_GBK32(162+18*7,84, RED,GRAY0,tbuf);}[/mw_shl_code]
已经解决了
一周热门 更多>