#asm
// mov _FLASH_DUKR,#0xae
// mov _FLASH_DUKR,#0x56
mov _FLASH_PUKR,#0x56 //解锁FLASH
mov _FLASH_PUKR,#0xae
clr $20 //清计数器
clr $21
clr $22
main1:
ldw y,sp
ldw x,#$9fff //写入高地址
ldw sp,x
mov _FLASH_CR2,#0x1; //按页写入AAAA
mov _FLASH_NCR2,#0xfe;
ldw x,#$aaaa
ld a,#32
pushw x
dec a
jrne *-2
btjt _FLASH_IAPSR,#6,* //等开始写 =0 HV ON
btjf _FLASH_IAPSR,#2,* //等开始写 end of prog
ld a,#32
testa:
popw x
cpw x,#$aaaa
jrne err1
dec a
jrne testa
mov _FLASH_CR2,#0x1; //按页写入5555
mov _FLASH_NCR2,#0xfe;
ldw x,#$5555
ld a,#32
pushw x
dec a
jrne *-2
btjt _FLASH_IAPSR,#6,* //等开始写 =0 HV ON
btjf _FLASH_IAPSR,#2,* //等开始写 end of prog
ld a,#32
test5:
popw x
cpw x,#$5555
jrne err1
dec a
jrne test5
inc 0x20
jrne main1
ldw sp,y
ldw x,$21
incw x
ldw $21,x
ld a,$21
call _TxByte
ld a,$22
call _TxByte
jra main1
ldw sp,y //串口输出256字节
ldw x,#$9f00
clr 40
LOOP:
ld a,(x)
call _TxByte
incw x
inc 40
jrne LOOP
err1: //错误陷阱 输出 00 00
ldw sp,y //恢复栈指针
clr a
call _TxByte
call _TxByte
jra *
#endasm
|