Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

TRAFFIC

PAGE 1

1 ;program for traffic controller


2 ;south side and North side Port A
3 ;east and west side Port B
4 ;day/night switch Port C PC1
5 ;normal/busy switch Port C PC2
6
7 $mod51
8200 8 org 8200h
8200 90A003 9 main: mov dptr,#0a003h ;8255 CWR address
8203 7481 10 mov a,#81h ;Port A and Port B output
8205 F0 11 movx @dptr,a ;Port C(L) as input
12
8206 90A002 13 input: mov dptr,#0a002h ;Port C address
8209 E0 14 movx a,@dptr ;read switches
15
820A 20E10F 16 jb acc.1,night ;0 for day
17 ;1 for night
18
820D 20E206 19 jb acc.2,normal ;0 for busy
20 ;1 for normal
8210 7E05 21 mov r6,#05h ;5 secs for green in busy
8212 7F02 22 mov r7,#2h ;2 secs for yellow
8214 801D 23 sjmp day
24
8216 7E03 25 normal: mov r6,#03h ;3 secs for green
8218 7F01 26 mov r7,#1h ;1 secs for yellow
821A 8017 27 sjmp day
28
821C 90A000 29 night: mov dptr,#0a000h ;make yellow on in south
821F 7422 30 mov a,#22h ;and north
8221 F0 31 movx @dptr,a
8222 A3 32 inc dptr ;make yellow on in east
8223 F0 33 movx @dptr,a ;and west
8224 5172 34 acall onesec ;one sec.delay
35
8226 90A000 36 mov dptr,#0a000h ;make yellow off in south
8229 7400 37 mov a,#00h ;and north
822B F0 38 movx @dptr,a
822C A3 39 inc dptr ;make yellow off in east
822D F0 40 movx @dptr,a ;and west
822E 5172 41 acall onesec ;one sec.delay
42
8230 028206 43 ljmp input ;monitor for switch input
44
8233 45 day:
46 ; step1
8233 90A000 47 mov dptr,#0a000h ;make south and north green
8236 7444 48 mov a,#44h
8238 F0 49 movx @dptr,a
50
8239 90A001 51 mov dptr,#0a001h ;make east and west red
823C 7499 52 mov a,#99h ;and switch on pedestrian
823E F0 53 movx @dptr,a
54
823F EE 55 mov a,r6 ;time for green in south and north
8240 FD 56 mov r5,a ;r5 is temporary reg.
8241 5172 57 k1: acall onesec
8243 DDFC 58 djnz r5, k1
TRAFFIC
PAGE 2

59
60 ; step2
8245 90A000 61 mov dptr,#0a000h ;make south and north yellow
8248 7422 62 mov a,#22h
824A F0 63 movx @dptr,a
64
824B EF 65 mov a,r7 time for yellow in south and north
824C FD 66 mov r5,a ;r5 is temporary reg.
824D 5172 67 k2: acall onesec
824F DDFC 68 djnz r5, k2
69
70 ; step3
8251 90A001 71 mov dptr,#0a001h ;make east and west green
8254 7444 72 mov a,#44h
8256 F0 73 movx @dptr,a
74
8257 90A000 75 mov dptr,#0a000h ;make south and north red
825A 7499 76 mov a,#99h ;and switch on pedestrian
825C F0 77 movx @dptr,a
78
825D EE 79 mov a,r6 ;time for green in
825E FD 80 mov r5,a ;east and west
825F 5172 81 k3: acall onesec
8261 DDFC 82 djnz r5, k3
83
84 ; step4
8263 90A001 85 mov dptr,#0a001h ;make east and west yellow
8266 7422 86 mov a,#22h
8268 F0 87 movx @dptr,a
88
8269 EF 89 mov a,r7 ;time for yellow in
826A FD 90 mov r5,a ;east and west
826B 5172 91 k4: acall onesec
826D DDFC 92 djnz r5, k4
93
826F 028206 94 ljmp input
95
8272 758910 96 onesec: mov tmod,#10h ;timer 1, mode 1
8275 7B0E 97 mov r3,#14 ;outer loop for time delay
8277 758B08 98 repeat: mov tl1,#08 ;tl reg. value
827A 758D01 99 mov th1,#01 ;th reg. value
827D D28E 100 setb tr1 ;switch on timer1
827F 308FFD 101 back: jnb tf1,back ;check for overflow flag
8282 C28E 102 clr tr1 ;if yes, switch off timer
8284 C28F 103 clr tf1 ;clear overflow flag
8286 DBEF 104 djnz r3,repeat ;repeat for 14 times
8288 22 105 ret
106
107 end

You might also like