Flash Memory Operation
5-13
Flash Memory Controller
; Write one block starting at 0F000h.
; Must be executed from RAM, Assumes Flash is already erased.
; 514 kHz < SMCLK < 952 kHz
; Assumes ACCVIE = NMIIE = OFIE = 0.
MOV #32,R5 ; Use as write counter
MOV #0F000h,R6 ; Write pointer
MOV #WDTPW+WDTHOLD,&WDTCTL ; Disable WDT
DINT ; Disable interrupts
L1 BIT #BUSY,&FCTL3 ; Test BUSY
JNZ L1 ; Loop while busy
MOV #FWKEY+FSSEL1+FN0,&FCTL2 ; SMCLK/2
MOV #FWKEY,&FCTL3 ; Clear LOCK
MOV #FWKEY+BLKWRT+WRT,&FCTL1 ; Enable block write
L2 MOV Write_Value,0(R6) ; Write location
L3 BIT #WAIT,&FCTL3 ; Test WAIT
JZ L3 ; Loop while WAIT=0
INCD R6 ; Point to next word
DEC R5 ; Decrement write counter
JNZ L2 ; End of block?
MOV #FWKEY,&FCTL1 ; Clear WRT,BLKWRT
L4 BIT #BUSY,&FCTL3 ; Test BUSY
JNZ L4 ; Loop while busy
MOV #FWKEY+LOCK,&FCTL3 ; Set LOCK
... ; Re-enable WDT if needed
EINT ; Enable interrupts