📄 traffic.lst
字号:
155 2 switch (inline[i]) { /* proceed to command function */
156 3 case 'D': /* Display Time Command */
157 3 printf ("Start Time: %02bd:%02bd:%02bd "
158 3 "End Time: %02bd:%02bd:%02bd\n",
159 3 start.hour, start.min, start.sec,
160 3 end.hour, end.min, end.sec);
161 3 printf (" type ESC to abort\r");
162 3
163 3 os_create_task (GET_ESC); /* ESC check in display loop */
164 3 escape = 0; /* clear escape flag */
165 3 display_time = 1; /* set display time flag */
166 3 os_clear_signal (COMMAND); /* clear pending signals */
167 3
168 3 while (!escape) { /* while no ESC entered */
169 4 printf ("Clock Time: %02bd:%02bd:%02bd\r", /* display time */
170 4 ctime.hour, ctime.min, ctime.sec);
171 4 os_wait (K_SIG, 0, 0); /* wait for time change or ESC */
172 4 }
173 3
174 3 os_delete_task (GET_ESC); /* ESC check not longer needed */
175 3 display_time = 0; /* clear display time flag */
176 3 printf ("\n\n");
177 3 break;
178 3
179 3 case 'T': /* Set Time Command */
C51 COMPILER V7.00 TRAFFIC 01/04/2003 15:10:31 PAGE 4
180 3 if (readtime (&inline[i+1])) { /* read time input and */
181 4 ctime.hour = rtime.hour; /* store in 'ctime' */
182 4 ctime.min = rtime.min;
183 4 ctime.sec = rtime.sec;
184 4 }
185 3 break;
186 3
187 3 case 'E': /* Set End Time Command */
188 3 if (readtime (&inline[i+1])) { /* read time input and */
189 4 end.hour = rtime.hour; /* store in 'end' */
190 4 end.min = rtime.min;
191 4 end.sec = rtime.sec;
192 4 }
193 3 break;
194 3
195 3 case 'S': /* Set Start Time Command */
196 3 if (readtime (&inline[i+1])) { /* read time input and */
197 4 start.hour = rtime.hour; /* store in 'start' */
198 4 start.min = rtime.min;
199 4 start.sec = rtime.sec;
200 4 }
201 3 break;
202 3
203 3 default: /* Error Handling */
204 3 printf (menu); /* display command menu */
205 3 break;
206 3 }
207 2 }
208 1 }
209
210
211 /******************************************************************************/
212 /* signalon: check if clock time is between start and end */
213 /******************************************************************************/
214 bit signalon (void) {
215 1 if (memcmp (&start, &end, sizeof (struct time)) < 0) {
216 2 if (memcmp (&start, &ctime, sizeof (struct time)) < 0 &&
217 2 memcmp (&ctime, &end, sizeof (struct time)) < 0) return (1);
218 2 }
219 1
220 1 else {
221 2 if (memcmp (&end, &ctime, sizeof (start)) > 0 &&
222 2 memcmp (&ctime, &start, sizeof (start)) > 0) return (1);
223 2 }
224 1 return (0); /* signal off, blinking on */
225 1 }
226
227
228 /******************************************************************************/
229 /* Task 3 'blinking': runs if current time is outside start & end time */
230 /******************************************************************************/
231 void blinking (void) _task_ BLINKING { /* blink yellow light */
232 1 red = 0; /* all lights off */
233 1 yellow = 0;
234 1 green = 0;
235 1 stop = 0;
236 1 walk = 0;
237 1
238 1 while (1) { /* endless loop */
239 2 yellow = 1; /* yellow light on */
240 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
241 2 yellow = 0; /* yellow light off */
C51 COMPILER V7.00 TRAFFIC 01/04/2003 15:10:31 PAGE 5
242 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
243 2 if (signalon ()) { /* if blinking time over */
244 3 os_create_task (LIGHTS); /* start lights */
245 3 os_delete_task (BLINKING); /* and stop blinking */
246 3 }
247 2 }
248 1 }
249
250
251 /******************************************************************************/
252 /* Task 4 'lights': executes if current time is between start & end time */
253 /******************************************************************************/
254 void lights (void) _task_ LIGHTS { /* traffic light operation */
255 1 red = 1; /* red & stop lights on */
256 1 yellow = 0;
257 1 green = 0;
258 1 stop = 1;
259 1 walk = 0;
260 1 while (1) { /* endless loop */
261 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
262 2 if (!signalon ()) { /* if traffic signal time over */
263 3 os_create_task (BLINKING); /* start blinking */
264 3 os_delete_task (LIGHTS); /* stop lights */
265 3 }
266 2 yellow = 1;
267 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
268 2 red = 0; /* green light for cars */
269 2 yellow = 0;
270 2 green = 1;
271 2 os_clear_signal (LIGHTS);
272 2 os_wait (K_TMO, 100, 0); /* wait for timeout: 100 ticks */
273 2 os_wait (K_TMO + K_SIG, 250, 0); /* wait for timeout & signal */
274 2 yellow = 1;
275 2 green = 0;
276 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
277 2 red = 1; /* red light for cars */
278 2 yellow = 0;
279 2 os_wait (K_TMO, 80, 0); /* wait for timeout: 80 ticks */
280 2 stop = 0; /* green light for walkers */
281 2 walk = 1;
282 2 os_wait (K_TMO, 250, 0); /* wait for timeout: 250 ticks */
283 2 stop = 1; /* red light for walkers */
284 2 walk = 0;
285 2 }
286 1 }
287
288
289 /******************************************************************************/
290 /* Task 5 'keyread': process key stroke from pedestrian push button */
291 /******************************************************************************/
292 void keyread (void) _task_ KEYREAD {
293 1 while (1) { /* endless loop */
294 2 if (key) { /* if key pressed */
295 3 os_send_signal (LIGHTS); /* send signal to task lights */
296 3 }
297 2 os_wait (K_TMO, 2, 0); /* wait for timeout: 2 ticks */
298 2 }
299 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 788 ----
C51 COMPILER V7.00 TRAFFIC 01/04/2003 15:10:31 PAGE 6
CONSTANT SIZE = 912 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 12 1
IDATA SIZE = 16 ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -