在线时间6 小时
UID112252
注册时间2009-2-25
NXP金币0
该用户从未签到
注册会员

- 积分
- 165
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2014-10-17 16:20:20
|
显示全部楼层
我想测试向地址0x1860内写入一个字节,内容为0xAA,代码如下:
主程序:
g_Buffer[0]=BOOT_CONNECT;
FlashPageWrite(0x1860);
写入函数:
FlashPageWrite:
STHX ADRS
LDA #1
STA LEN
LDHX #g_Buffer
STHX ADRR
lda #(mFSTAT_FPVIOL+mFSTAT_FACCERR) ;mask
sta FSTAT ;abort any command and clear errors
mov #ProgSubSize, STAT ;length of flash prog routine to STAT
tsx
sthx STACK
ldhx #ProgSubEnd-1 ;point at last byte to move to stack
; bra DoOnStack ;execute prog code from stack RAM
; fallthru to this routine
;*******************************************************************************************
DoOnStack:
lda ,x ;read from flash
psha ;move onto stack
aix #-1 ;next byte to move
dbnz STAT, DoOnStack
tsx ;point to sub on stack
jmp ,x ;execute the sub on the stack (will return on it's own)
;*******************************************************************************************
ProgSub:
lda FSTAT ;check FCBEF
and #mFSTAT_FCBEF ;mask it
beq ProgSub ;loop if not empty
ldhx ADRR
lda 0,x
aix #1
sthx ADRR
ldhx ADRS ;get flash address
sta 0,x ;write to flash; latch addr and data
aix #1
sthx ADRS
lda #mByteProg;#mBurstProg ;get flash command
sta FCMD ;write the flash command
lda #mFSTAT_FCBEF ;mask to initiate command
sta FSTAT ;[pwpp] register command
dbnz LEN,ProgSub ;all bytes in a row?
ChkDoneProg:
lda FSTAT ;[prpp] so FCCF is valid
lsla ;FCCF now in MSB
bpl ChkDoneProg ;loop if FCCF = 0
ldhx STACK
txs
rts
ProgSubEnd:
ProgSubSize: equ (*-ProgSub)
;******************************************************************************************* |
|