?? traffic light.lst
字號:
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE TRAFFIC_LIGHT
OBJECT MODULE PLACED IN traffic light.OBJ
COMPILER INVOKED BY: C:\Program Files\KeilC\C51\BIN\C51.EXE traffic light.c ROM(SMALL) BROWSE DEBUG OBJECTEXTEND PREPRIN
-T
line level source
1 #include <REG52.H>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <intrins.h>
5 #include <ctype.h>
6 #include <string.h>
7 #define uint unsigned int //定義一下方便使用
8 #define uchar unsigned char
9 #define ulong unsigned long
10
11 #define waits 100 //視覺效應差時間
12 #define delay_sec1 10
13 #define delay_sec2 20
14 #define s_a_green 30 //A道3燈正常顯示時間(單位--s)
15 #define s_a_yellow 5
16 #define s_a_red 20
17 #define s_b_green 15 //B道3燈正常顯示時間(單位--s)
18 #define s_b_yellow 5
19 #define s_b_red 35
20 #define sec_int1_yellow 5 //行人過街黃燈時間(單位--s)
21 #define sec_int0_yellow 5 //緊急車輛A,B道黃燈時間(單位--s)
22 #define sec_int0_red 15 //緊急車輛A,B道紅燈時間(單位--s)
23 sbit green_a = P1^0; //A,B道各燈所用端口號定義
24 sbit yellow_a = P1^1;
25 sbit red_a = P1^2;
26 sbit green_b = P1^5;
27 sbit yellow_b = P1^6;
28 sbit red_b = P1^7;
29 char flag;
30 /*視覺效應延時程序*/
31 void wait(int temp)
32 {
33 1 uint m;
34 1 for(m=temp;m>0;m--);
35 1 }
36 /*A道綠燈30s顯示程序*/
37 void disp7seg_a_green()
38 {
39 1 uint i,j, k;
40 1 flag = 0;
41 1 P1 = 0x7E;
42 1 for(k=s_a_green;k>0;k--)
43 1 {
44 2 for(i=delay_sec1;i>0;i--)
45 2 {
46 3 for(j=delay_sec2;j>0;j--)
47 3 {
48 4 P0=0x01;
49 4 P2=k/10;
50 4 wait(waits);
51 4 P0=0x02;
52 4 P2=k%10;
53 4 wait(waits);
54 4 P0=0x04;
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 2
55 4 P2=(k+5)/10;
56 4 wait(waits);
57 4 P0=0x08;
58 4 P2=(k+5)%10;
59 4 wait(waits);
60 4 }
61 3 }
62 2 }
63 1
64 1 }
65 /*A道黃燈5s顯示程序*/
66 void disp7seg_a_yellow()
67 {
68 1 uint i,j,k;
69 1 flag = 1;
70 1 P1 = 0x7D;
71 1 for(k=s_a_yellow;k>0;k--)
72 1 {
73 2 for(i=delay_sec1;i>0;i--)
74 2 {
75 3 for(j=delay_sec2;j>0;j--)
76 3 {
77 4 P0=0x01;
78 4 P2=k/10;
79 4 wait(waits);
80 4 P0=0x02;
81 4 P2=k%10;
82 4 wait(waits);
83 4 P0=0x04;
84 4 P2=k/10;
85 4 wait(waits);
86 4 P0=0x08;
87 4 P2=k%10;
88 4 wait(waits);
89 4 }
90 3 }
91 2 }
92 1 }
93 /*B道綠燈15s顯示程序*/
94 void disp7seg_b_green()
95 {
96 1 uint i,j,k;
97 1 flag = 2;
98 1 P1=0xDB;
99 1 for(k=s_b_green;k>0;k--)
100 1 {
101 2 for(i=delay_sec1;i>0;i--)
102 2 {
103 3 for(j=delay_sec2;j>0;j--)
104 3 {
105 4 P0=0x01;
106 4 P2=(k+5)/10;
107 4 wait(waits);
108 4 P0=0x02;
109 4 P2=(k+5)%10;
110 4 wait(waits);
111 4 P0=0x04;
112 4 P2=k/10;
113 4 wait(waits);
114 4 P0=0x08;
115 4 P2=k%10;
116 4 wait(waits);
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 3
117 4 }
118 3 }
119 2 }
120 1 }
121 /*B道黃燈5s顯示程序*/
122 void disp7seg_b_yellow()
123 {
124 1 uint i,j,k;
125 1 flag = 3;
126 1 P1=0xBB;
127 1 for(k=s_b_yellow;k>0;k--)
128 1 {
129 2 for(i=delay_sec1;i>0;i--)
130 2 {
131 3 for(j=delay_sec2;j>0;j--)
132 3 {
133 4 P0=0x01;
134 4 P2=k/10;
135 4 wait(waits);
136 4 P0=0x02;
137 4 P2=k%10;
138 4 wait(waits);
139 4 P0=0x04;
140 4 P2=k/10;
141 4 wait(waits);
142 4 P0=0x08;
143 4 P2=k%10;
144 4 wait(waits);
145 4 }
146 3 }
147 2 }
148 1 }
149 /*行人過街中斷服務子程序*/
150 void ex1_isr (void) interrupt 2
151 {
152 1 uint temp,i,j;
153 1 switch(flag)
154 1 {
155 2 case 0:
156 2 wait(0);
157 2 break;
158 2 case 1:
159 2 P1 = 0xBD;
160 2 wait(500);// eliminate the shaking
161 2 for(temp=sec_int1_yellow;temp>0;temp--)
162 2 {
163 3 for(i=delay_sec1;i>0;i--)
164 3 {
165 4 for(j=delay_sec2;j>0;j--)
166 4 {
167 5 P0 = 0x01;
168 5 P2 = temp/10;
169 5 wait(waits);
170 5 P0 = 0x02;
171 5 P2 = temp%10;
172 5 wait(waits);
173 5 P0 = 0x04;
174 5 P2 = temp/10;
175 5 wait(waits);
176 5 P0 = 0x08;
177 5 P2 = temp%10;
178 5 wait(waits);
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 4
179 5 }
180 4 }
181 3 }
182 2 P1 = 0x7D;
183 2 break;
184 2 case 2:
185 2 P1 = 0xBD;
186 2 wait(500);// eliminate the shaking
187 2 for(temp=sec_int1_yellow;temp>0;temp--)
188 2 {
189 3 for(i=delay_sec1;i>0;i--)
190 3 {
191 4 for(j=delay_sec2;j>0;j--)
192 4 {
193 5 P0 = 0x01;
194 5 P2 = temp/10;
195 5 wait(waits);
196 5 P0 = 0x02;
197 5 P2 = temp%10;
198 5 wait(waits);
199 5 P0 = 0x04;
200 5 P2 = temp/10;
201 5 wait(waits);
202 5 P0 = 0x08;
203 5 P2 = temp%10;
204 5 wait(waits);
205 5 }
206 4 }
207 3 }
208 2 P1 = 0xDB;
209 2 break;
210 2 case 3:
211 2 wait(0);
212 2 break;
213 2 }
214 1
215 1 }
216 /*緊急車輛中斷服務子程序*/
217 void ex0_isr (void) interrupt 0
218 {
219 1 uint temp1,temp2,i,j;
220 1 P1 = 0xBD;
221 1 for(temp1=sec_int0_yellow;temp1>0;temp1--)
222 1 {
223 2
224 2 //delay1s();
225 2 for(i=delay_sec1;i>0;i--)
226 2 {
227 3 for(j=delay_sec2;j>0;j--)
228 3 {
229 4 P0 = 0x01;
230 4 P2 = temp1/10;
231 4 wait(waits);
232 4 P0 = 0x02;
233 4 P2 = temp1%10;
234 4 wait(waits);
235 4 P0 = 0x04;
236 4 P2 = temp1/10;
237 4 wait(waits);
238 4 P0 = 0x08;
239 4 P2 = temp1%10;
240 4 wait(waits);
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 5
241 4 }
242 3 }
243 2 }
244 1 P1 = 0x7B;
245 1 for(temp2=sec_int0_red;temp2>0;temp2--)
246 1 {
247 2 for(i=delay_sec1;i>0;i--)
248 2 {
249 3 for(j=delay_sec2;j>0;j--)
250 3 {
251 4 P0 = 0x01;
252 4 P2 = temp2/10;
253 4 wait(waits);
254 4 P0 = 0x02;
255 4 P2 = temp2%10;
256 4 wait(waits);
257 4 P0 = 0x04;
258 4 P2 = temp2/10;
259 4 wait(waits);
260 4 P0 = 0x08;
261 4 P2 = temp2%10;
262 4 }
263 3 }
264 2 }
265 1 switch(flag)
266 1 {
267 2 case 0:
268 2 P1 = 0x7E;
269 2 break;
270 2 case 1:
271 2 P1 = 0x7D;
272 2 case 2:
273 2 P1 = 0xDB;
274 2 break;
275 2 case 3:
276 2 P1 = 0xBB;
277 2 break;
278 2 }
279 1 }
280 void main(void)
281 {
282 1 //配置外部中斷INT0
283 1 IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
284 1 EX0 = 1; // Enable EX0 Interrupt
285 1 //配置外部中斷INT1
286 1 IT1 = 1;
287 1 EX1 = 1;
288 1 //使能全局中斷
289 1 EA = 1; // Enable Global Interrupt Flag
290 1 while(1) //主循環(huán)
291 1 {
292 2 disp7seg_a_green();
293 2 disp7seg_a_yellow();
294 2 disp7seg_b_green();
295 2 disp7seg_b_yellow();
296 2 }
297 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1053 ----
CONSTANT SIZE = ---- ----
C51 COMPILER V7.50 TRAFFIC_LIGHT 07/08/2007 14:05:27 PAGE 6
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 26
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 + -