题目2_时钟.LST
上传用户:wzx8880901
上传日期:2009-04-09
资源大小:37k
文件大小:31k
开发平台:

C/C++

  1. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 1   
  2. C51 COMPILER V8.05a, COMPILATION OF MODULE 题目2_时钟
  3. OBJECT MODULE PLACED IN 题目2_时钟.OBJ
  4. COMPILER INVOKED BY: C:KeilC51BINC51.EXE 题目2_时钟.c DEBUG OBJECTEXTEND
  5. line level    source
  6.    1          #include <reg52.h>
  7.    2          #define uchar unsigned char
  8.    3          #define uint unsigned int
  9.    4          sbit p34=P2^2;
  10.    5          sbit p35=P2^1;
  11.    6          sbit p36=P2^0;
  12.    7          sbit dula=P2^7;
  13.    8          sbit wei1=P2^6;
  14.    9          sbit wei2=P2^5;
  15.   10          bit runnian,dayue,flag;
  16.   11          uchar code tabledu[]={
  17.   12          0x3f,0x06,0x5b,0x4f,
  18.   13          0x66,0x6d,0x7d,0x07,
  19.   14          0x7f,0x6f,0x00};
  20.   15          uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  21.   16          uchar nian,yue,ri,shi,fen,miao,xq,cont,day,days,s,tt,a;                                 
  22.   17          uint temp;
  23.   18          int week(int y,int m,int d) ;
  24.   19          void init();
  25.   20          void display1();
  26.   21          void display2();
  27.   22          void delay(uchar z);
  28.   23          void time();
  29.   24          void year();
  30.   25          void key();
  31.   26          void jia();
  32.   27          void jian();
  33.   28          void xiaoy();
  34.   29          void xiaoy1();
  35.   30          void dxyue();
  36.   31          
  37.   32          void main()
  38.   33          {  
  39.   34   1              init();                    //初始化
  40.   35   1              dxyue();
  41.   36   1              while(1)
  42.   37   1              {
  43.   38   2                      time();
  44.   39   2                      display1();
  45.   40   2                      display2();     
  46.   41   2                      key();
  47.   42   2              }
  48.   43   1      }
  49.   44          
  50.   45          void key()
  51.   46          {
  52.   47   1               if(p34==0)                                     //选择更改位。
  53.   48   1               {
  54.   49   2                       delay(20);                             //去抖
  55.   50   2                       if(p34==0)
  56.   51   2                       {
  57.   52   3                               while(!p34) 
  58.   53   3                              {               
  59.   54   4                                      display1();              //显示子函数打包
  60.   55   4                                      display2();
  61. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 2   
  62.   56   4                              }
  63.   57   3                               delay(10);
  64.   58   3                               s++;
  65.   59   3                               cont=0;                                //保证按键按下时间过长时,松开后,能马上闪烁而不用等待.
  66.   60   3                               if(s==7)                               
  67.   61   3                               {
  68.   62   4                                      s=0;
  69.   63   4                               }
  70.   64   3                       }
  71.   65   2               }
  72.   66   1               if(p35==0)                                     //加位
  73.   67   1               {
  74.   68   2                      if(s==0)                                // 没有按p34的情况下,按P35或P36的无效。
  75.   69   2                      {}
  76.   70   2                      else
  77.   71   2                      {       delay(10);
  78.   72   3                              if(p35==0)
  79.   73   3                              {
  80.   74   4                                      while(!p35)
  81.   75   4                                      {               
  82.   76   5                                      display1();              //显示子函数打包
  83.   77   5                                      display2();
  84.   78   5                                      }
  85.   79   4                                      jia();
  86.   80   4                               }
  87.   81   3                      }
  88.   82   2               }
  89.   83   1               if(p36==0)                                     //减位
  90.   84   1               {       
  91.   85   2                      if(s==0)                                // 没有按p34的情况下,按P35或P36的无效。
  92.   86   2                      {}
  93.   87   2                      else
  94.   88   2                      {       delay(10);
  95.   89   3                              if(p36==0)
  96.   90   3                              {
  97.   91   4                                      while(p36==0)
  98.   92   4                                      {               
  99.   93   5                                              display1();              //显示子函数打包
  100.   94   5                                              display2();
  101.   95   5                                      }
  102.   96   4                                      jian();
  103.   97   4                              }
  104.   98   3                      }
  105.   99   2               }       
  106.  100   1      }
  107.  101          void jian()              //减
  108.  102          {
  109.  103   1                if(s==1)                              //年
  110.  104   1                      {
  111.  105   2                              nian--;  xq=week(nian,yue,ri);
  112.  106   2                              if(nian==0xff)   //2099年
  113.  107   2                              {
  114.  108   3                                      nian=99;
  115.  109   3                              }
  116.  110   2                              year(); 
  117.  111   2                      }
  118.  112   1                      if(s==2)                         //月
  119.  113   1                      {
  120.  114   2                              yue--;  xq=week(nian,yue,ri);
  121.  115   2                              if(yue==0)
  122.  116   2                              {
  123.  117   3                                      yue=12;
  124. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 3   
  125.  118   3                              }
  126.  119   2                              dxyue();
  127.  120   2                      }
  128.  121   1                      if(s==3)                        //日
  129.  122   1                      {
  130.  123   2                              ri--;   xq=week(nian,yue,ri);
  131.  124   2                              if(ri==0)
  132.  125   2                              {
  133.  126   3                                      if(yue==2)
  134.  127   3                                      {
  135.  128   4                                              if(runnian)
  136.  129   4                                              {
  137.  130   5                                                      ri=29;
  138.  131   5                                              }
  139.  132   4                                              else
  140.  133   4                                              {
  141.  134   5                                                      ri=28;
  142.  135   5                                              }
  143.  136   4                                      }
  144.  137   3                                      else
  145.  138   3                                      {
  146.  139   4                                              if(dayue)
  147.  140   4                                              {
  148.  141   5                                                      ri=31;
  149.  142   5                                              }
  150.  143   4                                              else
  151.  144   4                                              {
  152.  145   5                                                      ri=30;
  153.  146   5                                              }
  154.  147   4                                      }
  155.  148   3                              }
  156.  149   2                      
  157.  150   2                      }
  158.  151   1                      if(s==4)
  159.  152   1                      {
  160.  153   2                              shi--;
  161.  154   2                              if(shi==0xff)
  162.  155   2                              {
  163.  156   3                                      shi=23;
  164.  157   3                              }
  165.  158   2                      }
  166.  159   1                      if(s==5)
  167.  160   1                      {
  168.  161   2                               fen--;
  169.  162   2                               if(fen==0xff)
  170.  163   2                               {
  171.  164   3                                      fen=59;
  172.  165   3                               }
  173.  166   2                      }
  174.  167   1                      if(s==6)
  175.  168   1                      {
  176.  169   2                              miao--;
  177.  170   2                              if(miao==0xff)
  178.  171   2                              {
  179.  172   3                                      miao=59;
  180.  173   3                              }
  181.  174   2                      }
  182.  175   1      }
  183.  176          void jia()
  184.  177          {
  185.  178   1                      if(s==1)
  186.  179   1                      {
  187. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 4   
  188.  180   2                              nian++; xq=week(nian,yue,ri);
  189.  181   2                              year();
  190.  182   2                      }
  191.  183   1                      if(s==2)
  192.  184   1                      {
  193.  185   2                              yue++;  xq=week(nian,yue,ri);
  194.  186   2                              if(yue==13)
  195.  187   2                              {
  196.  188   3                                      yue=1;
  197.  189   3                              }
  198.  190   2                              dxyue();
  199.  191   2                      }
  200.  192   1                      if(s==3)
  201.  193   1                      {
  202.  194   2                              ri++;   xq=week(nian,yue,ri);
  203.  195   2                              if(yue==2)
  204.  196   2                              {
  205.  197   3                                      
  206.  198   3                                      if(ri>=day)
  207.  199   3                                      {
  208.  200   4                                              ri=1;
  209.  201   4                                      }
  210.  202   3                              }
  211.  203   2                              else
  212.  204   2                              {       
  213.  205   3                                      if(ri>=days)
  214.  206   3                                      {
  215.  207   4                                              ri=1;
  216.  208   4                                      }
  217.  209   3                              }
  218.  210   2                      }
  219.  211   1                      if(s==4)
  220.  212   1                      {
  221.  213   2                              shi++;
  222.  214   2                              if(shi==24)
  223.  215   2                              {
  224.  216   3                                      shi=0;
  225.  217   3                              }
  226.  218   2                      }
  227.  219   1                      if(s==5)
  228.  220   1                      {
  229.  221   2                               fen++;
  230.  222   2                               if(fen==60)
  231.  223   2                               {
  232.  224   3                                      fen=0;
  233.  225   3                               }
  234.  226   2                      }
  235.  227   1                      if(s==6)
  236.  228   1                      {
  237.  229   2                              miao++;
  238.  230   2                              if(miao==60)
  239.  231   2                              {
  240.  232   3                                      miao=0;
  241.  233   3                              }
  242.  234   2                      }
  243.  235   1      }
  244.  236          void init()
  245.  237          {
  246.  238   1              flag=1;
  247.  239   1              TMOD=0x01;
  248.  240   1              TH0=0X4C;
  249.  241   1              TL0=0X00;
  250. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 5   
  251.  242   1              EA=1;
  252.  243   1              ET0=1;
  253.  244   1              TR0=1;
  254.  245   1              nian=8;
  255.  246   1              yue=11;
  256.  247   1              ri=22;
  257.  248   1              shi=20;
  258.  249   1              fen=30;
  259.  250   1              year();
  260.  251   1              s=0;
  261.  252   1              P0=0;
  262.  253   1              dula=wei1=wei2=0;
  263.  254   1      
  264.  255   1      }
  265.  256          void xiaoy()
  266.  257          {
  267.  258   1              //------------------------------
  268.  259   1              P0=0;
  269.  260   1              dula=1;
  270.  261   1              P0=0;
  271.  262   1              dula=0;
  272.  263   1              P0=0xff;
  273.  264   1              wei2=1;
  274.  265   1              P0=tablewe[7];
  275.  266   1              wei2=0;
  276.  267   1              delay(1);
  277.  268   1      //------------------------------
  278.  269   1      }
  279.  270          void xiaoy1()
  280.  271          {
  281.  272   1              //------------------------------
  282.  273   1              P0=0;
  283.  274   1              dula=1;
  284.  275   1              P0=0;
  285.  276   1              dula=0;
  286.  277   1              P0=0xff;
  287.  278   1              wei1=1;
  288.  279   1              P0=tablewe[7];
  289.  280   1              wei1=0;
  290.  281   1              delay(1);
  291.  282   1      //------------------------------
  292.  283   1      }
  293.  284          void display2()    //时分秒
  294.  285          {       
  295.  286   1              
  296.  287   1              uchar x,y;
  297.  288   1      //----------------------------------
  298.  289   1              x=shi%100/10;           //时十位
  299.  290   1              y=shi%10;                       //时个位
  300.  291   1              P0=0x00;
  301.  292   1              if(s==4)                  //校对时间时闪烁用。
  302.  293   1              {
  303.  294   2                      if(cont==12)
  304.  295   2                      {
  305.  296   3                              cont=0;
  306.  297   3                              flag=~flag;
  307.  298   3                              
  308.  299   3                      }
  309.  300   2                      if(flag)
  310.  301   2                              {
  311.  302   3                              x=0x0a;
  312.  303   3                              y=0x0a;
  313. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 6   
  314.  304   3                      
  315.  305   3                              }
  316.  306   2              }
  317.  307   1              P0=0;
  318.  308   1              dula=1;
  319.  309   1              P0=tabledu[x];
  320.  310   1              dula=0;
  321.  311   1              P0=0xff;
  322.  312   1              wei2=1;
  323.  313   1              P0=tablewe[0];
  324.  314   1              wei2=0;
  325.  315   1              delay(2);
  326.  316   1              //--------------------------
  327.  317   1              xiaoy();                        //消隐
  328.  318   1              //--------------------------
  329.  319   1              
  330.  320   1              P0=0;                   //时个
  331.  321   1              dula=1;
  332.  322   1              P0=tabledu[y];
  333.  323   1              dula=0;         
  334.  324   1              P0=0xff;
  335.  325   1              wei2=1;
  336.  326   1              P0=tablewe[1];
  337.  327   1              wei2=0;
  338.  328   1              delay(2);
  339.  329   1              //--------------------------
  340.  330   1              xiaoy();                        //消隐
  341.  331   1              //--------------------------
  342.  332   1      
  343.  333   1              x=fen%100/10;           //分十位
  344.  334   1              y=fen%10;                       //分个位
  345.  335   1                      if(s==5)
  346.  336   1              {
  347.  337   2                      if(cont==12)
  348.  338   2                      {
  349.  339   3                              cont=0;
  350.  340   3                              flag=~flag;
  351.  341   3                              
  352.  342   3                      }
  353.  343   2                      if(flag)
  354.  344   2                              {
  355.  345   3                              x=0x0a;
  356.  346   3                              y=0x0a;
  357.  347   3                      
  358.  348   3                              }
  359.  349   2              }
  360.  350   1              P0=0;           
  361.  351   1              dula=1;
  362.  352   1              P0=tabledu[x];
  363.  353   1              dula=0;         P0=0xff;
  364.  354   1              wei2=1;
  365.  355   1              P0=tablewe[2];
  366.  356   1              wei2=0;
  367.  357   1              delay(2);
  368.  358   1              //--------------------------
  369.  359   1              xiaoy();                        //消隐
  370.  360   1              //--------------------------    
  371.  361   1      
  372.  362   1                              //分个位
  373.  363   1              P0=0;
  374.  364   1              dula=1;
  375.  365   1              P0=tabledu[y];
  376. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 7   
  377.  366   1              dula=0;         P0=0xff;
  378.  367   1              wei2=1;
  379.  368   1              P0=tablewe[3];
  380.  369   1              wei2=0;
  381.  370   1              delay(2);       
  382.  371   1              //--------------------------
  383.  372   1              xiaoy();                        //消隐
  384.  373   1              //--------------------------
  385.  374   1              x=miao%100/10;          //秒十位
  386.  375   1              y=miao%10;              
  387.  376   1              
  388.  377   1                      //秒十位
  389.  378   1                      if(s==6)
  390.  379   1              {
  391.  380   2                      if(cont==12)
  392.  381   2                      {
  393.  382   3                              cont=0;
  394.  383   3                              flag=~flag;
  395.  384   3                              
  396.  385   3                      }
  397.  386   2                      if(flag)
  398.  387   2                              {
  399.  388   3                              x=0x0a;
  400.  389   3                              y=0x0a;
  401.  390   3                              }
  402.  391   2              }
  403.  392   1              P0=0;
  404.  393   1              dula=1;
  405.  394   1              P0=tabledu[x];
  406.  395   1              dula=0;         
  407.  396   1              P0=0xff;
  408.  397   1              wei2=1;
  409.  398   1              P0=tablewe[4];
  410.  399   1              wei2=0;  
  411.  400   1              delay(2);
  412.  401   1              //--------------------------
  413.  402   1              xiaoy();                        //消隐
  414.  403   1              //--------------------------  
  415.  404   1      
  416.  405   1              P0=0;   //秒个位
  417.  406   1              dula=1;
  418.  407   1              P0=tabledu[y];
  419.  408   1              dula=0;
  420.  409   1              
  421.  410   1              P0=0xff;
  422.  411   1              wei2=1;
  423.  412   1              P0=tablewe[5];
  424.  413   1              wei2=0;         
  425.  414   1              delay(2);
  426.  415   1              P0=0;
  427.  416   1              //--------------------------
  428.  417   1              xiaoy();                        //消隐
  429.  418   1              //--------------------------
  430.  419   1      //----------------------------------
  431.  420   1              P0=0;   //星期显示
  432.  421   1              dula=1;
  433.  422   1              P0=tabledu[xq];
  434.  423   1              dula=0;
  435.  424   1              
  436.  425   1              P0=0xff;
  437.  426   1              wei2=1;
  438.  427   1              P0=tablewe[6];
  439. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 8   
  440.  428   1              wei2=0;         
  441.  429   1              delay(2);
  442.  430   1              P0=0;
  443.  431   1      //--------------------------------
  444.  432   1              P0=0;   //无效作用位
  445.  433   1              dula=1;
  446.  434   1              P0=0;
  447.  435   1              dula=0;
  448.  436   1              
  449.  437   1              P0=0xff;
  450.  438   1              wei2=1;
  451.  439   1              P0=tablewe[7];
  452.  440   1              wei2=0;         
  453.  441   1              delay(2);
  454.  442   1              P0=0;
  455.  443   1      //-----------------
  456.  444   1      }
  457.  445          
  458.  446          void display1()                 //年月日
  459.  447          {       
  460.  448   1              uchar x,y;
  461.  449   1      //----------------------------------
  462.  450   1              x=nian%100/10;          //年十位
  463.  451   1              y=nian%10;                      //年个位
  464.  452   1              P0=0x00;
  465.  453   1              if(s==1)                                          //校对时间时闪烁用。
  466.  454   1              {
  467.  455   2                      if(cont==12)
  468.  456   2                      {
  469.  457   3                              cont=0;
  470.  458   3                              flag=~flag;
  471.  459   3                              
  472.  460   3                      }
  473.  461   2                      if(flag)
  474.  462   2                              {
  475.  463   3                              x=0x0a;
  476.  464   3                              y=0x0a;
  477.  465   3                              }
  478.  466   2              }
  479.  467   1              P0=0;
  480.  468   1              dula=0;
  481.  469   1              dula=1;
  482.  470   1              P0=tabledu[x];
  483.  471   1              dula=0;
  484.  472   1              
  485.  473   1              P0=0xff;
  486.  474   1              wei1=0;
  487.  475   1              wei1=1;
  488.  476   1              P0=tablewe[0];
  489.  477   1              wei1=0;
  490.  478   1              delay(2);
  491.  479   1              //--------------------------
  492.  480   1              xiaoy1();                       //消隐
  493.  481   1              //--------------------------
  494.  482   1      
  495.  483   1              dula=0;
  496.  484   1              P0=0;                   //年个
  497.  485   1              dula=1;
  498.  486   1              P0=tabledu[y];
  499.  487   1              dula=0;  
  500.  488   1              P0=0xff;
  501.  489   1              wei1=1;
  502. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 9   
  503.  490   1              P0=tablewe[1];
  504.  491   1              wei1=0;
  505.  492   1              delay(2);
  506.  493   1              //--------------------------
  507.  494   1              xiaoy1();                       //消隐
  508.  495   1              //--------------------------
  509.  496   1      //----------------------------------
  510.  497   1      //----------------------------------
  511.  498   1              x=yue%100/10;           //月十位
  512.  499   1              y=yue%10;                       //月个位
  513.  500   1              if(s==2)
  514.  501   1              {
  515.  502   2                      if(cont==12)
  516.  503   2                      {
  517.  504   3                              cont=0;
  518.  505   3                              flag=~flag;
  519.  506   3                              
  520.  507   3                      }
  521.  508   2                      if(flag)
  522.  509   2                              {
  523.  510   3                              x=0x0a;
  524.  511   3                              y=0x0a;
  525.  512   3                      
  526.  513   3                              }
  527.  514   2              }
  528.  515   1              P0=0;
  529.  516   1              dula=1;
  530.  517   1              P0=tabledu[x];
  531.  518   1              dula=0;         P0=0xff;
  532.  519   1              wei1=1;
  533.  520   1              P0=tablewe[2];
  534.  521   1              wei1=0;
  535.  522   1              delay(2);
  536.  523   1              //--------------------------
  537.  524   1              xiaoy1();                       //消隐
  538.  525   1              //--------------------------    
  539.  526   1      
  540.  527   1                              //月个位
  541.  528   1              P0=0;
  542.  529   1              dula=1;
  543.  530   1              P0=tabledu[y];
  544.  531   1              dula=0;         P0=0xff;
  545.  532   1              wei1=1;
  546.  533   1              P0=tablewe[3];
  547.  534   1              wei1=0;
  548.  535   1              delay(2); 
  549.  536   1              //--------------------------
  550.  537   1              xiaoy1();                       //消隐
  551.  538   1              //--------------------------    
  552.  539   1      //----------------------------------
  553.  540   1      //----------------------------------
  554.  541   1              x=ri%100/10;            //日十位
  555.  542   1              y=ri%10;                
  556.  543   1              
  557.  544   1                      //日个位
  558.  545   1                      if(s==3)
  559.  546   1              {
  560.  547   2                      if(cont==12)
  561.  548   2                      {
  562.  549   3                              cont=0;
  563.  550   3                              flag=~flag;
  564.  551   3                              
  565. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 10  
  566.  552   3                      }
  567.  553   2                      if(flag)
  568.  554   2                              {
  569.  555   3                              x=0x0a;
  570.  556   3                              y=0x0a;
  571.  557   3                      
  572.  558   3                              }
  573.  559   2              }
  574.  560   1              P0=0;
  575.  561   1              dula=1;
  576.  562   1              P0=tabledu[x];
  577.  563   1              dula=0;         P0=0xff;
  578.  564   1              wei1=1;
  579.  565   1              P0=tablewe[4];
  580.  566   1              wei1=0;  
  581.  567   1              delay(2); 
  582.  568   1              //--------------------------
  583.  569   1              xiaoy1();                       //消隐
  584.  570   1              //-------------------------- 
  585.  571   1      
  586.  572   1              P0=0;   //日个位
  587.  573   1              dula=1;
  588.  574   1              P0=tabledu[y];
  589.  575   1              dula=0;
  590.  576   1              P0=0xff;
  591.  577   1              wei1=1;
  592.  578   1              P0=tablewe[5];
  593.  579   1              wei1=0; 
  594.  580   1              P0=0;
  595.  581   1              delay(2);
  596.  582   1              //--------------------------
  597.  583   1              xiaoy1();                       //消隐
  598.  584   1              //--------------------------  
  599.  585   1      //----------------------------------
  600.  586   1              P0=0;   //第一锁存器无效作用位
  601.  587   1              dula=1;
  602.  588   1              P0=0 ;
  603.  589   1              dula=0;
  604.  590   1              P0=0xff;
  605.  591   1              wei1=1;
  606.  592   1              P0=tablewe[6];
  607.  593   1              wei1=0; 
  608.  594   1              P0=0;
  609.  595   1              delay(2); 
  610.  596   1      
  611.  597   1      //---------------------
  612.  598   1              
  613.  599   1      }
  614.  600          
  615.  601          
  616.  602          
  617.  603          
  618.  604          void year()                      //平润年
  619.  605          {
  620.  606   1              uint aaa;
  621.  607   1              aaa=2000+nian;                  //为了计算闰年。
  622.  608   1              if(((aaa%4 == 0)&&(aaa%100!=0)) || (aaa%400==0))
  623.  609   1              {
  624.  610   2                      runnian=1;
  625.  611   2                      day=30;         //闰年
  626.  612   2              }
  627.  613   1              else
  628. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 11  
  629.  614   1              {
  630.  615   2                      runnian=0;
  631.  616   2                      day=29;          //平年
  632.  617   2              }       
  633.  618   1      }
  634.  619          
  635.  620          void dxyue()       //大小月
  636.  621          {
  637.  622   1      
  638.  623   1              if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
  639.  624   1              {
  640.  625   2                      days=32; //31天
  641.  626   2              }
  642.  627   1              else
  643.  628   1              {                
  644.  629   2                      days=31;  //30天
  645.  630   2              }
  646.  631   1      }
  647.  632          void time()
  648.  633          {
  649.  634   1              if(cont==40)  //一秒钟加一。不是很精确。
  650.  635   1              {
  651.  636   2                 cont=0;
  652.  637   2                 miao++;
  653.  638   2                 if(miao==60)
  654.  639   2                 {
  655.  640   3                              miao=0;
  656.  641   3                              fen++;
  657.  642   3                              if(fen==60)
  658.  643   3                              {
  659.  644   4                                      fen=0;
  660.  645   4                                      shi++;
  661.  646   4                                      if(shi==24)
  662.  647   4                                      {
  663.  648   5                                              shi=0;
  664.  649   5                                              ri++; 
  665.  650   5                                              xq=week(nian,yue,ri);
  666.  651   5                                              dxyue();
  667.  652   5                                              if(yue!=2)
  668.  653   5                                              {
  669.  654   6                                                      if(ri==days)
  670.  655   6                                                      {
  671.  656   7                                                              ri=1;
  672.  657   7                                                              yue++;
  673.  658   7                                                              xq=week(nian,yue,ri);
  674.  659   7                                                              if(yue==13)
  675.  660   7                                                              {
  676.  661   8                                                                      yue=1;
  677.  662   8                                                                      nian++;
  678.  663   8                                                                      xq=week(nian,yue,ri);
  679.  664   8                                                                      year();
  680.  665   8                                                              }
  681.  666   7                                                      }       
  682.  667   6                                              }
  683.  668   5                                              else
  684.  669   5                                              {
  685.  670   6                                                      if(ri==day)
  686.  671   6                                                      {
  687.  672   7                                                              ri=1;
  688.  673   7                                                              yue++;
  689.  674   7                                                      }
  690.  675   6                                              }
  691. C51 COMPILER V8.05a   题目2_时钟                                                           09/19/2009 01:34:58 PAGE 12  
  692.  676   5                                      }
  693.  677   4                              }
  694.  678   3                 }    
  695.  679   2              }
  696.  680   1      
  697.  681   1      }       
  698.  682          void dingshi() interrupt 1
  699.  683          {
  700.  684   1              TH0=0x4C;
  701.  685   1              TL0=0x00;
  702.  686   1              cont++;
  703.  687   1      }
  704.  688          void delay(uchar z)
  705.  689          {
  706.  690   1              uint x,y;
  707.  691   1              for(x=z;x>0;x--)
  708.  692   1                      for(y=20;y>0;y--);              
  709.  693   1      }
  710.  694          int week(int y,int m,int d) 
  711.  695          { 
  712.  696   1              int m_d[12]={2,5,5,1,3,6,1,4,7,2,5,7}; 
  713.  697   1              int i,j,k=0; 
  714.  698   1              int s=2; 
  715.  699   1              int w=0; 
  716.  700   1              y=2000+y;
  717.  701   1              if (((y%4==0)&&(y%100!=0))||(y%400)==0) 
  718.  702   1                      { 
  719.  703   2                         if (m<=2) 
  720.  704   2                         j=y-1; 
  721.  705   2                         else 
  722.  706   2                         j=y; 
  723.  707   2                      } 
  724.  708   1              else 
  725.  709   1                      j=y; 
  726.  710   1              
  727.  711   1              for (i=1904;i<=y;i=i+4) 
  728.  712   1                      { 
  729.  713   2                         if (i%100!=0) 
  730.  714   2                         k++; 
  731.  715   2                         else if (i%400==0) 
  732.  716   2                                 k++; 
  733.  717   2                      } 
  734.  718   1              w=((j-1904+s+k)+m_d[m-1]+d)%7; 
  735.  719   1              return (w); 
  736.  720   1      } 
  737. MODULE INFORMATION:   STATIC OVERLAYABLE
  738.    CODE SIZE        =   1759    ----
  739.    CONSTANT SIZE    =     43    ----
  740.    XDATA SIZE       =   ----    ----
  741.    PDATA SIZE       =   ----    ----
  742.    DATA SIZE        =     15      38
  743.    IDATA SIZE       =   ----    ----
  744.    BIT SIZE         =      3    ----
  745. END OF MODULE INFORMATION.
  746. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)