📄 calender.lst
字号:
C51 COMPILER V3.96, SN-83203013 CALENDER 05/08/08 00:07:16 PAGE 8
408 /*
409 *********************************************************************************************************
410 * DETERMINE IF WE HAVE A LEAP YEAR
411 *
412 * Description : This function determines whether the 'year' passed as an argument is a leap year.
413 * Arguments : year is the year to check for leap year.
414 * Returns : TRUE if 'year' is a leap year.
415 * FALSE if 'year' is NOT a leap year.
416 *********************************************************************************************************
417 */
418 #if CLK_DATE_EN
419 static BOOL ClkIsLeapYear(UINT year)
420 {
421 if (!(year % 4) && (year % 100) || !(year % 400))
422 {
423 return TRUE;
424 }
425 else
426 {
427 return (FALSE);
428 }
429 }
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 ENTER_CRITICAL();
448 ClkMonth = month;
449 ClkDay = day;
450 ClkYear = year;
451 ClkUpdateDOW();
452 EXIT_CRITICAL();
453 }
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 *********************************************************************************************************
C51 COMPILER V3.96, SN-83203013 CALENDER 05/08/08 00:07:16 PAGE 9
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)
474 {
475 ENTER_CRITICAL(); /* Gain exclusive access to time-of-day clock */
476 ClkMonth = month;
477 ClkDay = day;
478 ClkYear = year;
479 ClkHr = hr;
480 ClkMin = min;
481 ClkSec = sec;
482 ClkUpdateDOW(); /* Compute the day of the week (i.e. Sunday ...) */
483 EXIT_CRITICAL(); /* Release access to time-of-day clock */
484 }
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 BOOL newmonth;
500
501 newmonth = TRUE;
502 if (ClkDay >= ClkMonthTbl[ClkMonth].MonthDays) { /* Last day of the month? */
503 if (ClkMonth == 2) { /* Is this February? */
504 if (ClkIsLeapYear(ClkYear) == TRUE) { /* Yes, Is this a leap year? */
505 if (ClkDay >= 29) { /* Yes, Last day in february? */
506 ClkDay = 1; /* Yes, Set to 1st day in March */
507 } else {
508 ClkDay++;
509 newmonth = FALSE;
510 }
511 } else {
512 ClkDay = 1;
513 }
514 } else {
515 ClkDay = 1;
516 }
517 } else {
518 ClkDay++;
519 newmonth = FALSE;
520 }
521 if (newmonth == TRUE) { /* See if we have completed a month */
522 if (ClkMonth >= 12) { /* Yes, Is this december ? */
523 ClkMonth = 1; /* Yes, set month to january... */
524 ClkYear++; /* ...we have a new year! */
525 } else {
526 ClkMonth++; /* No, increment the month */
527 }
528 }
529 ClkUpdateDOW(); /* Compute the day of the week (i.e. Sunday ...) */
530 }
531 #endif
C51 COMPILER V3.96, SN-83203013 CALENDER 05/08/08 00:07:16 PAGE 10
532 /*
533 *********************************************************************************************************
534 * COMPUTE DAY-OF-WEEK
535 *
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 UINT dow;
548
549 dow = ClkDay + ClkMonthTbl[ClkMonth].MonthVal;
550 if (ClkMonth < 3)
551 {
552 if (ClkIsLeapYear(ClkYear))
553 {
554 dow--;
555 }
556 }
557 dow += ClkYear + (ClkYear / 4);
558 dow += (ClkYear / 400) - (ClkYear / 100);
559 dow %= 7;
560 ClkDOW = dow;
561 }
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 if(ClkHr!=hr)
580 return(hr-ClkHr);
581 else if(ClkMin!= min)
582 return(min-ClkMin);
583 else
584 return(sec-ClkSec);
585 }
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 相等
C51 COMPILER V3.96, SN-83203013 CALENDER 05/08/08 00:07:16 PAGE 11
594 // >0 给定时间大于当前时间
595 // <0 给定时间小于当前时间
596 // 作者: 李艳平
597 // 日期: 2002-05-17
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 if(ClkYear!=year)
604 return(year-ClkYear);
605 else if(ClkMonth!=month)
606 return(month-ClkMonth);
607 else if(ClkDay!=day)
608 return(day-ClkDay);
609 else if(ClkHr!=hr)
610 return(hr-ClkHr);
611 else if(ClkMin!= min)
612 return(min-ClkMin);
613 else
614 return(sec-ClkSec);
615 }
616 #endif
617
618
619 #endif
C51 COMPILATION COMPLETE. 0 WARNING(S), 3 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -