481
19.7 Programming Example of 512K-Bit Flash Memory
;///////////////////////////////////////////////////////////////////
RAMPRG
CSEG
ABS=0FFH
ORG
0BC00H
;
////////////////////////////////////////////
;
Initialization
;
////////////////////////////////////////////
MOVW
RW0,#0500H
;RW0:Reserve RAM space for input
area 00:0500 to
MOVW
RW2,#0000H
;RW2:Flash memory write address
FF:0000 to
MOV
A,#00H
;DTB modification
MOV
DTB,A
;Bank specification for @RW0
MOV
A,#0FFH
;ADB modification 1
MOV
ADB,A
;Bank specification for write mode
specification address
MOV
PDR3,#00H
;Switch initialization
MOV
DDR3,#00H
;
WAIT1
BBC
PDR3:0,WAIT1
;Writing starts if PDR3:0 Hi.
;
;/////////////////////////////////////////////////
; Write (SA0)
;/////////////////////////////////////////////////
MOV
A,PDR1
MOVW
@RW0+00,A
;PDR1 data is stored in RAM.
MOV
FMCS,#20H
;Write mode setting
MOVW
ADB:COMADR1,#00AAH;Flash write command 1
MOVW
ADB:COMADR2,#0055H;Flash write command 2
MOVW
ADB:COMADR1,#00A0H;Flash write command 3
;
MOVW
A,@RW0+00
;Input data (RW0) is written
to flash memory (RW2).
MOVW
@RW2+00,A
WRITE
;Wait time check
;
////////////////////////////////////////////////////////////
;
If the "time-limit-exceeded" check flag is set while
toggling is on, branches to ERROR.
;
////////////////////////////////////////////////////////////
MOVW
A,@RW2+00
AND
A,#20H
;DQ5 time limit check
BZ
NTOW
;Time limit exceeded
MOVW
A,@RW2+00
;AH
MOVW
A,@RW2+00
;AL
XORW
A
;XOR of AH and AL (1 when the values
are different.)
AND
A,#40H
;Checks whether the DQ6 toggle bit
is different.
BNZ
ERROR
;If it is different, branches to
ERROR
;
////////////////////////////////////////////////
;
Write-end check (FMCS-RDY)
;
////////////////////////////////////////////////
NTOW
MOVW
A,FMCS
AND
A,#10H
;FMCS RDY bit (4 bit) is extracted.
BZ
WRITE
;Verifies that writing has ended.
MOV
FMCS,#00H
;Write mode is released.
;/////////////////////////////////////////////////////