You are on page 1of 8

91

Chapter11
Hardwarefeaturesof8051
SolutiontoNumerical/DESIGNBASEDEXERCISE:
1. Showthecircuitconnectionsforinterfacing16KofEPROMIC27128and8KofRAMIC
6264withthe8051.

Thefirststepininterfacingistoselectorfixtheaddressrangeforthechipstobeused.Asthe
27128has16KBofmemoryregisters,itrequires14addresslinestoselectonememorylocation
in it. The address map of the 27128 is fixed as 0000H3FFFH. The address range for the 8KB
RAMchip6264isselectedasC000HDFFFH.
The most significant bits A14 and A15 are used to decode and select the chip. For decoding
purposes, a 2to4 decoder chip, the 74139, is used. The 74319 has a dual 2to4 decoder and
oneofthemisusedforselectingtheEPROMchip.BitsA14andA15areatlogic0fortheEPROM
chip and the Y0 output is made active low for the corresponding A14 and A15 inputs. This Y0
signalisusedastheactivelowchipselectinputoftheIC27128.
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
92
BitsA14andA15areatlogic1fortheRAMchipandtheY3outputismadeactivelowforthe
A14andA15inputsaslogichigh.ThisY3signalisusedastheactivelowchipselectinputofthe
IC6264.TheconnectiondiagramisshowninFigure.The8bitlatchorregisterIC74373isused
todemultiplexthelowerorderaddressanddatabus.OEisthedatareadenablelineofthe
27128andisconnectedtothePENsignaloutputofthe8051.Thedatareadenablelineofthe
6264isOE,whichisconnectedtotheP3.7portoutputofthe8051.Similarly,thewriteenable
input6264isconnectedtotheportlineP3.6ofthe8051.
SolutionstoTHINKANDANSWERExercises
1. Whataretheconditionsforexternalmemoryaccessinthe8051?
Connecting the EA pin of the 8051 to logic 1 or +5 V will program the
microcontroller to use the internal program memory for the addresses starting at 0000H.
After the available internal memory is addressed, then the external memory is accessed.
Connecting EA pin to logic 0 will make the microcontroller use only external
memory for all the addresses starting from 0000H.
2. Whatisthepurposeofmultiplexingthelowerorderaddressbuswiththedatabusfor
externalmemoryaccess?
The purpose of multiplexing is to reduce the pin count and reduce the number of
pins required.
3. Whataretheadvantagesofseparatedataandprogrammemory(Harvardarchitecture)?
The separate data and program memory increases the memory addressing
capability of the microcontroller. Moreover, as the program and data are separate, the
chance of erasing of program memory by mistake as data is removed.
4. Writeadelayroutinefor1msusingTimer0ofthe8051,for12MHzcrystalfrequency.
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
93
The clock frequency to counter is 12MHz/12; the counter will get the clock pulses
at the 1 MHz rate. So, the counter will be incremented every 1 s. The program
uses 16-bit counter mode. The timer should produce a delay of 1000 s. So, the 16-
bit counter must be initialized to 64535 (i.e., 65535 - 1000). The hexadecimal
equivalent of this decimal value is FC17. Therefore, the lower-order eight bits of
the timer are initialized to 17H and the higher-order eight bits to FCH.
The following DELAY subroutine uses the polled method of waiting for 1msec and
then returns to main program.
DELAY: MOV TMOD,
#00000001B
; Set Timer 0 in mode 1 (16-bit operation).
CLR TF0 ; Clear the Timer 0 overflow flag.
LOOP: MOV TH0, #0FCH ; Initialize the 16 bits of Timer 0 with the appropriate value.
MOV TL0, #17H
SETB TR0 ; Start or run Timer 0 by setting the TR0 bit.
WAIT: J NB TF0, WAIT ; Read, check, and loop until the overflow bit TF0 in TCON
register is set.
CLR TR0
CLR TF0 ; Clear the overflow flag.
RET

5. Writearoutineusingatimerofthe8051tocountthecarsmovingonaroadandtogive
asignalwhenthecountvaluereaches100.
To count the external pulses, Timer 1 is initialized as a counter by setting the D6 bit of
TMOD. Mode 1 of Timer 1 is used in this example, as 100 objects are to be counted and
thiscanbeaccomplishedbythe8bittimerautoreloadmode.Timer1isloadedwiththe
value 155 (i.e., 255 100), which in hexadecimal form is 9B. This gives an interrupt after
100counts.
Theprogramiswrittenintwoparts.Themainprograminitializesthetimerand
runsit.Afterthat,themainprogramdoesnothing.Detectingthecountvalueof100is
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
94
doneautomatically,bygeneratinganinterruptandthengivinglogic1outputonportpin
isdoneintheInterruptserviceroutine.
Mainprogram:

MAIN: MOV TMOD, #01110000B ;SetTimer1inmode1(counter operation).


MOV TH1, #09BH ;LoadtheTimer1count.
MOV IE, #10001000B ;EnableTimer/Counter1interrupt
SETB TR1 ;StartTimer/Counter1.
LOOP: LJMP LOOP ;Loopanddonothing.
Interruptserviceroutine:
ISR_TIMER1:
CLR TR1 ;StopTimer1tobesafe.
SETB P1.0 ;SethighLSBofP1.
RETI ;Returnfrominterrupt.

6. WritetheInterruptPrioritywordformakingserialportandexternalinterrupt1ashigh
priorityandotherinterruptsaslowpriorityones.
InterruptPrioritywordformat
Bit D7 D6 D5 D4 D3 D2 D1 D0
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
95
position
Name EA PS PT1 PX1 PT0 PX0
1 0 0 1 0 1 0 0
Explanatio
n
Enable
Interrupt
s
Made 1
to
enable
all
interrupt
s
Undefine
d
Undefine
d
Set
Serial
interrup
t as
high
priority
Timer 1
interrup
t
priority
Set
Extern
al 1
interrup
t as
high
priority
Timer 0
interrup
t
priority
Extern
al 0
interrup
t
priority
CorrespondingInterruptprioritywordis94H.
7. Writethecontrolwordformaskingexternalinterruptsinan8051basedsystem.
InterruptEnableRegisterformat
Bit
position
D7 D6 D5 D4 D3 D2 D1 D0
Name EA ES ET1 EX1 ET0 EX0
1 0 0 1 1 0 1 0
Explanatio
n
Global
interrupt
enable/
disable
Undef
ined
Undefine
d
Enable
serial
interru
pt
Enable
Timer1
interru
pt
Disable
externa
l1
interru
pt
Enable
Timer0
interru
pt
Disable
externa
l0
interru
pt

8. Writethecontrolwordformatforsettingtheserialportinmode1.
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
96
BitpatternsforSCONregister
Bit Name Value Explanationoffunction
D7 SM0 0
D6 SM1 1
Serialportmodeselectbits
D5 SM2 0 Multiprocessorcommunicationsenablebit
D4 REN 1 ReceiverenableThisbitmustbeset,toreceivecharacters.
D3 TB8 0 Transmitbit8The9
th
bittotransmitinmodes2and3
D2 RB8 0 Receivebit8The9
th
bitreceivedinmodes2and3
D1 TI 0 TransmitInterruptflagSetwhenabytehasbeencompletelytransmitted
D0 RI 0 ReceiveInterruptflagSetwhenabytehasbeencompletelyreceived
CorrespondingSCONvalueis01010000Bi.e.50H.
9. CalculatethereloadvalueofTimer1forachievingabaudrateof4800inthe8051,fora
crystalfrequencyof11.0592MHz.
TherelationbetweenthebaudrateandtheTH1timerreloadvalueisgivenbelow.
TH1=256((Clockfrequency/384)/Baud)ifSMODinPCONSFRis0.
TH1=256((Clockfrequency/192)/Baud)ifSMODinPCONSFRis1
Accordingly,for4800baudrate,thereloadvalueisF9HifSMODbitis0andF3HifSMODbit
is1.
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
97
10. Writean8051ALPtotransmitHelloWorldseriallyat9600baudforacrystalfrequency
of11.0592MHz.
Following program assumes that the ASCII code for the
characters Hello World are stored consecutively in the
internal memory 40H onwards.
MAIN: ;SetupTimer1todrivebaudrateof9600.
MOV TMOD, #00100000B;SetTimer1inmode2(8bittimer).
MOV TH1, #0FDH ;TimeTimer1for9600baud.
SETB TR1 ;EnableTimer1forfreerun.
MOV SCON, #01000000B;Initializeserialportformode1operation.
MOV R0, #40H ;Initializememorypointer.
MOV R1, #0BH ;Intializeacounterforthenumberof
charactersinthewordsHelloWorld.
SEND: MOV SBUF,@R0 ;GetthedatafrommemoryandsendittoSBUFfor
transmission.
LOOP: JNB TI, LOOP ;TestTIflagtocheckwhetherdatahasbeensent.
CLR TI ;ClearTI.
INC R0 ;Pointtothenextdata.
DJNZ R1, SEND ;Loopagaintosenddata,ifnotcompleted.
END
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
98

Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan


Oxford University Press 2011

You might also like