ok,THANKS for your help.作者: rdboy 时间: 2010-4-25 18:31
本帖最后由 rdboy 于 2010-4-26 09:10 编辑
Hi,Sir
Thanks for your help.
在正常模式下,我必须用下面的代码,但是不能成功写flash(重新连上BDM,查看对应地址的数据不对).如果我用机器码:PrgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D,程序会crash。困惑啊。
bset FSTAT,#mFSTAT_CCIF
Wait_CCIF:
brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF;if this bit is 0x0,wait here. Wait a while for CCIF to be set
brset FCLKDIV,#mFCLKDIV_FDIVLD,Wait_CCIF0 ;if set ,jump// if((temp & 0x80) == 0x80)
;else,run here
ldaa #FCLK_DIV_4M
staa FCLKDIV ;FCLKDIV = FCLK_DIV;
oraa #$80
cmpa FCLKDIV;check FCLKDIV is FCLK_DIV | 0x80 // if(FCLKDIV != (FCLK_DIV | 0x80))//Check to make sure value is written.
jmp ret_Launch;if not equ,return
Wait_CCIF0:
brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF0;if this bit is 0x0,wait here. Wait a while for CCIF to be set
brclr FSTAT,#mFSTAT_CCIF,ret_Launch;
;BDM,must use these 2 lines. or CAN not write into flash.
;ldab #48
;stab FSTAT;Use store instruction to clear ACCERR, FPVIOL.
;NS,must use these 2 lines.or crash.
bset FSTAT,#mFSTAT_ACCERR
bset FSTAT,#mFSTAT_FPVIOL
;**********SET UP THE FTM COMMAND AND PARAMETERS***********
ldaa #$03
;jsr Delay32nop,pcr
Write_CCOB:
nop
nop
inc FCCOBIX
ldy a,x
sty FCCOB;Write next word parameter to CCOB1 buffer.
inca
inca
decb ;because register store param number
beq Con_Oper;if b is 0,return
bra Write_CCOB
Con_Oper:
;BMD,use the following code,write ok.
jmp PrgOfRam,pcr
;NS,use the following code,CAN communication is okay,but not write ok.
;bset FSTAT,#mFSTAT_CCIF
;Wait_CCIF:
; brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF;if this bit is 0x0,wait here. Wait a while for CCIF to be set