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

📄 switch_wait.lst

📁 Embedded C 这本书的范例光碟程式
💻 LST
字号:
C51 COMPILER V6.21  SWITCH_WAIT                                                            01/23/2002 17:24:57 PAGE 1   


C51 COMPILER V6.21, COMPILATION OF MODULE SWITCH_WAIT
OBJECT MODULE PLACED IN Switch_Wait.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE Switch_Wait.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             Switch_Wait.C (v1.00)
   4          
   5            ------------------------------------------------------------------
   6          
   7             Simple library for debouncing a switch input.
   8          
   9             NOTE: Duration of function is highly variable!
  10          
  11             COPYRIGHT
  12             ---------
  13          
  14             This code is associated with the book:
  15          
  16             EMBEDDED C by Michael J. Pont 
  17             [Pearson Education, 2002: ISBN: 0-201-79523-X].
  18          
  19             This code is copyright (c) 2001 by Michael J. Pont.
  20           
  21             See book for copyright details and other information.
  22          
  23          -*------------------------------------------------------------------*/
  24          
  25          #include "Main.H"
  26          #include "Port.H"
  27          
  28          #include "Switch_wait.h"
  29          #include "Delay_loop.h"
  30          
  31          /*------------------------------------------------------------------*-
  32          
  33            SWITCH_Init()
  34          
  35            Initialization function for the switch library.
  36          
  37          -*------------------------------------------------------------------*/
  38          void SWITCH_Init(void)
  39             {
  40   1         Switch_pin = 1; // Use this pin for input
  41   1         }
  42          
  43          /*------------------------------------------------------------------*-
  44            
  45            SWITCH_Get_Input()
  46          
  47            Reads and debounces a mechanical switch as follows:
  48          
  49            1. If switch is not pressed, return SWITCH_NOT_PRESSED.
  50          
  51            2. If switch is pressed, wait for DEBOUNCE_PERIOD (in ms).
  52               a. If switch is not pressed, return SWITCH_NOT_PRESSED. 
  53               b. If switch is pressed, wait (indefinitely) for
  54                  switch to be released, then return SWITCH_PRESSED
  55          
C51 COMPILER V6.21  SWITCH_WAIT                                                            01/23/2002 17:24:57 PAGE 2   

  56            See Switch_Wait.H for details of return values.
  57            
  58          -*------------------------------------------------------------------*/
  59          bit SWITCH_Get_Input(const tByte DEBOUNCE_PERIOD)
  60             {
  61   1         bit Return_value = SWITCH_NOT_PRESSED;
  62   1      
  63   1         if (Switch_pin == 0)
  64   1            {
  65   2            // Switch is pressed
  66   2            
  67   2            // Debounce - just wait...
  68   2            DELAY_LOOP_Wait(DEBOUNCE_PERIOD);
  69   2      
  70   2            // Check switch again
  71   2            if (Switch_pin == 0)
  72   2               {
  73   3               // Wait until the switch is released.
  74   3               while (Switch_pin == 0);
  75   3               Return_value = SWITCH_PRESSED;
  76   3               }
  77   2            }
  78   1         
  79   1         // Now (finally) return switch value
  80   1         return Return_value;
  81   1         }
  82          
  83          /*------------------------------------------------------------------*-
  84            ---- END OF FILE -------------------------------------------------
  85          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     24    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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