Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

I

NTERFACI
NG:

Ther
ear
ethr
eebasi
cway
stogetdat
aint
ooroutofamemor
y:

i
. Pr
ogr
ammedI
/O

i
i
. I
nter
rupt
-dr
ivenI
/O

i
i
i. Di
rectmemor
yaccess(
DMA)

Al
thoughpr
ogrammedI/Oi
stheslowestoft
het
hree,
iti
susedi
nsi
mpl
ermi
cropr
ocessor
sy
stemswherespeedi
suni
mportant.

Ast
hesy
stem becomesmor
ecompl
ex,
thei
nter
ruptappr
oachbecomesnecessar
y.

Inmostadvancedsyst
ems,DMAisneededbecausei
tist
heonl
ywayt
otr
ansf
erl
arge
amountsofdatainashor
tti
me.

i
. Pr
ogr
ammedI
/O

Thismethodusesinstr
ucti
onstogetdat
aintooroutofaCPU.Tocor r
ectl
yti
methet
ransf
er,
programmedI/Oreli
eseit
heronclockt
iming(sy
nchronous)oronhandshaki
ng
(asynchr
onous)
.

Handshaki
ngi
susedmor
eof
tenbecausei
tissi
mpl
er.

Fi
gur
e1.Pr
ogr
ammedi
nput

Fig.1showsaCPUconnectedt
oports10H,
11H,and12H.Bi
t6ofpor
t10Hisconnectedt
o
theSTARTinputoft
heper
ipher
aldev
ice,
andbi
t7ofport11Htot
heSTATUSoutput.

Thedev
icecansenddat
atot
heCPUt
hroughi
nputpor
t12H.

Thebasicideaisthat
,whent
heCPUi
sreadyt
oinputawor
d,i ghSTARTbi
tsendsahi tto
theper
ipheraldev
ice.

Whenthedevi
cehasthedat
areadyf
ort
ransf
er,
itsendsahighSTATUSbittopor
t111H.
Unt
ilheSTATUSbi
t ti
shigh,
theCPUwai
ts.Assoonast heSTATUSbitgoeshi
gh,t
heCPU
i
nputs1byt
eofdata.

Supposewewantt
oinput256by
tesandst
oret
hem ataddr
esses2000Ht
hrough20FFH.
Label Mnemoni
cs Comment
s

LXIH,
2000H ;
Ini
ti
ali
seHLpoi
nt

MVIC,
00H ;
Ini
ti
ali
secount
er

LOOP: MVIA,
40H SetSTARTbi
; t

OUT10H ;
Sendhi
ghSTARTbi
t

WAI
T: I
N11H GetSTATUSbi
; t

ANI80H ;
Isol
ateSTATUSbi
t

JZWAI
T ;
Wai
tifdev
icenotr
eady

I
N12H ;
Inputdat
a

MOVM,
A ;
Stor
edat
a

I
NXH ;
Updat
eHLpoi
nter

MVIA,
00H ResetSTARTbi
; t

OUT10H ; owSTARTbi
Sendl t

DCRC ;
Countdown

JNZLOOP ;
Gobacki
fnotf
ini
shed

HLT

LXIHset
stheHLpoi
nterat2000H,
thel
ocat
ionoft
hef
ir
stby
tet
obest
ored.

TheMVICcl
ear
stheCr
egi
ster
,whi
chact
sli
keacount
erdur
ingt
hispr
ogr
am.

TheMVIAset
sbit6togetaccumul
atorcont
ent
sof40H.Thent
heOUT10Ht
ransf
erst
he
word40Hi
nport10H.

Bit6ofport10Hisconnect
edt
otheSTARTi
nputoft
heper
ipher
aldev
ice;
ther
efor
e,t
he
devi
cereceiv ghSTARTbi
esahi t
.

Whenr
eadyf
ort
hedat
atr
ansf
er,
thedev
icewi
l
l ghSTATUSbi
sendbackahi t.

TheI N11HandANI80Hisol
atetheSTATUSbit
.Asl
ongastheSTATUSbiti
slow,the
program remai
nsi
ntheWAITloop.Af
t heSTATUSbi
ert tgoeshi
gh,t
heprogram f
all
s
throughtheJZ.

TheI
N12Hi
nput
sthedat
afr
om t
hedev
ice.TheMOVM,
Ast
orest
hisdat
aat2000H.

TheINXHincr
ement
stheHLpoi
nter
.TheMVIA, 00HandOUT10Hcl eartheSTARTbi
t.
ThentheDCRCdecr
ement
sthecounter
.Att
hispoint
,theCr
egi
stercontai
nsFFH.

JNZLOOPt
henr
etur
nst
hepr
ogr
am t
otheLOOPpoi
nt,
wher
ethecy
clesst
artov
er.
After256by
tesofdat
ahavebeenst
oredat2000Ht
hrough20FFH,
thepr
ogr
am f
all
sthr
ough
theJNZLOOPt otheHLT.

I
ntheFigure1,onl
y1bitofport10Hisused;
theother7bi
tsaredon’
tcares.Li
kewiseinpor
t
11H,onl
y1bi ti
sused.Por
ts10Hand11Har enecessaryf
orthehandshaki
ngoperati
ons;
por
t12Hi sneededfort
hedatatransf
er.

Out
put

Fi
g.2.Pr
ogr
ammedOut
put

Fi
gure2showsaCPUconnectedt
ohandshaki
ngport
s10Hand11H.Iti
salsoconnectedt
o
out
putpor
t12H.Asbef
ore,
bit6ofpor
t10HistheSTARTbi
t,andbi
t7ofport11Histhe
STATUSbit
.

WhentheCPUisready,i
twi
ll
lat
chthedatai
ntopor
t12H.t
hen,
t ghSTART
heCPUsendsahi
bi
ttoi
ndicat
ethatval
i
ddataiswai
ti
ngfortr
ansf
er.

Af
tert
heper
ipher
aldev
icehasl
oadedt
hedat
a,i
tret
ur ghSTATUSbi
nsahi t.

Supposei
tisr
equi
redt
oout
put256by
tesf
rom memor
ylocat
ions2000Ht
o20FFH.

Label Mnemoni
c Comment

LXIH,
2000H ;
Ini
ti
ali
seHLpoi
nter

MVIC,
00H ;
Ini
ti
ali
secount
er

LOOP: MOVA,
M ;
Getnextby
te

OUT12H ;
Lat
chdat
aint
opor
t12H

MVIA,
40H SetSTARTbi
; t

OUT10H ; ghSTARTbi
Sendhi t

WAI
T: I
N11H GetSTATUSbi
; t

ANI80H ;
Isol
ateSTATUSbi
t
JZWAI
T ;
Wai
tf ghSTATUS
orhi

I
NXH ;
Updat
epoi
nt

MVIA,
00H ResetSTARTbi
; t

OUT10H ; owSTARTbi
Sendl t

DCRC ;
Countdown

JNZLOOP ;
Gobacki
fcountnotzer
o

HLT

TheLXIpr
eset
stheHLpoint
erat2000H,
andt
heMVICclear
st hecount
er.TheMOVA, M
l
oadsthedat
aint
otheaccumul
atorandt
heOUT12Hl
atchesthisdat
aintoport12H.

TheMVIAset stheSTATUSbit
,andt
heOUT10Hsendst hi ghSTARTbi
shi ttoport10H.At
thi
spoint
,theprogram ent
erst
heWAITloop.TheI
N11H, ANI80H,andJZWAI Twi l
lbe
execut
edov erandoverunti
l ghSTATUSbi
ahi tisr
etur
nedbytheperipher
aldevi
ce.

ghSTATUSbi
Thehi tindi
cat
est
hatt
hedev
icehasl
oadedt
hedat
aandi
sreadyf
ort
henext
byt
e.

TheINXHi
ncrementstheHLpointer;t
heMVIA,00HandOUT10Hcl heSTARTbi
eart t
;and
theDCRCdecrementsthecount
ertogetFFH.TheJNZLOOPr
etur
nstheprogr
am t
othe
MOVA,M,wherethenextcycl
ebegins.

Theprogr
am wi
l
lloopuntil
256by t
esofdat
ahavebeentr
ansfer
redf
rom addr
esses2000H
to20FFHtot
heperipher
aldev
ice.Thent
heprogr
am f
all
sthr
oughtheJNZt ot
heHLT.

Progr
ammedI /
Oissomet i
mesr ef
erredtoaspol l
edI/O.Thei nci
dencesexplor
edabov e
haveusedsof
twar
etocontroltheI/Ot r
ansfer
sofasi ngleperi
pheraldev
ice.Bymodif
ying
thesoft
war
e,wecanpol
lseveralperi
pheral
devicesandtransf
erdatawheneachisready.

Exampl
e1:Key
boar
d

Fi
gur
e3.Key
boar
dcont
rol
l
er

Por
t:anaddr
essabl
eregi
ster

- i
nputonl
ypor
ts:
CPUonl
yreadsf
rom i
t
- out
putonl
ypor
ts:
CPUonl
ywr
it
est
oit

- por
tsf
orbot
hinputandout
put

Ever
yporthasanumber
.Apor
tcanber
efer
redt
oinanassembl
ylanguagepr
ogr
am byi
ts
number
,suchas: I
N 1

Stat
usport:checkedbyt
heCPUt
oseei
fakeyhasbeenpr
essedanddat
aisr
eadyt
obe
senttoCPU

Dat
apor
t:whenakeyi
spr
essed,
itsASCI
Icodei
sfoundi
nthedat
apor
t

Pol
li
ng:
CPUcont
inual
l
yex
ami
nest
hest
atuspor
tunt
ilakeyi
spr
essed(
Progr
ammedI
/O)

Ex:
Readi
ngachar
act
erf
rom key
boar
d

KEYI
N:I
N 0 ;
readst
atuspor
tintoA
ANA A ;t
estA(10H–keyi
spr
essed,
00H–ot
her
wise)
JZ KEYI
N ;j
umpif00H
I
N 1 ;t
akedataint
oA
RET

Exampl
e2:
Pri
nter

Fi
gur
e4.Pr
int
ercont
rol
l
er

Dat
apor
t:char
act
ert
obepr
int
edi
sputi
nthi
spor
t

Cont
rolpor
t:whenthecharacteri
sreadyinthedat
apor
t,st
robesi
gnal(
thatt
ell
sthepr
int
er
t
hati
tcantakethechar
acterindataport
)issent
.

Ati
mi ngl
oopmustbeusedintheCPUsot
hatt
hechar
act
ersar
enev
erpassedt
othepr
int
er
ataratef
ast
ert
hanitcanaccept
.

• Speci
alchar
act
ers:

- car
ri
ager
etur
n:causest
hepr
int
erheadt
omov
etot
hel
eftsi
deoft
hepaper

- l
i
nef
eed:
causest
hepr
int
ert
oadv
ancet
hepaperbyonel
i
ne
Ex:
Wri
ti
ngachar
act
ert
opr
int
er

CHAROUT: OUT 3 ;putchar .inaccumulatorintooutputpor


t
CALL DELAY ;
makesureprinterisready
MVI A, 10H ;setupst robewor d(10H–char .i
ndata
portisav ail
ableforpri
nti
ng)
OUT 2 ;putitintocont rolporttostartstr
obesignalt
o
pr
inter
MVI A,
00H ;resetst robe( 00H –char .indataportisnot
av ai
l
ableforprint
ing)
OUT 2 ;putitintocont rol
porttofini
shstrobesi
gnal
RET
Summary
Devi
cehasr
egi
ster
s,accessi
blev
iasy
stem bus.Forout
put
:

 CPUpl
acesdat
aindat
aregi
ster

 CPUput
swr
it
ecommandi
ncommandr
egi
ster

 CPUbusy
-wai
tsr
eadi
ngst
atusr
egi
sterunt
ilr
eadyf
lagi
sset

Si
mil
arl
yfori
nput
,wher
eCPUr
eadsf
rom dat
aregi
ster
.

i
i
. I
nter
rupt
-dr
ivenI
/O

Aninterr
uptisasi gnalthatcausest hecomput ert
oal t
erit
snor malflowofinstr
uction
executi
on.E.g.divide byzer o,time out ,I
/O operat
ion.The inter
ruptautomat i
call
y
tr
ansferscontr
oltoani nter
ruptprocessingrout
inewhichtakessomeact i
oninresponse
totheconditi
onthatcausedt heinterrupt,
andthencontroli
sreturnedtotheprogram at
whichit
sexecutionwasi nter
rupted.

pr
ogr
am

i
nter
ruptr
out
ine

i
nter
ruptoccur
s

Somei
nter
ruptt
ypes:

-I
/Oi
nter
rupt
:Gener
atedbyanI
/Ochannel
ordev
ice.

-Program i
nter
rupt
:Generat
edbysomeconditi
onthatoccur
sdur
ingpr
ogr
am execut
ion
(eg.di
videbyzero,
il
legal
machi
neinst
ruct
ion,
etc.
)
-Ti
meri
nter
rupt
:Gener
atedbyani
nter
nal
timerwi
thi
ntheCPU

-Super
visorcal
lint
errupt(
SVC) :ASVCinst
ructi
ongenerat
esanint
err
uptt
hattransf
ers
cont
rolt
oanOSser vicerout
ine.TheCPUswitchesf
rom usermodet
osuper
visormode.

Whenani nter
r uptoccurs,
thestatusoft
heCPUi ssaved(regi
sters,
program counteret
c.)
andtheinterruptser vi
cerouti
neisexecuted.Aftertheinter
ruptisprocessed,theyare
rest
oredbyt hei nterr
uptrout
ineandcont r
olistransfer
redtot heprogram.Sav i
ngand
rest
ori
ngthepr ocessorst
atusiscall
edcontextswit
ching.

I
nter
ruptpr
ior
it
y:Dur
ingt
hepr
ocessi
ngofani
nter
rupt
,al
lint
err
upt
sofequalorl
ower
pri
ori
tyar
einhi
bited,hi
gherpri
ori
tyint
err
uptsar
eal
lowed.Attheendofani nter
rupt
,if
ther
earemorethanoneinter
ruptpendi
ng,onewi
tht
hehighestpr
ior
it
yisexecut
ed.

I
nter
ruptmaski
ng,i
susedt
opr
eventcer
tai
nint
err
upt
sfr
om occur
ri
ngwhi
l
ethef
ir
stone
i
sbei
ngpr
ocessed.

Devicesignal
sit
sreadinessbyani nt
err
upt
.Processorperf
ormsther
equi
redI
/O by
executi
nganISR.Ot
herwisepr
ocessori
sbusydoi
ngotheruseful
wor
k.

Fi e.Di
gur skcont
rol
l
er

i
i
i. DMA
DMA–Aspecialcont
rol
uni
tmaybeprovi
dedtotransferablockofdat
adi
rect
lybetweenan
I
/Odev
iceandthemainmemor
y,wi
thoutcont
inuousinter
venti
onbethepr
ocessor.

Cont
rol
unitwhi
chperfor
mst
heset
ransfer
sisapar
toft
heI
/Odev
ice’
sint
erf
aceci
rcui
t.
Thi
scontr
oluni
tiscal
l
edaDMAcontrol
l
er.

DMAcont
rol
l
erper
for
msf
unct
ionst
hatwoul
dbenor
mal
l
ycar
ri
edoutbyt
hepr
ocessor
:

- f
oreachwor
d,i
tpr
ovi
dest
hememor
yaddr
essandal
lthecont
rol
signal
s,

- Totr
ansferabl
ockofdat
a,i
tincr
ement
sthememor
yaddr
essesandkeepst
rackoft
he
numberoftr
ansf
ers.

DMAcont r
oll
ercantransf
erablockofdatafr
om anext
ernal
dev
icet
othepr
ocessor
,the
wi
thoutanyint
ervent
ionfrom t
heprocessor
.

However,
theoper
ati
onoftheDMAcontr
ollermustbeundert
hecont
rol
ofapr ogr
am
execut
edbythepr
ocessor
.Thati
s,t
heprocessormusti
nit
iat
etheDMAtransf
er.

Toi
nit
iat
etheDMAt
ransf
er,
thepr
ocessori
nfor
mst
heDMAcont
rol
l
erof
:

- St
art
ingaddr
ess

- Numberofwor
dsi
nthebl
ock

- Di
rect
ionoft
ransf
er(
I/Odev
icet
othememor
y,ormemor
ytot
heI
/Odev
ice)

OncetheDMAcont
rol
l
ercompl
etest
heDMAt
ransf
er,
iti
nfor
mst
hepr
ocessorbyr
aisi
ngan
i
nter
ruptsi
gnal
.
i
v.
.

You might also like