bclr 4,porta
bclr 5,porta
rts
;LEDs off
;-------- WRITE TO EEPROM Routines ----------------------------------
;
;
wrflash: burns A into flash at location pointed by H:X
-------
wrflash: sthx flshadr
sta flshbyt
tsx
;this is the address in the flash
;and the byte we want to put there
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)
;H:X points to beginning of flash programming code
;get 1st byte from flash
ldhx #ersflsh
doall: lda 0,x
sta 0,sp
aix #$0001
ais #$0001
cphx #lastbyt
bne doall
ldhx memSP
txs
;copy it into RAM
;HX:=HX+1
;SP:=SP+1
;and continue until we reach the last byte
;once done, restore the SP
jsr ramfree
rts
;and run the subroutine from RAM, you cannot write the flash while
;running a code in it, so the RAM has to take over for that piece
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;*************** THE FOLLOWING CODE WILL BE COPIED INTO AND WILL RUN FROM RAM ******
ersflsh: lda #$02
sta flcr
;textbook way to erase flash
lda flbpr
clra
ldhx flshadr
sta 0,x
bsr delayf
lda #$0A
sta flcr
bsr delayf
lda #$08
sta flcr
bsr delayf
clra
sta flcr
bsr delayf
pgmflsh: lda #$01
sta flcr
;textbook way to program flash
lda flbpr
clra
ldhx flshadr
sta 0,x
bsr delayf
lda #$09
sta flcr
bsr delayf
lda flshbyt
ldhx flshadr
sta 0,x
bsr delayf
lda #$08
sta flcr
bsr delayf
clra
sta flcr
AN1950
18
Sensors
Freescale Semiconductor