Rev. 1.20 42 January 23, 2015 Rev. 1.20 43 January 23, 2015
BS82B12A-3/BS82C16A-3/BS82D20A-3
Touch Key 8-Bit Flash MCU with LED/LCD Driver
BS82B12A-3/BS82C16A-3/BS82D20A-3
Touch Key 8-Bit Flash MCU with LED/LCD Driver
Reading Data from the EEPROM
ToreaddatafromtheEEPROM,thereadenablebit,RDEN,intheEECregistermustrstbeset
hightoenablethereadfunction.TheEEPROMaddressofthedatatobereadmustthenbeplaced
intheEEAregister.IftheRDbitintheEECregisterisnowsethigh,areadcyclewillbeinitiated.
SettingtheRDbithighwillnotinitiateareadoperationiftheRDENbithasnotbeenset.When
thereadcycleterminates,theRDbitwillbeautomaticallyclearedtozero,afterwhichthedatacan
bereadfromtheEEDregister.ThedatawillremainintheEEDregisteruntilanotherreadorwrite
operationisexecuted.TheapplicationprogramcanpolltheRDbittodeterminewhenthedatais
validforreading.
Writing Data to the EEPROM
TowritedatatotheEEPROM,theEEPROMaddressofthedatatobewrittenmustrstbeplaced
intheEEAregisterandthedataplacedintheEEDregister.Thenthewriteenablebit,WREN,
intheEECregistermustfirstbesethightoenablethewritefunction.Afterthis,theWRbitin
theEECregistermustbeimmediatelysethightoinitialawritecycle.Thesetwoinstructions
mustbeexecutedconsecutively.TheglobalinterruptbitEMIshouldalsofirstbeclearedbefore
implementinganywriteoperations,andthensetagainafterthewritecyclehasstarted.Notethat
settingtheWRbithighwillnotinitiateawritecycleiftheWRENbithasnotbeenset.Asthe
EEPROMwritecycleiscontrolledusinganinternaltimerwhoseoperationisasynchronousto
microcontrollersystemclock,acertaintimewillelapsebeforethedatawillhavebeenwritteninto
theEEPROM.Detectingwhenthewritecyclehasnishedcanbeimplementedeitherbypollingthe
WRbitintheEECregisterorbyusingtheEEPROMinterrupt.Whenthewritecycleterminates,
theWRbitwillbeautomaticallyclearedtozerobythemicrocontroller,informingtheuserthatthe
datahasbeenwrittentotheEEPROM.TheapplicationprogramcanthereforepolltheWRbitto
determinewhenthewritecyclehasended.
Write Protection
Protectionagainstinadvertentwriteoperationisprovidedinseveralways.Afterthedeviceis
powered-ontheWriteEnablebitinthecontrolregisterwillbeclearedpreventinganywrite
operations.Alsoatpower-ontheBankPointer,BP,willberesettozero,whichmeansthatData
MemoryBank0willbeselected.AstheEEPROMcontrolregisterislocatedinBank1,thisaddsa
furthermeasureofprotectionagainstspuriouswriteoperations.Duringnormalprogramoperation,
ensuringthattheWriteEnablebitinthecontrolregisterisclearedwillsafeguardagainstincorrect
writeoperations.
EEPROM Interrupt
TheEEPROMwriteinterruptisgeneratedwhenanEEPROMwritecyclehasended.TheEEPROM
interruptmustfirstbeenabledbysettingtheDEEbitintherelevantinterruptregister.Whenan
EEPROMwritecycleends,theDEFrequestflagwillbeset.IftheglobalandEEPROMwrite
interruptsisenabledandthestackisnotfull,ajumptotheassociatedInterruptvectorwilltake
place.Whentheinterruptisserviced,theEEPROMinterruptagwillbeautomaticallyreset.