⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtc.c

📁 arm电子日历arm electricity calendar
💻 C
📖 第 1 页 / 共 4 页
字号:





#include	"RTC.h"
#include	"RTC_ICO.c"
#include	"Simulate_Clock_Pane.c"
#include	"Clock_Logo.c"

#include	"Time_Date_Icon.c"
#include	"Time_Date_SmallIcon.c"

/*============================================================================*/

/*============================================================================*/
/*============================================================================*/


#define		Set_Year_H	0
#define		Set_Year_L	1
#define		Set_Month_H	2
#define		Set_Month_L	3
#define		Set_Day_H	4
#define		Set_Day_L	5
#define		Set_Hour_H	6
#define		Set_Hour_L	7
#define		Set_Min_H	8
#define		Set_Min_L	9
#define		Set_Sec_H	10
#define		Set_Sec_L	11

/*============================================================================*/


/*============================================================================*/

//extern	const U8 gImage_Desktop[];

//全局变量声明:
volatile	float	RTC_TimeZone_Buf;

static		U8		Button_Num;
volatile	U8		RTC[8];

static		struct	RTC_TIME	RTCTime;

struct		GUI_BUTTON	RTC_Button[8];
////

/*
struct	GUI_Option_A_t	World_Time_Option[]={

										{	0,	0.00,	"GMT+00:00",		GMT00_00_ZONE	},
										{	1,	1.00,	"GMT+01:00",		GMT01_00_ZONE	},																																				
										{	2,	2.00,	"GMT+02:00",		GMT02_00_ZONE	},
										{	3,	3.00,	"GMT+03:00",		GMT03_00_ZONE	},
										{	4,	3.50,	"GMT+03:30",		GMT03_30_ZONE	},
										{	5,	4.00,	"GMT+04:00",		GMT04_00_ZONE	},
										{	6,	4.50,	"GMT+04:30",		GMT04_30_ZONE	},
										{	7,	5.00,	"GMT+05:00",		GMT05_00_ZONE	},
										{	8,	5.50,	"GMT+05:30",		GMT05_30_ZONE	},
										{	9,	5.75,	"GMT+05:45",		GMT05_45_ZONE	},
										{	10,	6.00,	"GMT+06:00",		GMT06_00_ZONE	},
										{	11,	6.50,	"GMT+06:30",		GMT06_30_ZONE	},
										{	12,	7.00,	"GMT+07:00",		GMT07_00_ZONE	},
										{	13,	8.00,	"GMT+08:00",		GMT08_00_ZONE	},	
										{	14,	9.00,	"GMT+09:00",		GMT09_00_ZONE	},	
										{	15,	9.50,	"GMT+09:30",		GMT09_30_ZONE	},	
										{	16,	10.00,	"GMT+10:00",		GMT10_00_ZONE	},	
										{	17,	11.00,	"GMT+11:00",		GMT11_00_ZONE	},	
										{	18,	12.00,	"GMT+12:00",		GMT12_00_ZONE	},	
										
										{	19,	-1.00,	"GMT-01:00",		_GMT01_00_ZONE	},	
										{	20,	-2.00,	"GMT-02:00",		_GMT02_00_ZONE	},	
										{	21,	-3.00,	"GMT-03:00",		_GMT03_00_ZONE	},	
										{	22,	-3.50,	"GMT-03:30",		_GMT03_30_ZONE	},	
										{	23,	-4.00,	"GMT-04:00",		_GMT04_00_ZONE	},	
										{	24,	-5.00,	"GMT-05:00",		_GMT05_00_ZONE	},
										{	25,	-6.00,	"GMT-06:00",		_GMT06_00_ZONE	},	
										{	26,	-7.00,	"GMT-07:00",		_GMT07_00_ZONE	},	
										{	27,	-8.00,	"GMT-08:00",		_GMT08_00_ZONE	},	
										{	28,	-9.00,	"GMT-09:00",		_GMT09_00_ZONE	},
										{	29,	-10.00,	"GMT-10:00",		_GMT10_00_ZONE	},	
										{	30,	-11.00,	"GMT-11:00",		_GMT11_00_ZONE	},	
										{	31,	-12.00,	"GMT-12:00",		_GMT12_00_ZONE	},			

										{	255,	0,	"---",	"----"},

};

*/
/*============================================================================*/

const char	*RTCDateName[7]={"SUN","MON","TUE","WED","THU","FRI","SAT",};
const char	*RTCMonthName[13]={"---","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

						

/*============================================================================*/

void	RTC_2Button_Below(int	RGB0,int RGB1,char *Name0,char *Name1)

{

	GUI_SetButton(	&RTC_Button[0],
					0,LCD_YSIZE-32,(LCD_XSIZE>>1)-1,32,
					RGB565(00,00,00),RGB565(16,32,16),RGB565(10,20,10),
					KEY_ID_ESC,BN_3D,UP,
					0,
					FONT(ASCII8x16,HZ16x16),Name0);
	
	GUI_SetButton(	&RTC_Button[1],
					LCD_YSIZE>>1,LCD_YSIZE-32,(LCD_XSIZE>>1)-1,32,
					RGB565(00,00,00),RGB565(16,32,16),RGB565(10,20,10),
					KEY_ID_ENTER,BN_3D,UP,
					0,
					FONT(ASCII8x16,HZ16x16),Name0);
	
				
	
	RTC_Button[2].Style=0;
	
	GUI_Buttons(RTC_Button);
	
}

/*============================================================================*/

void	RTC_Reset(void)
{
		struct	RTC_TIME	RTCTimeReset={RTC_TIME_INIT};
		////
				
		Uart_Puts(0,"RTC Reset!!!\n");


		RTC_SetTime(&RTCTimeReset);
		
		////
}

/*============================================================================*/

/*============================================================================*/
/*============================================================================*/

int	IsLeapyear(int year)
{
	if(year&0x03)	return 0;		//平年
	return 1;						//闰年
}

/*============================================================================*/

								
const	U8	LeapYearDayTab[12]={31,29,31,30,31,30,31,31,30,31,30,31};
const	U8	UnLeapYearDayTab[12]={31,28,31,30,31,30,31,31,30,31,30,31};

/*============================================================================*/

int	RTC_GetMonthDays(int year,int month)
{
	int	i;
	////
	
	if(IsLeapyear(year))
	{
		//闰年.
		i=LeapYearDayTab[month-1];
	}
	else
	{
		//平年.
		i=UnLeapYearDayTab[month-1];
	}
	
	return i;
}

/*============================================================================*/

int	RTC_GetYearDayOffset(int year,int month,int day)
{
	int	i,j;
	////
	
	j=0;
	for(i=1;i<month;i++)
	{
		j+=RTC_GetMonthDays(year,i);
	}
	
	j+=day;
	return j;
}

/*============================================================================*/

int	RTC_GetCenturyDayOffset(int year,int month,int day)
{

	int	i,j;
	////
	
	j=0;
	
	for(i=2000;i<year;i++)
	{
		if(i&0x03)
		{
			//平年
			j+=365;
		}
		else
		{
			//闰年
			j+=366;
		}
	
	}
	////
	
	j+=RTC_GetYearDayOffset(year,month,day);
	return j;
}

/*============================================================================*/

//计算某年某月是星期几.

int	RTC_GetWeek(int year,int month,int day)
{
	int	i,date,days;
	////

	
	i=RTC_GetCenturyDayOffset(year,month,day)-1;
//	Uart_Printf(0,"GetCenturyDay: %d-%d-%d -> %d\n",year,month,day,i);
	
	i+=6;		//2000-1-1 -> 星期六
	i%=7;
	return i;
	
//	Uart_Printf(0,"GetYearDay: %d-%d-%d  -> %d\n",year,month,day,days);
	

}

/*============================================================================*/

const U8	Hex2ASC_Tab[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',};
/*============================================================================*/


/*============================================================================*/

void	Display_SimulateClock(int x,int y,int dx,int dy)
{

		U8	hour,min,sec;
		U16	x_addr,y_addr;
		U8	Clock_radius;
		////
		
		hour=0;
		min	=0;
		sec	=0;
	
		Clock_radius=64;								//时钟背景的半径.
					
		x_addr=x+((dx-(Clock_radius<<1))>>1);		//水平居中.	
		y_addr=y+((dy-(Clock_radius<<1))>>1);		//垂直居中.
		////
					
	//	Get_RTC_Data();
							
		hour=(rBCDHOUR>>4)*10;
		hour+=(rBCDHOUR&0x0f);
		////
		min=(rBCDMIN>>4)*10;
		min+=(rBCDMIN&0x0f);
		////
		sec=(rBCDSEC>>4)*10;
		sec+=(rBCDSEC&0x0f);
					
		////////
		
		GUI_MemdevEnable();
		
		GUI_TransICO(x_addr,y_addr,gImage_Simulate_Clock_Pane);		//背景.
		GUI_Label(x,y+40,dx,24,RGB565(4,8,4),RGB_TRANS,RGB_TRANS,Center,FONT(ASCII8x16,HZ16x16),(char*)RTCDateName[rBCDDATE]);
					////
				
		GUI_SimulateClock(x_addr+Clock_radius,y_addr+Clock_radius,Clock_radius-20,RGB_TRANS,RGB_Pur,RGB_Blue(31),RGB_Red(31),hour,min,sec);
		GUI_FillCircle(x_addr+Clock_radius,y_addr+Clock_radius,3,RGB_Red(31));
		////

	//	GUI_DisplayUpdate(x,y,dx,dy);

}

/*============================================================================*/

int	Display_RTC_WinProc(HWND wnd,int msg,int paramt0,void *paramt1)
{
		
		U8	hour,min,sec;
		U16	x_addr,y_addr;
		U8	Clock_radius;
		
		
		
		#define	TIME_AREA	20,LCD_YSIZE-100,LCD_XSIZE-20*2,100
		////
		
		switch(msg)
		{
			
			case	MSG_TIMER:
			
			
		//	break;
			
			////////
		
			case	MSG_PAINT:
					
					Clock_radius=64;								//时钟背景的半径.
					
					x_addr=(LCD_XSIZE-(Clock_radius<<1))>>1;		//水平居中.	
					y_addr=40;
					////
					
				//	Get_RTC_Data();
						
					hour=0;
					min	=0;	
					sec	=0;
					
					hour=(rBCDHOUR>>4)*10;
					hour+=(rBCDHOUR&0x0f);
					////
					min=(rBCDMIN>>4)*10;
					min+=(rBCDMIN&0x0f);
					////
					sec=(rBCDSEC>>4)*10;
					sec+=(rBCDSEC&0x0f);
					
					////////
					
					GUI_MemdevEnable();
					GUI_PaintWindowBkGrd(wnd);
		//			GUI_ICO(x_addr,y_addr,gImage_Simulate_Clock_Pane);		//背景.
					GUI_TransICO(x_addr,y_addr,gImage_Simulate_Clock_Pane);		//背景.
			
					
					GUI_Label(90,y_addr+56,LCD_XSIZE-90-90,24,RGB565(16,32,16),RGB_TRANS,RGB_TRANS,Center,FONT(ASCII12x24,HZ16x16),(void*)RTCDateName[rBCDSEC]);
					////
				
					GUI_SimulateClock(x_addr+Clock_radius,y_addr+Clock_radius,Clock_radius-20,RGB_TRANS,RGB_Pur,RGB_Blue(31),RGB_Red(31),hour,min,sec);
					GUI_FillCircle(x_addr+Clock_radius,y_addr+Clock_radius,3,RGB_Red(31));
					////
					
				//	GUI_LabelPrintf((LCD_XSIZE-160)>>1,y_addr+(Clock_radius<<1)+8,160,32,RGB565(10,20,10),RGB565(26,52,26),RGB565(20,40,20),Center,FONT(ASCII12x24,HZ16x16),"20%02X-%02X-%02X",RTC[Year],RTC[Month],RTC[Day]);
				//	GUI_LabelPrintf(((LCD_XSIZE-160)>>1)+2,y_addr+(Clock_radius<<1)+8+1,160,32,RGB_Green(48),RGB_TRANS,RGB_TRANS,Center,FONT(ASCII12x24,HZ16x16),"20%02X-%02X-%02X",RTC[Year],RTC[Month],RTC[Day]);
					
				
					GUI_LabelPrintf(0,y_addr+(Clock_radius<<1)+8+1,LCD_XSIZE,50,RGB565(31,63,0),RGB_TRANS,RGB_TRANS,Center,FONT(ASCII24x48,HZ16x16),"20%02X-%02X-%02X",rBCDYEAR,rBCDMON,rBCDDAY);
					
					
					GUI_LabelPrintf(TIME_AREA,RGB565(31,63,0),RGB_TRANS,RGB_TRANS,Center,FONT(ASCII24x48,HZ16x16),"%02X:%02X:%02X",rBCDHOUR,rBCDMIN,rBCDSEC);

					GUI_DisplayUpdate(0,0,LCD_XSIZE,LCD_YSIZE);

					
			
			
			break;
			
			/////////
			
			case	MSG_CLOSE:
			
					//GUI_DestroyWindow(wnd);
					break;
			
			default:
			
			
			
			
			
			break;
			
			/////////
		
		
		
		}


}

/*============================================================================*/

int	Display_RTC(void *pdata)

{
	
	HWND	wnd;
	struct	MESSAGE	msg;
	U8		a,Uart_Key;
	U8		*font;
	
	/////////////	
	if(pdata)
	{
		struct	PGM_INFO *pInfo	=pdata;
		pInfo->Name			="RealTime";
		pInfo->pIcon		=(void*)gImage_RTC_ICO;
		pInfo->pSmallIcon	=0;
		pInfo->ExtraInfo	="Version:1.0";
		return	1;
	
	}
	/////////////

	GUI_MemdevEnable();
	
	wnd=GUI_CreateWindow(	0,0,LCD_XSIZE,LCD_YSIZE,
							0,RGB565(0,10,10),GUI_GetWallpaper(),
							0,
							Display_RTC_WinProc,
							"System Time");
			

	//Key_Scan_Clr_Stop();
	TS_Free();
	////
	Uart_Puts(0,"Display RTC.\n");
	SendMessage(wnd,MSG_PAINT,0,0);

	while(GetMessage(wnd,&msg)!=MSG_CLOSE){
		
		Uart_Key=Uart_GetKey(0);
		if(Uart_Key!=0)				SendMessage(wnd,MSG_CLOSE,0,0);
		
		if(TS_Press_100ms())		SendMessage(wnd,MSG_CLOSE,0,0);
				
		if(a!=rBCDSEC){
		
			a=rBCDSEC;
			SendMessage(wnd,MSG_TIMER,0,0);
			
		
		}

	}
	////
	
	TS_Free();
	Key_Free();	
}

/*============================================================================*/

void	Display_World_Time(void)		//世界时间.
{
	/*
	U8		a,b,i,Uart_Key,time;
	int		time_min_offset;
	int		year_offset,month_offset,day_offset,hour_offset,min_offset,sec_offset;
	int		year,month,day,hour,min,sec;
	int		H,M,S;
	
	struct	Button_Pt Button[5];
	

	////
	
	TS_Scan_Clr_Stop();
	Key_Scan_Clr_Stop();
	GUI_ClrScreen(RGB565(16,32,16));
		
	////
	RdIIC(System_EEPROM,RTC_TimeZone_ID_Adr,&i);
	a=GUI_Option_A(0,0,LCD_XSIZE,LCD_YSIZE-132,Button,World_Time_Option,"World Time",i);	

	////
	
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,"←"))
					{
						Buz_Output(2000,buz_62ms_mode,1);
						goto	TimeZone_Dec;
					}
					////
					
					if(Cmp_Str(Button[b].Str,"→"))
					{
						Buz_Output(2000,buz_62ms_mode,1);
						goto	TimeZone_Inc;
					}
					////
				
				}

			}
			////////
			
			if(RTC_Back_Key_Pressed())		goto	TimeZone_Dec;		// Back Key.
			if(RTC_Next_Key_Pressed())		goto	TimeZone_Inc;		// Next Key.
			
			if(RTC_Cancel_Key_Pressed())	return;						// Cancel Key.
			
			////////
			
			goto	TimeZone_Wait;
	
TimeZone_Inc:
			
			////
			i++;
			if(i>(a-1))	i=0;
			////
			goto	TimeZone_Updata;
			
			////

TimeZone_Dec:	
	
			i--;
			if(i>(a-1))	i=a-1;
			////
			goto	TimeZone_Updata;
			
			////
			
TimeZone_Updata:
			a=GUI_Option_A(0,0,LCD_XSIZE,LCD_YSIZE-132,Button,World_Time_Option,"World Time",i);
			////
TimeZone_Wait:
		
			////
			
			Key_Scan_Clr_Stop();	
			TS_Scan_Clr_Stop();
			Uart_Key=Uart_GetKey(0);
			Uart_Key=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -