-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.txt
More file actions
123 lines (107 loc) · 3.59 KB
/
Code.txt
File metadata and controls
123 lines (107 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
; P0.0 as top, P0.1 as right, P0.2 as bottom and P0.3 as left
; P1.0 as top, P1.1 as right, P1.2 as bottom and P1.3 as left
; P2.0 as top, P2.1 as right, P2.2 as bottom and P2.3 as left
; P0 as red, P1 as yellow, P2 as green
ORG 00H
TOP: ACALL START ;call SET
ACALL DELAYRED ;call DELAYRED subroutine
SETB P0.0 ;turn TOP red traffic light lights off
MOV A, #0EH
MOV P2, A ;turn TOP green traffic light lights on
ACALL DELAYGREEN ;call DELAYGREEN subroutine
MOV P2, #0FH ;turn TOP green traffic light lights off
MOV P1, #0EH ;turn TOP yellow traffic light lights on
ACALL DELAYYELLOW ;call DELAYYELLOW subroutine
MOV P1, B ;make all Yellow light lights off
RIGHT: ACALL SET ;call SET
MOV A,#02H
MOV P0,A ;turn RIGHT red traffic light lights off
MOV A, #0DH
MOV P2, A ;turn RIGHT green traffic light lights on
ACALL DELAYGREEN ;call DELAYGREEN subroutine
MOV P2, #0FH ;turn RIGHT green traffic light lights off
MOV P1, #0DH ;turn RIGHT yellow traffic light lights on
ACALL DELAYYELLOW ;call DELAYYELLOW subroutine
MOV P1, B ;make all Yellow light lights off
BOTTOM: ACALL SET ;call SET
MOV A,#04H
MOV P0,A
MOV A, #0BH
MOV P2, A ;turn BOTTOM green traffic light lights on
ACALL DELAYGREEN ;call DELAYGREEN subroutine
MOV P2, #0FH ;turn BOTTOM green traffic light lights off
MOV P1, #0BH ;turn BOTTOM yellow traffic light lights on
ACALL DELAYYELLOW ;call DELAYYELLOW subroutine
MOV P1, B ;make all Yellow light lights off
LEFT: ACALL SET ;call SET
MOV P0,#08H
MOV A, #07H
MOV P2,A ;turn LEFT red traffic light lights off
ACALL DELAYGREEN ;call DELAYGREEN subroutine
MOV P2, #0FH ;turn LEFT red traffic light lights off
MOV P1, #07H ;turn LEFT green traffic light lights on
ACALL DELAYYELLOW ;call DELAYYELLOW subroutine
MOV P1, B ;make all Yellow light lights off
MOV A, #0F0H
MOV P0, A ;make all RED light lights on
AJMP TOP
start: MOV A, #0F0H ;move F0 to A
MOV B, #0FH ;move 0F to B
MOV P1, B ;make all Yellow light lights off
MOV P2, B ;make all Green light lights off
MOV P0, A ;make all RED light lights on
SET: MOV A,#06H
MOV R4,A ;red timer
MOV A,#09H
MOV R3,A ;green timer
MOV A,#03H
MOV R5,A ;yellow timer
MOV DPTR,#SEG
RET
;DELAYGREEN subroutine
DELAYGREEN: MOV A,R3 ;move #09H to A
MOVC A,@A+DPTR ;point to the memory address and pass the value inside the value
MOV P3,A
MOV R1, #06H ;delay for 6 seconds
DELAYGREEN1: MOV R2, #09H
DEC R3 ;decrement the value of the R3
MOV A,R3 ;pass the decremented value to A
ANL A,#0FH
MOVC A,@A+DPTR ;point to the address of A
MOV P3,A
DELAYGREEN2: DJNZ R2, DELAYGREEN2
DJNZ R1, DELAYGREEN1
RET
;DELAYYELLOW subroutine
DELAYYELLOW: MOV A,R5 ;move #03H to A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P3,A
MOV R1, #03H ;delay for 3 seconds
DELAYYELLOW1: MOV R2, #05H
DEC R5
MOV A,R5
ANL A,#0FH
MOVC A,@A+DPTR
MOV P3,A
DELAYYELLOW2: DJNZ R2, DELAYYELLOW2
DJNZ R1, DELAYYELLOW1
MOV P3, #040H ; set the display to become "-"
RET
;DELAYRED subroutine
DELAYRED: MOV A,R4
ANL A,#0FH
MOVC A,@A+DPTR
MOV P3,A
MOV R1, #06H
DELAYRED1: MOV R2, #06H
DEC R4
MOV A,R4
ANL A,#0FH
MOVC A,@A+DPTR
MOV P3,A
DELAYRED2: DJNZ R2, DELAYRED2
DJNZ R1, DELAYRED1
RET
SEG: DB 3FH,06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6Fh
END