
3–409
Motorola Sensor Device Data
For More Information On This Product,
Go to: www.freescale.com
rts
;__________________________________________________________
wrflash: sthx flshadr ;this is the address in the flash
sta flshbyt ;and the byte we want to put there
FLASH: tsx
sthx memSP ;store SP in memSP, so it can be temporarily used as a 2nd index regis-
ter
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
jsr ramfree ;and run the subroutine from RAM, you cannot write the flash while
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
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 ;textbook way to program flash
sta flcr
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
bsr delayf
rts
delayf: ldhx #$0005
mov #$36,tsc ;stop TIM & / 64
sthx tmodh ;count H:X x 20us
bclr 5,tsc ;start clock
delayfls: brclr 7,tsc,delayfls
rts
lastbyt: nop
;–––––––– GENERAL Routines ––––––––––––––––––––––––––––––––––––––––––
ALLINIT: bset 0,config1 ;disable COP
mov #$38,ddra ;PTA0=MPAK,PTA1=SEL,PTA2=ENT,PTA3=E,PTA4=RS,PTA5=clk
bclr 3,porta ;E=0
bclr 4,porta ;grn=OFF; RS=0
bclr 5,porta ;red=OFF; CLK=0
mov #$30,adiclk ;ADC clock /2
rts
;– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
WARMUP: bclr 4,porta
F
Freescale Semiconductor, Inc.
n
.