Documentos de Académico
Documentos de Profesional
Documentos de Cultura
TIMEDELAYFORVARIOUS8051CHIPS
whatwhenhow
InDepthTutorialsandInformation
TIMEDELAYFORVARIOUS8051CHIPS
SECTION3.3:TIMEDELAYFORVARIOUS8051CHIPS
InthelastsectionweusedtheDELAYsubroutine.Inthissectionwediscusshowtogeneratevarioustimedelaysandcalculateexactdelaysforthe
8051andDS89C4xO.
Machinecycleforthe8051
TheCPUtakesacertainnumberofclockcyclestoexecuteaninstruction.Inthe8051family,theseclockcyclesarereferredtoasmachinecycles.
TableAlprovidesthelistof8051instructionsandtheirmachinecycles.Tocalculateatimedelay,weusethislist.Inthe8051family,thelengthof
themachinecycledependsonthefrequencyofthecrystaloscillatorconnectedtothe8051system.Thecrystaloscillator,alongwithonchipcircuitry,
providetheclocksourceforthe8051CPU(seeChapter8).Thefrequencyofthecrystalconnectedtothe8051familycanvaryfrom4MHzto30
MHz,dependingonthechipratingandmanufacturer.Veryoftenthe11.0592MHzcrystaloscillatorisusedtomakethe8051basedsystem
compatiblewiththeserialportoftheIBMPC(seeChapter10).Intheoriginal8051,onemachinecyclelasts12oscillatorperiods.Therefore,to
calculatethemachinecycleforthe8051,wetake1/12ofthecrystalfrequency,thentakeitsinverse,asshowninExample313.
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
1/13
24/11/2016
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
TIMEDELAYFORVARIOUS8051CHIPS
2/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Treehouse
LearntoCode
Everwantedtobuildanapp?Learntocodeyourdreams.
Delaycalculationfor8051
Asseeninthelastsection,adelaysubroutineconsistsoftwoparts:(1)settingacounter,and(2)aloop.Mostofthetimedelayisperformedbythe
bodyoftheloop,asshowninExample315.
Example315
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
3/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Veryoftenwecalculatethetimedelaybasedontheinstructionsinsidetheloopandignoretheclockcyclesassociatedwiththeinstructionsoutsidethe
loop.
InExample315,thelargestvaluetheR3registercantakeis255therefore,onewaytoincreasethedelayistouseNOPinstructionsintheloop.
NOP,whichstandsfornooperation,simplywastestime.ThisisshowninExample316.
Loopinsideloopdelay
Anotherwaytogetalargedelayistousealoopinsidealoop,whichisalsocalledanestedloop.SeeExample317.
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
4/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Treehouse
LearntoCode
Everwantedtobuildanapp?Learntocodeyourdreams.
Example316
Solution:
ThetimedelayinsidetheHEREloopis[250(1+1+1+1+2)]x1.085us=1500x1.085us=1627.5us.Addingthetwoinstructionsoutsidethe
loopwehave1627.5us+3xl.085|is=1630.755us.
Ifmachinecycletimingiscriticaltoyoursystemdesign,makesurethatyoucheckthemanufacturesdatasheetsforthedevicespecification.For
example,theDS89C420has3machinecyclesinsteadof2machinecyclesfortheRETinstruction.
Example317
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
5/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
FortheHEREloop,wehave(4x250)xl.085us=1085us.TheAGAINlooprepeatstheHEREloop200timestherefore,wehave200x1085us=
217000,ifwedonotincludetheoverhead.However,theinstructionsMOVR3,#250andDJNZR2,AGAINatthebeginningandendofthe
AGAINloopadd(3x200x1.085us)=651ustothetimedelay.Asaresultwehave217000+651=217651us=217.651millisecondsfortotal
time delay associated with the above DELAY subroutine. Notice that in the case of a nested loop, as in all other time delay loops, the time is
approximatesincewehaveignoredthefirstandlastinstructionsinthesubroutine.
Delaycalculationforotherversionsof8051
IncreatingatimedelayusingAssemblylanguageinstructions,onemustbemindfuloftwofactorsthatcanaffecttheaccuracyofthedelay.
productsfromPhilipsSemiconductorshavetheoptionofusingeither6or12clockspermachinecycle.Table32showssomeofthe8051versions
withtheirmachinecycles.
1.Thecrystalfrequency:Thefrequencyofthecrystaloscillatorconnectedto
theXIX2inputpinsisonefactorinthetimedelaycalculation.Theduration
oftheclockperiodforthemachinecycleisafunctionofthiscrystalfrequen
cy.
2.The8051Design:Sincetheoriginal8051wasdesignedin1980,boththefield
of1Ctechnologyandthearchitecturaldesignofmicroprocessorshaveseen
greatadvancements.Duetothelimitationsof1CtechnologyandlimitedCPU
designexperienceatthattime,themachinecycledurationwassetat12clocks.
Advancesinboth1CtechnologyandCPUdesigninrecentyearshavemade
the1clockmachinecycleacommonfeatureofmanynew8051chips.Indeed,
onewaytoincreasethe8051performancewithoutlosingcodecompatibility
withtheoriginal8051istoreducethenumberofclockcyclesittakestoexe
cuteaninstruction.Forthesereasons,thenumberofmachinecyclesandthe
numberofclockperiodspermachinecyclevariesamongthedifferentversions
ofthe8051microcontrollers.Whiletheoriginal8051designused12clock
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
6/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
periodspermachinecycle,manyofthenewergenerationsofthe8051use
muchfewerclockspermachinecycle.Forexample,theDS5000uses4clock
periodspermachinecyclewhiletheDS89C4xOusesonlyoneclockper
machinecycle.The8051
TaDie32:ClocksperMachineCycle(MC)for
Various8051Versions
Example318
DelaycalculationforDS89C4xO
InthecaseoftheDS89C4xO,sincethenumberclockspermachinecyclewasreducedfrom12to1,thenumberofmachinecyclesusedto
executeaninstructionhadtobechangedtoreflectthisreality.Table33comparesthemachinecyclesfortheDS89C4xOand8051forsome
instructions.
Example319
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
7/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Table33:Comoarisonof8051andDS89C4xOMachineCvcles
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
8/13
24/11/2016
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
TIMEDELAYFORVARIOUS8051CHIPS
9/13
24/11/2016
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
TIMEDELAYFORVARIOUS8051CHIPS
10/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Example322
Fromtheabovediscussionweconcludethatuseoftheinstructioningeneratingtimedelayisnotthemostreliablemethod.Togetmoreaccuratetime
delay we use timers as described in Chapter 9. Meanwhile, to get an accurate time delay for a given 8051 microcontroller, we must use an
oscilloscopetomeasuretheexacttimedelay.
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
11/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
SJMPtoitselfusing$sign
Incaseswherethereisnomonitorprogram,weneedtoshortjumptoitselfinordertokeepthemicrocontrollerbusy.Asimplewayofdoingthatis
tousethe$sign.Thatmeansinplaceofthis
SUMMARY
Theflowofaprogramproceedssequentially,frominstructiontoinstruction,unlessacontroltransferinstructionisexecuted.Thevarioustypesof
controltransferinstructionsinAssemblylanguageincludeconditionalandunconditionaljumps,andcallinstructions.
Theloopingactionin8051Assemblylanguageisperformedusingaspecialinstruction,whichdecrementsacounterandjumpstothetopoftheloop
ifthecounterisnotzero.Otherjumpinstructionsjumpconditionally,basedonthevalueofthecarryflag,theaccumulator,orbitsoftheI/Oport.
Unconditional jumps can be long or short, depending on the relative value of the target address. Special attention must be given to the effect of
LCALLandACALLinstructionsonthestack.
Adsby Google
Adsby Google
HowtoCalculate
TimeTable
ComputerChips
AssemblyMachine
Nextpost:I/OPORTPROGRAMMING
Previouspost:8051CALLINSTRUCTIONS
RelatedLinks
8051Microcontroller
8051MICROCONTROLLERS
MICROCONTROLLERSANDEMBEDDEDPROCESSORS
OVERVIEWOFTHE8051FAMILY
8051ASSEMBLYLANGUAGEPROGRAMMING
INSIDETHE8051
::SearchWWH::
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
12/13
24/11/2016
TIMEDELAYFORVARIOUS8051CHIPS
Search
CustomSearch
HelpUnprivilegedChildrenCareersPrivacyStatementCopyrightInformation
http://whatwhenhow.com/8051microcontroller/timedelayforvarious8051chips/
13/13