📄 time.lst
字号:
673 2 }
674 1 if(month==2&&judge1==1)
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 12
675 1 {s=29;
676 2 return(s);
677 2 }
678 1 }
679 /****************星期判断子函数*****************/
680 int date(int year,int month)
681
682 {
683 1 int a,c,d,judge;
684 1 int year1;
685 1 year1=year;
686 1 if(year>2000) for(a=1,year--;year>2000;year--) /*计算除当年外有几个闰年*/
687 1 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
688 1 a++;
689 1
690 1 if(year<2000) for(a=0,year++;year<2000;year++)
691 1 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
692 1 a++;
693 1 year=year1;
694 1 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)) judge=1;/*判断当年是否为闰年*/
695 1 else judge=0;
696 1 if(month==1) d=0;
697 1 if(month==2) d=31;
698 1 if(month==3) d=59+judge;
699 1 if(month==4) d=90+judge;
700 1 if(month==5) d=120+judge;
701 1 if(month==6) d=151+judge;
702 1 if(month==7) d=181+judge;
703 1 if(month==8) d=212+judge;
704 1 if(month==9) d=243+judge;
705 1 if(month==10) d=273+judge;
706 1 if(month==11) d=304+judge;
707 1 if(month==12) d=334+judge; /*计算月份的天数差*/
708 1 /*计算当月一日是星期几*/
709 1 if(year<2000)
710 1 {
711 2 c=((2000-year)*365+a+judge-d-day)%7;
712 2 switch(c)
713 2 {
714 3 case 0: c=5;break;
715 3 case 1: c=4;break;
716 3 case 2: c=3;break;
717 3 case 3: c=2;break;
718 3 case 4: c=1;break;
719 3 case 5: c=0;break;
720 3 case 6: c=6;break;
721 3 }
722 2 }
723 1 if(year==2000)
724 1 {
725 2 if((month==1)&&(day==1)) c=6;
726 2 else c=(day+d-2)%7;
727 2 }
728 1 if(year>2000) c=((year-2000)*365+a+d+day-2)%7;
729 1 return(c);
730 1 }
731 /****************年的转换子函数*****************/
732 int yearchange(int year)
733 {
734 1 s1=year/1000;
735 1 s2=(year-s1*1000)/100;
736 1 s3=(year-s1*1000-s2*100)/10;
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 13
737 1 s4=year-s1*1000-s2*100-s3*10;
738 1 }
739 /***************定时器t1初始化*******************/
740
741 void init_timer1(void)
742 {
743 1 TMOD=0x11; //time1为定时器,方式1
744 1 TH1=0x3c; //预置计数初值
745 1 TL1=0xb0;
746 1 ET1=1;
747 1 }
748 /***********定时器t0中断子函数**************/
749
750 void timer1(void) interrupt 3 using 3 //定时器1方式1,50ms中断一次
751 {
752 1 TH1=0x3c;
753 1 TL1=0xb0;
754 1 mstcnt1++;
755 1
756 1 if(disturb==1)
757 1 {
758 2 if(ss==0)
759 2 {
760 3
761 3 if(mstcnt1>=100)
762 3 {
763 4 speaker=0; //蜂鸣器关
764 4 mstcnt1=0;
765 4 ss=1;
766 4 }
767 3 }
768 2 if(ss==1)
769 2 {
770 3 if(mstcnt1>=40)
771 3 {
772 4 speaker=1;
773 4 mstcnt1=0;
774 4 ss=2;
775 4 }
776 3 }
777 2 if(ss==2)
778 2 {
779 3
780 3 if(mstcnt1>=100)
781 3 {
782 4 mstcnt1=0;
783 4 speaker=0;
784 4 ss=0;
785 4 TR1=0;
786 4 }
787 3 }
788 2 }
789 1 if(disturb==0)
790 1 { speaker=0; TR1=0;ss=0; }
791 1
792 1 }
793 /***************定时器t0初始化*******************/
794
795 void init_timer0(void)
796 {
797 1 TMOD=0x01; //time0为定时器,方式1
798 1 TH0=0x3c; //预置计数初值
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 14
799 1 TL0=0xb0;
800 1 EA=1;
801 1 ET0=1;
802 1 TR0=1;
803 1 }
804 /***********定时器t0中断子函数**************/
805
806 void timer0(void) interrupt 1 using 0 //定时器0方式1,50ms中断一次
807 {
808 1 TH0=0x3c;
809 1 TL0=0xb0;
810 1 mstcnt0++;
811 1 if(mstcnt0>=20 )
812 1 {
813 2 second++;
814 2 mstcnt0=0;
815 2
816 2 }
817 1 if(second>59)
818 1 {
819 2 minite++;
820 2 second=0;
821 2 for(n=0;n<32;n++)
822 2 {
823 3 if((hourjudge[n]==hour)&&(minitejudge[n]==minite))
824 3 {
825 4
826 4 mstcnt1=0;
827 4 disturb=1;
828 4 TR1=1;
829 4 TH1=0x3c;
830 4 TL1=0xb0;
831 4 speaker=1;
832 4
833 4 }
834 3 }
835 2 }
836 1 if(minite>59)
837 1 {
838 2 hour++;
839 2 minite=0;
840 2
841 2 }
842 1 if(hour>23)
843 1 {
844 2 // week1++;
845 2 day++;
846 2 hour=0;
847 2 k=dayjudge(year,month);
848 2 if(status==0)
849 2 {
850 3 weekjudge=date(year,month);
851 3 if(weekjudge==0)
852 3 {
853 4 weekjudge=7;
854 4 }
855 3
856 3 DisplayOneChar(15,0,weekjudge+0x30);
857 3 }
858 2 if(day>k)
859 2 {
860 3 month++;
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 15
861 3 }
862 2 if(month>12)
863 2 {
864 3 year++;
865 3 month=0;
866 3 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
867 3 {DisplayListChar(11,1,"RUN ");}
868 3 else DisplayListChar(11,1,"PING");
869 3 }
870 2 }
871 1 }
872
873 /**********主程序*************/
874
875 void main(void)
876 {
877 1 speaker=0;
878 1 P1=0xff; //初始化p1口,全设为1
879 1 // week1=date(year,month);
880 1 delay(500); //延时500ms启动
881 1 LCDInit( ); //LCD初始化
882 1 init_timer0( );
883 1 init_timer1(); //时钟定时器0和1初始化
884 1 while (1)
885 1 {
886 2 keyscan();
887 2 }
888 1 }
889 void displaytime(void)
890 {
891 1 if(view==0)
892 1 {
893 2 view=1;
894 2 WriteCommand(0x01);
895 2 DisplayOneChar(2,1,0x3A);
896 2 DisplayOneChar(5,1,0x3A);
897 2 DisplayOneChar(7,0,0x2D);
898 2 DisplayOneChar(4,0,0x2D);
899 2 DisplayListChar(11,0,"Week");
900 2 weekjudge=date(year,month);
901 2 if(weekjudge==0)
902 2 {
903 3 weekjudge=7;
904 3 }
905 2
906 2 DisplayOneChar(15,0,weekjudge+0x30);
907 2 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
908 2 {DisplayListChar(11,1,"RUN ");}
909 2 else DisplayListChar(11,1,"PING");
910 2 // DisplayListChar(0,1,"Time:");
911 2 // DisplayListChar(0,0,"Date:");
912 2 }
913 1 if(set!=0)
914 1 {
915 2 TR0=0;
916 2 }
917 1 if(set>6)
918 1 {
919 2 set=0;
920 2 TR0=1;
921 2 mstcnt0=0;
922 2 // DisplayListChar(9,1,"Week")
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 16
923 2 weekjudge=date(year,month);
924 2 if(weekjudge==0)
925 2 {
926 3 weekjudge=7;
927 3 }
928 2
929 2 DisplayOneChar(15,0,weekjudge+0x30);
930 2 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
931 2 {DisplayListChar(11,1,"RUN ");}
932 2 else DisplayListChar(11,1,"PING");
933 2 }
934 1 switch(set) //LCD根据工作模式显示
935 1 {
936 2
937 2 case 0:displaytimejudge();//delay(800); //正常工作显示时间
938 2 break;
939 2 case 1:changehour();//delay(200); //调整分显示
940 2 break;
941 2 case 2:changeminite();//delay(1000); //调整时显示
942 2 break;
943 2 case 3:changesecond();//delay(1000); //调整时显示
944 2 break;
945 2 case 4:changeyear();//delay(1000);
946 2 break;
947 2 case 5:changemonth();//delay(1000);
948 2 break;
949 2 case 6:changeday();//delay(1000);
950 2 break;
951 2 default:
952 2 break;
953 2 }
954 1 delay(300);
955 1 } /*
956 void displaydate(void)
957 {
958 if(view==0)
959 {
960 WriteCommand(0x01);
961 view=1;
962 DisplayListChar(0,0,"Today is ");
963 }
964
965 DisplayListChar(9,0,week[date(year,month)]);
966
967 if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
968 DisplayListChar(2,1,"Lesp year");
969 else DisplayListChar(1,1,"Non-Leap year");
970
971 } */
972 void displayclock(void)
973 {
974 1 if(view==0)
975 1 {
976 2 WriteCommand(0x01);
977 2 view=1;
978 2 DisplayListChar(0,0,"Set Clock:");
979 2 }
980 1
981 1 DisplayOneChar(11,1,0x3a);
982 1 DisplayOneChar(12,0,(set+1)/10+0x30);
983 1 DisplayOneChar(13,0,(set+1)%10+0x30);
984 1 switch(set1)
C51 COMPILER V8.02 TIME 06/05/2008 19:24:28 PAGE 17
985 1 {
986 2 case 0:displayclockjudge();break;
987 2 case 1:displayclockjudge();
988 2 break;
989 2 case 2:displayclockjudge();break;
990 2 // case 3:displayclockjudge(); //WriteCommand(0x0f);WriteCommand(0x88+set2); delay(2000);
991 2 // break;
992 2 default:
993 2 break;
994 2 }
995 1
996 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 4006 ----
CONSTANT SIZE = 28 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 44 23
IDATA SIZE = 96 ----
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 + -