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

📄 upsd_timer.lst

📁 TI公司的增强型8位单片机upsd32xx系列芯片
💻 LST
字号:
C51 COMPILER V7.06   UPSD_TIMER                                                            10/13/2004 10:12:16 PAGE 1   


C51 COMPILER V7.06, 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

stmt level    source

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

  56   1        TR0 = 1;                              /* start timer 0 */
  57   1      
  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      
  71   1        timer0_tick = 0;
  72   1      
  73   1        TR0 = 0;                      /* stop timer 0 */
  74   1      
  75   1        TMOD &= 0xF0;                 /* clear timer 0 mode bits - bottom 4 bits */
  76   1        TMOD |= 0x01;                 /* put timer 0 into 16-bit no prescale */
  77   1      
  78   1        // Calculate timer tollover based on FREQ_OSC to be 10ms periods (100hz)
  79   1        timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);
  80   1      
  81   1        TL0 = (timer0_value & 0x00FF);
  82   1        TH0 = (timer0_value >> 8);
  83   1        //TL0 = 0XFF;
  84   1        //TH0 = 0XFF;
  85   1        PT0 = 1;                      /* set high priority for timer 0 */
  86   1        ET0 = 1;                      /* enable timer 0 interrupt */
  87   1      
  88   1        TR0 = 1;                      /* start timer 0 */
  89   1      
  90   1        EA = 1;                       /* enable interrupts */
  91   1      }
  92          
  93          
  94          /*------------------------------------------------------------------------------
  95          unsigned int timer0_count (void);
  96          
  97          This function returns the current timer0 tick count.
  98          ------------------------------------------------------------------------------*/
  99          unsigned int timer0_count (void)
 100          {
 101   1        unsigned int t;
 102   1      
 103   1        EA = 0;                               // disable ints so we cna read steady value
 104   1        t = timer0_tick;
 105   1        EA = 1;                               // enable
 106   1        return(t);
 107   1      }
 108          
 109          
 110          /*------------------------------------------------------------------------------
 111          void timer0_delay (
 112            unsigned count);
 113          
 114          This function waits for 'count' timer ticks to pass.
 115          ------------------------------------------------------------------------------*/
 116          void timer0_delay (unsigned int count)
 117          {
C51 COMPILER V7.06   UPSD_TIMER                                                            10/13/2004 10:12:16 PAGE 3   

 118   1      unsigned int start_count;
 119   1      
 120   1      start_count = timer0_count(); /* get the start count */
 121   1      
 122   1      while ((timer0_count() - start_count) <= count)   /* wait for count "ticks" */
 123   1        {
 124   2        }
 125   1      }
 126          
 127          
 128          void delay_10ms()               
 129                  { 
 130   1              //timer0_delay(1);
 131   1             int i;
 132   1             for(i=0;i<5;i++){;}
 133   1              }
 134          
 135          void delay_1sec(void)
 136                  {
 137   1              //timer0_delay(100);
 138   1             int i;
 139   1             for(i=0;i<100;i++){delay_10ms();}
 140   1              }
 141          
 142          void delay_2sec(void)
 143                  {
 144   1          //delay_1sec();
 145   1          //delay_1sec();
 146   1             int i;
 147   1             for(i=0;i<200;i++){delay_10ms();}
 148   1              }
 149          /*
 150          void delay_10sec(void)
 151                  {
 152              delay_2sec();
 153              delay_2sec();
 154              delay_2sec();
 155              delay_2sec();
 156              delay_2sec();
 157                  }
 158          
 159          void delay_0_5sec(void)
 160                  {
 161                  timer0_delay(50);
 162              }
 163          
 164          void delay_0_1sec(void)
 165                  {
 166                  timer0_delay(10);
 167             }
 168          */
 169          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    163    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      2    ----
   IDATA SIZE       =      2    ----
   BIT SIZE         =   ----    ----
C51 COMPILER V7.06   UPSD_TIMER                                                            10/13/2004 10:12:16 PAGE 4   

END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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