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

📄 upsd3300_timer.lst

📁 增强型8位单片机upsd33xx系列芯片PWM结合ADC例程
💻 LST
字号:
C51 COMPILER V7.50   UPSD3300_TIMER                                                        07/11/2005 15:30:31 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE UPSD3300_TIMER
OBJECT MODULE PLACED IN upsd3300_timer.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\C51.EXE upsd3300_timer.c OPTIMIZE(9,SIZE) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*------------------------------------------------------------------------------
   2          upsd3300_timer.c
   3          
   4          Version:
   5          November 2, 2004 - commented out functions not used by the PWM_ADC example
   6          to reduce the total code size of the demo.
   7          
   8          August 2004 Ver 2.0 - Updated include file names, modified comments.
   9          
  10          Dependencies:
  11          FREQ_OSC - used to set up timer properly.  
  12          FREQ_OSC is specified in upsd3300_hardware.h and must be defined
  13          Timer0 ISR makes use of Register Set 1.
  14          
  15          Description:
  16          uPSD3300 Timer 0 device driver functions.  This function sets
  17          up timer 0 as a timer used to count 10ms periods used to
  18          delay and timing functions.
  19          
  20          
  21          Copyright (c) 2004 STMicroelectronics Inc.
  22          
  23          This example demo code is provided as is and has no warranty,
  24          implied or otherwise.  You are free to use/modify any of the provided
  25          code at your own risk in your applications with the expressed limitation
  26          of liability (see below) so long as your product using the code contains
  27          at least one uPSD product (device).
  28          
  29          LIMITATION OF LIABILITY:   NEITHER STMicroelectronics NOR ITS VENDORS OR 
  30          AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
  31          INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
  32          CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
  33          OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  34          ------------------------------------------------------------------------------*/
  35          
  36          #include "upsd3300.h"
  37          #include "upsd3300_hardware.h"
  38          #include "upsd3300_timer.h"
  39          
  40          /*------------------------------------------------------------------------------
  41                        Global Variable Declarations
  42          ------------------------------------------------------------------------------*/
  43          static unsigned int idata timer0_tick;
  44          static unsigned int idata timer0_value;
  45          
  46          /*------------------------------------------------------------------------------
  47          timer0_isr()
  48          
  49          This function is an interrupt service routine for TIMER 0.  It should never
  50          be called by a C or assembly function.  It will be executed automatically
  51          when TIMER 0 overflows.
  52          
  53          This ISR stops timer0, adjusts the counter so that another interrupt occurs in
  54          10ms, and then restarts the timer.
  55          ------------------------------------------------------------------------------*/
C51 COMPILER V7.50   UPSD3300_TIMER                                                        07/11/2005 15:30:31 PAGE 2   

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

 118   1      
 119   1          start_count = timer0_count(); /* get the start count */
 120   1      
 121   1          while ((timer0_count() - start_count) <= count)   /* wait for count "ticks" */
 122   1          {
 123   2              PCON |= 0x01;    // Idle MCU to wait for timer tick
 124   2          }
 125   1      }
 126          
 127          
 128          /*------------------------------------------------------------------------------
 129          delay_10ms ();
 130          
 131          This is a 10 ms delay function.
 132          ------------------------------------------------------------------------------*/
 133          void delay_10ms()
 134          {
 135   1          timer0_delay(1);
 136   1      }
 137          
 138          /*------------------------------------------------------------------------------
 139          delay_1sec ();
 140          
 141          This is a 1 second delay function.
 142          ------------------------------------------------------------------------------*/
 143          void delay_1sec(void)
 144          {
 145   1          timer0_delay(100);
 146   1      }
 147          
 148          /*------------------------------------------------------------------------------
 149          delay_2sec ();
 150          
 151          This is a 2 second delay function.
 152          ------------------------------------------------------------------------------*/
 153          /*
 154          void delay_2sec(void)
 155          {
 156              delay_1sec();
 157              delay_1sec();
 158          }
 159          */
 160          /*------------------------------------------------------------------------------
 161          delay_10sec ();
 162          
 163          This is a 10 second delay function.
 164          ------------------------------------------------------------------------------*/
 165          /*
 166          void delay_10sec(void)
 167          {
 168              delay_2sec();
 169              delay_2sec();
 170              delay_2sec();
 171              delay_2sec();
 172              delay_2sec();
 173          }
 174          */
 175          /*------------------------------------------------------------------------------
 176          delay_0_5sec ();
 177          
 178          This is a 0.5 second delay function.
 179          ------------------------------------------------------------------------------*/
C51 COMPILER V7.50   UPSD3300_TIMER                                                        07/11/2005 15:30:31 PAGE 4   

 180          /*
 181          void delay_0_5sec(void)
 182          {
 183              timer0_delay(50);
 184          }
 185          */
 186          /*------------------------------------------------------------------------------
 187          delay0_1sec ();
 188          
 189          This is a 0.1 second delay function.
 190          ------------------------------------------------------------------------------*/
 191          /*
 192          void delay_0_1sec(void)
 193          {
 194              timer0_delay(10);
 195          }
 196          */


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