Micro133: Microprocessor Systems Midterm Lecture 2: IO Interfacing with 8255 & Assembly Language PART I – Introduction to 8255 (PPI) 8255 PPI (Pro!r"mm"#$e Perip%er"$ Inter&"ce)
A very popular low-cost interfacing component found in many applications !as 2" pins for I#O$ programmable in groups of %2 pins that are used in three separate mode of operation an be interface any ''L ('ransistor-'r ('ransistor-'ransistor ansistor Logic) compatible device to the microprocessor 8255
34 33 32 31 30 29 28 27
D0
PA0 PA0
D1
PA1 PA1
D2
PA2 PA2
D3
PA3 PA3
D4 D5
PA4 PA4 PA5 PA5
D6
PA6 PA6
D7
PA7 PA7 PB0 PB1 PB2
5 36 9 SELECTS INPUT PINS
8 35 6
PB3 RD’
4 3 2 1 40 39
`
PORT A PINS
38 37 18 19 20 21 22 23
WR’
PB4 PB5
A0
PB6
A1
PB7
RESET CS’
PC0
14
PC1
15
PC2
16
PC3
17
PC4 PC5
13 12
PORT B PINS
24 25
PC6
11
PC7
10
PORT C PINS
'i!ure 11 *ins Assignment Assignment of 8255 Three I/O port of PPI: % *ort A - (*A+ , *A) 2 *ort . - (*.+ , *.) / *ort - (*+ , *C *C7 )
Two group connections of PPI: % 0roup 0rou p A - *ort A (*A+ , *A) and upper half of *ort (*-*") 2 0roup . - *ort . (*.+ , *.) and lower half of *ort (*/-*+)
Select input pins of PPI: % CS’ % CS’ , , use to select for the programming$ and reading and writing to a port 2 A 2 A1 and A0 , , register selection that selects an internal register for programming or operation
/ RD’ , use to select the read (input) operation of **I " WR’ - use to select the write (output) operation of **I 5 RESET , this input pin use to initiali1e the device
T"#$e 11 I#+ *ort assignments for the 8255 A1
A
'unction
+ + % %
+ % + %
*ort A *ort . *ort ommand egister ()
*8+ Port Addresses 3+ 3% 32 3/
MTS88c Port Addresses 1+ 1% 12 1/
Pro!r"mmin! t%e 8255 Two Command byte A of PPI: % 0roup . – Port B (PB 0 – PB7 ) and lower half of Port C (PC 3-PC0 ) - are programmed as either input or output pins in mode + or mode % 2 0roup A - Port A (PA0 – PA7 ) and !!er half of Port C (PC 7 -PC") - are programmed as either input or output pins in mode +$ mode %$ or mode 2
Three Mode Operation of PPI: % Mode , operation that allows the 8255 to function either as a input device or latched output .asic Input#Output operation 2 Mode 1 , strobe input or strobe output operation auses port A and#or port . to functions as latching input devices / Mode 2 , bi-directional operation$ which allows only group A$ port A becomes bi-directional$ allowing data to transmitted and received over the same eight wires Co((.%) /t* A 7
,omm"nd re!ister: 6 5 4 #yte 3 o& 2 t%e 1 comm"nd 0
1
Co((.%) /t* B Port C PC3 ! PC0" 1 # $%&'t 0 # o't&'t
7
6
5
4
0
X
X
X
3
2
1
0
B$t *tr**t Port B PB7 ! PB0" 1 # $%&'t 0 # o't&'t ,o)* 0 # (o)* 0 1 # (o)* 1+ 2
1 # *t 0 # r**t
S**t /$t
Port C PC7 ! PC4" 1 # $%&'t 0 # o't&'t Port A PA7 ! PA0" 1 # $%&'t 0 # o't&'t ,o)* 00 # (o)* 0 01 # (o)* 1 1- # (o)* 2 Co((.%) /t* **t 1 ! o((.%) /t* Aor (o)* 0 o%" 0 ! o((.%) /t* B or (o)* 1 or (o)* 2 o%"
-.T/: 3ou will need first to determine the command byte of 8255 for the command register in order to 4now the operations (input#output) of the three I#O ports Co##and $%te B is not used if youre only using the #ode 0 operation of 8255
E&1' 6etermine the command byte for mode + operation$ where port A and port . pins of 8255 are inputs$ and *ort pins are outputs 7oln ommand byte for command register for e9ample no % is e:ual to 02% Co((.%) /t* A 7
6
5
4
3
2
1
0
1
0
0
1
0
0
1
0
E&' 6etermine the command byte for mode + operation$ where port . and lower half of port pin s are inputs$ and port A and upper half of port pins are output 7oln ommand byte for command register for e9ample no 2 is e:ual to 83% Co((.%) /t* A 7
6
5
4
3
2
1
0
1
0
0
0
0
0
1
1
P"rt II S"mp$e App$ic"tion o& Inter&"cin! I. deice it% 8255 "nd Assem#$y Pro!r"m APPLI,ATI.- 1 ;orward and everse 6 6 indicators (;orward$ everse$ and 7top) at *O'A$ and % toggle switch connected at *O' If switch is ?O@?$ motor will turn on to a forward and reverse status for /+ seconds but there is 2 seconds stop interval between e ach state
.MODEL small
;model directive (program not greater than 64KB) ;stack directive (occupies only 1 st 64KB of stack data) ;data segment directive (declaration of all variables)
.STACK 64 .DATA
;---liasing !!" !orts using #$% (e&ual) -----------------------------!' #$% *+**h ;e&uating !' to address *+**h !'B #$% *+*1h ;e&uating !'B to address *+*1h !', #$% *+*h ;e&uating !', to address *+*h ,./0# #$% *+*+h ;e&uating ,./0# to address *+*+h i /B * 2 /B *
;setting variable i to * ;setting variable 2 to *
.CODE
;---3et starting program offset and clear all general purpose registers --org 1**h ;set program starting offset at *1** call clear0reg ;clear registers 2mp init0port ;2ump to init0port label ;--- initialied !!" ports ----------------------------------------------init0port5 mov d7 ,./0# ;initialied command byte of 899 mov al7 8:h ;!',*-!',(1)7 !'*-!'(*)7 !'B*-!'B(*) < .'/# * out d7 al ;transfer byte to ,./0# 2mp check0s=itch ;2ump to chech0s=itch (read status of s=itch) ;--- check the status of the toggle s=itch connected at !', *7 * > 'ff7 1 > 'n ---check0s=itch5 mov d7 !', ;initialied !', in al7 d ;read input of s=itch cmp al7 *1h ;if al?*1h then 2e @orev.otor ;2ump to @orev.otor cmp al7**h 2e 'ff.otor 2mp check0s=itch @orev.otor5 mov d7 !' mov al7 *:h out d7 al call delay+*s
;if al?**h then ;2ump to 'ff.otor
;initialied !' ;!'*?17!'1?*7!'?*7!'+?17!'4?*7!'9?*7!',6?!'?* ;send data to !' (for=ard motor for +* secs) ;call subroutine delay+*s (+* seconds delay)
mov al7 *h out d7 al call delays
;!'*?*7!'1?*7!'?*7!'+?*7!'4?*7!'9?17!',6?!'?* ;send data to !' (stop motor for secs) ;call subroutine delays ( seconds delay)
mov al7 14h
;!'*?*7!'1?*7!'?17!'+?*7!'4?17!'9?*7!',6?!'?*
out d7 al call delay+*s
mov al7 *h out d7 al call delays
;send data to !' (reverse motor for +* secs) ;call subroutine delay+*s (+* seconds delay)
;!'*?*7!'1?*7!'?*7!'+?*7!'4?*7!'9?17!',6?!'?* ;send data to !' (stop motor for secs) ;call subroutine delays ( seconds delay)
2mp check0s=itch
;2ump to check0s=itch (read status of s=itch)
'ff.otor5 mov d7 !' mov al7 **h out d7 al
;initialied !' ;!'*?*7 !'1?*7 !'?*7 !'+?* !'4?*7 !'9-!'?* ;send data to !'
2mp check0s=itch
;2ump to chech0s=itch (read status of s=itch)
call eit
;eit the =hole program
;--- start of procedures declaration --;--- clear0reg procedure ---clear0reg proc near or a7 a ;clear register A or b7 b ;clear register BA or c7 c ;clear register ,A or d7 d ;clear register /A ret clear0reg endp ;--- delay1sec procedure ---delay1sec proc near mov b7*fffh del15 mov c7*ffffh del5 nop nop nop nop nop loop del dec b cmp b7* 2ne del1 ret delay1sec endp ;--- delay+*sec procedure ---delay+*sec proc near mov i7* del+*5 call delay1s inc i cmp i7+* 2ne del+* ret delay+*sec endp ;--- delaysec procedure ---delaysec proc near mov 27* del*5 call delay1sec inc 2 cmp 27 2ne del* ret delaysec endp
;appro 1 sec delay
;appro +* secs delay
;appro secs delay
;eit procedure ah74ch > int 1h service used terminate program (similar to CD) eit proc near mov ah7 4ch int 1h ret eit endp #E/ init0port
;end of init0port (1 st label in the program - =hole program)
APPLI,ATI.- 2 oin-Operated 0asoline 7tation 6esign <*=-based oin-Operated 0asoline 7tation 'his gasoline station will accept %+ peso coin to set gasoline valve for certain time which corresponds to number of liter per seconds % 2 / "
coin , +/ liter (valve will opens coins , plus +/ liters (valve will coins , plus +/ liters (valve will coins , plus +/ liters (valve will
for / seconds) opens for seconds) opens for B seconds) opens for %2 seconds)
A. Conditional Table
INPUTS (PORTC) NC
NC
NC
NC
PC 7
PC 6
PC 5
PC 4
RS T PC 3
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
STATU S
OP
GV
PA 1
PA 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
1
1
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
0
0
0
1
0
1
S!"#$% O&&
S!"#$% * C,* 0 D$#$+#$ 1 S#./# F,
OU T
IN (HEX)
(HE X)
00' 01' 04' 05'
00'
02'
0+'
03'
0+'
06'
0'
0Ah/ 0bh/
0
0
0
0
1
1
0
0
0
0
1
1
0
0
R$"$#
0eh/0
0'
fh
B. Command Byte Value = 81h MODE
PORTA
UPORTC
MODE
PORT
PORTC
0
1
0
0
1
1 0
C P//.% C-$
.'/#D small 3,K 64 / ;constant declaration !' e&u *+**h !', e&u *+*h ,D0# e&u *+*+h ,./0BF# e&u 8:h
0
3F3#.0'E e&u *h ,'"E0/##, e&u *+h 30@"DD e&u *6h 3F3#.0'E0'% e&u *ch 3F3#.0'@@0'% e&u **h #3#0'% e&u *ch ,'"E0/##,0'% e&u *ch 30@"DD0'% *bh "E"0,E e&u * ;variable declarations coin0counter db "E"0,E t0cntr db "E"0,E ,'/# org 1**h call ,lear0egs 2mp init0ports init0ports5 mov mov out 2mp
d7 ,D0# al7 ,./0BF# d7 al check0inputs
check0inputs5 mov d7 !', in al7 d cmp al7 3F3#.0'E 2e system0on cmp al7 ,'"E0/##, 2e coin0detect cmp al7 30@"DD 2e gasoline0fill 2mp system0off system0on5
mov mov out 2mp
d7 !' al7 3F3#.0'E0'% d7 al check0inputs
coin0detect5 inc coin0counter 2mp check0inputs system0off5 mov d7 !', in al7 d cmp al7 3F3#.0'E 2e reset mov d7 !' mov al7 3F3#.0'@@0'% out d7 al 2mp check0inputs reset5 mov mov mov out 2mp gasoline0fill5
coin0counter7 "E"0,E d7 !' al7 #3#0'% d7 al check0inputs
cmp coin0counter7 2e cond1 cmp coin0counter7 2e cond cmp coin0counter7 2e cond+ cmp coin0counter7 2e cond4
1 + 4
2mp reset cond15
mov /A7 !' mov al7 30@"DD0'% out d7 al call delay+s 2mp reset
cond5
mov /A7 !' mov al7 30@"DD0'% out d7 al call delay6s 2mp reset
cond+5
mov /A7 !' mov al7 30@"DD0'% out d7 al call delay:s 2mp reset
cond45
mov /A7 !' mov al7 30@"DD0'% out d7 al call delay1s 2mp reset
call #it ;procedures declarations ,lear0egs !', E# or a7a or b7b or c7c or d7d ret ,lear0egs #E/! delay !', E# mov b7*fffh d15 mov c7 *ffffh d5 nop nop nop loop d dec b cmp b7* 2ne d1 ret delay #E/! delay+s !', E# mov t0cntr7*
5
call delay inc t0cntr cmp t0cntr7+ 2ne ret delay+s #E/! delay6s !', E# mov t0cntr7* y5 call delay+s inc t0cntr cmp t0cntr7 2ne y ret delay6s #E/! delay:s !', E# mov t0cntr7* 5 call delay+s inc t0cntr cmp t0cntr7+ 2ne y ret delay:s #E/! delay1s !', E# call delay+s call delay:s ret delay1s #E/! #it !', E# mov ah7 4ch int 1h ret #it #E/! #E/ init0ports
APPLI,ATI.- 3 .ottle onveyor 7ystem 'his <*=-based system consists of two inputs (start and stop) and three outputs (conveyor motor %$ counter indicator$ and conveyor motor 2) onveyor motor % turns O@ while bottle counter is not e:ual to else conveyor motor 2 turn O@ and conveyor motor % turn O;; for five seconds and counter will reset to 1ero ounter indicator indicates the counting by turning O@ and O;; the lights with an interval of % second 7tart input is use to turn O@ the system while stop input is use to terminate all the process
APPLI,ATI.- omport oom