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

📄 timer.lst

📁 ST公司的upsd34XX评估板固定源程序
💻 LST
字号:
C51 COMPILER V7.06   TIMER                                                                 10/10/2004 20:51:47 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE TIMER
OBJECT MODULE PLACED IN timer.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE timer.c LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------------------
   2          TIMER.C:  Timer tick routines.
   3          
   4          Copyright 1995-1996 Keil Software, Inc.
   5          ------------------------------------------------------------------------------*/
   6          
   7          #include "upsd_cfg.h"
   8          
   9          #include "upsd.h"                               // SFRs
  10          #include "upsd_xreg.h"                  // extended registers in uPSD
  11          
  12          #include "timer_func.h"
  13          
  14          /*------------------------------------------------------------------------------
  15                           Local Macro and Manifest Constant Declarations
  16          ------------------------------------------------------------------------------*/
  17          #define INT_DISABLE     EA = 0
  18          #define INT_ENABLE      EA = 1
  19          
  20          #define TIMER0_COUNT    (0-((OSC/(12*TIMER0_PERIOD))-17))
  21          //#define TIMER0_COUNT   0xdb62     /* 10000h - ((16 Mhz / (12 * FREQ)) - 17)  */
  22                                              /*  16Mhz = 0xcbfc           100hz        */
  23                                                                  /*  12mHZ = 0xd8ff                        */
  24                                                                          /*  11.059Mhz =  0xdb62      */
  25                                                                                  /*   6Mhz = 0xec89    */
  26          
  27          /*------------------------------------------------------------------------------
  28                                    Local Variable Declarations
  29          ------------------------------------------------------------------------------*/
  30          
  31          static idata unsigned int timer0_tick;
  32          
  33          /*------------------------------------------------------------------------------
  34          static void timer0_isr (void);
  35          
  36          This function is an interrupt service routine for TIMER 0.  It should never
  37          be called by a C or assembly function.  It will be executed automatically
  38          when TIMER 0 overflows.
  39          ------------------------------------------------------------------------------*/
  40          static void timer0_isr (void) interrupt TF0_VECTOR using 1
  41          {
  42   1      
  43   1      /*------------------------------------------------
  44   1      Adjust the timer 0 counter so that we get another 
  45   1      interrupt in 10ms.
  46   1      ------------------------------------------------*/
  47   1              TR0 = 0;                                /* stop timer 0 */
  48   1      
  49   1              TL0 = TL0 + (TIMER0_COUNT & 0x00FF);
  50   1              TH0 = TH0 + (TIMER0_COUNT >> 8);
  51   1      
  52   1              TR0 = 1;                                /* start timer 0 */
  53   1      
  54   1      /*------------------------------------------------
  55   1      Increment the timer tick.  This interrupt should
C51 COMPILER V7.06   TIMER                                                                 10/10/2004 20:51:47 PAGE 2   

  56   1      occur approximately every 10ms. So, the resulotion
  57   1      of the timer will be 100Hz not including interrupt
  58   1      latency.
  59   1      ------------------------------------------------*/
  60   1              timer0_tick++;
  61   1      
  62   1              do_timer0();
  63   1      }
  64          
  65          /*------------------------------------------------------------------------------
  66          This function enables TIMER 0.  TIMER 0 will generate a synchronous interrupt
  67          once every 1kHz.
  68          ------------------------------------------------------------------------------*/
  69          void timer0_initialize (void)
  70          {
  71   1              INT_DISABLE;                    /* disable interrupts */
  72   1      
  73   1              timer0_tick = 0;
  74   1      
  75   1              TR0 = 0;                                /* stop timer 0 */
  76   1      
  77   1              TMOD &= ~0x0F;                  /* clear timer 0 mode bits */
  78   1              TMOD |= 0x01;                   /* put timer 0 into 16-bit no prescale */
  79   1      
  80   1              TL0 = (TIMER0_COUNT & 0x00FF);
  81   1              TH0 = (TIMER0_COUNT >> 8);
  82   1      
  83   1              PT0 = 0;                        /* set low priority for timer 0 */
  84   1              ET0 = 1;                        /* enable timer 0 interrupt */
  85   1      
  86   1              TR0 = 1;                        /* start timer 0 */
  87   1      
  88   1              INT_ENABLE;                     /* enable interrupts */
  89   1      }
  90          
  91          /*------------------------------------------------------------------------------
  92          This function returns the current timer0 tick count.
  93          ------------------------------------------------------------------------------*/
  94          unsigned int timer0_count (void)
  95          {
  96   1      unsigned int t;
  97   1      
  98   1              INT_DISABLE;
  99   1              t = timer0_tick;
 100   1              INT_ENABLE;
 101   1      
 102   1      return (t);
 103   1      }
 104          
 105          /*------------------------------------------------------------------------------
 106          This function returns the number of timer ticks that have elapsed since the
 107          specified count.
 108          ------------------------------------------------------------------------------*/
 109          unsigned int timer0_elapsed_count (unsigned int count)
 110          {
 111   1      return (timer0_count () - count);
 112   1      }
 113          
 114          /*------------------------------------------------------------------------------
 115          This function waits for 'count' timer ticks to pass.
 116          ------------------------------------------------------------------------------*/
 117          void timer0_wait (unsigned int count)
C51 COMPILER V7.06   TIMER                                                                 10/10/2004 20:51:47 PAGE 3   

 118          {
 119   1      unsigned int start_count;
 120   1      
 121   1              start_count = timer0_count ();
 122   1      
 123   1              while (timer0_elapsed_count (start_count) <= count)
 124   1              {
 125   2              //
 126   2              }
 127   1      }
 128          
 129          /*------------------------------------------------------------------------------
 130          ------------------------------------------------------------------------------*/
 131          
 132           
 133          
 134          


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