?? switch_wait_timeoutl.lst
字號:
C51 COMPILER V7.06 SWITCH_WAIT_TIMEOUTL 12/16/2004 10:23:59 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE SWITCH_WAIT_TIMEOUTL
OBJECT MODULE PLACED IN Switch_Wait_TimeoutL.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE Switch_Wait_TimeoutL.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 Switch_Wait_TimeoutL.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 Simple library for processing a switch input.
8
9 (Made more reliable by means of a ~10-second timeout.)
10
11
12 COPYRIGHT
13 ---------
14
15 This code is associated with the book:
16
17 EMBEDDED C by Michael J. Pont
18 [Pearson Education, 2002: ISBN: 0-201-79523-X].
19
20 This code is copyright (c) 2001 by Michael J. Pont.
21
22 See book for copyright details and other information.
23
24 -*------------------------------------------------------------------*/
25
26 #include "Main.H"
27 #include "Port.H"
28
29 #include "Switch_wait_TimeoutL.H"
30 #include "Delay_T0.h"
31 #include "TimeoutL.H"
32
33 /*------------------------------------------------------------------*-
34
35 SWITCH_Init()
36
37 Initialization function for the switch library.
38
39 -*------------------------------------------------------------------*/
40 void SWITCH_Init(void)
41 {
42 1 Switch_pin = 1; // Use this pin for input
43 1 }
44
45 /*------------------------------------------------------------------*-
46
47 SWITCH_Get_Input()
48
49 Reads and debounces a mechanical switch as follows:
50
51 1. If switch is not pressed, return SWITCH_NOT_PRESSED.
52
53 2. If switch is pressed, wait for DEBOUNCE_PERIOD (in ms).
54 a. If switch is not pressed, return SWITCH_NOT_PRESSED.
55 b. If switch is pressed, wait (with timeout) for
C51 COMPILER V7.06 SWITCH_WAIT_TIMEOUTL 12/16/2004 10:23:59 PAGE 2
56 switch to be released. If it times out,
57 then return SWITCH_NOT_PRESSED: otherwise, return
58 SWITCH_PRESSED.
59
60 See Switch_Wait.H for details of return values.
61
62 -*------------------------------------------------------------------*/
63 bit SWITCH_Get_Input(const tByte DEBOUNCE_PERIOD)
64 {
65 1 bit Return_value = SWITCH_NOT_PRESSED;
66 1 tLong Timeout_loop = LOOP_TIMEOUT_INIT_10000ms;
67 1
68 1 if (Switch_pin == 0)
69 1 {
70 2 // Switch is pressed
71 2
72 2 // Debounce - just wait...
73 2 DELAY_T0_Wait(DEBOUNCE_PERIOD);
74 2
75 2 // Check switch again
76 2 if (Switch_pin == 0)
77 2 {
78 3 // Wait until the switch is released.
79 3 // (WITH TIMEOUT LOOP - 10 seconds)
80 3 while ((Switch_pin == 0) && (++Timeout_loop != 0));
81 3
82 3 // Check for timeout
83 3 if (Timeout_loop == 0)
84 3 {
85 4 Return_value = SWITCH_NOT_PRESSED;
86 4 }
87 3 if(Switch_pin == 1)
88 3 {
89 4 Return_value = SWITCH_PRESSED;
90 4 }
91 3 }
92 2 }
93 1
94 1 // Now (finally) return switch value
95 1 return Return_value;
96 1 }
97
98 /*------------------------------------------------------------------*-
99 ---- END OF FILE -------------------------------------------------
100 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 78 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
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 + -