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

📄 calender.lst

📁 带农历显示的万年历,功能齐全
💻 LST
📖 第 1 页 / 共 3 页
字号:
 416          *********************************************************************************************************
 417          */
 418          #if CLK_DATE_EN
 419          static  BOOL  ClkIsLeapYear(UINT year)
 420          {
 421   1          if (!(year % 4) && (year % 100) || !(year % 400)) 
 422   1           {
 423   2              return TRUE;
 424   2           } 
 425   1          else 
 426   1           {
 427   2              return (FALSE);
 428   2           }
 429   1      }
 430          #endif
 431          /*
 432          *********************************************************************************************************
 433          *                                            SET DATE ONLY
 434          *
 435          * Description : Set the date of the time-of-day clock
 436          * Arguments   : month     is the desired month (1..12)
 437          *               day       is the desired day   (1..31)
 438          *               year      is the desired year  (CLK_TS_BASE_YEAR .. CLK_TS_BASE_YEAR+63)
 439          * Returns     : None.
 440          * Notes       : It is assumed that you are specifying a correct date (i.e. there is no range checking
 441          *               done by this function).
 442          *********************************************************************************************************
 443          */
 444          #if  CLK_DATE_EN
 445          void  Clk_set_date (UCHAR month, UCHAR day, UINT year)
 446          {
 447   1          ENTER_CRITICAL();                         
 448   1          ClkMonth = month;
 449   1          ClkDay   = day;
 450   1          ClkYear  = year;
 451   1          ClkUpdateDOW();                             
 452   1          EXIT_CRITICAL();                         
 453   1      }
 454          #endif
 455          /*
 456          *********************************************************************************************************
 457          *                                          SET DATE AND TIME
 458          *
 459          * Description : Set the date and time of the time-of-day clock
 460          * Arguments   : month     is the desired month   (1..12)
 461          *               day       is the desired day     (1..31)
 462          *               year      is the desired year    (2xxx)
 463          *               hr        is the desired hour    (0..23)
 464          *               min       is the desired minutes (0..59)
 465          *               sec       is the desired seconds (0..59)
 466          * Returns     : None.
 467          * Notes       : It is assumed that you are specifying a correct date and time (i.e. there is no range
 468          *               checking done by this function).
 469          *********************************************************************************************************
 470          */
 471          
 472          #if  CLK_DATE_EN
 473          void  Clk_set_date_time (UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
C51 COMPILER V7.50   CALENDER                                                              02/24/2006 20:38:40 PAGE 9   

 474          {
 475   1          ENTER_CRITICAL();                         /* Gain exclusive access to time-of-day clock         */
 476   1          ClkMonth = month;
 477   1          ClkDay   = day;
 478   1          ClkYear  = year;
 479   1          ClkHr    = hr;
 480   1          ClkMin   = min;
 481   1          ClkSec   = sec;
 482   1          ClkUpdateDOW();                              /* Compute the day of the week (i.e. Sunday ...)      */
 483   1          EXIT_CRITICAL();                          /* Release access to time-of-day clock                */
 484   1      }
 485          #endif
 486          /*
 487          *********************************************************************************************************
 488          *                                            UPDATE THE DATE
 489          *
 490          * Description : This function is called to update the date (i.e. month, day and year)
 491          * Arguments   : None.
 492          * Returns     : None.
 493          * Notes       : This function updates ClkDay, ClkMonth, ClkYear and ClkDOW.
 494          *********************************************************************************************************
 495          */
 496          #if CLK_DATE_EN
 497          static  void  ClkUpdateDate (void)
 498          {
 499   1          BOOL newmonth;
 500   1          
 501   1          newmonth = TRUE;
 502   1          if (ClkDay >= ClkMonthTbl[ClkMonth].MonthDays) {  /* Last day of the month?                        */
 503   2              if (ClkMonth == 2) {                          /* Is this February?                             */
 504   3                  if (ClkIsLeapYear(ClkYear) == TRUE) {     /* Yes, Is this a leap year?                     */
 505   4                      if (ClkDay >= 29) {                   /* Yes, Last day in february?                    */
 506   5                          ClkDay = 1;                       /* Yes, Set to 1st day in March                  */
 507   5                      } else {
 508   5                          ClkDay++;
 509   5                          newmonth = FALSE;
 510   5                      }
 511   4                  } else {
 512   4                      ClkDay = 1;
 513   4                  }
 514   3              } else {
 515   3                  ClkDay = 1;
 516   3              }
 517   2          } else {
 518   2              ClkDay++;
 519   2              newmonth = FALSE;
 520   2          }
 521   1          if (newmonth == TRUE) {                      /* See if we have completed a month                   */
 522   2              if (ClkMonth >= 12) {                    /* Yes, Is this december ?                            */
 523   3                  ClkMonth = 1;                        /* Yes, set month to january...                       */
 524   3                  ClkYear++;                           /*      ...we have a new year!                        */
 525   3              } else {
 526   3                  ClkMonth++;                          /* No,  increment the month                           */
 527   3              }
 528   2          }
 529   1          ClkUpdateDOW();                              /* Compute the day of the week (i.e. Sunday ...)      */
 530   1      }
 531          #endif
 532          /*
 533          *********************************************************************************************************
 534          *                                         COMPUTE DAY-OF-WEEK
 535          *
C51 COMPILER V7.50   CALENDER                                                              02/24/2006 20:38:40 PAGE 10  

 536          * Description : This function computes the day of the week (0 == Sunday) based on the current month,
 537          *               day and year.
 538          * Arguments   : None.
 539          * Returns     : None.
 540          * Notes       : - This function updates ClkDOW.
 541          *               - This function is called by ClkUpdateDate().
 542          *********************************************************************************************************
 543          */
 544          #if CLK_DATE_EN
 545          static  void  ClkUpdateDOW (void)
 546          {
 547   1          UINT dow;
 548   1          
 549   1          dow = ClkDay + ClkMonthTbl[ClkMonth].MonthVal;
 550   1          if (ClkMonth < 3)
 551   1          {
 552   2              if (ClkIsLeapYear(ClkYear)) 
 553   2              {
 554   3                  dow--;
 555   3              }
 556   2          }
 557   1          dow    += ClkYear + (ClkYear / 4);
 558   1          dow    += (ClkYear / 400) - (ClkYear / 100);
 559   1          dow    %= 7;
 560   1          ClkDOW  = dow;
 561   1      }
 562          #endif
 563          
 564          //@@***********************************************************
 565          //
 566          //   功能:  给定的时间与当前时间比较
 567          //   函数:  int Cmp_now_time(UCHAR hr, UCHAR min, UCHAR sec)
 568          //   语言:  C
 569          //   输入:         
 570          //   输出:  0   相等
 571          //          >0  给定时间大于当前时间
 572          //          <0  给定时间小于当前时间 
 573          //   作者:  李艳平
 574          //   日期:  2002-05-17
 575          //@@***********************************************************
 576          //------------------------------------------------------------- 
 577          int Cmp_now_time(UCHAR hr, UCHAR min, UCHAR sec)
 578          {
 579   1         if(ClkHr!=hr)
 580   1           return(hr-ClkHr);
 581   1         else if(ClkMin!= min) 
 582   1           return(min-ClkMin);   
 583   1         else
 584   1           return(sec-ClkSec);    
 585   1      }
 586          
 587          //@@***********************************************************
 588          //
 589          //   功能:  给定的时间与当前时间比较
 590          //   函数:  int Cmp_now_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
 591          //   语言:  C
 592          //   输入:         
 593          //   输出:  0   相等
 594          //          >0  给定时间大于当前时间
 595          //          <0  给定时间小于当前时间 
 596          //   作者:  李艳平
 597          //   日期:  2002-05-17
C51 COMPILER V7.50   CALENDER                                                              02/24/2006 20:38:40 PAGE 11  

 598          //@@***********************************************************
 599          //------------------------------------------------------------- 
 600          #if CLK_DATE_EN
 601          int Cmp_now_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
 602          {
 603   1         if(ClkYear!=year)
 604   1             return(year-ClkYear);
 605   1         else if(ClkMonth!=month)
 606   1                 return(month-ClkMonth);
 607   1         else if(ClkDay!=day)
 608   1                 return(day-ClkDay);
 609   1         else if(ClkHr!=hr)
 610   1             return(hr-ClkHr);
 611   1         else if(ClkMin!= min) 
 612   1             return(min-ClkMin);   
 613   1         else
 614   1             return(sec-ClkSec);    
 615   1      }
 616          #endif
 617          
 618          
 619          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1391    ----
   CONSTANT SIZE    =    277    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     23      30
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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