📄 swit_c.lst
字号:
C51 COMPILER V6.10 SWIT_C 04/18/2001 16:15:53 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE SWIT_C
OBJECT MODULE PLACED IN .\SWIT_C.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\SWIT_C.C OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 SWIT_C.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 On-Off Switch 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_C.h"
28
29 // ------ Public variable definitions ------------------------------
30
31 bit Sw_pressed_G = 0; // The current switch status
32
33
34 // ------ Private constants ----------------------------------------
35
36 // Allows NO or NC switch to be used (or other wiring variations)
37 #define SW_PRESSED (0)
38
39 // SW_THRES must be > 1 for correct debounce behaviour
40 #define SW_THRES (3)
41
42 // ------ Private variables ----------------------------------------
43
44 static tByte Sw_press_duration_G = 0;
45 static tByte Sw_blocked_G = 0;
46
47
48 /*------------------------------------------------------------------*-
49
50 FUNCTION: SWITCH_ON_OFF_Init()
51
52 Initialisation function for the switch library.
53
54 -*------------------------------------------------------------------*/
55 void SWITCH_ON_OFF_Init(void)
C51 COMPILER V6.10 SWIT_C 04/18/2001 16:15:53 PAGE 2
56 {
57 1 Sw_pin = 1; // Use this pin for input
58 1
59 1 Sw_pressed_G = 0; // Switch is initially OFF
60 1 Sw_press_duration_G = 0;
61 1 Sw_blocked_G = 0;
62 1 }
63
64 /*------------------------------------------------------------------*-
65
66 FUNCTION: SWITCH_ON_OFF_Update()
67
68 This is the main on-off switch function.
69
70 It should be scheduled every 50 - 500 ms.
71
72 -*------------------------------------------------------------------*/
73 void SWITCH_ON_OFF_Update(void)
74 {
75 1 // If the switch is blocked, decrement the count and return
76 1 // without checking the switch pin status.
77 1 // This is done to give the user time to remove their finger
78 1 // from the switch - otherwise if they keep their finger on
79 1 // the switch for more than 0.4s the light will switch off again.
80 1
81 1 if (Sw_blocked_G)
82 1 {
83 2 Sw_blocked_G--;
84 2 return;
85 2 }
86 1
87 1 if (Sw_pin == SW_PRESSED)
88 1 {
89 2 Sw_press_duration_G += 1;
90 2
91 2 if (Sw_press_duration_G > SW_THRES)
92 2 {
93 3 Sw_press_duration_G = SW_THRES;
94 3
95 3 // Change switch state
96 3 if (Sw_pressed_G == 1)
97 3 {
98 4 Sw_pressed_G = 0; // Switch state changed to OFF
99 4 }
100 3 else
101 3 {
102 4 Sw_pressed_G = 1; // Switch state changed to ON
103 4 }
104 3
105 3 // Allow no other changes for ~1 second
106 3 Sw_blocked_G = 5;
107 3 return;
108 3 }
109 2
110 2 // Switch pressed, but not yet for long enough
111 2 return;
112 2 }
113 1
114 1 // Switch not pressed - reset the count
115 1 Sw_press_duration_G = 0;
116 1 }
117
C51 COMPILER V6.10 SWIT_C 04/18/2001 16:15:53 PAGE 3
118
119 /*------------------------------------------------------------------*-
120 ---- END OF FILE -------------------------------------------------
121 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 49 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 ----
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 + -