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

C/C++

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