📄 flash.asm
字号:
**********************************************************************
* Flash.asm *
* This file takes the data received through the serial interface *
* and burns it into the Flash NVM. *
**********************************************************************
Wrflash:
FLASH: TSX
STHX MEMSP ;store SP in MEMSP, so it can be temporarily used as a 2nd index register
LDHX #RAMFREE+1 ;SP now points to RAM (remember to add 1 to the address!!!, HC08 quirk)
TXS ;SP changed (careful not to push or call subroutines)
LDHX #Ersflsh ;H:X points to beginning of flash programming code
Doall: LDA 0,X ;get 1st byte from flash
STA 0,SP ;copy it into RAM
AIX #$0001 ;HX:=HX+1
AIS #$0001 ;SP:=SP+1
CPHX #Lastbyt ;and continue until we reach the last byte
BNE Doall
LDHX MEMSP ;once done, restore the SP
TXS
SEI
JSR Ramfree ;and run the subroutine from RAM, you cannot write the flash while
CLI
RTS ;running a code in it, so the RAM has to take over for that piece
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ersflsh: LDA #$02 ;textbook way to erase flash
STA FLCR
LDA FLBPR
STA FLASHVARS
LDA #$F
DBNZA * ;Delay min of 10us.
LDA #$0A
STA FLCR
CLR TEMP
DBNZ TEMP,* ;Delay min of 1ms.
LDA #$08
STA FLCR
LDA #$F
DBNZA * ;Delay min of 5us.
CLRA
STA FLCR
LDA #$F ;Delay min of 1us.
DBNZA *
Pgmflsh: LDA #$01 ;textbook way to program flash
STA FLCR
LDA FLBPR
STA FLASHVARS
LDA #$F
DBNZA * ;Delay min of 10us.
LDA #$09
STA FLCR
LDA #$F ;Delay min of 5us.
DBNZA *
TSX
STHX MEMSP ;store SP in MEMSP, so it can be temporarily used as a 2nd index register
LDHX #FLASHVARS+1 ;SP now points to Flash (remember to add 1 to the address!!!, HC08 quirk)
TXS ;SP changed (careful not to push or call subroutines)
LDHX #THRESHOLD ;H:X points to the new values
Doall2 LDA 0,X ;get 1st byte from flash
STA 0,SP ;copy it into RAM
AIX #$0001 ;HX:=HX+1
AIS #$0001 ;SP:=SP+1
LDA #$F
DBNZA * ;Delay min of 30us between each byte write.
CPHX #RRID+4 ;and continue until we reach the last byte
BNE Doall2
LDHX MEMSP ;once done, restore the SP
TXS
LDA #$08
STA FLCR
LDA #$F
DBNZA * ;Delay min of 5us.
CLRA
STA FLCR
LDA #$F ;Delay min of 1us.
DBNZA *
RTS
Lastbyt: NOP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -