?? 12-1.lst
字號:
C51 COMPILER V7.09 12_1 08/11/2005 18:15:08 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE 12_1
OBJECT MODULE PLACED IN 12-1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 12-1.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //#pragma SRC
2 #include <stdio.h>
3 #include <reg51.h>
4
5 #define TRUE 1
6 #define FALSE 0
7 #define DELAY_VALUE 3
8
9 #define PinDrvKey1 P1_0
10 #define PinDrvKey2 P1_1
11 #define PinDrvKey3 P1_2
12 #define PinDrvKey4 P1_3 //鍵盤掃描的驅動線
13
14 #define PinScanKey1 P1_4
15 #define PinScanKey2 P1_5
16 #define PinScanKey3 P1_6
17 #define PinScanKey4 P1_7 //鍵盤掃描的信號獲取線
18
19 #define PinLamp P0_0 //指示燈驅動管腳
20 #define PinSpeaker P0_1 //蜂鳴器驅動管腳
21
22 sbit P0_0=P0^0;
23 sbit P0_1=P0^1;
24 sbit P0_2=P0^2;
25 sbit P0_3=P0^3;
26 sbit P0_4=P0^4;
27 sbit P0_5=P0^5;
28 sbit P0_6=P0^6;
29 sbit P0_7=P0^7;
30
31 sbit P1_0=P1^0;
32 sbit P1_1=P1^1;
33 sbit P1_2=P1^2;
34 sbit P1_3=P1^3;
35 sbit P1_4=P1^4;
36 sbit P1_5=P1^5;
37 sbit P1_6=P1^6;
38 sbit P1_7=P1^7;
39
40 sbit P2_0=P2^0;
41 sbit P2_1=P2^1;
42 sbit P2_2=P2^2;
43 sbit P2_3=P2^3;
44 sbit P2_4=P2^4;
45 sbit P2_5=P2^5;
46 sbit P2_6=P2^6;
47 sbit P2_7=P2^7;
48
49
50 void initial(void); //初始化子程序
51 void delay(short i);
52 unsigned char keyscan(void);
53
54 void main(void)
55 {
C51 COMPILER V7.09 12_1 08/11/2005 18:15:08 PAGE 2
56 1
57 1 unsigned char keyword;
58 1
59 1 initial(); //鍵盤驅動信號都設為低
60 1
61 1 keyword=keyscan();
62 1
63 1 }
64
65 void initial(void)
66 {
67 1 P1_0=FALSE;
68 1 P1_1=FALSE;
69 1 P1_2=FALSE;
70 1 P1_3=FALSE; //鍵盤驅動信號都設為低
71 1 P0_0=TRUE; //發光二極管設為不亮
72 1 P0_1=TRUE; //蜂鳴器不叫
73 1 }
74
75 unsigned char keyscan()
76 {
77 1 PinDrvKey1=TRUE;
78 1 if(PinScanKey1==TRUE)
79 1 PinLamp=FALSE;
80 1 PinSpeaker=FALSE;
81 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
82 1 PinLamp=TRUE;
83 1 PinSpeaker=TRUE;
84 1 if(PinScanKey1==TRUE)
85 1 {
86 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
87 2 if(PinScanKey1==TRUE)
88 2 return 1;} //確認確實有按鍵信號,返回鍵值
89 1 if(PinScanKey2==TRUE)
90 1 PinLamp=FALSE;
91 1 PinSpeaker=FALSE;
92 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
93 1 PinLamp=TRUE;
94 1 PinSpeaker=TRUE;
95 1 if(PinScanKey2==TRUE)
96 1 {
97 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
98 2 if(PinScanKey2==TRUE)
99 2 return 5;} //確認確實有按鍵信號,返回鍵值
100 1 if(PinScanKey3==TRUE)
101 1 PinLamp=FALSE;
102 1 PinSpeaker=FALSE;
103 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
104 1 PinLamp=TRUE;
105 1 PinSpeaker=TRUE;
106 1 if(PinScanKey3==TRUE)
107 1 {
108 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
109 2 if(PinScanKey3==TRUE)
110 2 return 9;} //確認確實有按鍵信號,返回鍵值
111 1 if(PinScanKey4==TRUE)
112 1 PinLamp=FALSE;
113 1 PinSpeaker=FALSE;
114 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
115 1 PinLamp=TRUE;
116 1 PinSpeaker=TRUE;
117 1 if(PinScanKey2==TRUE)
C51 COMPILER V7.09 12_1 08/11/2005 18:15:08 PAGE 3
118 1 {
119 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
120 2 if(PinScanKey2==TRUE)
121 2 return 12;} //確認確實有按鍵信號,返回鍵值
122 1 PinDrvKey1=FALSE; //以上語句掃描第一列
123 1 PinDrvKey2=TRUE;
124 1 if(PinScanKey1==TRUE)
125 1 PinLamp=FALSE;
126 1 PinSpeaker=FALSE;
127 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
128 1 PinLamp=TRUE;
129 1 PinSpeaker=TRUE;
130 1 if(PinScanKey1==TRUE)
131 1 {
132 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
133 2 if(PinScanKey1==TRUE)
134 2 return 2;} //確認確實有按鍵信號,返回鍵值
135 1 if(PinScanKey2==TRUE)
136 1 PinLamp=FALSE;
137 1 PinSpeaker=FALSE;
138 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
139 1 PinLamp=TRUE;
140 1 PinSpeaker=TRUE;
141 1 if(PinScanKey2==TRUE)
142 1 {
143 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
144 2 if(PinScanKey2==TRUE)
145 2 return 6;} //確認確實有按鍵信號,返回鍵值
146 1 if(PinScanKey3==TRUE)
147 1 PinLamp=FALSE;
148 1 PinSpeaker=FALSE;
149 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
150 1 PinLamp=TRUE;
151 1 PinSpeaker=TRUE;
152 1 if(PinScanKey3==TRUE)
153 1 {
154 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
155 2 if(PinScanKey3==TRUE)
156 2 return 0;} //確認確實有按鍵信號,返回鍵值
157 1 if(PinScanKey4==TRUE)
158 1 PinLamp=FALSE;
159 1 PinSpeaker=FALSE;
160 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
161 1 PinLamp=TRUE;
162 1 PinSpeaker=TRUE;
163 1 if(PinScanKey4==TRUE)
164 1 {
165 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
166 2 if(PinScanKey4==TRUE)
167 2 return 13;} //確認確實有按鍵信號,返回鍵值
168 1 PinDrvKey2=FALSE; //以上語句掃描第二列
169 1 PinDrvKey3=TRUE;
170 1 if(PinScanKey1==TRUE)
171 1 PinLamp=FALSE;
172 1 PinSpeaker=FALSE;
173 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
174 1 PinLamp=TRUE;
175 1 PinSpeaker=TRUE;
176 1 if(PinScanKey1==TRUE)
177 1 {
178 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
179 2 if(PinScanKey1==TRUE)
C51 COMPILER V7.09 12_1 08/11/2005 18:15:08 PAGE 4
180 2 return 3;} //確認確實有按鍵信號,返回鍵值
181 1 if(PinScanKey2==TRUE)
182 1 PinLamp=FALSE;
183 1 PinSpeaker=FALSE;
184 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
185 1 PinLamp=TRUE;
186 1 PinSpeaker=TRUE;
187 1 if(PinScanKey2==TRUE)
188 1 {
189 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
190 2 if(PinScanKey2==TRUE)
191 2 return 7;} //確認確實有按鍵信號,返回鍵值
192 1 if(PinScanKey3==TRUE)
193 1 PinLamp=FALSE;
194 1 PinSpeaker=FALSE;
195 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
196 1 PinLamp=TRUE;
197 1 PinSpeaker=TRUE;
198 1 if(PinScanKey3==TRUE)
199 1 {
200 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
201 2 if(PinScanKey3==TRUE)
202 2 return 10;} //確認確實有按鍵信號,返回鍵值
203 1 if(PinScanKey4==TRUE)
204 1 PinLamp=FALSE;
205 1 PinSpeaker=FALSE;
206 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
207 1 PinLamp=TRUE;
208 1 PinSpeaker=TRUE;
209 1 if(PinScanKey4==TRUE)
210 1 {
211 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
212 2 if(PinScanKey4==TRUE)
213 2 return 14;} //確認確實有按鍵信號,返回鍵值
214 1 PinDrvKey3=FALSE; //以上語句掃描第三列
215 1 PinDrvKey4=TRUE;
216 1 if(PinScanKey4==TRUE)
217 1 PinLamp=FALSE;
218 1 PinSpeaker=FALSE;
219 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
220 1 PinLamp=TRUE;
221 1 PinSpeaker=TRUE;
222 1 if(PinScanKey1==TRUE)
223 1 {
224 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
225 2 if(PinScanKey1==TRUE)
226 2 return 4;} //確認確實有按鍵信號,返回鍵值
227 1 if(PinScanKey2==TRUE)
228 1 PinLamp=FALSE;
229 1 PinSpeaker=FALSE;
230 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
231 1 PinLamp=TRUE;
232 1 PinSpeaker=TRUE;
233 1 if(PinScanKey2==TRUE)
234 1 { delay(DELAY_VALUE); //假如判斷還有信號,則再延時
235 2 if(PinScanKey2==TRUE)
236 2 return 8;} //確認確實有按鍵信號,返回鍵值
237 1 if(PinScanKey3==TRUE)
238 1 PinLamp=FALSE;
239 1 PinSpeaker=FALSE;
240 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
241 1 PinLamp=TRUE;
C51 COMPILER V7.09 12_1 08/11/2005 18:15:08 PAGE 5
242 1 PinSpeaker=TRUE;
243 1 if(PinScanKey3==TRUE)
244 1 {
245 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
246 2 if(PinScanKey3==TRUE)
247 2 return 11;} //確認確實有按鍵信號,返回鍵值
248 1 if(PinScanKey4==TRUE)
249 1 PinLamp=FALSE;
250 1 PinSpeaker=FALSE;
251 1 delay(DELAY_VALUE); //如果判斷有信號,則延時一次
252 1 PinLamp=TRUE;
253 1 PinSpeaker=TRUE;
254 1 if(PinScanKey4==TRUE)
255 1 {
256 2 delay(DELAY_VALUE); //假如判斷還有信號,則再延時
257 2 if(PinScanKey4==TRUE)
258 2 return 15;} //假如判斷還有信號,則再延時
259 1 PinDrvKey3=FALSE; //以上語句掃描第四列
260 1 return 16;
261 1 }
262
263 void delay(short i)
264 {
265 1 int j=0;
266 1 int k=0;
267 1 k=i*DELAY_VALUE;
268 1 while (j<k)j++;
269 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 465 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 1
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 + -