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

📄 电子钟.lst

📁 用单片机制作的电子钟。程序编写用的是C语言。
💻 LST
字号:
C51 COMPILER V7.50   电子钟                                                                11/08/2007 12:03:31 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE 电子钟
OBJECT MODULE PLACED IN 电子钟.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 电子钟.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg51.h>
   2          unsigned char hour=0,min=0,sec=0,t_hour=0,t_min=0,set=0,t_sec=0;
   3          unsigned char deda=0;
   4          unsigned int count;
   5          bit flag0_5=0;
   6          bit o_f=0;
   7          sbit P23=P2^3;sbit P17=P1^7;sbit P07=P0^7;sbit P35=P3^5;sbit P27=P2^7;
   8          sbit P20=P2^0;sbit P06=P0^6;sbit P25=P2^5;sbit P12=P1^2;sbit P21=P2^1;
   9          sbit P22=P2^2;sbit P26=P2^6;sbit P30=P3^0;sbit P31=P3^1;sbit P32=P3^2;
  10          sbit P36=P3^6;sbit P24=P2^4;sbit P05=P0^5;sbit P34=P3^4;sbit P04=P0^4;
  11          void initial_time();
  12          void Delay(unsigned int i);
  13          void scankey();
  14          
  15          void xianshi();
  16          void runtime();
  17          void c_xianshi();
  18          void ctime_adj();
  19          void clock();
  20          unsigned char code seg[]={0x05,0xdd,0x46,0x54,0x9c,0x34,0x24,0x5d,0x04,0x14};
  21          
  22          
  23          void initial_time()     //定时器初始化函数.
  24          {
  25   1       TMOD=0x11;
  26   1      TH1=(65536-4598)/256;
  27   1       TL1=(65536-4598)%256;             //定时5MS
  28   1       TH0=0xfe;              //定时5MS
  29   1       TL0=0xb0;
  30   1       TR1=1;
  31   1       TR0=0;
  32   1       EA=1;
  33   1       ET1=1;
  34   1       PT1=1;
  35   1       PT0=0;
  36   1       }
  37          
  38          void Delay(unsigned int i)  //延时函数
  39          {unsigned int j;
  40   1       for(;i>0;i--)
  41   1       {
  42   2        for(j=0;j<125;j++)
  43   2        {;}
  44   2       }
  45   1      }
  46          /**键盘扫描**/
  47          void scankey()             
  48          {
  49   1       Delay(1);
  50   1       if(P07==0){set++;ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}
  51   1       if(set==3) set=0;
  52   1       F:if(P07==0) goto F;
  53   1       }
  54          
  55          
C51 COMPILER V7.50   电子钟                                                                11/08/2007 12:03:31 PAGE 2   

  56          /****走时显示*****/
  57          void xianshi()                   
  58          {unsigned char tem;
  59   1        tem=hour/10;
  60   1        P3=0x20;                       
  61   1        P1=seg[tem];
  62   1        Delay(1);
  63   1        P3=0x00;
  64   1        tem=hour%10;
  65   1        P3=0x80;
  66   1        P1=seg[tem];
  67   1        Delay(1);
  68   1        if(flag0_5==0) P12=0;else P12=1;Delay(1);
  69   1        P3=0x00;
  70   1        tem=min/10;
  71   1        P3=0x02;
  72   1        P1=seg[tem];
  73   1        Delay(1);
  74   1        P3=0x00;
  75   1        tem=min%10;
  76   1        P3=0x04;
  77   1        P1=seg[tem];
  78   1        Delay(1);
  79   1        if(flag0_5==0) P12=0;else P12=1;Delay(1);
  80   1        P3=0x00;
  81   1        tem=sec/10;
  82   1        P3=0x08;
  83   1        P1=seg[tem];
  84   1        Delay(1);
  85   1        P3=0x00;
  86   1        tem=sec%10;
  87   1        P3=0x10;
  88   1        P1=seg[tem];
  89   1        Delay(1);
  90   1         if(o_f==0)  P12=1;else P12=0; Delay(1); 
  91   1        P3=0x00;
  92   1           
  93   1       }
  94          /*闹铃函数*/
  95          void didi()
  96          {
  97   1       if(t_hour==hour&&t_min==min)
  98   1       {
  99   2       if(o_f==1)
 100   2       {
 101   3        count++;
 102   3        if(count==50){ET0=1;TR0=1;}
 103   3        if(count==60){ET0=0;TR0=0;}
 104   3        if(count==75){ET0=1;TR0=1;}
 105   3        if(count==85){ET0=0;TR0=0;count=0;}
 106   3        
 107   3       }
 108   2        
 109   2      }
 110   1      }
 111          /***走时函数****/
 112          void runtime()               
 113          {didi();
 114   1       xianshi();                                    
 115   1      }
 116          
 117          
C51 COMPILER V7.50   电子钟                                                                11/08/2007 12:03:31 PAGE 3   

 118          /**调整时间**/
 119          void time_adj()                
 120          {
 121   1       unsigned int i;
 122   1       if(P06==0)Delay(1);    
 123   1       if(P06==0){hour++;ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}      
 124   1       if(hour==24) hour=0;
 125   1      for(i=0;i<10;i++)                   
 126   1      {xianshi();
 127   2      }                                  
 128   1       if(P05==0)Delay(1);    
 129   1       if(P05==0){min++; ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}   
 130   1       if(min==60) min=0;
 131   1      for(i=0;i<10;i++)                   
 132   1      {xianshi();
 133   2      }
 134   1      }
 135          /**闹钟时间显示**/
 136          void c_xianshi()          
 137          {
 138   1       P3=0x20;
 139   1       P1=seg[t_hour/10];
 140   1       Delay(1);
 141   1       P3=0x00;
 142   1       P3=0x80;
 143   1       P1=seg[t_hour%10];
 144   1       Delay(1);
 145   1       P3=0x00;
 146   1       P3=0x02;
 147   1       P1=seg[t_min/10];
 148   1       Delay(1);
 149   1       P3=0x00;
 150   1       P3=0x04;
 151   1       P1=seg[t_min%10];
 152   1       Delay(1);
 153   1       P3=0x00;
 154   1       P3=0x08;
 155   1       P1=seg[0];
 156   1       Delay(1);
 157   1       P3=0x00;
 158   1       P3=0x10;
 159   1       P1=seg[0];
 160   1       Delay(1);
 161   1       P3=0x00;
 162   1      }
 163          /**调整闹钟时间.**/
 164          void ctime_adj()           
 165          {unsigned int i;
 166   1       if(P06==0)
 167   1       Delay(1);
 168   1       if(P06==0){t_hour++;ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}
 169   1       if(t_hour==24) t_hour=0;
 170   1       for(i=0;i<10;i++)
 171   1       {
 172   2        c_xianshi();
 173   2        }
 174   1      
 175   1       if(P05==0)
 176   1       Delay(1);
 177   1       if(P05==0){t_min++;ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}
 178   1      if(t_min==60)t_min=0;
 179   1       for(i=0;i<10;i++)
C51 COMPILER V7.50   电子钟                                                                11/08/2007 12:03:31 PAGE 4   

 180   1       {
 181   2        c_xianshi();
 182   2        }
 183   1      } 
 184          
 185          
 186          /****主函数****/
 187          void main()               
 188          {initial_time();
 189   1      while(1)
 190   1      { 
 191   2       if(P07==0) scankey();
 192   2       if(P04==0)
 193   2        {Delay(3);
 194   3         if(P04==0)
 195   3        {o_f=~o_f;ET0=1;TR0=1;Delay(10);ET0=0;TR0=0;}
 196   3        }
 197   2        while(P04==0);
 198   2       switch(set)
 199   2       {
 200   3        case 0:runtime();break;
 201   3        case 1:time_adj();break;
 202   3        case 2:ctime_adj();break;
 203   3       }
 204   2      }
 205   1      }
 206           
 207          /**定时器0中断函数,获得时间.**/
 208          void timer1() interrupt 3    
 209          {
 210   1       TH1=(65536-4598)/256;
 211   1       TL1=(65536-4598)%256;
 212   1       deda++;
 213   1       if(deda<=100) flag0_5=0; else flag0_5=1;
 214   1       if(deda>=200) {sec++;deda=0;}        //注意::::deda不一定等于200.
 215   1       if(sec==60)   {min++;sec=0;}
 216   1       if(min==60)   {hour++;min=0;}
 217   1       if(hour==24)  {hour=0;}
 218   1      } 
 219          /*响铃中断*/
 220          void timer0() interrupt 1
 221          {
 222   1       TH0=0xfe;
 223   1       TL0=0xb0;
 224   1       P20=~P20;
 225   1      }
 226          
 227          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    778    ----
   CONSTANT SIZE    =     10    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     10       2
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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