12b. Elevator interface program

vtu mp 12b
Q) Drive an Elevator interface in the following way:
i. Initially the elevator should be in the ground floor, with all requests in OFF state.
ii. When a request is made from a floor, the elevator should move to that floor, wait there for a couple of seconds (approximately), and then come down to ground floor and stop.
If some requests occur during going up or coming down they should be ignored

This program will implement an simple elevator request simulation using an Elevator interface. Initially the elevator will be on the ground floor. And when a request is made from any floor, it will go the particular floor, wait for some time (using delay function) and come down to ground floor by clearing the floor’s request.

Algorithm:
Step 1: Initialize the control word 82H and store it in the control register.
Step 2: Initialize BL=0 to indicate that the elevator at the ground floor.
Step 3: Clear all request using OR instruction.
Step 4: Get the status of the request key using IN instruction through Port B.
Step 5: Determine the floor where service is required and move the LED to the particular requested floor.
Step 6: Wait for some times and comes back to the ground floor.
Step 7: Repeat Step 4 to Step 6 until no more request is made.
Step 8: Stop.

CODE:

Explanation:
Before explanation, know that the floor LED’s values are assigned as follows,
Ground floor button pressed  - 1110
First floor button pressed    - 1101
Second floor button pressed  - 1011
Third floor button pressed   - 0111

.MODEL SMALL
.CODE
MOV AL,82H
MOV DX,0E803H
OUT DX,AL
Programming model small, one data one code segment respectively.
In the code segment, initializing h/w interface as usual with control word 82h and control register address (0E803H).
CALL CLR_ALL_FLR 
AGAIN:
CALL CHECK_FLR   
CMP AL,0FFH     
JE AGAIN
Call the procedure CLR_ALL_FLR to clear the bulb of all floors. Then call CHECK_FLR again and again until user presses a floor button. If user enters any floor button, its associated bit value is stored in AL.( see why in CHECK_FLR definition below).
If user did not press any button, the floor associated value is 1111. That is 0FFH. Keep on calling CHECK_FLR until AL isn't 0FFH.

Now that you have floor associated value in AL. Whichever bit is 0, is the selected floor. Right most bit being for ground floor, the next bits to the left for each next floors.
Shift right the floor bit by 1 and if carry flag is zero, it means pressed button is from ground floor. Keep on shifting right until you find ‘zero’ in the ‘carry flag’, and move the lift to the floor accordingly.
SHR AL,01
JC M01           
CALL DELAY      
CALL DELAY
CALL CLR_GF
JMP FINISH
Shift right the AL(floor associated number), check the carry flag, if it is 1, ground floor button was not pressed. Go to label M01 to check if first floor button was pressed. If Carry flag is not 1, then wait in the ground floor for some time using DELAY function. Then call CLR_GF to clear the ground floor bulb. Then jump to finish.
M01: SHR AL,01            
JC M02                    
MOV AL,0F0H
MOV CX,03
CALL MOVE_UP     
CALL DELAY
CALL DELAY
CALL CLR_FF          
MOV CX,03
CALL MOVE_DOWN      
JMP FINISH
M01 is a label. Again shift right the AL here. If carry is 1, move to second floor checking. Else, move the lift to first floor (AL=0F0H is the first bulb’s bit value. CX=3 because there are 3 bulbs in between ground floor and first floor). Call MOVE_UP to move the lift CX times upwards. And wait for some time using DELAY. Clear that floor bulb and then come back using MOVE_DOWN again with CX=3. Then jump to finish.
M02: SHR AL,01
JC M03
MOV AL,0F0H
MOV CX,06
CALL MOVE_UP
CALL DELAY
CALL DELAY
CALL CLR_SF
MOV CX,06
CALL MOVE_DOWN
JMP FINISH
This is for second floor checking, shift right AL again, if carry is 1, it is obviously third floor. Else move the lift 6 times (CX=6, 6 bulbs between ground and second floor). Wait in that floor using DELAY and clear the floor and come back. Jump to finish.
M03: MOV AL,0F0H
MOV CX,09
CALL MOVE_UP
CALL DELAY
CALL DELAY
CALL CLR_TF
MOV CX,09
CALL MOVE_DOWN  
If none of the ground, first and second floor were pressed, it is obviously third floor. Move 9 to CX (9 bulbs). Go up, wait there, clear the floor and come down. That’s it.
FINISH: CALL CLR_ALL_FLR
MOV AH,4CH
INT 21H
At the end, Clear all the floors using CLR_ALL_FLR, and terminate.
MOVE_UP PROC NEAR
MOV DX,0E800H
L1:  INC AL
CALL DELAY
OUT DX,AL
LOOP L1
CALL DELAY
CALL DELAY
RET
MOVE_UP ENDP
I had told above, AL is the ground floor bit. Here, increase and output AL each time, (CX times using Port A, that is 0E800H). Give some delay. Then return.
MOVE_DOWN PROC NEAR
MOV DX,0E800H
L2: DEC AL                                                 
CALL DELAY
OUT DX,AL
LOOP L2                                                
CALL DELAY
CALL DELAY
RET
MOVE_DOWN ENDP
Move the lift downwards CX times each time decreasing AL and Outputting it through port A, that is 0E800H. Then return.
CHECK_FLR PROC NEAR
MOV DX,0E801H
IN AL,DX
OR AL,0F0H
RET
CHECK_FLR ENDP
Function to check the floor button which was pressed. Take the value through port B, 0E801H and it will be in AL. We need only the last 4 digits, so make the first 4 digits 1 by ORing with 0F0H. Then return.
CLR_ALL_FLR PROC NEAR
MOV AL,0F0H
MOV DX,0E800H
OUT DX,AL
RET
CLR_ALL_FLR ENDP
0F0H is the value when all the floor bulbs are off. Move it to AL and output it through port A,0E800H, to clear all the floor bulbs.
CLR_GF PROC NEAR
MOV DX,0E800H
AND AL,0F0H
OR AL,0E0H
OUT DX,AL
RET
CLR_GF ENDP
This function is to clear the ground floor bulb.
Move the value to clear all the floor into AL, that is 0F0H. This will clear all the floors, we need to clear only the ground floor. So OR it with ground floor bulb value(That is 1110, which in hexadecimal is 0E0H). Then output through port A.
CLR_FF PROC NEAR
MOV DX,0E800H
AND AL,0F0H
OR AL,0D0H
OUT DX,AL
RET
CLR_FF ENDP
This function is to clear the first floor bulb.
Same procedure as above except OR with first floor bulb value(That is 1101, which in hexadecimal is 0D0H). Then output through port A.
CLR_SF PROC NEAR
MOV DX,0E800H
AND AL,0F0H
OR AL,0E0H
OUT DX,AL
RET
CLR_SF ENDP
This function is to clear the second floor bulb.
Same procedure as above except OR with second floor bulb value(That is 1011, which in hexadecimal is 0B0H). Then output through port A.
CLR_TF PROC NEAR
MOV DX,0E800H
AND AL,0F0H
OR AL,70H
OUT DX,AL
RET
CLR_TF ENDP
This function is to clear the third floor bulb.
Same procedure as above except OR with third floor bulb value(That is 0111, which in hexadecimal is 70H). Then output through port A.
DELAY PROC NEAR 
PUSH AX
PUSH CX
PUSH DX
MOV CX,3FFFH
L4: MOV AX,0FFFFH
L3: DEC AX
JNZ L3
LOOP L4
POP DX
POP CX
POP AX
RET
DELAY  ENDP         
END
Delay function is explained in the H/W basics though. Visit here if you do not understand.

Output:
Seen in elevator interface.

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

2 comments

Write comments
Unknown
AUTHOR
9 May 2017 at 14:50 delete

may i view the source code please yomuevans@gmail.com

Reply
avatar
Unknown
AUTHOR
12 May 2017 at 23:32 delete

Hey there, Post updated. Please find code above. Thanks!

Reply
avatar

Share your views about this article!