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

📄 timer_funcs.lst

📁 CAN工业节点设计、CAN控制器为SJA1000.C源码
💻 LST
字号:
C51 COMPILER V8.09   TIMER_FUNCS                                                           03/13/2008 06:00:59 PAGE 1   


C51 COMPILER V8.09, COMPILATION OF MODULE TIMER_FUNCS
OBJECT MODULE PLACED IN TIMER_funcs.OBJ
COMPILER INVOKED BY: E:\Keil\C51\BIN\C51.EXE TIMER_funcs.c ROM(COMPACT) BROWSE INCDIR(E:\Keil\C51\INC) DEBUG OBJECTEXTEN
                    -D

line level    source

   1          #include <REGX52.h>
   2          #include "xkcan_defs.h"
   3          #include "timer_defs.h"
   4          #include "max7219.h"
   5          #include "DIG_defs.h"
   6          
   7          
   8          ubyte volatile  timer_tick_500ms;
   9          uint  volatile  timer_tick;
  10          ubyte volatile  timer_tick_5s;
  11          ubyte volatile  timer_half;
  12          
  13          ubyte idata timer_set_hr;
  14          ubyte idata timer_set_min;
  15          ubyte idata timer_set_sec;
  16          ubyte idata timer_exp_set_hr;
  17          ubyte idata timer_exp_set_min;
  18          ubyte idata timer_exp_set_sec;
  19          
  20          ubyte volatile idata timer_hr;
  21          ubyte volatile idata timer_min;
  22          ubyte volatile idata timer_sec;
  23          
  24          ubyte volatile idata timer_exp_hr;
  25          ubyte volatile idata timer_exp_min;
  26          ubyte volatile idata timer_exp_sec;
  27          
  28          void TIMER_Init(void)
  29          {
  30   1              // Use T2 as a 25ms timer
  31   1              ET2 = 0;                                        // 关闭T2的中断
  32   1              T2MOD = 0x00;                   // T2工作在模式0
  33   1              T2CON = 0x00;                   // 
  34   1              RCAP2L = 0xb0;          // 产生25ms中断 |24 MHz          0x10000 - 0xC350 = 0x3CB0
  35   1              RCAP2H = 0x3c;
  36   1              TL2 = RCAP2L;
  37   1              TH2 = RCAP2H;
  38   1              ET2 = 1;                                  // 打开T2的中断
  39   1      
  40   1              timer_tick = 0;
  41   1              timer_half = 0;
  42   1              timer_clock_pause = 1;
  43   1              timer_exp_clock_pause = 1;
  44   1              timer_tick_500ms = 0;
  45   1      
  46   1      }
  47          
  48          void timer2_int(void) interrupt 5 using 1 
  49          {                 
  50   1              EA = 0;
  51   1              TF2 = 0;
  52   1              timer_tick++;
  53   1      
  54   1              if ( (timer_tick % 20) == 0 )
C51 COMPILER V8.09   TIMER_FUNCS                                                           03/13/2008 06:00:59 PAGE 2   

  55   1              {
  56   2                      timer_tick_500ms = 1;
  57   2              }
  58   1              if ( (timer_tick % 200) == 0 )
  59   1              {
  60   2                      timer_tick_5s = 1;
  61   2              }
  62   1      
  63   1              EA = 1;
  64   1      }
  65          
  66          
  67          void TIMER_Reset()
  68          {
  69   1              TR2 = 0;
  70   1              timer_tick = 0;
  71   1              TR2 = 1;
  72   1      }
  73          
  74          
  75          void TIMER_Start()
  76          {
  77   1              TR2 = 1;                                // 打开T2
  78   1      }
  79          void TIMER_Stop()
  80          { 
  81   1              TR2 = 0;
  82   1              timer_tick = 0;
  83   1      
  84   1              timer_hr = timer_set_hr;
  85   1              timer_min = timer_set_min;
  86   1              timer_sec = timer_set_sec;
  87   1      }
  88          void TIMER_Restart()
  89          {
  90   1              TIMER_Stop();
  91   1              TIMER_Start();                          // 打开T2
  92   1      }
  93          
  94          void TIMER_Pause()
  95          {
  96   1              TR2 = 0;                                // 打开T2
  97   1      }
  98          
  99          uint TIMER_Count()
 100          {
 101   1              uint t;
 102   1              t = timer_tick ;
 103   1              return t;
 104   1      }
 105          
 106          void CLOCK_Pause()
 107          {
 108   1              timer_clock_pause = 1;
 109   1      }
 110          
 111          void CLOCK_Start()
 112          {
 113   1              timer_clock_pause = 0;
 114   1      }
 115          
 116          void CLOCK_Stop()
C51 COMPILER V8.09   TIMER_FUNCS                                                           03/13/2008 06:00:59 PAGE 3   

 117          {
 118   1              timer_hr = timer_set_hr;
 119   1              timer_min = timer_set_min;
 120   1              timer_sec = timer_set_sec;
 121   1              timer_clock_pause = 1;
 122   1      }
 123          
 124          void CLOCK_Reset()
 125          {
 126   1              CLOCK_Stop();
 127   1              CLOCK_Start();
 128   1      }
 129          
 130          void CLOCK_Exp_Init()
 131          {
 132   1              flag_timer_exp_set = 0;
 133   1              flag_timer_exp_timeup = 0;
 134   1              timer_exp_clock_pause = 1;
 135   1      }
 136          
 137          void CLOCK_Exp_Pause()
 138          {
 139   1              timer_exp_clock_pause = 1;
 140   1      }
 141          
 142          void CLOCK_Exp_Start()
 143          {
 144   1              timer_exp_clock_pause = 0;
 145   1      }
 146          
 147          void CLOCK_Exp_Stop()
 148          {
 149   1              if (flag_timer_exp_set == 1)
 150   1              {
 151   2                      timer_exp_hr = timer_exp_set_hr;
 152   2                      timer_exp_min = timer_exp_set_min;
 153   2                      timer_exp_sec = timer_exp_set_sec;
 154   2              }
 155   1              timer_exp_clock_pause = 1;
 156   1      }
 157          
 158          void CLOCK_Exp_Reset()
 159          {
 160   1              CLOCK_Exp_Stop();
 161   1              CLOCK_Exp_Init();
 162   1      }
 163          
 164          void CLOCK_Set(ubyte hr, ubyte min, ubyte sec)
 165          {
 166   1      
 167   1              CLOCK_Stop();
 168   1      
 169   1              timer_set_hr = hr;
 170   1              timer_set_min = min;
 171   1              timer_set_sec = sec;
 172   1              timer_half = 0;
 173   1      
 174   1              timer_hr = timer_set_hr;
 175   1              timer_min = timer_set_min;
 176   1              timer_sec = timer_set_sec;
 177   1      }
 178          
C51 COMPILER V8.09   TIMER_FUNCS                                                           03/13/2008 06:00:59 PAGE 4   

 179          void CLOCK_Exp_Set(ubyte hr, ubyte min, ubyte sec)
 180          {
 181   1              CLOCK_Exp_Stop();
 182   1              
 183   1              timer_exp_set_hr = hr;
 184   1              timer_exp_set_min = min;
 185   1              timer_exp_set_sec = sec;
 186   1      
 187   1              timer_exp_hr = timer_exp_set_hr;
 188   1              timer_exp_min = timer_exp_set_min;
 189   1              timer_exp_sec = timer_exp_set_sec;
 190   1      
 191   1              flag_timer_exp_set = 1;
 192   1      
 193   1      
 194   1      }
 195          
 196          void UpdateClock()
 197          {
 198   1              if (timer_clock_pause == 1)
 199   1              {
 200   2                      return;
 201   2              }
 202   1              
 203   1              // The normal Clock
 204   1              if ( timer_half == 0 )
 205   1              {
 206   2                      timer_sec++;
 207   2                      if ( timer_sec == 60 )
 208   2                      {
 209   3                              timer_min++;
 210   3                              timer_sec = 0;
 211   3                      }
 212   2                      if ( timer_min == 60 ) 
 213   2                      {
 214   3                              timer_hr++;
 215   3                              timer_min = 0;
 216   3                      }
 217   2                      timer_half = 1;
 218   2              }
 219   1              else
 220   1              {
 221   2                      timer_half = 0;
 222   2              }
 223   1      
 224   1              // The Countdown clock for experiment
 225   1              if (timer_exp_clock_pause == 1)
 226   1              {
 227   2                      return;
 228   2              }
 229   1              if ( timer_half == 1 )
 230   1              {
 231   2                      timer_exp_sec--;
 232   2                      if ( timer_exp_sec == 0xff )
 233   2                      {
 234   3                              timer_exp_min--;
 235   3                              timer_exp_sec = 59;
 236   3                      }
 237   2                      if ( timer_exp_min == 0xff ) 
 238   2                      {
 239   3                              timer_exp_hr--;
 240   3                              timer_exp_min = 59;
C51 COMPILER V8.09   TIMER_FUNCS                                                           03/13/2008 06:00:59 PAGE 5   

 241   3                      }
 242   2                      if ( timer_exp_hr == 0xff )
 243   2                      {
 244   3                              timer_exp_min = 0;
 245   3                              timer_exp_sec = 0;
 246   3                              timer_exp_hr = 0;
 247   3                              flag_timer_exp_timeup = 1;
 248   3                      }
 249   2              }
 250   1      }
 251          
 252          
 253          void UpdateTimeDisplay( void )
 254          {
 255   1              if ( timer_exp_clock_pause == 0 )
 256   1              {
 257   2                      DIG_Update ( _7219_DIG0,        timer_exp_min / 10 );                                                                                                           
 258   2                      DIG_Update ( _7219_DIG1,        timer_exp_min % 10 );
 259   2                      DIG_Update ( _7219_DIG2,        timer_exp_sec / 10 );
 260   2                      DIG_Update ( _7219_DIG3,        (timer_half<<_7219_SEG_DP)|timer_exp_sec % 10 );
 261   2              }               
 262   1              else
 263   1              {
 264   2                      DIG_Update ( _7219_DIG0,        timer_min / 10 );                                                                                                               
 265   2                      DIG_Update ( _7219_DIG1,        timer_min % 10 );
 266   2                      DIG_Update ( _7219_DIG2,        timer_sec / 10 );
 267   2                      DIG_Update ( _7219_DIG3,        (timer_half<<_7219_SEG_DP)|timer_sec % 10 );
 268   2              }
 269   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    532    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      5    ----
   IDATA SIZE       =     12    ----
   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 + -