📄 flash.asm
字号:
CALL flash_write ;write the XPC of the third section(.vectors)
BC nexte,ANEQ ;if A!=0 ,write next data
B $
nexte: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #300H,4H
CALL flash_write ;write the PC of the third section(.vectors)
BC nextf,ANEQ ;if A!=0 ,write next data
B $
nextf: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
STM #0,AH
STM #0300H,AL
STLM A,AR1 ;write the address of third section(.vectors) to AR1
NOP
NOP
NOP
STM #0,AH
STM #078H,AL
STLM A,AR2 ;AR2 is the longth of the third section(.vectors)
DLD 6H,A ;get the address of flash
CALL bwrite ;write to flash
BC bnext3,ANEQ ;if(a=0),write to flash is error
B $
bnext3: NOP
NOP
DLD 2H,A
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
******************************************************************************************
* write the fourth section(.vector) to flash *
******************************************************************************************
DLD 6H,A ;get the address of flash
ST #01H,4H
CALL flash_write ;write the size of the fourth section(.trap)
BC next10,ANEQ ;if A!=0 ,write next data
B $
next10: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #0,4H
CALL flash_write ;write the XPC of the fourth section(.trap)
BC next11,ANEQ ;if A!=0 ,write next data
B $
next11: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #60H,4H
CALL flash_write ;write the PC of the fourth section(.trap)
BC next12,ANEQ ;if A!=0 ,write next data
B $
next12: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
STM #0,AH
STM #060H,AL
STLM A,AR1 ;write the address of fourth section(.trap) to AR1
NOP
NOP
NOP
STM #0,AH
STM #01H,AL
STLM A,AR2 ;AR2 is the longth of the fourth section(.trap)
DLD 6H,A ;get the address of flash
CALL bwrite ;write to flash
BC bnext4,ANEQ ;if(a=0),write to flash is error
B $
bnext4: NOP
NOP
DLD 2H,A
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
*****************************************************************************************
* the seventh step of the bootload: *
* write the indicates the end of the boot table (0000) *
*****************************************************************************************
DLD 6H,A ;get the address of flash
ST #00H,4H
CALL flash_write ;write the size of the fourth section(.trap)
BC next1f,ANEQ ;if A!=0 ,write next data
next1f: B $
******************************************************************************************
B $ ;boot table is writing over
******************************************************************************************
* FUCTION *
******************************************************************************************
******************************************************************************************
* *
* the block for flash write *
* register A is the distination address of you want to write *
* register AR2 is the longth for you write to flash * *
* register AR1 is the source address of the code to be writen to *
* *
******************************************************************************************
bwrite: DST A,2H ; save the address
LD *AR1+,A
STL A,4H ;store the data to 4H
DLD 2H,A ; get the flash address
CALL flash_write;write a data to flash
BC fover,AEQ ;if A!=0 ,write next data
LDM AR2,A
STM #0,AH
SUB #1,A ; the long size sub one
BC fover1,AEQ ;if A=0 ,write flash is over
STLM A,AR2 ; save the changed long size
DLD 2H,A ; get the flash address
ADD #1,A ; address of flash +1
B bwrite ;write next data
fover1: LD #1,A ; write is over
NOP
NOP
NOP
RET ;exit with OK
fover: NOP ;exit with error
NOP
NOP
RET
******************************************************************************************
* write a 16-bit data to the flash address *
* register A is the address of the flash that we want write to *
* relative address 4H is the data you want to write to the flash *
******************************************************************************************
flash_write: DST A,0H ; save the address of the flash
STM #Flash_base,AH ; The address of the flash is 0x80555H
STM #Flash_5555,AL
STM #Flash_UL1,BL ; write operation code to 1H
WRITA *(BL) ; AAH --> (80555H)
STM #Flash_2AAA,AL ; The address of the flash is 0x802aaH
STM #Flash_UL2,BL ; write operation code to 1H
WRITA *(BL) ; 55H --> (802AAH)
STM #Flash_5555,AL ; The address of the flash is 0x80555H
STM #Flash_PRG,BL ; write operation code to 1H
WRITA *(BL) ; A0H --> (80555H)
DLD 0H,A ; get the flash address
WRITA 4H ; 3H is your data of wanting to write to the flash
write_poll: READA *(BL)
XOR 4H,B ; data ^ B
BITF *(BL),#Polling_Bit
BC write_poll,TC ;Is the action for write "ok"?
READA *(BL)
XOR 4H,B
STM #0,BH ; Is the data is ok?
LD #1,A ; if ok,write 1 to A
XC 1,BNEQ
LD #0,A ; else ,wriet 0 to A
RET
******************************************************************************************
* erase the all the 39VF400b *
******************************************************************************************
flash_erase: STM #Flash_base,AH ; High address of the flash is 0x80000H
STM #Flash_5555,AL
ST #Flash_UL1,1H
WRITA 1H ;AAH --> (80555H)
STM #Flash_2AAA,AL
ST #Flash_UL2,1H
WRITA 1H ;55H --> (802AAH)
STM #Flash_5555,AL
ST #Flash_ERASE,1H
WRITA 1H ;80H --> (80555H)
STM #Flash_5555,AL
ST #Flash_UL1,1H
WRITA 1H ;AAH --> (80555H)
STM #Flash_2AAA,AL
ST #Flash_UL2,1H
WRITA 1H ;55H --> (802AAH)
STM #Flash_5555,AL
ST #Flash_CE,1H
WRITA 1H
nop
nop
nop
nop
nop ;AAH --> (80555H)
erase_poll: STM #0H,AL
READA 1H
BITF 1H,#Polling_Bit
BC erase_poll,NTC ; Is the action for erase "ok"?
STM #0H,AL
STM #03H,BH
STM #0FFFFH,BL
erase_check: READA 1H
CMPM 1H,#Flash_BLANK
BCD erase_err,NTC
ADD #1,A
SUB #1,B
BCD erase_check,BNEQ
NOP
NOP
NOP
NOP
LD #1,A
NOP
NOP
BD erase_end
erase_err: LD #0H,A
erase_end: NOP
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -