Rev. 1.71 34 April 11, 2017 Rev. 1.71 35 April 11, 2017
HT66F002/HT66F0025/HT66F003/HT66F004
Cost-Effective A/D Flash MCU with EEPROM
HT66F002/HT66F0025/HT66F003/HT66F004
Cost-Effective A/D Flash MCU with EEPROM
Writing Data to the EEPROM
TheEEPROMaddressofthedatatobewrittenmustrstbeplacedintheEEAregisterandthedata
placedintheEEDregister.TowritedatatotheEEPROM,thewriteenablebit,WREN,intheEEC
registermustrstbesethightoenablethewritefunction.Afterthis,theWRbitintheEECregister
mustbeimmediatelysethightoinitiateawritecycle.Thesetwoinstructionsmustbeexecuted
consecutively.TheglobalinterruptbitEMIshouldalsorstbeclearedbeforeimplementingany
writeoperations,andthensetagainafterthewritecyclehasstarted.NotethatsettingtheWRbit
highwillnotinitiateawritecycleiftheWRENbithasnotbeenset.AstheEEPROMwritecycleis
controlledusinganinternaltimerwhoseoperationisasynchronoustomicrocontrollersystemclock,
acertaintimewillelapsebeforethedatawillhavebeenwrittenintotheEEPROM.Detectingwhen
thewritecyclehasnishedcanbeimplementedeitherbypollingtheWRbitintheEECregisteror
byusingtheEEPROMinterrupt.Whenthewritecycleterminates,theWRbitwillbeautomatically
clearedtozerobythemicrocontroller,informingtheuserthatthedatahasbeenwrittentothe
EEPROM.TheapplicationprogramcanthereforepolltheWRbittodeterminewhenthewritecycle
hasended.
Write Protection
Protectionagainstinadvertentwriteoperationisprovidedinseveralways.Afterthedevices
arepowered-ontheWriteEnablebitinthecontrolregisterwillbeclearedpreventinganywrite
operations.Alsoatpower-ontheBankPointer,BP,willberesettozero,whichmeansthatData
MemoryBank0willbeselected.AstheEEPROMcontrolregisterislocatedinBank1,thisaddsa
furthermeasureofprotectionagainstspuriouswriteoperations.Duringnormalprogramoperation,
ensuringthattheWriteEnablebitinthecontrolregisterisclearedwillsafeguardagainstincorrect
writeoperations.
EEPROM Interrupt
TheEEPROMwriteinterruptisgeneratedwhenanEEPROMwritecyclehasended.TheEEPROM
interruptmustfirstbeenabledbysettingtheDEEbitintherelevantinterruptregister.Whenan
EEPROMwritecycleends,theDEFrequestagwillbeset.Iftheglobal,EEPROMInterruptare
enabledandthestackisnotfull,asubroutinecalltotheEEPROMInterruptvector,willtakeplace.
WhentheEEPROMInterruptisserviced,theEEPROMInterruptagDEFwillbeautomatically
cleared.TheEMIbitwillalsobeautomaticallyclearedtodisableotherinterrupts.