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

📄 calendarpatch.c

📁 主要用于液晶电视解码,内置51单片机,全部代码用C编写,编译环境为KEILC
💻 C
字号:
#define _CALENDAR_C_

#include "types.h"
#include "board.h"
#include "global.h"
#include "debug.h"
#include "msOSD.h"
#include "Menudef.h"
#include "menufunc.h"
#include "CalendarPatch.h"
#if CALENDAR_ENABLE
#define START_YEAR		1600
#define MAX_YEAR		899
#define MIN_YEAR		0
#define INIT_YEAR		405
#define INIT_MONTH		1
//===============================================
BYTE code tMonthDayNormal[] =
{// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12
    0,31,28,31,30,31,30,31,31,30,31,30,31
};

void InitializeCalendarVariable(void)
{

	if(gc_solar_calendar_year<MIN_YEAR||gc_solar_calendar_year>MAX_YEAR)gc_solar_calendar_year=INIT_YEAR;
	if(gc_solar_calendar_month<1||gc_solar_calendar_month>12)gc_solar_calendar_month=INIT_MONTH;

	temp_total_day = 0;
	gc_solar_calendar_date= 1;
	gc_lunar_calendar_year= 0;
	gc_lunar_calendar_month= 0;
	gc_lunar_calendar_date= 0;
	start_day_of_week= 0;
	gc_lunar_leap_month= 0;
}

BYTE get_solar_day_date(void)//Faster and less code
{
    WORD ucTmp,ucLeapYear,uc100Year,uc400year;
    BYTE ucValue;

    start_day_of_week = 6;//1600
    temp_total_day = 0;

    if (gc_solar_calendar_year)
    {
        ucLeapYear = gc_solar_calendar_year-1;
        ucLeapYear >>= 2;
	    ucLeapYear++;//1600 is 366 days

	    uc100Year= gc_solar_calendar_year-1;
	    uc100Year=uc100Year/100;
		ucLeapYear-=uc100Year;

	    uc400year= gc_solar_calendar_year-1;
	    uc400year=uc400year/400;
		ucLeapYear+=uc400year;

	    ucTmp = gc_solar_calendar_year-ucLeapYear;

        temp_total_day = (DWORD)ucLeapYear*366+(DWORD)ucTmp*365;
        if (!(gc_solar_calendar_year%100)&&((gc_solar_calendar_year+START_YEAR)%400))
            ucLeapYear = 1;
        else
            ucLeapYear = gc_solar_calendar_year&0x03;
    }
    else
    {
        ucLeapYear = 0;//1600
    }
    temp_total_day += start_day_of_week;

    for(ucTmp=0;ucTmp<gc_solar_calendar_month;ucTmp++)
        temp_total_day += tMonthDayNormal[ucTmp];

    ucValue = tMonthDayNormal[ucTmp];
    if (!ucLeapYear)
    {
        if (gc_solar_calendar_month == 2)
            ucValue++;
        if (gc_solar_calendar_month >2)
            temp_total_day++;
    }
    start_day_of_week = temp_total_day%7;

    return ucValue;
}


void DrawCalendarYear(void)
{
     Osd_SetTextColor(CP_RedColor, CP_YellowColor);
     DrawNum(6,1,4,(gc_solar_calendar_year + START_YEAR));
}

void DirectDrawCalendar(void)
{
    XDATA BYTE strNumToStr[3];//for internal use only

	BYTE  ucX,ucY;
  	BYTE  ucTmp;
  	BYTE  ucEndValue;
	BYTE  ucShowValue;

	strNumToStr[2] = '\0';

	DrawCalendarYear();

    ucEndValue = get_solar_day_date();

    ucEndValue += start_day_of_week;
    ucShowValue = 0;
    ucY = 5;

	for(ucTmp = 0;ucTmp <= 36;ucTmp++)
    {
    	    //-------------------------------------------------
    	    if (ucTmp < start_day_of_week)
    	        ucShowValue = 0;
    	    else if(ucTmp < ucEndValue)
    	        ucShowValue ++;
    	    else
    	        ucShowValue = 0;
          //-------------------------------------------------
          if((ucTmp%7) == 0)
          {
             ucY += 1;
             ucX = 0;
          }
          //-------------------------------------------------
          if (ucShowValue==0)
          {
      	      strNumToStr[1] = ' ';
      	      strNumToStr[0] = ' ';
          }
          else if (ucShowValue <10)
          {
              strNumToStr[1] = ucShowValue + OSD_0_INDEX;
              strNumToStr[0] = ' ';
          }
          else
          {
              strNumToStr[1] = ucShowValue % 10 + OSD_0_INDEX;
              strNumToStr[0] = ucShowValue/10 + OSD_0_INDEX;
          }
                if((ucX==0)||(ucX==18))
    		Osd_SetTextColor(CP_RedColor, CP_BlueColor);
    	     else
    		Osd_SetTextColor(CP_GreenColor, CP_BlueColor);

          Osd_DrawStr(ucX, ucY, strNumToStr);
          //-------------------------------------------------
    		  ucX += 3;
    }
}

BOOL EnterCalendarMenuExec(void)
{
  Osd_SetTextColor(CP_RedColor, CP_BlueColor);
  Osd_DrawStr(0, 4, "SU                SA");
  Osd_SetTextColor(CP_YellowColor, CP_BlueColor);
  Osd_DrawStr(3, 4, "MO TU WE TH FR");

  DirectDrawCalendar();
  return TRUE;
}

BOOL AdjustCalendarYearORMonth(MenuItemActionType action)
{

    if(action==MIA_CalendarmonthIncValue)
    	{
    		if(gc_solar_calendar_month==12)
    			{
    				gc_solar_calendar_month=1;
				gc_solar_calendar_year++;
				if(gc_solar_calendar_year==MAX_YEAR)
					gc_solar_calendar_year=MIN_YEAR;
    			}
		else
    		gc_solar_calendar_month= DecIncValue(MIA_IncValue, gc_solar_calendar_month, 1, 12, 1);
    	}
    else if(action==MIA_CalendarmonthDecValue)
	{
    		if(gc_solar_calendar_month==1)
    			{
    				gc_solar_calendar_month=12;
				gc_solar_calendar_year--;
				if(gc_solar_calendar_year==MIN_YEAR)
					gc_solar_calendar_year=MAX_YEAR;
    			}
		else
    		gc_solar_calendar_month= DecIncValue(MIA_DecValue, gc_solar_calendar_month, 1, 12, 1);
    	}
    else
    	{
    		if(gc_solar_calendar_year==MIN_YEAR&&action==MIA_DecValue)
					gc_solar_calendar_year=MAX_YEAR;
		else if(gc_solar_calendar_year==MAX_YEAR&&action==MIA_IncValue)
					gc_solar_calendar_year=MIN_YEAR;
		else
	 		gc_solar_calendar_year = DecIncValue(action, gc_solar_calendar_year, MIN_YEAR, MAX_YEAR, 1);
    	}

    DirectDrawCalendar();
    return TRUE;
}

#endif

⌨️ 快捷键说明

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