📄 rtc.c
字号:
////
while(1)
{
int xpst,ypst,ico_xsize,ico_ysize,Clock_radius;
////
Get_RTC_Data();
year=(RTC[Year]>>4)*10+(RTC[Year]&0x0f);
month=(RTC[Month]>>4)*10+(RTC[Month]&0x0f);
day=(RTC[Day]>>4)*10+(RTC[Day]&0x0f);
hour=(RTC[Hour]>>4)*10+(RTC[Hour]&0x0f);
min=(RTC[Min]>>4)*10+(RTC[Min]&0x0f);
sec=(RTC[Sec]>>4)*10+(RTC[Sec]&0x0f);
H=hour;
M=min;
S=sec;
////
sec_offset=0;
min_offset=time_min_offset%60;
hour_offset=time_min_offset/60;
time_min_offset=(((World_Time_Option[i].Val)-RTC_TimeZone_Buf)*60);
//Uart_Printf(0,"Time Offset=%d:%d:%d\n",hour_offset,min_offset,sec_offset);
////
if((min+min_offset)<0)
{
hour--;
min=(min+60)+min_offset;
}
else if((min+min_offset)>=60)
{
hour_offset+=(min+min_offset)/60;
min=(min+min_offset)%60;
}
else
{
min+=min_offset;
}
////////
if((hour+hour_offset)<0)
{
hour=(hour+24)+hour_offset;
}
else if((hour+hour_offset)>=24)
{
hour=(hour+hour_offset)%24;
}
else
{
hour+=hour_offset;
}
////////
// GUI_LabelPrintf(0,240,RGB_Brown,RGB565(16,32,16),RGB_TRANS,LCD_XSIZE,32,Center,Font_ASC_24_48,"%X%X:%X%X:%X%X",hour/10,hour%10,min/10,min%10,sec/10,sec%10);
// GUI_LabelPrintf(0+2,240+1,RGB_Orange,RGB_TRANS,RGB_TRANS,LCD_XSIZE,32,Center,Font_ASC_24_48,"%X%X:%X%X:%X%X",hour/10,hour%10,min/10,min%10,sec/10,sec%10);
// GUI_LabelPrintf(0,LCD_YSIZE-20,RGB_Black,RGB565(0,40,20),RGB_Black,LCD_XSIZE,20,Right,FONT(ASCII8x16,HZ16x16),"Local Time:%X%X:%X%X:%X%X",RTC[Hour]>>4,RTC[Hour]&0x0f,RTC[Min]>>4,RTC[Min]&0x0f,RTC[Sec]>>4,RTC[Sec]&0x0f);
ico_xsize=100;
ico_ysize=100;
Clock_radius=50;
xpst=(((LCD_XSIZE>>1)-ico_xsize)>>1)+(0*(LCD_XSIZE>>1)); //Worl Time.
ypst=LCD_YSIZE-ico_ysize-32;
GUI_ICO(xpst,ypst,gImage_Clock_Logo);
GUI_SimulateClock(xpst+Clock_radius,ypst+Clock_radius,Clock_radius-20,RGB_TRANS,RGB_Pur,RGB_Blue(31),RGB_Red(31),hour,min,sec);
ypst+=ico_ysize+2;
GUI_LabelPrintf(xpst,ypst,RGB_Brown,RGB565(16,32,16),RGB_TRANS,ico_xsize,1,Center,Font_ASC_5_8,"%X%X:%X%X:%X%X",hour/10,hour%10,min/10,min%10,sec/10,sec%10);
ypst+=16;
GUI_Label(xpst,ypst,RGB_Brown,RGB565(16,32,16),RGB_TRANS,ico_xsize,1,Center,Font_ASC_5_8,"World Time");
////////
xpst=(((LCD_XSIZE>>1)-ico_xsize)>>1)+(1*(LCD_XSIZE>>1)); //Local Time.
ypst=LCD_YSIZE-ico_ysize-32;
GUI_ICO(xpst,ypst,gImage_Clock_Logo);
GUI_SimulateClock(xpst+Clock_radius,ypst+Clock_radius,Clock_radius-20,RGB_TRANS,RGB_Pur,RGB_Blue(31),RGB_Red(31),H,M,S);
ypst+=ico_ysize+2;
GUI_LabelPrintf(xpst,ypst,RGB_Brown,RGB565(16,32,16),RGB_TRANS,ico_xsize,1,Center,Font_ASC_5_8,"%X%X:%X%X:%X%X",H/10,H%10,M/10,M%10,S/10,S%10);
ypst+=16;
GUI_Label(xpst,ypst,RGB_Brown,RGB565(16,32,16),RGB_TRANS,ico_xsize,1,Center,Font_ASC_5_8,"Local Time");
////////
time=rBCDSEC;
while(time==rBCDSEC)
{
Uart_Key=Uart_GetKey(0);
////
if(Uart_Key!=0) goto TimeZone_ST;
if(TS_Press_100ms()) goto TimeZone_ST;
if(RTC_Any_Key_Pressed()) goto TimeZone_ST;
}
////
}
}
*/
}
/*============================================================================*/
/*时区设置*/
void RTC_TimeZone_Setting(void)
{
/*
U8 a,b,i,Uart_Key,time;
struct Button_Pt Button[5];
////
TS_Scan_Clr_Stop();
Uart_Key=Uart_GetKey(0);
Uart_Key=0;
GUI_ClrScreen(RGB565(16,32,16));
////
RdIIC(System_EEPROM,RTC_TimeZone_ID_Adr,&i);
a=GUI_Option_A(0,0,LCD_XSIZE,LCD_YSIZE,Button,World_Time_Option,"TimeZone Setting",i);
////
Set_TimeZone_ST:
while(1)
{
if(TS_Press_100ms()) //TS_Press_100ms.
{
if(TS_Run_GUI_Button_Pt(Button,&b))
{
if(Cmp_Str(Button[b].Str,"X")) return;
////
if(Cmp_Str(Button[b].Str,"OK")) goto Set_TimeZone_Enter;
////
if(Cmp_Str(Button[b].Str,"←"))
{
Buz_Output(2000,buz_62ms_mode,1);
goto Set_TimeZone_Dec;
}
////
if(Cmp_Str(Button[b].Str,"→"))
{
Buz_Output(2000,buz_62ms_mode,1);
goto Set_TimeZone_Inc;
}
////
}
}
////////
if(RTC_Back_Key_Pressed()) goto Set_TimeZone_Dec; // Back Key.
if(RTC_Next_Key_Pressed()) goto Set_TimeZone_Inc; // Next Key.
if(RTC_Cancel_Key_Pressed()) return; // Cancel Key.
if(RTC_Enter_Key_Pressed()) goto Set_TimeZone_Enter; // Enter Key.
////////
goto Set_TimeZone_Wait;
Set_TimeZone_Inc:
////
i++;
if(i>(a-1)) i=0;
////
goto Set_TimeZone_Updata;
////
Set_TimeZone_Dec:
i--;
if(i>(a-1)) i=a-1;
////
goto Set_TimeZone_Updata;
////
Set_TimeZone_Updata:
a=GUI_Option_A(0,0,LCD_XSIZE,LCD_YSIZE,Button,World_Time_Option,"TimeZone Setting",i);
////
Set_TimeZone_Wait:
Key_Scan_Clr_Stop();
TS_Scan_Clr_Stop();
Uart_Key=Uart_GetKey(0);
Uart_Key=0;
////
while(1)
{
time=rBCDSEC;
while(time==rBCDSEC)
{
Uart_Key=Uart_GetKey(0);
////
if(TS_Press_100ms()) goto Set_TimeZone_ST;
if(RTC_Any_Key_Pressed()) goto Set_TimeZone_ST;
}
////
}
}
Set_TimeZone_Enter:
Buz_Output(2000,buz_125ms_mode,2);
WrIIC(System_EEPROM,RTC_TimeZone_ID_Adr,i);
Delay_n15ms(150/15);
RdIIC(System_EEPROM,RTC_TimeZone_ID_Adr,&i);
RTC_TimeZone_Buf=World_Time_Option[i].Val;
Uart_Printf(0,"Set TimeZone ID=%d;Value=%.2f\n",i,RTC_TimeZone_Buf);
*/
}
/*============================================================================*/
void Updata_RTC_Date_Time_Setting(struct RTC_TIME *time,U8 *sel_num)
{
#define char_xsize 14;
#define BK_RGB RGB565(20,40,20)
int xpst,ypst;
GUI_Printf(4,60,RGB_Red(31),BK_RGB,FONT(ASCII12x24,HZ16x16),"%04d-%02d-%02d-%s",time->Year,time->Month,time->Day,RTCDateName[RTC_GetWeek(time->Year,time->Month,time->Day)]);
GUI_Printf(4,104,RGB_Red(31),BK_RGB,FONT(ASCII12x24,HZ16x16),"%02d:%02d:%02d",time->Hour,time->Min,time->Sec);
/////
if(*sel_num>Set_Sec_L) *sel_num=Set_Year_H;
switch(*sel_num)
{
case Set_Year_H:
xpst=4+2*char_xsize;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",(time->Year-2000)/10);
return;
////
case Set_Year_L:
xpst=4+3*char_xsize;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",(time->Year-2000)%10);
return;
////
case Set_Month_H:
xpst=4+5*char_xsize;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Month/10);
return;
////
case Set_Month_L:
xpst=4+6*char_xsize;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Month%10);
return;
////
case Set_Day_H:
xpst=4+8*char_xsize;;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Day/10);
return;
////
case Set_Day_L:
xpst=4+9*char_xsize;
ypst=60;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Day%10);
return;
////
case Set_Hour_H:
xpst=4+0*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Hour/10);
return;
////
case Set_Hour_L:
xpst=4+1*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Hour%10);
return;
////
case Set_Min_H:
xpst=4+3*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Min/10);
return;
////
case Set_Min_L:
xpst=4+4*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Min%10);
return;
////
case Set_Sec_H:
xpst=4+6*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Sec/10);
return;
////
case Set_Sec_L:
xpst=4+7*char_xsize;
ypst=104;
GUI_Printf(xpst,ypst,RGB_White,RGB_Black,FONT(ASCII12x24,HZ16x16),"%d",time->Sec%10);
return;
////
default: return;
}
}
/*============================================================================*/
void RTC_Set_Inc(struct RTC_TIME *time,U8 *Object)
{
int h,l;
////
if(*Object>Set_Sec_L) *Object=Set_Year_H;
////
switch(*Object)
{
case Set_Year_H:
h=(time->Year-2000)/10;
l=(time->Year-2000)%10;
if(h>=9)
{
h=0;
}
else
{
h++;
}
time->Year=2000+(h*10)+l;
return;
////
case Set_Year_L:
h=(time->Year-2000)/10;
l=(time->Year-2000)%10;
if(l>=9)
{
l=0;
}
else
{
l++;
}
time->Year=2000+(h*10)+l;
return;
////////
case Set_Month_H:
h=time->Month/10;
l=time->Month%10;
if(h>=1)
{
h=0;
}
else
{
h++;
}
time->Month=(h*10)+l;
return;
////
case Set_Month_L:
h=time->Month/10;
l=time->Month%10;
if(l>=9)
{
l=0;
}
else
{
l++;
}
time->Month=(h*10)+l;
return;
////////
case Set_Day_H:
h=time->Day/10;
l=time->Day%10;
if(h>=2)
{
h=0;
}
else
{
h++;
}
time->Day=(h*10)+l;
return;
////
case Set_Day_L:
h=time->Day/10;
l=time->Day%10;
if(l>=9)
{
l=0;
}
else
{
l++;
}
time->Day=(h*10)+l;
return;
////////
case Set_Hour_H:
h=time->Hour/10;
l=time->Hour%10;
if(h>=5)
{
h=0;
}
else
{
h++;
}
time->Hour=(h*10)+l;
return;
////
case Set_Hour_L:
h=time->Hour/10;
l=time->Hour%10;
if(l>=9)
{
l=0;
}
else
{
l++;
}
time->Hour=(h*10)+l;
return;
////////
case Set_Min_H:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -