D0
D1
PA0
PA1
D2
PA2
D3
D4
D5
PA3
PA4
PA5
D6
D7
PA6
PA7
PB0
PB1
5
RD
36
WR
9
A0
8
A1
35
RESET
6
CS
PB2
PB3
PB4
PB5
PB6
PB7
PC0
PC1
PC2
PC3
PC4
PC5
4
3
2
1
40
39
PORT A PINS
38
37
18
19
20
21
22
23
PORT B PINS
24
25
14
15
16
17
13
12
PC6
11
PC7
10
PORT C PINS
A0
Function
0
0
1
1
0
1
0
1
Port A
Port B
Port C
Command Register (CR)
x86 Port
Addresses
0300
0301
0302
0303
MTS-88c Port
Addresses
0010
0011
0012
0013
Command
register:
6
5
4 byte
3 of
2 the
1 command
0
Command byte B
Port C (PC3 PC0)
1 = input
0 = output
0
Bit set/reset
1 = set
0 = reset
Select bits
EX1. Determine the command byte for mode 0 operation, where port A and port B pins of 8255 are
inputs, and Port C pins are outputs.
Soln:
Command byte for command register for example no. 1 is equal to 92h
Command byte A
7
EX2. Determine the command byte for mode 0 operation, where port B and lower half of port C pins
are inputs, and port A and upper half of port C pins are output.
Soln:
Command byte for command register for example no. 2 is equal to 83h
Command byte A
7
Part II - Sample Application of Interfacing IO device with 8255 and Assembly Program
APPLICATION 1 - Forward and Reverse DC Motor
Design an MPU-based system that will interface DC motor into 8255. This system consists of bidirectional DC motor connected to PORTA of PPI, 3 LED indicators (Forward, Reverse, and Stop) at
PORTA, and 1 toggle switch connected at PORTC. If switch is "ON", motor will turn on to a forward and
reverse status for 30 seconds but there is 2 seconds stop interval between each state.
.MODEL small
.STACK 64
.DATA
;setting variable i to 0
;setting variable j to 0
.CODE
;---Set starting program offset and clear all general purpose registers --org 100h
;set program starting offset at 0100
call clear_reg
;clear registers
jmp init_port
;jump to init_port label
;--- initialized PPI ports ----------------------------------------------init_port:
mov dx, CMD_REG
;initialized command byte of 8255
mov al, 89h
;PORTC0-PORTC7(1), PORTA0-PORTA7(0), PORTB0-PORTB7(0) & MODE 0
out dx, al
;transfer byte to CMD_REG
jmp check_switch
;jump to chech_switch (read status of switch)
;--- check the status of the toggle switch connected at PORTC 0, 0 Off, 1 On ---check_switch:
mov dx, PORTC
;initialized PORTC
in al, dx
;read input of switch
cmp al, 01h
;if al=01h then
je ForRevMotor
;jump to ForRevMotor
cmp al,00h
je OffMotor
jmp check_switch
ForRevMotor:
mov dx, PORTA
mov al, 09h
out dx, al
call delay30s
;initialized PORTA
;PORTA0=1,PORTA1=0,PORTA2=0,PORTA3=1,PORTA4=0,PORTA5=0,PORTC6=PORTA7=0
;send data to PORTA (forward motor for 30 secs)
;call subroutine delay30s (30 seconds delay)
;PORTA0=0,PORTA1=0,PORTA2=0,PORTA3=0,PORTA4=0,PORTA5=1,PORTC6=PORTA7=0
;send data to PORTA (stop motor for 2 secs)
;call subroutine delay2s (2 seconds delay)
;PORTA0=0,PORTA1=0,PORTA2=1,PORTA3=0,PORTA4=1,PORTA5=0,PORTC6=PORTA7=0
out dx, al
call delay30s
;PORTA0=0,PORTA1=0,PORTA2=0,PORTA3=0,PORTA4=0,PORTA5=1,PORTC6=PORTA7=0
;send data to PORTA (stop motor for 2 secs)
;call subroutine delay2s (2 seconds delay)
jmp check_switch
OffMotor:
mov dx, PORTA
mov al, 00h
out dx, al
;initialized PORTA
;PORTA0=0, PORTA1=0, PORTA2=0, PORTA3=0 PORTA4=0, PORTA5-PORTA7=0
;send data to PORTA
jmp check_switch
call exit
;--- start of procedures declaration --;--- clear_reg procedure ---clear_reg proc near
xor ax, ax
;clear register AX
xor bx, bx
;clear register BX
xor cx, cx
;clear register CX
xor dx, dx
;clear register DX
ret
clear_reg endp
;--- delay1sec procedure ---delay1sec proc near
mov bx,0fffh
del1: mov cx,0ffffh
del2: nop
nop
nop
nop
nop
loop del2
dec bx
cmp bx,0
jne del1
ret
delay1sec endp
;--- delay30sec procedure ---delay30sec proc near
mov i,0
del30: call delay1s
inc i
cmp i,30
jne del30
ret
delay30sec endp
;--- delay2sec procedure ---delay2sec proc near
mov j,0
del02: call delay1sec
inc j
cmp j,2
jne del02
ret
delay2sec endp
;exit procedure ah,4ch int 21h service used terminate program (similar to HLT)
exit proc near
mov ah, 4ch
int 21h
ret
exit endp
END init_port
A. Conditional Table
INPUTS (PORTC)
NC
NC
NC
NC
PC
7
PC
6
PC
5
PC
4
RS
T
PC
3
STATU
S
OUTPUTS (PORTA)
SF
MS
CS
NC
NC
NC
NC
PW
R
PC
2
PC
1
PC
0
PA
7
PA
6
PA
5
PA
4
PA3
RD
Y
PA
2
OP
GV
PA
1
PA
0
System
Off
System
on
Coin
Detecte
d
Start Fill
Reset
OU
T
IN
(HEX)
(HE
X)
00h/
01h/
04h/
05h
00h
02h
0ch
03h
0ch
06h
0Ah/
0bh/
0eh/0
fh
0bh
0bh
MODE
0
C. Program Code
.MODEL small
.STACK 64
.DATA
;constant declaration
PORTA equ 0300h
PORTC equ 0302h
CTRL_REG equ 0303h
CMD_BYTE equ 89h
PORTA
U-PORTC
MODE
PORTB
L-PORTC
mov
mov
out
jmp
dx, CTRL_REG
al, CMD_BYTE
dx, al
check_inputs
check_inputs:
mov dx, PORTC
in al, dx
cmp al, SYSTEM_ON
je system_on
cmp al, COIN_DETECT
je coin_detect
cmp al, START_FILL
je gasoline_fill
jmp system_off
system_on:
mov
mov
out
jmp
dx, PORTA
al, SYSTEM_ON_OUT
dx, al
check_inputs
coin_detect:
inc coin_counter
jmp check_inputs
mov
mov
mov
out
jmp
gasoline_fill:
coin_counter, INIT_CNT
dx, PORTA
al, RESET_OUT
dx, al
check_inputs
cmp coin_counter,
je cond1
cmp coin_counter,
je cond2
cmp coin_counter,
je cond3
cmp coin_counter,
je cond4
1
2
3
4
jmp reset
cond1:
cond2:
cond3:
cond4:
call Exit
;procedures declarations
Clear_Regs PROC NEAR
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
ret
Clear_Regs ENDP
delay PROC NEAR
mov bx,0fffh
d1:
mov cx, 0ffffh
d2:
nop
nop
nop
loop d2
dec bx
cmp bx,0
jne d1
ret
delay ENDP
delay3s PROC NEAR
mov t_cntr,0
x:
call delay
inc t_cntr
cmp t_cntr,3
jne x
ret
delay3s ENDP
delay6s PROC NEAR
mov t_cntr,0
y:
call delay3s
inc t_cntr
cmp t_cntr,2
jne y
ret
delay6s ENDP
delay9s PROC NEAR
mov t_cntr,0
z:
call delay3s
inc t_cntr
cmp t_cntr,3
jne y
ret
delay9s ENDP
delay12s PROC NEAR
call delay3s
call delay9s
ret
delay12s ENDP
Exit PROC NEAR
mov ah, 4ch
int 21h
ret
Exit ENDP
END init_ports
APPLICATION 3 - Bottle Conveyor System
This MPU-based system consists of two inputs (start and stop) and three outputs (conveyor
motor 1, counter indicator, and conveyor motor 2). Conveyor motor 1 turns ON while bottle counter is
not equal to 6 else conveyor motor 2 turn ON and conveyor motor 1 turn OFF for five seconds and
counter will reset to zero. Counter indicator indicates the counting by turning ON and OFF the lights
with an interval of 1 second. Start input is use to turn ON the system while stop input is use to
terminate all the process.
APPLICATION 4 - Comport Room Monitoring
Design an MPU-based Comport Room Monitoring. This system will monitor the number of person
entering and leaving. The total capacity of Comport Room can accommodate up to 5 persons. The
system will provide an automatic door-lock if the comport room is loaded. The entrance door is only
open if the number of persons entering is less than the maximum capacity of the Comport Room. Other
features of this system will also provide an automatic flushing for those terminal/s used. Inputs are five
sensors for each terminal, 0-5 up/down counter, and for the outputs use 6 solenoid valves: one for
door-lock and five for the terminals flushing. Assume that the entrance door is unidirectional door. Use
port B and C of your PPI as the input pins, and port A as your output pins.