Q) Read the status of two 8-bits inputs (X & Y) from the Logic Controller Interface and display X*Y.
This program will display the product of two 8 bit input numbers x and y (inputted from logic controller) on the logic controller.
Algorithm:
This program will display the product of two 8 bit input numbers x and y (inputted from logic controller) on the logic controller.
Algorithm:
Step 1: Connect Logic Controller to PC.
Step 2: Set the 8255 using control word.
Step 3: Read the first data (Port B) from logic controller and store in X.
Step 4: Read the second data (Port B) from logic controller and store in Y.
Step 5: res=X*Y
Display(higher 8 bit data of res)
Step 6: Call delay procedure or wait some time.
Step 7: Stop
Step 2: Set the 8255 using control word.
Step 3: Read the first data (Port B) from logic controller and store in X.
Step 4: Read the second data (Port B) from logic controller and store in Y.
Step 5: res=X*Y
Display(higher 8 bit data of res)
Step 6: Call delay procedure or wait some time.
Step 7: Stop
CODE:
Explanation:
ASSUME CS:CODE,DS:DATAProgramming model selected contains one data segment(DS) and one code segment (CS).
DATA SEGMENT
CR EQU 0e803H
PA EQU 0e800H
PB EQU 0e801H
PC EQU 0e802H
DATA ENDS
Our data segment contains three memory locations assigned with port addresses of the logical interface. Port A(PA), Port B(PB), Port C(PC) and Control registers(CR) are equated with appropriate port addresses.
CODE SEGMENTCode segment starts with initializing of data segment at the line 3 and 4 in the snippet.
START:
MOV AX,DATA
MOV DS,AX
MOV DX,CRActivating Controller using normal procedure.(first 3 lines)
MOV AL,82H
OUT DX,AL
MOV DX,PB
IN AL,DX
MOV BL,AL
CALL DELAY
Inputting a number using IN instruction (Port B is input and its address is moved into DX).
Inputted number (x) is moved to BL. (this is first number for multiplication)
Call some delay after entering first number.
Take second number (Y) using IN command,(DX containing the input port address).
MOV DX,PB
IN AL,DX
MUL BL
First number is in BL and second one in AL.
Multiply content of AL and BL using MUL BL. Result of multiplication is stored in AL.
MOV DX,PAMove Output port address into DX and Display the result which is AL using OUT command. Finally terminate.
OUT DX,AL
MOV AH,4CH
INT 21H
DELAY PROCDelay procedure is same.See explanation See explanation here.
PUSH BX
PUSH DX
MOV DX,0FFFH
UP2: MOV BX,0FFFFH
UP1:NOP
DEC BX
JNZ UP1
DEC DX
JNZ UP2
POP DX
POP BX
RET
DELAY ENDP
CODE ENDS
END START
Output:
Seen in logic controller
Share your views about this article!