PIC18微控制器的堆栈操纵
Traditionally,themicrocontrollerstackhasonlybeen
usedasastoragespaceforreturnaddressesofsub-
routinesorinterruptroutines,whereall‘push’and‘pop’
operationswerehidden.Forthemostpart,usershad
nodirectaccesstotheinformationonthestack.The
PIC18microcontrollerdivergesfromthistradition
slightly.WiththenewPIC18core,usersnowhave
accesstothestackandcanmodifythestackpointer
andstackdatadirectly.Havingsuchlevelsofaccessto
thestackallowsforsomeuniqueandinteresting
programmingpossibilities.
Thisapplicationnotedescribesspecificinformation,
registers,andinstructionsrelatedtoaccessingthe
stack.Anexampleisalsoincludeddemonstratinga
verysimpletaskmanager,anessentialelementfora
real-timeoperatingsystem(RTOS).MAN818ManipulatingtheStackofthePIC18MicrocontrollerAuthor:RossM.FoslerThepointertothetopofthestackisprovidedinregisterMicrochipTechnologyInc.STKPTR.Thepointerisonlyfive-bitswide,whichaccountsforastackdepthof32words.However,thefirstlocationisnotcounted,sinceitisnotphysicallyaINTRODUCTIONmemorylocationinthestack.ThefirstlocationalwaysTraditionally,themicrocontrollers