8
91 Chapter 11 Hardware features of 8051 Solution to Numerical/DESIGNBASED EXERCISE: 1. Show the circuit connections for interfacing 16K of EPROM IC 27128 and 8 K of RAM IC 6264 with the 8051. The first step in interfacing is to select or fix the address range for the chips to be used. As the 27128 has 16 KB of memory registers, it requires 14 address lines to select one memory location in it. The address map of the 27128 is fixed as 0000H–3FFFH. The address range for the 8KB RAM chip 6264 is selected as C000H–DFFFH. 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 one of them is used for selecting the EPROM chip. Bits A14 and A15 are at logic 0 for the EPROM chip and the Y0 output is made active low for the corresponding A14 and A15 inputs. This Y0 signal is used as the active low chip select input of the IC 27128. Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan © Oxford University Press 2011

354 39 Solutions Instructor Manual 11 Hardware Features 8051 Chapter 11

Embed Size (px)

DESCRIPTION

microcontroller ppt

Citation preview

  • 91

    Chapter11Hardwarefeaturesof8051

    SolutiontoNumerical/DESIGNBASEDEXERCISE:

    1. Showthecircuitconnectionsforinterfacing16KofEPROMIC27128and8KofRAMIC6264withthe8051.

    Thefirststepininterfacingistoselectorfixtheaddressrangeforthechipstobeused.Asthe27128has16KBofmemoryregisters,itrequires14addresslinestoselectonememorylocationin it.Theaddressmapof the27128 is fixedas0000H3FFFH.Theaddress range for the8KBRAMchip6264isselectedasC000HDFFFH.

    Themost significantbitsA14 andA15 areused todecode and select the chip. Fordecodingpurposes,a2to4decoderchip,the74139, isused.The74319hasadual2to4decoderandoneofthemisusedforselectingtheEPROMchip.BitsA14andA15areatlogic0fortheEPROMchipand theY0output ismadeactive low for thecorrespondingA14andA15 inputs.ThisY0signalisusedastheactivelowchipselectinputoftheIC27128.

    Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan

    Oxford University Press 2011

  • 92

    BitsA14andA15areatlogic1fortheRAMchipandtheY3outputismadeactivelowfortheA14andA15inputsaslogichigh.ThisY3signalisusedastheactivelowchipselectinputoftheIC6264.TheconnectiondiagramisshowninFigure.The8bitlatchorregisterIC74373isusedtodemultiplexthelowerorderaddressanddatabus.OEisthedatareadenablelineofthe27128andisconnectedtothePENsignaloutputofthe8051.Thedatareadenablelineofthe6264isOE,whichisconnectedtotheP3.7portoutputofthe8051.Similarly,thewriteenableinput6264isconnectedtotheportlineP3.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. Whatisthepurposeofmultiplexingthelowerorderaddressbuswiththedatabusforexternalmemoryaccess?

    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: JNB 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.Tocount theexternalpulses,Timer1 is initializedasacounterby setting theD6bitofTMOD.Mode1ofTimer1 isused inthisexample,as100objectsaretobecountedandthiscanbeaccomplishedbythe8bittimerautoreloadmode.Timer1isloadedwiththevalue155(i.e.,255 100),which inhexadecimalform is9B.Thisgivesan interruptafter100counts.

    Theprogramiswrittenintwoparts.Themainprograminitializesthetimerandrunsit.Afterthat,themainprogramdoesnothing.Detectingthecountvalueof100is

    Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan

    Oxford University Press 2011

  • 94

    doneautomatically,bygeneratinganinterruptandthengivinglogic1outputonportpinisdoneintheInterruptserviceroutine.

    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.InterruptPrioritywordformatBit 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

    Explanation

    Enable Interrupt

    s Made 1

    to enable

    all interrupt

    s

    Undefined

    Undefined

    Set Serial

    interrupt as high

    priority

    Timer 1 interrup

    t priority

    Set Extern

    al 1 interrup

    t as high

    priority

    Timer 0 interrup

    t priority

    External 0

    interrupt

    priority

    CorrespondingInterruptprioritywordis94H.7. Writethecontrolwordformaskingexternalinterruptsinan8051basedsystem.InterruptEnableRegisterformatBit

    positionD7 D6 D5 D4 D3 D2 D1 D0

    Name EA ES ET1 EX1 ET0 EX0

    1 0 0 1 1 0 1 0

    Explanatio

    nGlobal

    interruptenable/disable

    Undef

    inedUndefine

    d

    Enableserialinterru

    pt

    EnableTimer1interru

    pt

    Disableexterna

    l1interru

    pt

    EnableTimer0interru

    pt

    Disableexterna

    l0interru

    pt

    8. Writethecontrolwordformatforsettingtheserialportinmode1.

    Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan

    Oxford University Press 2011

  • 96

    BitpatternsforSCONregister

    Bit NameValue Explanationoffunction

    D7 SM0 0

    D6 SM1 1Serialportmodeselectbits

    D5 SM2 0 Multiprocessorcommunicationsenablebit

    D4 REN 1 ReceiverenableThisbitmustbeset,toreceivecharacters.

    D3 TB8 0 Transmitbit8The9thbittotransmitinmodes2and3

    D2 RB8 0 Receivebit8The9thbitreceivedinmodes2and3

    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)ifSMODinPCONSFRis1Accordingly,for4800baudrate,thereloadvalueisF9HifSMODbitis0andF3HifSMODbitis1.

    Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan

    Oxford University Press 2011

  • 97

    10. Writean8051ALPtotransmitHelloWorldseriallyat9600baudforacrystalfrequencyof11.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 ;IntializeacounterforthenumberofcharactersinthewordsHelloWorld.

    SEND: MOV SBUF,@R0 ;GetthedatafrommemoryandsendittoSBUFfortransmission.

    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