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

📄 pulcnt_h.lst

📁 时间触发嵌入式系统设计模式:使用8051系列微控制器开发可靠应用
💻 LST
字号:
C51 COMPILER V6.10  PULCNT_H                                                               04/19/2001 11:58:05 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE PULCNT_H
OBJECT MODULE PLACED IN .\PULCNT_H.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\PULCNT_H.C BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             PulCnt_H.C (v1.10)
   4          
   5            ------------------------------------------------------------------
   6          
   7             Hardware pulse-count library (see Chapter 30).
   8          
   9          
  10             COPYRIGHT
  11             ---------
  12          
  13             This code is from the book:
  14          
  15             PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
  16             [Pearson Education, 2001; ISBN: 0-201-33138-1].
  17          
  18             This code is copyright (c) 2001 by Michael J. Pont.
  19           
  20             See book for copyright details and other information.
  21          
  22          -*------------------------------------------------------------------*/
  23          
  24          #include "Main.h"
  25          #include "Port.h"
  26          
  27          #include "Bargraph.h"
  28          
  29          #include "PulCnt_H.h"
  30          
  31          // ------ Public variable declarations -----------------------------
  32          
  33          // Global count variable - stores the latest count value
  34          extern tBargraph Count_G;
  35          
  36          /*------------------------------------------------------------------*-
  37          
  38            PC_HARD_Init_T0()
  39          
  40            Prepare for 'Hardware Pulse Count' using Timer 0.
  41          
  42          -*------------------------------------------------------------------*/
  43          void PC_HARD_Init_T0(void)
  44             {
  45   1         // Timer 0 used as 16-bit timer, counting pulses 
  46   1         // (falling edges) on Pin 3.4 (T0 pin)
  47   1         TMOD &= 0xF0;      // Clear all T0 bits (T1 left unchanged)
  48   1         TMOD |= 0x05;      // Set required T0 bits (T1 left unchanged) 
  49   1         
  50   1         TH0 = 0; TL0 = 0;  // Set timer count to 0
  51   1         Count_G = 0;       // Set global count to 0
  52   1      
  53   1         TR0 = 1;           // Start the counter
  54   1         }
  55          
C51 COMPILER V6.10  PULCNT_H                                                               04/19/2001 11:58:05 PAGE 2   

  56          /*------------------------------------------------------------------*-
  57          
  58            PC_HARD_Get_Count_T0()
  59          
  60            Schedule this function at regular intervals.
  61          
  62            Remember: max count is 65536 (16-bit counter)
  63            - it is your responsibility to ensure this count
  64            is not exceeded.  Choose an appropriate schedule
  65            interval and allow a margin for error.
  66          
  67            For high-frequency pulses, you need to take account of
  68            the fact that the count is stopped for a (very brief) period,
  69            to read the counter.  
  70          
  71            Note: the delay before the first count is taken should 
  72            generally be the same as the inter-count interval,
  73            to ensure that the first count is as accurate as possible.
  74          
  75            For example, this is OK:
  76          
  77              Sch_Add_Task(PC_HARD_Get_Count_T0, 1000, 1000);
  78          
  79            While this will give a very low first count:
  80          
  81             Sch_Add_Task(PC_HARD_Get_Count_T0, 10, 1000);
  82          
  83          -*------------------------------------------------------------------*/
  84          void PC_HARD_Get_Count_T0(void)
  85             {
  86   1         TR0 = 0; // Stop counter
  87   1      
  88   1         Count_G = (TH0 << 8) + TL0;  // Read count
  89   1      
  90   1         TH0 = 0; TL0 = 0;            // Reset count
  91   1      
  92   1         if (TF0 == 1)
  93   1            {
  94   2            // Timer has overflowed 
  95   2            // - pulse frequency too high 
  96   2            // - or schedule rate too low
  97   2            
  98   2            // We code this error as a 'max count'
  99   2            // - could also set a global error flag, if required
 100   2            Count_G = 65535;
 101   2            TF0 = 0;
 102   2            }
 103   1      
 104   1         TR0 = 1; // Restart counter
 105   1         }
 106          
 107          /*------------------------------------------------------------------*-
 108            ---- END OF FILE -------------------------------------------------
 109          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     55    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
C51 COMPILER V6.10  PULCNT_H                                                               04/19/2001 11:58:05 PAGE 3   

   IDATA SIZE       =   ----    ----
   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 + -