Introduction - World of Microcontrollers - Book - PIC Microcontrollers
Introduction - World of Microcontrollers - Book - PIC Microcontrollers
[Link] 1/16
TOC Introduction Ch. 1 Ch. 2 Ch. 3 Ch 4. Ch. 5 Ch. 6 Ch. 7 Ch. 8 Ch. 9 App. A App. B App. C
Book:PICMicrocontrollers
Introduction:Worldofmicrocontrollers
Thesituationwefindourselvestodayinthefieldofmicrocontrollershaditsbeginningsinthedevelopmentoftechnologyofintegratedcircuits.
[Link]
[Link],input/outputlines,timersandotherstoit.
[Link]
thefirstchipcontainingamicrocomputerlaterknownasamicrocontrollerhasdeveloped.
Thisishowitallgotstarted...
Intheyear1969,ateamofJapaneseengineersfromBUSICOMcametotheUSAwitharequestthatafewintegratedcircuitsforcalculators
[Link]
experienceworkingwithacomputer,thePDP8,hecameupwithanideatosuggestfundamentallydifferentsolutionsinsteadofthesuggested
[Link]
thatconfigurationwouldbesimpler,[Link],
eventhoughtheJapaneseengineersweretryingtofindaneasiersolution,[Link]
[Link],Intelsucceededindevelopingsucha
[Link]
[Link],[Link]
[Link],anAmericancompanyCTCrequestedfrom
[Link],Intel
andTexasInstrumentskeptworkingonthemicroprocessorandinApril1972thefirst8bitmicroprocessorcalledthe8008appearedonthe
market.Itwasabletoaddress16Kbofmemory,[Link]
wasthepredecessorofalltodaysmicroprocessors.IntelkeptondevelopingitandinApril1974itlaunchedan8bitprocessorcalledthe
8080.Itwasabletoaddress64Kbofmemory,had75instructionsandinitialpricewas$360.
AnotherAmericancompanycalledMotorola,quicklyrealizedwhatwasgoingon,[Link]
[Link],Motorolawasthefirstcompanythatalsomanufacturedotherperipheralssuch
[Link]
[Link].
AttheWESCONexhibitionintheUSAin1975,[Link]
thatitwassellingprocessors6501and6502at$25each,[Link]
manythoughtitwasakindoffraud,consideringthatcompetingcompaniesweresellingthe8080and6800at$[Link]
theexhibit,inresponsetothecompetitor,bothMotorolaandIntelcutthepricesoftheirmicroprocessorsto$[Link]
[Link],MOSTechnologygaveupfurthermanufactureofthe6501,
[Link]
lowprice,6502becameverypopularsoitwasinstalledintocomputerssuchasKIM1,AppleI,AppleII,Atari,Commodore,Acorn,Oric,
Galeb,Orao,Ultraandmanyothers.Soonseveralcompaniesbeganmanufacturingthe6502(Rockwell,Sznertek,GTE,NCR,Ricoh,
CommodoretookoverMOSTechnology).Intheyearofitsprosperity1982,thisprocessorwasbeingsoldatarateof15millionprocessors
peryear!
[Link].In1976Zilogannounced
[Link].The8080hadalreadybeendevelopedandherealizedthat
[Link]
hedecidedthatanewprocessorhadtobecompatiblewiththe8080,i.e.ithadtobeabletoperformalltheprogramswrittenforthe8080.
Apartfromthat,[Link]
directlyaddress64Kbofmemory,had176instructions,alargenumberofregisters,abuiltinoptionforrefreshingdynamicRAMmemory,a
singlepowersupply,[Link]
[Link],othernewmanufacturerssuchasMostek,NEC,
SHARPandSGSappearedsoon.TheZ80wastheheartofmanycomputerssuchas:Spectrum,Partner,TRS703,Z3andGalaxy.
[Link],theZ80wassomuchbetterthatIntel
[Link](6809,2650,SC/MPetc.),thediehadalreadybeen
[Link],sothe6502andZ80alongwiththe
6800remainedchiefrepresentativesofthe8bitmicroprocessorsofthattime.
MicrocontrollerversusMicroprocessor
[Link]
microprocessormaybeused,[Link]
powerfulcomputingmachines,theirweakpointisthattheyarenotadjustedtocommunicatingtoperipheralequipment.
Simply,Inordertocommunicatewithperipheralenvironment,[Link]
[Link].
FeaturedDevelopmentTools
FreeOnlineBooks
EasyPICv7DevelopmentSystem
EasyPICv7istopsellingPIC
DevelopmentBoardfor250Microchip
[Link]
USB2.0programmer/debuggerandover
17essentialmodulesnecessaryin
[Link]
PIC18F45K22.[moreinfo]
Book:PICMicrocontrollers
ProgramminginC
Whataremicrocontrollers,anyway?
Electroniccomponentsbuiltintoone
singlechipcapableofcontrollingasmall
submarine,acraneoranelevator
[Link]
[Link]
writeaprogramanddumpitintothe
microcontroller.[moreinfo]
Login | Cart (0)
Products Solutions Store Distributors Libstock Contact Us search here
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 2/16
Fig.01MicrocontrollerversusMicroprocessor
Ontheotherhand,[Link]
[Link]
designadevice.
BASICCONCEPT
Didyouknowthatallpeoplecanbeclassifiedintooneof10groupsthosewhoarefamiliarwithbinarynumbersystemandthosewhoarenot
[Link]?[Link]
textdescribingbrieflysomeofthebasicconceptsusedfurtherinthisbook(justtobesureweareonthesamepage).
WorldofNumbers
Mathematicsissuchagoodscience![Link].
But,doesitreallyhavetobelikethat?Doweneedexactlytendigits?Ofcoursenot,[Link]
[Link],whatdoesthenumber764mean:fourunits,[Link]!Coulditbedescribedinabit
morecomplicatedway?Ofcourseitcould:4+60+[Link]?Naturally:4*1+6*10+7*[Link]
morescientific?Theanswerisyes:4*10^0+6*10^1+7*10^[Link]?Whydoweuseexactlythesenumbers:100,101
and102?Whyisitalwaysaboutthenumber10?Thatisbecauseweusetendifferentdigits(0,1,2,...8,9).Inotherwords,becauseweuse
base10numbersystem,[Link].
Fig.02Thenumber764representedinthreedifferentways
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 3/16
BinaryNumberSystem
Whatwouldhappenifonlytwodigitswouldbeused0and1?Orifwewouldnotknowtodeterminewhethersomethingis3or5timesgreater
thansomethingelse?Orifwewouldberestrictedwhencomparingtwosizes,[Link](1)ordoesnot
exist(0)?Nothingspecialwouldhappen,wewouldkeeponusingnumbersinthesameway,[Link]:
11011010.Howmanypagesofabookdoesthenumber11011010include?Inordertolearnthat,followthesamelogiclikeintheprevious
example,butinreverseorder.Bearinmindthatallthisisaboutmathematicswithonlytwodigits0and1,i.e.base2numbersystem(binary
numbersystem).
Fig.03Thenumber218representedinbinaryanddecimalsystem
Clearly,[Link]
[Link](2)isusedtowritethenumber2indecimalsystem,whereastwodigits(1and0)areusedtowritethatnumberinbinary
system.Doyounowagreethatthereare10groupsofpeople?Welcometotheworldofbinaryarithmetic!Doyouhaveanyideawhereitis
used?
Exceptingstrictlycontrolledlaboratoryconditions,themostcomplicatedelectroniccircuitscannotaccuratelydeterminethedifferencebetween
twosizes(twovoltagevalues,forexample)iftheyaretoosmall(lowerthanseveralvolts).Thereasonsareelectricalnoisesandsomething
calledtherealworkingenvironment(unpredictablechangesofpowersupplyvoltage,temperaturechanges,tolerancetovaluesofbuiltin
componentsetc.).Imagineacomputerwhichwouldoperateupondecimalnumbersbyrecognizing10digitsinthefollowingway:0=0V,1=5V,
2=10V,3=15V,4=20V...9=45V!?Didanybodysaybatteries?Afarsimplersolutionistheuseofbinarylogicwhere0indicatesthatthereis
[Link]
zero(0)andlogicone(1)whichelectronicsperfectlyconformswithandeasilyperformsallthoseendlesslycomplexmathematicaloperations.
Itiselectronicswhichinrealityappliesmathematicsinwhichallnumbersarerepresentedbytwodigitsonlyandinwhichitisonlyimportantto
[Link],wearetalkingaboutdigitalelectronics.
HexadecimalNumberSystem
[Link],
[Link],[Link]
weareusedto(0,1,2,3,...9)[Link],thesixlettersofalphabetA,B,C,
D,[Link],1,2,3,4,5,6,7,8,9,A,B,C,D,E,[Link]
isthepurposeofthisseeminglybizarrecombination?Justlookhowperfectlyeverythingfitsthestoryaboutbinarynumbers.
Fig.04BinaryandHexadecimalnumber
[Link]
[Link]
skillfullyitisused?[Link]
thecomputeruses8digitbinarynumbers.
BCDCode
[Link]
[Link]
digits(0,1,2,3...8,9).Eventhoughfourdigitscangiveatotalof16possiblecombinations,onlythefirsttenareused.
NumberSystemConversion
Thebinarynumberingsystemisthemostcommonlyused,thedecimalsystemisthemostunderstandablewhilethehexadecimalsystemis
[Link],itisveryimportanttolearnhowtoconvertnumbersfromonenumberingsystemtoanother,[Link]
turnaseriesofzerosandunitsintovaluesunderstandabletous.
BinarytoDecimalNumberConversion
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 4/16
Comparativetablebelowcontainsthevaluesof
numbers0255inthreedifferentnumbering
systems.
MarkingNumbers
Thehexadecimalnumberingsystemisalongwithbinaryanddecimal
[Link]
makeconversionofanyhexadecimalnumbertobinaryanditisalsoeasy
[Link],[Link]
example,whatdoesthestatementItisnecessarytocountup110
productsonassemblylineactuallymean?Dependingonwhetheritis
aboutbinary,decimalorhexadecimal,theresultcouldbe6,110or272
products,respectively!Accordingly,inordertoavoidmisunderstanding,
[Link]
prefix$or0xaswellasthesuffixhmarksthenumbersinhexadecimal
[Link],hexadecimalnumber10AFmaylookasfollows
$10AF,[Link],binarynumbersusuallygetthesuffix
%or0b,whereasdecimalnumbersgetthesuffixD.
[Link],eachpositioncancontaineither1or0
[Link]
multiplyvalueswiththecorrespondingdigits(0or1)[Link]...You
doubt?Lookattheexample:
110=1*2^2+1*2^1+0*2^0=6
[Link],extrabinarydigitsmustbeadded.
Thus,fornumbersfrom0to7youneedthreedigits,[Link],thelargestbinarynumber
[Link],ifn=4:
2^41=161=15
Accordingly,using4binarydigitsitispossibletorepresentdecimalnumbersfrom0to15,includingthesetwodigits,whichamountsto16
differentvaluesintotal.
HexadecimaltoDecimalNumberConversion
Inordertomakeconversionofahexadecimalnumbertodecimal,eachhexadecimaldigitshouldbemultipliedwiththenumber16raisedby
[Link]:
Fig.05Hexadecimaltodecimalnumberconversion
HexadecimaltoBinaryNumberConversion
[Link]
replacedbytheappropriatefourbinarydigits.Sincethemaximumhexadecimaldigitisequivalenttodecimalnumber15,weneedtousefour
[Link]:
Fig.06Hexadecimaltobinarynumberconversion
Bit
Theorysaysabitisthebasicunitofinformation...[Link]
[Link](for
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 5/16
exampledigitsinthenumber444arethesame,buthavedifferentvalues),thesignificanceofthebitdependsonthepositionithasinthe
[Link],thereisnopointtalkingaboutunits,[Link],hereitisaboutthezerobit(rightmostbit),firstbit(second
fromtheright)[Link],sincethebinarysystemusestwodigitsonly(0and1),thevalueofonebitcanbe0or1.
Dontbeconfusedifyoufindsomebithasvalue4,[Link],wehave
[Link],
[Link]...Besides,howwouldit
soundnumber:oneonezeroonezero...
Byte
[Link],[Link]
operationscanbeperformeduponthem,[Link],bytedigitsdo
[Link](MSB).Therightmostbithastheleast
valueandisthereforecalledtheleastsignificantbit(LSB).Sinceeightzerosandunitsofonebytecanbecombinedin256differentways,the
largestdecimalnumberwhichcanberepresentedbyonebyteis255(onecombinationrepresentszero).
[Link](leftorright),therearehighandlownibbles.
Fig.08HighandLownibbles
LogicCircuits
Haveyoueverwonderedwhatelectronicswithinsomedigitalintegratedcircuits,microcontrollersorprocessorslooklike?Whatdothecircuits
performingcomplicatedmathematicaloperationsandmakingdecisionslooklike?Doyouknowthattheirseeminglycomplicatedschematics
compriseonlyafewdifferentelementscalledlogiccircuitsorlogicgates?
TheoperationoftheseelementsisbasedontheprinciplesestablishedbyBritishmathematicianGeorgeBooleinthemiddleofthe19th
centuryevenbeforethefirstbulbwasinvented!Inbrief,[Link]
wassoontransformedintoapracticalproductwhichfarlaterevaluatedinwhattodayisknownasAND,[Link]
[Link]
logicgatesexceptintheformofcommands,theprincipleoftheiroperationwillbediscussedhere.
ANDGate
[Link](1)
willappearonitsoutputonlyincasebothinputs(AANDB)aredriventologicone(1).
Thetableshowsmutualdependencebetweeninputsandoutput.
Whenthegatehasmorethantwoinputs,theprincipleofoperationisthe
same:alogicone(1)willappearonitsoutputonlyifcaseallinputsare
driventologicone(1).Anyothercombinationofinputvoltageswillresultina
logiczero(0)atitsoutput.
Whenusedinaprogram,alogicANDoperationisperformedbytheprogram
instruction,[Link],itisenoughtoremember
thatlogicANDinaprogramreferstothecorrespondingbitsoftworegisters.
ORGate
Similarlytothepreviouscase,ORgatesalsohavetwoormoreinputsand
[Link](1)willappearonitsoutputifeitherinput(AORB)is
driventologicone(1).Ifallinputsareatlogiczero(0),theoutputwillbe
driventologiczero(0).
Inaprogram,logicORoperationisperformedbetweenthecorrespondingregistersbitsthesameasinlogicANDoperation.
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 6/16
NOTGate
[Link]
[Link](0)appearsonitsinput,alogicone
(1)[Link]
[Link].
Ifaprogram,[Link]
[Link],theinvertedvalueisactuallya
complementofthatnumber,[Link]
toittomakeitreachthemaximal8bitvalue(255).
EXCLUSIVEORGate
TheEXCLUSIVEOR(XOR)[Link]
[Link](1)appearsonitsoutputonlywhentheinputshavedifferent
logicstates.
Inaprogram,[Link]
beusedforthesamepurpose(iftheresultis0,bytesareequal).Theadvantageof
thislogicoperationisthatthereisnodangertosubtractlargernumberfromsmaller
one.
Register
Aregisteroramemorycellisanelectroniccircuitwhichcanmemorizethestateofonebyte.
Fig.017Register
SpecialFunctionRegister
Inadditiontotheregisterswhichdonothaveanyspecialandpredeterminedfunction,everymicrocontrollerhasanumberofregisterswhose
[Link](literally)tointernalcircuitssuchastimers,A/Dconverter,oscillators
andothers,[Link]
commandofsomesmallercircuitswithinthemicrocontrolleryouareright!SpecialFunctionRegisters(SFRs)doexactlythat!
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 7/16
Fig.018SpecialFunctionRegister
Input/OutputPorts
Inordertomakethemicrocontrolleruseful,ithastobeconnectedtoadditionalelectronics,[Link]
moreregisters(calledaport)[Link]/output?Becauseyoucanchangethepinsfunctionasyou
[Link],supposeyouwantyourdevicetoturnthreesignalLEDsandsimultaneouslymonitorthelogicstateoffivesensorsorpush
[Link](connectedtotheLEDs)andfiveinputs(connectedtosensors).
Itissimplyperformedbysoftware,whichmeansthatthepinsfunctioncanbechangedduringoperation.
Fig.019Input/Outputports
Oneofthemoreimportantspecificationsofinput/output(I/O)[Link],current
obtainedfromonepinissufficienttoactivateanLEDorothersimilarlowcurrentdevice(1020mA).IfthemicrocontrollerhasmanyI/Opins,
[Link],youcannotexpectallpinstogivemaximumcurrentiftherearemorethan80of
[Link]
microprocessorissharedacrossallI/Oports.
[Link]
[Link]
havepullupresistorsconfigurablebysoftware.
Usually,eachI/OportisundercontrolofanotherSFR,whichmeansthateachbitofthatregisterdeterminesthestateofthecorresponding
[Link],bywritinglogicone(1)toonebitofthatcontrolregisterSFR,theappropriateportpinisautomatically
[Link],bywritingzerototheSFR,the
[Link](0Vor5V)correspondstothestateoftheappropriatebitoftheportregister.
MemoryUnit
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 8/16
[Link]
[Link],[Link]
drawerbyreadingthelabelonthefrontofthedrawer.
[Link]
[Link]
[Link]
microcontroller.
ReadOnlyMemory(ROM)
ROM(ReadOnlyMemory)[Link]
thesizeofthismemory.Todaysmicrocontrollerscommonlyuse16bitaddressing,whichmeansthattheyareabletoaddressupto64Kbof
memory,[Link],[Link]
ROM.
[Link]
[Link],[Link]...
OneTimeProgrammableROM(OTPROM).Ifthemicrocontrollercontainsthismemory,youcandownloadaprogramintothismemory,but
theprocessofprogramdownloadingisaonewayticket,[Link],
theonlythingyoucandoistodownloadthecorrectedprogramtoanotherchip.
UVErasableProgrammableROM(UVEPROM).Boththemanufacturingprocessandcharacteristicsof
[Link],thepackageofthismicrocontrollerhasa
[Link]
UVlamp,whicheffectivelyerasesandprogramfromtheROM.
Installationofthiswindowisverycomplicated,[Link],
unfortunatelynegative...
Flashmemory.Thistypeofmemorywasinventedinthe80sinthelaboratoriesofINTELandwererepresentedasthesuccessortotheUV
[Link],themicrocontrollerswith
FlashROMareidealforlearning,[Link],themostmicrocontrollersare
[Link],ifyouaregoingtobuyamicrocontroller,thetypetolookforisdefinitelyFlash!
RandomAccessMemory(RAM)
OncethepowersupplyisoffthecontentsofRAM(RandomAccessMemory)[Link]
[Link],iftheprogramperformsanaddition(ofwhatever),itis
[Link],oneoftheregistersinRAMiscalledthe
sumandusedforstoringresultsofaddition.
ElectricallyErasableProgrammableROM(EEPROM)
ThecontentsoftheEEPROMmaybechangedduringoperation(similartoRAM),butremainspermanentlysavedevenuponthepower
supplygoesoff(similartoROM).Accordingly,anEEPROMisoftenusedtostorevalues,createdduringoperation,whichmustbe
[Link],ifyoudesignanelectroniclockoranalarm,itwouldbegreattoenabletheusertocreateandentera
password,[Link].
Interrupt
[Link]
[Link],whensomeeventtakesplace,themicrocontrollerdoessomething...Forexample,whenyoupushabuttonona
remotecontroller,themicrocontrollerwillregisteritandrespondtotheorderbychangingachannel,[Link]
microcontrollerspentmostofitstimeendlesslyafewbuttonsforhoursordays...Itwouldnotbepractical.
[Link],themicrocontrollerdelegatesthewait
issuetothespecialistwhichwillreactonlywhensomethingattentionworthyhappens.
ThesignalwhichinformsthecentralprocessoraboutsuchaneventiscalledanINTERRUPT.
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 9/16
CentralProcessorUnit(CPU)
Asitsnamesuggests,[Link],
ofwhichthemostimportantare:
InstructionDecoderisapartoftheelectronicswhichrecognizesprograminstructionsandrunsothercircuitsonthe
[Link]
circuit.
ArithmeticalLogicalUnit(ALU)performsallmathematicalandlogicaloperationsupondata.
[Link]
uponwhichsomeoperationshouldbeperformed(addition,shift/moveetc.).Italsostorestheresultsreadyforusein
[Link],calledaStatusRegister(PSW),[Link]
atanygivenmomentthestatusofanumberstoredintheaccumulator(numberisgreaterorlessthanzeroetc.).
Fig.022CentralProcessorUnitCPU
Bus
Physically,thebusconsistsof8,[Link]:[Link]
[Link]
wideasthedata,[Link].
SerialCommunication
Parallelconnectionsbetweenthemicrocontrollerandperipheralsviainput/outputportsistheidealsolutionforshorterdistancesuptoseveral
[Link],inothercaseswhenitisnecessarytoestablishcommunicationbetweentwodevicesonlongerdistancesitisnotpossible
[Link],serialcommunicationisthebestsolution.
Today,[Link]
systemswillbeuseddependsonmanyfactorsofwhichthemostimportantare:
Howmanydevicesthemicrocontrollerhastoexchangedatawith?
Howfastthedataexchangehastobe?
Whatisthedistancebetweendevices?
Isitnecessarytosendandreceivedatasimultaneously?
OneofthemostimportantthingsconcerningserialcommunicationistheProtocolwhich
Fig.023Serialcommunication
[Link]
[Link],themicrocontrollersautomaticallytakecareofthis,sotheworkoftheprogrammer/userisreducedtosimplewrite
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 10/16
(datatobesent)andread(receiveddata).
BaudRate
ThetermBaudrateiscommonlyusedtodenotethenumberofbitstransferredpersecond[bps].
Itshouldbenotedthatitreferstobits,notbytes!Itisusuallyrequiredbytheprotocolthateachbyteistransferredalongwithseveralcontrol
[Link],ifthebaudrateis300bpsthenmaximum37and
minimum27bytesmaybetransferredpersecond,whichdependsontypeofconnectionandprotocolinuse.
Themostcommonlyusedserialcommunicationsystemsare:
I2C(InterIntegratedCircuit)isasystemusedwhenthedistance
betweenthemicrocontrollersisshortandspecializedintegrated
circuitsofofanewgeneration(receiverandtransmitterareusually
onthesameprintedcircuitboard).Connectionisestablishedvia
twoconductorsoneisusedfordatatransferwhereasanotheris
usedforsynchronization(clocksignal).Asseeninfigure,one
[Link]
chip(subordinated)[Link]
[Link]
rateisusually100Kb/sec(standardmode)or10Kb/sec(slowbaudratemode).Systemswiththebaudrateof3.4Mb/sechaverecently
[Link].
SPI(SerialPeripheralInterfaceBus)isasystemforserial
communicationwhichusesuptofourconductors(usuallythree)
onefordatareceiving,onefordatasending,onefor
synchronizationandone(alternatively)forselectingthedeviceto
[Link],whichmeansthat
[Link]
ishigherthaninI2Cconnection.
UART(UniversalAsynchronousReceiver/Transmitter)
Thisconnectionisasynchronous,[Link]
crucial(forexample,radioconnectionorinfraredwavesremotecontrol).Sinceonlyonecommunicationlineisused,bothreceiverand
[Link]
sinceitbasicallyrepresentsconversionof8bitdatafromparalleltoserialformat.Baudrateisnothighupto1Mbit/sec.
Oscillator
Evenpulsescomingfromtheoscillatorenableharmonicand
[Link]
oscillatormoduleisusuallyconfiguredtousequartzcrystalor
[Link],itcan
alsooperatewithoutelementsforfrequencystabilization(likeRC
oscillator).Itisimportanttosaythatinstructionsarenotexecutedat
therateimposedbytheoscillatoritself,[Link]
[Link]
somemicrocontrollers,thesamenumberofcyclesisneededto
executeanyinstruction,whileinothers,theexecutiontimeisnot
[Link],ifthesystemusesquartz
crystalwithafrequencyof20Mhz,executiontimeofaninstruction
isnot50nS,but200,400or800nS,dependingonthetypeof
MicrocontrollerUnit(MCU)!
Powersupplycircuit
Therearetwothingsworthattentionconcerningthemicrocontrollerpowersupplycircuit:
Brownoutisapotentiallydangerousstatewhichoccursatthemomentthemicrocontrollerisbeingturnedofforinsituationswhenpower
[Link]
levels,[Link],themicrocontrollerusuallyhasbuiltincircuitforbrownout
[Link].
ResetpinisusuallymarkedasMCLR(MasterClearReset)andservesforexternalresetofthemicrocontrollerbyapplyinglogiczero(0)or
one(1),[Link],asimpleexternalcircuitforbrownoutresetcan
beconnectedtothispin.
Timers/Counters
[Link],therearemanyreasonstouseit.
Namely,thefrequencyofsuchoscillatorispreciselydefinedandverystable,thepulsesitgeneratesarealwaysofthe
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 11/16
Fig.027Timers/Counters
samewidth,[Link]
betweentwoevents,[Link].
Mostprogramsusetheseminiatureelectronicstopwatches.Thesearecommonly8or16bitSFRsandtheircontentisautomatically
[Link]!
Ifthetimerregistersuseaninternalquartzoscillatorfortheiroperationthenitispossibletomeasuretimebetweentwoevents(iftheregister
valueisT1atthemomentmeasurementhasstarted,andT2atthemomentithasfinished,thentheelapsedtimeisequaltotheresultof
subtractionT2T1).Iftheregistersusepulsescomingfromexternalsourcethensuchatimeristurnedintoacounter.
Thisisonlyasimpleexplanationoftheoperationitself.
Howdoesatimeroperate?
Inpracticepulsescomingfromthequartzoscillatorareoncepereachmachinecycledirectlyorviaaprescalerbroughttothecircuitwhich
[Link](onemachinecycle)lastsforfourquartzoscillatorperiodsthen,byembedding
quartzwiththefrequencyof4MHz,thisnumberwillbechangedamilliontimespersecond(eachmicrosecond).
Fig.028TimerOperation
Itiseasytomeasureshorttimeintervals(upto256microseconds)inthewaydescribedabovebecauseitisthelargestnumberthatone
[Link],registerswithmorebits,
[Link].
Usingprescalerintimeroperating
[Link]
output,itisnecessarytobring1,2,[Link]
[Link].
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 12/16
Oneprescalerisusuallysharedbytimerandwatchdogtimer,whichmeansthatitcannotbeusedbybothofthemsimultaneously.
Fig.029Usingprescalerintimeroperating
Usingtheinterruptintimeroperation
Ifthetimerregisterconsistsof8bits,thelargestnumberthatcanbewrittentoitis255(for16bitregistersitisthenumber65.535).Ifthis
numberisexceeded,[Link]
fromwithintheprogram,suchoverflowcancauseaninterrupt,[Link],thestateofregisters
usedforcountingseconds,[Link](exceptinterruptroutine)is
automaticallyperformedinthebackground,whichenablesthemaincircuitsofthemicrocontrollertoperformotheroperations.
Fig.030Usingtheinterruptintimeroperation
[Link]
executioncanbeeasilyobtainedbyassigningaprescalertothetimer.
Counters
[Link],[Link]
differenceisthatinthiscasepulsestobecountedcomethroughtheportsandtheirduration(width)[Link]
cannotbeusedfortimemeasurement,butcanbeusedtomeasureanythingelse:productsonanassemblyline,numberofaxisrotation,
passengersetc.(dependingonsensorinuse).
WatchdogTimer
TheWatchdogTimerisatimerconnectedtoacompletelyseparateRCoscillatorwithinthemicrocontroller.
Ifthewatchdogtimerisenabled,everytimeitcountsuptotheprogramend,themicrocontrollerresetoccursandprogramexecutionstarts
[Link]
everyprogramisexecutedinseverallongerorshorterloops.
Ifinstructionswhichresetthewatchdogtimeraresetattheappropriateprogramlocations,besidescommandsbeingregularlyexecuted,then
[Link](usuallyelectricalnoisesinindustry),theprogram
countergetsstuckonsomememorylocationfromwhichthereisnoreturn,thewatchdogwillnotbeclearedandtheregistersvaluebeing
constantlyincrementedwillreachthemaximumetvoila!Resetoccurs!
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 13/16
Fig.031WatchdogTimer
A/DConverter
Externalsignalsareusuallyfundamentallydifferentfromthosethemicrocontrollerunderstands(OnesandZeros),sothattheyhavetobe
[Link]
[Link]
[Link],thismoduleisusedforinputpinvoltagemeasurement(analoguevalue).The
resultofmeasurementisanumber(digitalvalue)usedandprocessedlaterintheprogram.
Fig.032A/DConverter
InternalArchitecture
AllupgradedmicrocontrollersuseoneoftwobasicdesignmodelscalledHarvardandvonNeumannarchitecture.
Briefly,theyaretwodifferentwaysofdataexchangebetweenCPUandmemory.
vonNeumannArchitecture
Microcontrollersusingthisarchitecturehaveonlyonememoryblockandone8bitdatabus.Asalldataareexchangedbyusingthese8lines,
[Link]/writedatafrom/to
[Link],ifsomeprogramline
saysthatRAMmemoryregistercalledSUMshouldbeincrementedbyone(instruction:incfSUM),themicrocontrollerwilldothefollowing:
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 14/16
Thesamedatabusisusedforalltheseintermediateoperations.
HarvardArchitecture
Microcontrollersusingthisarchitecturehavetwodifferentdata
[Link]
consistsofseverallines(12,14or16)andconnectsCPUtoROM.
Accordingly,theCPUcanreadaninstructionandperformadata
[Link]
are8bitswide,alldatawithinthemicrocontrollerareexchangedin
[Link],duringprogramwriting,only8
[Link],allyoucaneverchange
fromwithintheprogramandallyoucanaffectwillbe8bitswide.A
programwrittenforsomeofthesemicrocontrollerswillbestoredin
themicrocontrollerinternalROMuponhavingbeingcompiledinto
[Link],thesememorylocationsdonothave
8,but12,14or16bits.Therestofbits4,6or8representsthe
instructionitselfspecifyingtotheCPUwhattodowiththe8bit
data.
Theadvantagesofsuchdesignarethefollowing:
Alldatainaprogramisonebyte(8bit)[Link](12,14or
16),[Link],allinstructionsare
[Link].
Owingtothefactthataprogram(ROM)andtemporarydata(RAM)areseparate,theCPUcanexecutetwo
[Link],whileRAMreadorwriteisinprogress(theendofoneinstruction),thenext
programinstructionisbeingreadviaanotherbus.
WhenusingmicrocontrollerswithvonNeumannarchitectureoneneverknowshowmuchmemoryistobeoccupied
[Link],eachprograminstructionoccupiestwomemorylocations(onecontainsinformationon
WHATshouldbedone,whereasanothercontainsinformationuponWHICHdataitshouldbedone).However,itis
notahardandfastrule,[Link],theprogrambusis
widerthanonebyte,[Link]:oneprogram
wordoneinstruction.
INSTRUCTIONSET
[Link]
programinassemblylanguage,youactuallytellastorybyspecifyinginstructionsintheordertheyshouldbe
[Link]
oneofthetwofollowingstrategies:
RISC(ReducedInstructionSetComputer)
Inthiscase,themicrocontrollerrecognizesandexecutesonlybasicoperations(addition,subtraction,copyingetc.).Allothermore
complicatedoperationsareperformedbycombiningthese(forexample,multiplicationisperformedbyperformingsuccessiveaddition).The
constrainsareobvious(trybyusingonlyafewwords,toexplaintosomeonehowtoreachtheairportinsomeothercity).However,thereare
[Link],[Link],themicrocontrollerisveryfastsothatitisnotpossibletosee
[Link],itisnotsodifficulttoexplain
[Link]:left,right,kilometersetc.
CISC(ComplexInstructionSetComputer)
1. ReadthepartoftheprograminstructionspecifyingWHATshouldbedone(inthisverycaseitistheincf
instructionforincrement).
2. ReadfurtherthesameinstructionspecifyinguponWHICHdataitshouldbeperformed(inthisverycaseitisthe
SUMregister).
3. Afterbeingincremented,thecontentsofthisregistershouldbewrittentotheregisterfromwhichitwasread
(SUMregisteraddress).
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 15/16
CISCistheoppositeofRISC!Microcontrollersdesignedtorecognizemorethan200differentinstructionscandomuchandareveryfast.
However,oneneedstounderstandhowtotakeallthatsucharichlanguageoffers,whichisnotatalleasy...
Howtomaketherightchoice
Ok,[Link]
choice!However,[Link],butthe
opposite!
Beforeyoustartdesigningsomedevicebasedonthemicrocontroller,thinkofthefollowing:howmanyinput/outputlineswillIneedfor
operation?Shoulditperformsomeotheroperationsthantosimplyturnrelayson/off?Doesitneedsomespecializedmodulesuchasserial
communication,A/[Link],theselectionrangeisconsiderablyreduced,thenitis
[Link]?Severalhundred?Amillion?Anyway,yougetthepoint...
[Link],[Link],select
themanufacturer,[Link],[Link]
need,[Link]
thatfamily.
Rememberlearningtorideabicycle:afterseveralunavoidablebruisesatthebeginning,youwillmanagetokeepbalanceandwillbeableto
[Link],youwillneverforgettheskillinprogrammingjustasyouwillneverforgetridingbicycles!
PICmicrocontrollers
[Link]...
TherealnameofthismicrocontrollerisPICmicro(PeripheralInterfaceController),[Link]
[Link],byaddingEEPROM
memory,[Link],MicrochipTechnologyannouncesamanufacturingofthe5
billionthsample...
Inorderthatyoucanbetterunderstandthereasonsforitspopularity,wewillbrieflydescribeseveralimportantthings.
Family
ROM
[Kbytes]
RAM
[bytes]
Pins
Clock
Freq.
[MHz]
A/D
Inputs
Resolution
of A/D
Converter
Compar-
ators
8/16
bit
Timers
Serial
Comm.
PWM
Outputs
Others
Base-Line 8 - bit architecture, 12-bit Instruction Word Length
PIC10FXXX
0.375 -
0.75
16 - 24 6 - 8 4 - 8 0 - 2 8 0 - 1 1 x 8 - - -
PIC12FXXX
0.75 -
1.5
25 - 38 8 4 - 8 0 - 3 8 0 - 1 1 x 8 - - EEPROM
PIC16FXXX 0.75 - 3
25 -
134
14 -
44
20 0 - 3 8 0 - 2 1 x 8 - - EEPROM
PIC16HVXXX 1.5 25
18 -
20
20 - - - 1 x 8 - -
Vdd =
15V
Mid-Range 8 - bit architecture, 14-bit Instruction World Length
PIC12FXXX
1.75 -
3.5
64 -
128
8 20 0 - 4 10 1
1 - 2 x
8 1 x
16
- 0 - 1 EEPROM
PIC12HVXXX 1.75 64 8 20 0 - 4 10 1
1 - 2 x
8 1 x
16
- 0 - 1 -
PIC16FXXX 1.75 - 14
64 -
368
14 -
64
20 0 - 13 8 or 10 0 - 2
1 - 2 x
8 1 x
16
USART
I2C SPI
0 - 3 -
PIC16HVXXX
1.75 -
3.5
64 -
128
14 -
20
20 0 - 12 10 2
2 x 8 1
x 16
USART
I2C SPI
- -
High-End 8 - bit architecture, 16-bit Instruction Word Length
PIC18FXXX 4 - 128
256 -
3936
18 -
80
32 -
48
4 - 16 10 or 12 0 - 3
0 - 2 x
8 2 - 3
x 16
USB2.0
CAN2.0
USART
I2C SPI
0 - 5 -
PIC18FXXJXX 8 - 128
1024 -
3936
28 -
100
40 -
48
10 - 16 10 2
0 - 2 x
8 2 - 3
x 16
USB2.0
USART
Ethernet
I2C SPI
2 - 5 -
PIC18FXXKXX 8 - 64
768 -
3936
28 -
44
64 10 - 13 10 2
1 x 8 3
x 16
USART
I2C SPI
2 -
AllPICmicrocontrollersuseharvardarchitecture,whichmeansthattheirprogrammemoryisconnectedtoCPUviamorethan8lines.
Dependingonthebuswidth,thereare12,[Link]
categories.
Asseeninthetableonthepreviouspage,excepting16bitmonstersPIC24FXXXandPIC24HXXXallPICmicrocontrollershave8bit
[Link],dependingonthesizeofaprogramwordtherearefirst,second
andthirdcategory,i.e.12,14or16bitmicrocontrollers.Havingsimilar8bitcore,allofthemusethesameinstructionsetandthebasic
hardwareskeletonconnectedtomoreorlessperipheralunits.
8/27/2014 Introduction: World of microcontrollers - Book: PIC Microcontrollers
[Link] 16/16
tableofcontents|nextchapter
Inordertoavoidtediousexplanationsandendlessstoryabouttheusefulfeaturesofdifferentmicrocontrollers,thisbookdescribesthe
operationofoneparticularmodelbelongingtohighmiddleclass.ItisaboutPIC16F887powerfulenoughtobeworthattentionandsimple
enoughtobeeasilypresentedtoeverybody.
Copyright 1998 - 2014. MikroElektronika. All rights reserved. All trade and/or services marks mentioned are the property of their respective owners.
MikroElektronika Embedded Solutions
Follow us on
PIC Solution
PIC Development Boards
PIC Compilers
PIC Programmers/Debuggers
PIC Kits
PIC Books
PIC32 Solution
PIC32 Development Boards
PIC32 Compilers
PIC32 Programmers/Debuggers
PIC32 Kits
dsPIC Solution
dsPIC Development Boards
dsPIC Compilers
dsPIC Programmers/Debuggers
dsPIC Kits
dsPIC Books
AVR Solution
AVR Development Boards
AVR Compilers
AVR Programmers/Debuggers
AVR Kits
STM32 Solution
STM32 Development Boards
STM32 Compilers
STM32 Programmers/Debuggers
STM32 Kits
Tiva C Series Solution
Tiva C Development Boards
Tiva C Compilers
Tiva C Programmers/Debuggers
Tiva C Kits
8051 Solution
8051 Dev. Boards
8051 Compilers
8051 Programmers
8051 Books
8051 Kits
Additional Software
Visual TFT
Visual GLCD
Package Manager
GLCD Font Creator
Timer Calculator
Add-on boards
Click Boards
mikromedia shields
Communication
Storage
Real Time Clock
Display
Measurement
Audio & Voice
Power Supply
GPS
GSM/GPRS
Support Forum mikroBUS Lets make Press Legal Archive About Us Customization