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

📄 swit_d.lst

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


C51 COMPILER V6.10, COMPILATION OF MODULE SWIT_D
OBJECT MODULE PLACED IN .\SWIT_D.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\SWIT_D.C OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             SWIT_D.C (v1.00)
   4           
   5            ------------------------------------------------------------------
   6          
   7             4-state switch interface code, with software debounce.
   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 "Swit_D.h"
  28          
  29          
  30          // ------ Public variables -----------------------------------------
  31          
  32          tByte Sw_status_G; // The current switch status
  33          
  34          // ------ Private constants ----------------------------------------
  35          
  36          // SW_THRES must be > 1 for correct debounce behaviour
  37          #define SW_THRES (1)
  38          #define SW_THRES_X2 (SW_THRES + SW_THRES + SW_THRES + SW_THRES)
  39          #define SW_THRES_X3 (SW_THRES_X2 + SW_THRES_X2)
  40          
  41          // Allows NO or NC switch to be used (or other wiring variations)
  42          #define SW_PRESSED (0)
  43          
  44          // ------ Private variables ----------------------------------------
  45          
  46          static tByte Sw_press_duration_G = 0;
  47          
  48          
  49          /*------------------------------------------------------------------*-
  50          
  51            SWITCH_MS_Init()
  52          
  53            Initialisation function for the switch library.
  54           
  55          -*------------------------------------------------------------------*/
C51 COMPILER V6.10  SWIT_D                                                                 04/19/2001 10:29:51 PAGE 2   

  56          void SWITCH_MS_Init(void)
  57             {
  58   1         Sw_pin = 1; // Use this pin for input
  59   1      
  60   1         Sw_status_G = 0;  // Switch is initially OFF
  61   1         Sw_press_duration_G = 0;  
  62   1         }
  63          
  64          /*------------------------------------------------------------------*-
  65          
  66            SWITCH_MS_Update()
  67            
  68            This is the main switch function.  It should be scheduled every
  69            50 - 500 ms.
  70          
  71            Alters Sw_press_duration_G depending on duration of switch press.
  72          
  73          -*------------------------------------------------------------------*/
  74          void SWITCH_MS_Update(void)
  75             {
  76   1         if (Sw_pin == SW_PRESSED)
  77   1            {
  78   2            Sw_press_duration_G += 1;
  79   2      
  80   2            if (Sw_press_duration_G > (SW_THRES_X3))
  81   2               {
  82   3               Sw_press_duration_G = SW_THRES_X3;
  83   3               Sw_status_G = 3;  // Switch has been pressed for a long time...
  84   3               return;
  85   3               } 
  86   2      
  87   2            if (Sw_press_duration_G > (SW_THRES_X2))
  88   2               {
  89   3               Sw_status_G = 2;  // Switch has been pressed for a medium time...
  90   3               return;
  91   3               }
  92   2          
  93   2            // SW_THRES must be > 1 for software debounce  
  94   2            if (Sw_press_duration_G > SW_THRES)
  95   2               {
  96   3               Sw_status_G = 1;  // Switch has been pressed for a short time...
  97   3               return;
  98   3               }
  99   2      
 100   2            // switch pressed, but not yet for long enough
 101   2            Sw_status_G = 0; 
 102   2            return; 
 103   2            }
 104   1          
 105   1         // Switch not pressed - reset the count
 106   1         Sw_press_duration_G = 0;
 107   1         Sw_status_G = 0;  // Switch not pressed...
 108   1         }
 109          
 110          /*------------------------------------------------------------------*-
 111            ---- END OF FILE -------------------------------------------------
 112          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     59    ----
   CONSTANT SIZE    =   ----    ----
C51 COMPILER V6.10  SWIT_D                                                                 04/19/2001 10:29:51 PAGE 3   

   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      2    ----
   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 + -