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

📄 timer.lst

📁 upsd 3200序列的usb驱动
💻 LST
字号:
C51 COMPILER V7.00 Beta 6  TIMER                                                           02/19/2003 15:59:28 PAGE 1   


C51 COMPILER V7.00 Beta 6, 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          
   5          /*---------------------------------------------------------------------------
   6          Copyright (c) 2002 ST Microelectronics
   7          This example demo code is provided as is and has no warranty,
   8          implied or otherwise.  You are free to use/modify any of the provided
   9          code at your own risk in your applications with the expressed limitation
  10          of liability (see below) so long as your product using the code contains
  11          at least one uPSD products (device).
  12          
  13          LIMITATION OF LIABILITY:   NEITHER STMicroelectronics NOR ITS VENDORS OR 
  14          AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
  15          INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
  16          CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
  17          OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  18          --------------------------------------------------------------------------*/
  19          
  20          #include "upsd_cfg.h"
  21          #include "upsd3200.h"
  22          #include "timer_func.h"
  23          
  24          /*------------------------------------------------------------------------------
  25                           Local Macro and Manifest Constant Declarations
  26          ------------------------------------------------------------------------------*/
  27          #define INT_DISABLE     EA = 0
  28          #define INT_ENABLE      EA = 1
  29          
  30          #define TIMER0_COUNT    (0-((OSC/(12*TIMER0_PERIOD))-17))
  31          //#define TIMER0_COUNT   0xdb62     /* 10000h - ((16 Mhz / (12 * FREQ)) - 17)  */
  32                                              /*  16Mhz = 0xcbfc           100hz        */
  33                                                                  /*  12mHZ = 0xd8ff                        */
  34                                                                          /*  11.059Mhz =  0xdb62      */
  35                                                                                  /*   6Mhz = 0xec89    */
  36          
  37          /*------------------------------------------------------------------------------
  38                                    Local Variable Declarations
  39          ------------------------------------------------------------------------------*/
  40          
  41          static idata unsigned int timer0_tick;
  42          
  43          /*------------------------------------------------------------------------------
  44          static void timer0_isr (void);
  45          
  46          This function is an interrupt service routine for TIMER 0.  It should never
  47          be called by a C or assembly function.  It will be executed automatically
  48          when TIMER 0 overflows.
  49          ------------------------------------------------------------------------------*/
  50          static void timer0_isr (void) interrupt TF0_VECTOR using 1
  51          {
  52   1      
  53   1      /*------------------------------------------------
  54   1      Adjust the timer 0 counter so that we get another 
  55   1      interrupt in 10ms.
C51 COMPILER V7.00 Beta 6  TIMER                                                           02/19/2003 15:59:28 PAGE 2   

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

 118          ------------------------------------------------------------------------------*/
 119          unsigned int timer0_elapsed_count (unsigned int count)
 120          {
 121   1      return (timer0_count () - count);
 122   1      }
 123          
 124          /*------------------------------------------------------------------------------
 125          This function waits for 'count' timer ticks to pass.
 126          ------------------------------------------------------------------------------*/
 127          void timer0_wait (unsigned int count)
 128          {
 129   1      unsigned int start_count;
 130   1      
 131   1              start_count = timer0_count ();
 132   1      
 133   1              while (timer0_elapsed_count (start_count) <= count)
 134   1              {
 135   2              //
 136   2              }
 137   1      }
 138          
 139          /*------------------------------------------------------------------------------
 140          ------------------------------------------------------------------------------*/
 141          
 142           
 143          
 144          


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 + -