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

📄 calendar.c

📁 万年历的完整算法:1900~2100 它首先计算出对应阳历月第一天对应是星期几
💻 C
📖 第 1 页 / 共 4 页
字号:
    if(dRTCTime.minute<10)
    {
        DrawString(X_start,Y_start,"0");
        DrawString(X_start+8,Y_start,buf);
    }
    else
        DrawString(X_start,Y_start,buf);
}

/*此函数显示时间模块的花边 外边框*/
void Time_Display_Init(void)
{
    BYTE i;
    BYTE X_Screen,Y_Screen;
    BYTE buf[30],temp[4];

    /*画所有的横线  */
    GetBmp(B1,buf);   /* 显示个位 */
    X_Screen=0;
    Y_Screen=0;
    for(i=0;i<5;i++)
        DrawBitmap(i*32,Y_Screen,buf);
    Y_Screen=76;
    for(i=0;i<5;i++)
        DrawBitmap(i*32,Y_Screen,buf);
    X_Screen=4;
    Y_Screen=16;
    DrawBitmap(X_Screen,Y_Screen,buf);
    X_Screen=124;
    DrawBitmap(X_Screen,Y_Screen,buf);
    X_Screen=21;
    Y_Screen=27;
    for(i=0;i<3;i++)
        DrawBitmap(X_Screen+i*32,Y_Screen,buf);
    DrawBitmap(109,Y_Screen,buf);
    Y_Screen=51;
    for(i=0;i<3;i++)
        DrawBitmap(X_Screen+i*32,Y_Screen,buf);
    DrawBitmap(109,Y_Screen,buf);

    /* 画所有的竖线 */
    GetBmp(B2,buf);   /* 显示个位 */
    X_Screen=0;
    Y_Screen=4;
    for(i=0;i<3;i++)
        DrawBitmap(X_Screen,Y_Screen+i*24,buf);
    X_Screen=156;
    for(i=0;i<3;i++)
        DrawBitmap(X_Screen,Y_Screen+i*24,buf);
    X_Screen=21;
    Y_Screen=31;
    DrawBitmap(X_Screen,Y_Screen,buf);
    X_Screen=137;
    DrawBitmap(X_Screen,Y_Screen,buf);
}
#endif
void Calendar_Search_Invert(BYTE situation)
{
    BYTE X_start,Y_start;
    /* 反色显示下一位置的数*/
    switch(situation)
    {
        case 6:
            X_start=88;
            Y_start=42;
            break;
        case 1:
            X_start=80;
            Y_start=23;
            break;
        case 3:
            X_start=96;
            Y_start=23;
            break;
        case 4:
            X_start=104;
            Y_start=23;
            break;
        case 8:
            X_start=88;
            Y_start=61;
            break;
        case 5:
            X_start=80;
            Y_start=42;
            break;
        case 7:
            X_start=80;
            Y_start=61;
            break;
        case 2:
            X_start=88;
            Y_start=23;
            break;
    }
    InvertArea(X_start,Y_start,6,12);
}

/* 日历查询模块 */
BYTE Calendar_Search(DATE Cal_Date,DATE *Cal_search)
{
    BYTE X_start,Y_start;
    BYTE tempkey,tempkey1;
    //BYTE Sbuf;
    BYTE situation,tempsituat;
    BYTE dataerror;
    BYTE buf[10];
    DATE tempsearch;
    DATE CalRTCDate;

    dataerror = FALSE;
    ClearScreen();
//    SetLcdFlag(FLAG_UP|FLAG_DOWN|FLAG_LEFT|FLAG_RIGHT );
	DrawRect(0,0,239,159);

    X_start=40;
    Y_start=3;
    DrawString(X_start,Y_start,"[日    期]");

    /*GetDate(&CalRTCDate);*/
    memcpy(&CalRTCDate,&Cal_Date,sizeof(DATE));
    CalRTCDate.year+=1900;
    X_start=56;
    Y_start+=20;
    DrawString(X_start,Y_start,"年:");

    X_start+=24;
    itoa(CalRTCDate.year,buf);
    DrawString(X_start,Y_start,buf);

    X_start=56;
    Y_start+=19;
    DrawString(X_start,Y_start,"月:");
    X_start+=24;
    itoa(CalRTCDate.month,buf);
    if(CalRTCDate.month<10)
    {
        DrawString(X_start,Y_start,"0");
        DrawString(X_start+8,Y_start,buf);
    }
    else
        DrawString(X_start,Y_start,buf);

    X_start=56;
    Y_start+=19;
    DrawString(X_start,Y_start,"日:");

    X_start+=24;
    itoa(CalRTCDate.day,buf);
    if(CalRTCDate.day<10)
    {
        DrawString(X_start,Y_start,"0");
        DrawString(X_start+8,Y_start,buf);
    }
    else
        DrawString(X_start,Y_start,buf);
    /*  InvertArea(X_Start,Y_Start,8,16);    反色显示初始年的起始数字 */



    InvertArea(80,23,8,16);
    tempsituat=0;
    situation=1;
    /*oldinputmode=ModifyInputMode(NUM_VALID);*/

    memcpy(&tempsearch,&CalRTCDate,sizeof(DATE));
    do
    {
        tempkey1 = GetKey();
        tempkey = IsNumberKey(tempkey1);
        if(tempkey == 0)
            tempkey = tempkey1;
        if (IsFuncKey(tempkey))
            return tempkey;
        if(('0'<=tempkey)&&(tempkey<='9'))
        {
            tempkey=tempkey-'0';
            switch(situation)
            {
                case 1:
                    switch(tempkey)
                    {
                        case 1:
                        case 2:
                            itoa(tempkey,buf);
                            DrawString(80,23,buf);
                            tempsearch.year=tempsearch.year%1000+tempkey*1000;
                            if(tempsearch.year/1000==1)
                            {
                                DrawString(88,23,"9");
                                tempsearch.year=1900+tempsearch.year%100;
                            }
                            else    /* 当是2000年后的时候百位不能输入*/
                            {
                                DrawString(88,23,"0");
                                tempsearch.year=2000+tempsearch.year%100;
                            }
                            tempsituat=1;
                            situation=3;
                            Calendar_Search_Invert(situation);
                            break;
                    }
                    break;
                case 3:
                    itoa(tempkey,buf);
                    DrawString(96,23,buf);
                    tempsearch.year=(tempsearch.year/100)*100+tempsearch.year%10+tempkey*10;
                    tempsituat=3;
                    situation=4;
                    Calendar_Search_Invert(situation);
                    break;
                case 4:
                    itoa(tempkey,buf);
                    DrawString(104,23,buf);
                    tempsearch.year=(tempsearch.year/10)*10+tempkey;
                    tempsituat=4;
                    situation=5;
                    Calendar_Search_Invert(situation);
                    break;
                case 8:
                    switch(tempsearch.day/10)
                    {
                        case 0: /*小于十号*/
                            if(tempkey>0)
                            {
                                itoa(tempkey,buf);
                                DrawString(88,61,buf);
                                tempsearch.day=(tempsearch.day/10)*10+tempkey;
                                tempsituat=8;
                                situation=1;
                                Calendar_Search_Invert(situation);
                            }
                            break;
                        case 1:
                        case 2:
                            itoa(tempkey,buf);
                            DrawString(88,61,buf);
                            tempsearch.day=(tempsearch.day/10)*10+tempkey;
                            tempsituat=8;
                            situation=1;
                            Calendar_Search_Invert(situation);
                            break;
                        case 3:
                            if(tempkey==0 || tempkey==1)
                            {
                                itoa(tempkey,buf);
                                DrawString(88,61,buf);
                                tempsearch.day=(tempsearch.day/10)*10+tempkey;
                                tempsituat=8;
                                situation=1;
                                Calendar_Search_Invert(situation);
                            }
                            break;
                    }
                    break;
                case 5:     /* 月份的十位只能是 0,1 */
                    if(tempkey==0 || tempkey==1)
                    {
                        itoa(tempkey,buf);
                        DrawString(80,42,buf);
                        tempsearch.month=tempsearch.month%10+tempkey*10;
                        tempsituat=situation;
                        situation++;
                        Calendar_Search_Invert(situation);
                    }
                    break;
                case 6:
                    if(tempsearch.month/10==0)
                    {
                        if( tempkey!=0)
                        {
                            itoa(tempkey,buf);
                            DrawString(88,42,buf);
                            tempsearch.month=tempkey;
                            tempsituat=situation;
                            situation++;
                            Calendar_Search_Invert(situation);
                        }
                    }
                    else
                    {
                        if(tempkey==0 || tempkey==1 || tempkey==2)
                        {
                            itoa(tempkey,buf);
                            DrawString(88,42,buf);
                            tempsearch.month=10+tempkey;
                            tempsituat=situation;
                            situation++;
                            Calendar_Search_Invert(situation);
                        }
                    }
                    break;
                case 7:     /*  号数十位设定  */
                    if(0<=tempkey && tempkey<=3)
                    {
                        itoa(tempkey,buf);
                        DrawString(80,61,buf);
                        tempsearch.day=tempsearch.day%10+tempkey*10;
                        tempsituat=situation;
                        situation++;
                        Calendar_Search_Invert(situation);
                    }
                    break;
            }
        }
        else
        {
            switch(tempkey)
            {
                case KEY_LEFT:
                    tempsituat=situation;
                    if(situation>0 && situation<5)
                    {
                        situation--;
                        if(situation<1)
                            situation=4;
                        Calendar_Search_Invert(tempsituat);
                        Calendar_Search_Invert(situation);
                    }
                    else
                    {
                        switch(situation)
                        {
                            case 6:
                                situation=5;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                            case 5:
                                situation=6;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                            case 8:
                                situation=7;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                            case 7:
                                situation=8;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                        }
                    }
                    break;
                case KEY_RIGHT:
                    tempsituat=situation;
                    if(situation<5 && situation>0)
                    {
                        situation++;
                        if(situation>4)
                            situation=1;
                        Calendar_Search_Invert(tempsituat);
                        Calendar_Search_Invert(situation);
                    }
                    else
                    {
                        switch(situation)
                        {
                            case 6:
                                situation=5;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                            case 5:
                                situation=6;
                                Calendar_Search_Invert(tempsituat);
                                Calendar_Search_Invert(situation);
                                break;
                            case 8:
                                situation=7;

⌨️ 快捷键说明

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