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

📄 upsd_timer.lst

📁 Demo for I2C Master and Slave
💻 LST
字号:
C51 COMPILER V7.20   UPSD_TIMER                                                            07/21/2004 16:31:42 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE UPSD_TIMER
OBJECT MODULE PLACED IN upsd_timer.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE upsd_timer.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*------------------------------------------------------------------------
   2          uPSD_timer.c
   3          
   4          Version:
   5          June 2004, Version 1.1 - Comments edited.
   6          
   7          Description:
   8          The uPSD3200 timer counter.
   9          
  10          Dependencies:
  11          FREQ_OSC (from upsd_hardware.h) - used in the calculation that
  12          determines the appropriate setting for Timer 0.
  13          
  14          
  15          Copyright (c) 2004 ST Microelectronics
  16          
  17          This example demo code is provided as is and has no warranty,
  18          implied or otherwise.  You are free to use/modify any of the provided
  19          code at your own risk in your applications with the expressed limitation
  20          of liability (see below) so long as your product using the code contains
  21          at least one uPSD products (device).
  22          
  23          LIMITATION OF LIABILITY:   NEITHER STMicroelectronics NOR ITS VENDORS OR 
  24          AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
  25          INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
  26          CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
  27          OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  28          -------------------------------------------------------------------------*/
  29          #pragma optimize(8,size)
  30          
  31          #include "upsd3200.h"
  32          #include "upsd_hardware.h"
  33          #include "upsd_timer.h"
  34          
  35          /*------------------------------------------------------------------------------
  36                                    Local Variable Declarations
  37          ------------------------------------------------------------------------------*/
  38          static unsigned int idata timer0_tick;
  39          unsigned int timer0_value;
  40          
  41          /*------------------------------------------------------------------------------
  42          static void timer0_isr (void);
  43          
  44          This function is an interrupt service routine for TIMER 0.  It should never
  45          be called by a C or assembly function.  It will be executed automatically
  46          when TIMER 0 overflows.
  47          ------------------------------------------------------------------------------*/
  48          static void timer0_isr (void) interrupt TF0_VECTOR using 1
  49          {
  50   1      /*------------------------------------------------
  51   1      Stop timer, adjust the timer 0 counter so that we get another
  52   1      interrupt in 10ms, and restart the timer.
  53   1      ------------------------------------------------*/
  54   1        TR0 = 0;                                              /* stop timer 0 */
  55   1        TL0 = (timer0_value & 0x00FF);
C51 COMPILER V7.20   UPSD_TIMER                                                            07/21/2004 16:31:42 PAGE 2   

  56   1        TH0 = (timer0_value >> 8);
  57   1        TR0 = 1;                                              /* start timer 0 */
  58   1        timer0_tick++;                                // Increment global var timer_tick (number of 10ms ticks)
  59   1      }
  60          
  61          /*------------------------------------------------------------------------------
  62          void timer0_init(void);
  63          
  64          This function enables TIMER 0.  TIMER 0 will generate a synchronous interrupt
  65          once every 100Hz.
  66          ------------------------------------------------------------------------------*/
  67          void timer0_init (void)
  68          {
  69   1              EA = 0;                                 /* disable interrupts */
  70   1              timer0_tick = 0;
  71   1              TR0 = 0;                                /* stop timer 0 */
  72   1              TMOD &= 0xF0;                   /* clear timer 0 mode bits - bottom 4 bits */
  73   1              TMOD |= 0x01;                   /* put timer 0 into 16-bit no prescale */
  74   1      
  75   1              // Calculate timer tollover based on FREQ_OSC to be 10ms periods (100hz)
  76   1              timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);
  77   1              TL0 = (timer0_value & 0x00FF);
  78   1              TH0 = (timer0_value >> 8);
  79   1      
  80   1              PT0 = 1;                                /* set high priority for timer 0 */
  81   1              ET0 = 1;                                /* enable timer 0 interrupt */
  82   1              TR0 = 1;                                /* start timer 0 */
  83   1              EA = 1;                                 /* enable interrupts */
  84   1      }
  85          
  86          
  87          /*------------------------------------------------------------------------------
  88          unsigned int timer0_count (void);
  89          
  90          This function returns the current timer0 tick count.
  91          ------------------------------------------------------------------------------*/
  92          unsigned int timer0_count (void)
  93          {
  94   1        unsigned int t;
  95   1      
  96   1        EA = 0;                               // disable ints so we cna read steady value
  97   1        t = timer0_tick;
  98   1        EA = 1;                               // enable
  99   1        return(t);
 100   1      }
 101          
 102          
 103          /*------------------------------------------------------------------------------
 104          void timer0_delay (
 105            unsigned count);
 106          
 107          This function waits for 'count' timer ticks to pass.
 108          ------------------------------------------------------------------------------*/
 109          void timer0_delay (unsigned int count)
 110          {
 111   1      unsigned int start_count;
 112   1      
 113   1      start_count = timer0_count(); /* get the start count */
 114   1      
 115   1      while ((timer0_count() - start_count) <= count)   /* wait for count "ticks" */
 116   1        {
 117   2        }
C51 COMPILER V7.20   UPSD_TIMER                                                            07/21/2004 16:31:42 PAGE 3   

 118   1      }
 119          
 120          
 121          void delay_10ms()               
 122                  { 
 123   1              timer0_delay(1);
 124   1              }
 125          
 126          void delay_1sec(void)
 127                  {
 128   1              timer0_delay(100);
 129   1              EA=0;
 130   1              }
 131          
 132          void delay_2sec(void)
 133                  {
 134   1          delay_1sec();
 135   1          delay_1sec();
 136   1              }
 137          
 138          


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