5-11AT89C51In-CircuitProgrammingThisapplicationnoteillustratesthein-cir-cuitprogrammabilityoftheAtmelAT89C51Flash-basedmicrocontroller.Guidelinesfortheadditionofin-circuitprogrammabilitytoAT89C51applica-tionsarepresentedalongwithanappli-cationexampleandthemodificationstoitrequiredtosupportin-circuitprogram-ming.AmethodisthenshownbywhichtheAT89C51microcontrollerintheapplicationcanbereprogrammedremotely,overacommercialtelephoneline.Thecircuitrydescribedinthisappli-cationnotesupportsfivevoltprogram-mingonly,requiringtheuseofanAT89C51-XX-5.ThestandardAT89C51requires12voltsforprogramming.ThesoftwareforthisapplicationmaybeobtainedbydownloadingfromAtmel’sBBS:(408)436-4309.GeneralConsiderationsCircuitryaddedtosupportAT89C51in-circuitprogrammingshouldappeartransparenttotheapplicationwhenpro-grammingisnottakingplace.EA/VPPmustbeheldhighduringpro-gramming.Inapplicationswhichdonotutilizeexternalprogrammemory,thispinmaybepermanentlystrappedtoVCC.Applicationsutilizingexternalprogrammemoryrequirethatthispinbeheldlowduringnormaloperation.RSTmustbeheldactiveduringpro-gramming.Ameansmustbeprovidedforoverridingtheapplicationresetcir-cuit,whichtypicallyassertsRSTonlybrieflyafterpowerisapplied.PSENmustbeheldlowduringprogram-ming,butmustnotbedrivenduringnor-maloperation.ALE/PROGispulsedlowduringpro-gramming,butmustnotbedrivenduringnormaloperation.Duringprogramming,AT89C51I/Oportsareusedfortheapplicationofmodeselect,addressesanddata,possiblyrequiringthatthecontrollerbeisolatedfromtheapplicationcircuitry.Howthisisdoneisapplicationdependentandwillbeaddressedhereonlyingeneralterms.PortUsedforInputDuringprogramming,thecontrollermustbeisolatedfromsignalssourcedbytheapplicationcircuitry.Abufferwiththree-stateoutputsmightbeinsertedbetweentheapplicationcircuitryandthecontrol-ler,withthebufferoutputsthree-statedwhenprogrammingisenabled.Alter-nately,amultiplexermightbeusedtoselectbetweensignalsources,withsig-nalsappliedtothecontrollerbyeithertheapplicationcircuitryortheprogram-mercircuitry.PortUsedforOutputNocircuitchangesarerequirediftheapplicationcircuitrycantoleratethestatechangeswhichoccurattheportduringprogramming.Ifthepriorstateoftheapplicationcircuitrymustbemaintainedduringprogramming,alatchmightbeinsertedbetweenthecontrollerandtheapplicationcircuitry.Thelatchisenabledduringprogramming,preservingthestateoftheapplicationcircuitry.AnApplicationExampleTheAT89C51applicationshowninFig-ure1isanimplementationofamovingdisplay.Thisapplicationwasselectedforitssimplicityandabilitytoshowgraphi-callytheresultsofin-circuitreprogram-ming.Thetexttobedisplayedispro-grammedintothecontrolleraspartofitsfirmware,andcannotbechangedwith-outreprogrammingthedevice.0287D-B–9/978-BitMicrocontrollerwithFlashApplicationNoteMicrocontroller5-12Thedisplayedtextispresentedinoneoftwomodesselectedbythefour-positionDIPswitch.Inthefirstmode,onecharacteratatimeentersthedisplayfromtherightandmovesquicklytotheleftthrougheachelementofthedisplaytoitsfinalpositionintheassembledmessage.Inthesecondmode,themessagemovesthroughthedisplay,fromrighttoleft,withthedisplayactingasawindowontothemessage.Thismodeisfamiliarasthemethodoftenusedindisplaysofstockprices.TheoutputconsistsoffourDL1414T,four-digit,17-seg-mentalphanumericdisplayswithintegraldecodersanddrivers.Thisyields16totaldisplayelements,eachcapableofdisplayingdigits0-9,theuppercasealphabet,andsomepunctuationcharacters.ThedisplayablecharactercodesareASCII20H-5FH.Apower-onresetcircuitanda6-MHzcrystaloscillatorcompletetheapplication.Neitherexternalprogrammemorynorexternaldatamemoryisused.ModificationstotheApplicationtoSupportIn-CircuitProgrammingFigure2showstheapplicationmodifiedforin-circuitprogramming.Itisassumedthattheprogrammer,wheninactive,willnei-therdrivenorexcessivelyloadtheapplication.Sincetheapplicationdoesnotuseexternalprogrammem-ory,EA/VPPonthecontrollerisconnectedtoVCC.Thismeetstherequirementforprogramming.Theresetcircuithasbeenmodifiedbytheadditionoftwotransistors,whichallowRSTonthecontrollertobeforcedhighbytheprogrammer.PSENandALE/PROG,unusedinthebasicapplication,areunderthedirectcontroloftheprogrammer.ProgrammingrequiresprogrammeraccesstoallofthefourAT89C51I/Oports,asdocumentedinthedatasheet.Theprogrammerisconnecteddirectlytothosecontrollerpinswhichareunusedbytheapplication,whileaccesstopinsusedbytheapplicationrequiresspecialtreatment,asexplainedinthefollowingparagraphs.Theleastsignificantfourbitsoftheaddressgeneratedbytheprogrammeraremultiplexedontoportoneofthecon-trollerwiththedatafromtheDIPswitch.Notethatthefourresistorsaddedattheswitcharenotrequiredinthebasicapplication,sincetheAT89C51providesinternalpull-upsonportone.Duringthenormaloperationoftheapplication,controllerportszeroandtwoprovidedataandcontrolsignals(respectively)tothedisplays.Duringprogrammingandpro-gramverification,theprogrammerassertscontrolofportzeroandpartofporttwo.Theprogrammerisconnectedtoportszeroandtwowithoutbuffering,since,wheninactive,itspresencedoesnotaffectthenormaloperationoftheapplication.Atransparentlatchhasbeenaddedbetweenporttwoo