📄 keypro.lst
字号:
C51 COMPILER V7.07 KEYPRO 05/03/2006 14:29:44 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE KEYPRO
OBJECT MODULE PLACED IN KEYPRO.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE KEYPRO.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //*****************************************************************************
2 // KEYPROC.C
3 // date : 2001/07/15
4 //*****************************************************************************
5 #include <reg52.h> /* special function register declarations */
6 /* for the intended 8051 derivative */
7 #include <stdio.h> /* prototype declarations for I/O functions */
8 #include <intrins.h>
9
10 #define _def_keyproc
11
12 #include "uSYSTEM.h"
*** WARNING C318 IN LINE 12 OF KEYPRO.C: can't open file 'uSYSTEM.h'
13 #include inc_struc
*** ERROR C309 IN LINE 13 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 13 OF KEYPRO.C: can't open file ''
14 #include inc_uSYS
*** ERROR C129 IN LINE 14 OF KEYPRO.C: missing ';' before 'inc_uSYS'
*** ERROR C309 IN LINE 14 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 14 OF KEYPRO.C: can't open file ''
15 #include inc_main
*** ERROR C309 IN LINE 15 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 15 OF KEYPRO.C: can't open file ''
16 #include inc_proc
*** ERROR C309 IN LINE 16 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 16 OF KEYPRO.C: can't open file ''
17 #include inc_menu
*** ERROR C309 IN LINE 17 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 17 OF KEYPRO.C: can't open file ''
18 #include inc_macro
*** ERROR C309 IN LINE 18 OF KEYPRO.C: bad or missing filename
*** WARNING C318 IN LINE 18 OF KEYPRO.C: can't open file ''
19
20 BYTE code cVerKeyProc[] = "A2";
21 //*****************************************************************************************
22 // define constant :
23 //*****************************************************************************************
24 #define cMakeDebunce 2 // 48ms at 16ms.
25 #define cRepeatDelay 31 // 500ms at 16ms.
26 #define cRepeatDebunce 16 // 250ms at 16ms.
27 #define cBreakDebunce 2 // 32ms at 16ms.
28 #define cDoubleDebunce 31 // 500ms at 16ms.
29 #ifndef cKeyHideBreak
30 #define cKeyHideBreak 0 // 1 = hide break out if double click occur.(break delay out)
31 #endif
32
33 //*****************************************************************************************
34 // define local variables :
35 //*****************************************************************************************
36 BYTE idata gKeyState; // KeyPad read state machine
37 BYTE idata gKeyScan; // Key scan code.
38 BYTE idata gKeyCode; // Key code
39 BYTE idata gKeyAttr; // Key attribute
40 BYTE idata gRepeatDebunce;
41 void code* ptQkMenuItem;
C51 COMPILER V7.07 KEYPRO 05/03/2006 14:29:44 PAGE 2
42 //PMenuItems ptQkMenuItem;
43 //struct _MenuKeyProc code* idata ptKeyProc;
44 PMenuKeyProc idata ptKeyProc;
45
46 //*****************************************************************************************
47 // KeyProess subroutine
48 //*****************************************************************************************
49 void sKeyMPro(){ // process a matrix of Keycode
50 // struct _MenuKeyProc *ptKeyProc;
51 struct _MenuKeyProc* idata tmpKeyProc;
52
53 if (gKeyAttr){
54 if (gKeyCode != 0xff) {
55 // ptKeyProc = ptMenuItem->pKeyProc;
56 tmpKeyProc = ptKeyProc;
57
58 while (tmpKeyProc->iKeyCode != 0xff) {
59 if ((gKeyCode == tmpKeyProc->iKeyCode) && (gKeyAttr & tmpKeyProc->iKeyAttr)) {
60 gMenuCount = gMenuTimer;
61 ptQkMenuItem = tmpKeyProc->QkNode;
62 tmpKeyProc->KeyProc();
63 break;
64 } else tmpKeyProc += 1;
65 }
66 if (tmpKeyProc->iKeyCode == 0xff)
67 tmpKeyProc->KeyProc();
68 }
69 gKeyAttr = 0;
70 }
71 }
72 //*****************************************************************************************
73 // key pad process :
74 // OUT : gKeyCode
75 // gKeyAttr = cAttrMake : key pressed.
76 // = cAttrBreak : key release.
77 // = cAttrRepeatFast : key pressed more then 300ms & send every 250ms.
78 // = cAttrRepeatSlow : key pressed more then 300ms & send every 500ms.
79 // = cAttrLongMake : key pressed more then 1s.
80 // = cAttrDouble : key release less then 500ms & pressed again.
81 //*****************************************************************************************
82 void sReadKey(){
83
84 if (fProcFlag & !fKeyLock) {
85 iTmpD0.b[0] = sKeySnap();
86 switch (gKeyState & 0xe0){
87 case 0x00 : // wait for key pressed.
88 fDoubClick = 0;
89 if (iTmpD0.b[0] != 0xff){
90 gKeyScan = iTmpD0.b[0];
91 gKeyState = 0x20 | cMakeDebunce;
92 }
93 break;
94 case 0x20 : // wait for make.
95 if (iTmpD0.b[0] == gKeyScan){
96 if ((--gKeyState & 0x1f) == 0){
97 gKeyState = 0x40 | cRepeatDelay;
98 gRepeatDebunce = cRepeatDebunce;
99 sConvertKeyCode();
100 if (gKeyCode != 0xff){
101 if (fDoubClick)
102 gKeyAttr = cAttrMake | cAttrDouble;
103 else
C51 COMPILER V7.07 KEYPRO 05/03/2006 14:29:44 PAGE 3
104 gKeyAttr = cAttrMake;
105 }
106 }
107 } else gKeyState = 0x00;
108 break;
109 case 0x40 : // wait for repeat - 1.
110 if (iTmpD0.b[0] == gKeyScan){
111 if ((--gKeyState & 0x1f) == 0){
112 gKeyState = 0x60 | gRepeatDebunce;
113 gKeyAttr = cAttrRepeatFast | cAttrRepeatSlow;
114 }
115 } else gKeyState = 0xc0 | cBreakDebunce;
116 break;
117 case 0x60 : // wait for repeat - 2.
118 if (iTmpD0.b[0] == gKeyScan){
119 if ((--gKeyState & 0x1f) == 0){
120 gKeyState = 0x80 | gRepeatDebunce;
121 gKeyAttr = cAttrRepeatFast;
122 }
123 } else gKeyState = 0xc0 | cBreakDebunce;
124 break;
125 case 0x80 : // wait for repeat - 3 & delay.
126 if (iTmpD0.b[0] == gKeyScan){
127 if ((--gKeyState & 0x1f) == 0){
128 gKeyState = 0xa0 | gRepeatDebunce;
129 gKeyAttr = cAttrRepeatFast | cAttrRepeatSlow;
130 }
131 } else gKeyState = 0xc0 | cBreakDebunce;
132 break;
133 case 0xa0 : // wait for repeat - 3 & delay.
134 if (iTmpD0.b[0] == gKeyScan){
135 if ((--gKeyState & 0x1f) == 0){
136 gKeyState = 0x40 | gRepeatDebunce;
137 if (gRepeatDebunce == cRepeatDebunce) gKeyAttr = cAttrRepeatFast | cAttrLongMake;
138 else gKeyAttr = cAttrRepeatFast;
139 if (gRepeatDebunce > 4) gRepeatDebunce -= 4;
140 }
141 } else gKeyState = 0xc0 | cBreakDebunce;
142 break;
143 case 0xc0 : // wait for break.
144 if (iTmpD0.b[0] != gKeyScan){
145 if ((--gKeyState & 0x1f) == 0){
146 gKeyState = 0xe0 | cDoubleDebunce;
147 #if cKeyHideBreak == 0
148 if (iTmpD0.b[0] == 0xff)
149 gKeyAttr = cAttrBreak;
150 #endif
151 }
152 } else
153 gKeyState = 0x40 | cRepeatDebunce;
154 break;
155 case 0xe0 : // wait for double click
156 if (iTmpD0.b[0] == 0xff){
157 if ((--gKeyState & 0x1f) == 0) {
158 gKeyState = 0x00;
159 #if cKeyHideBreak == 1
gKeyAttr = cAttrBreak;
#endif
162 }
163 } else {
164 if (iTmpD0.b[0] == gKeyScan){
165 fDoubClick = 1;
C51 COMPILER V7.07 KEYPRO 05/03/2006 14:29:44 PAGE 4
166 gKeyState = 0x20 | cMakeDebunce;
167 } else {
168 gKeyState = 0x00;
169 #if cKeyHideBreak == 1
iTmpD0.b[0] ^= 0xff;
gKeyScan ^= 0xff;
iTmpD0.b[0] &= gKeyScan;
if (iTmpD0.b[0] == 0x00)
gKeyAttr = cAttrBreak;
#endif
176 }
177 }
178 break;
179 }
180 iDataIF.w = 0xff00;
181 sReadDirectKey();
182 if (iDataIF.b[0] != 0xff) {
183 gKeyCode = iDataIF.b[0];
184 gKeyAttr = iDataIF.b[1];
185 }
186 }
187 }
188 //*********************************************************
189 // convert scan code to key code.
190 // IN : gKeyScan
191 // tKeyCode[]
192 // OUT : gKeyCode.
193 //*********************************************************
194 void sConvertKeyCode(){
195 gKeyCode = 0;
196 while (tKeyCode[gKeyCode] != 0xff){
197 if (gKeyScan == tKeyCode[gKeyCode])
198 return;
199 gKeyCode++;
200 }
201 gKeyCode = 0xff;
202 }
C51 COMPILATION COMPLETE. 7 WARNING(S), 7 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -