Q. To provide preference to the pedestrians, for the system in question 3, push button as
shown below is also placed at the two sides of the road. If the push button is pressed 50
times the green light for pedestrians is turned on immediately for 4 seconds, and then the
operation continues as before. Assume D0 pin of input port 35H to be connected to the
push button and then to the microprocessor. Modify the program of question 3 to
accommodate the changes.
Solution:
Main Program
START: MVI B, 00H ; allocation for count
LABEL0: MVI A, 01H ; turn the green light on
OUT 66H
MVI C, 08h ; time required to turn on green light
LABEL1: CALL DELAY1
DCR C
JNZ LABEL1
MVI A, 80H ; turn the red light on
OUT 66H
MVI C, 64H ; time required to turn on red light
LABEL2: CALL DELAY2
DCR C
JNZ LABEL2
JMP START ; repeat the task
Delay Subroutine1
DELAY1: LXI H, F69AH ; count for 0.5 second delay
LABEL3: DCX H
MOV A, L
ORA H
JNZ LABEL3
RET
Delay Subroutine2
DELAY2: LXI H, 3152H ; count for 0.1 second delay
LABEL4: DCX H
MOV A, L
ORA H
JNZ LABEL4
IN 35H ; check if push button pressed
ANI 01H
JZ END ; if no return
INR B ; if yes count the signal
MOV A, B
CPI 32H ; check if count is equal to 50
JZ LABEL0 ; if yes turn on green light
END: RET ; else return
shown below is also placed at the two sides of the road. If the push button is pressed 50
times the green light for pedestrians is turned on immediately for 4 seconds, and then the
operation continues as before. Assume D0 pin of input port 35H to be connected to the
push button and then to the microprocessor. Modify the program of question 3 to
accommodate the changes.
Solution:
Main Program
START: MVI B, 00H ; allocation for count
LABEL0: MVI A, 01H ; turn the green light on
OUT 66H
MVI C, 08h ; time required to turn on green light
LABEL1: CALL DELAY1
DCR C
JNZ LABEL1
MVI A, 80H ; turn the red light on
OUT 66H
MVI C, 64H ; time required to turn on red light
LABEL2: CALL DELAY2
DCR C
JNZ LABEL2
JMP START ; repeat the task
Delay Subroutine1
DELAY1: LXI H, F69AH ; count for 0.5 second delay
LABEL3: DCX H
MOV A, L
ORA H
JNZ LABEL3
RET
Delay Subroutine2
DELAY2: LXI H, 3152H ; count for 0.1 second delay
LABEL4: DCX H
MOV A, L
ORA H
JNZ LABEL4
IN 35H ; check if push button pressed
ANI 01H
JZ END ; if no return
INR B ; if yes count the signal
MOV A, B
CPI 32H ; check if count is equal to 50
JZ LABEL0 ; if yes turn on green light
END: RET ; else return
Comments
Post a Comment