英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流
标题:
关于dsPIC的EEPROM
[打印本页]
作者:
winnie
时间:
2009-3-12 15:42
标题:
关于dsPIC的EEPROM
我在用MPLAB IDE (C30)仿真dsPIC30F3011写自带EEPROM时,把NVMCON.WR置1时,但结果总是为0,数据也没有写入EEPROM。谁能帮我解答一下
作者:
winnie
时间:
2009-3-12 15:42
汇编
读EEPROM
ReadEE(__builtin_tblpage(&fooArrayInDataEE[0]),
__builtin_tbloffset(&fooArrayInDataEE[0]),&fooArray2inRAM[0], ROW);
写EEPROM
WriteEE(&fooArray1inRAM[0],__builtin_tblpage(&fooArrayInDataEE[0]),
__builtin_tbloffset(&fooArrayInDataEE[0]), ROW);
.include "p30fxxxx.inc"
.equ EE_WORD_ERASE_CODE, 0x4044
.equ EE_WORD_WRITE_CODE, 0x4004
.equ EE_ROW_ERASE_CODE, 0x4045
.equ EE_ROW_WRITE_CODE, 0x4005
.equ EE_ALL_ERASE_CODE, 0x4046
.equ CONFIG_WORD_WRITE_CODE, 0x4006
.global _ReadEE
.global _EraseEE
.global _WriteEE
.section .text
/* DATA EEPROM Read Routines */
_ReadEE:
push TBLPAG
mov w0, TBLPAG
cp w3, #1
bra z, L0
cp w3, #16 ;EEPROM数据个数
bra z, L0
mov #-1, w0
bra L1
L0: tblrdl [w1++],[w2++]
dec w3, w3
bra nz, L0
L1: pop TBLPAG
return
/* DATA EEPROM Erase Routines */
_EraseEE:
push.d w4
bclr SR, #Z
mov #EE_WORD_ERASE_CODE, W4
cp w2, #1
bra z, L2
mov #EE_ROW_ERASE_CODE, W4
cp w2, #16
bra z, L2
mov #EE_ALL_ERASE_CODE, W4
mov #0xFFFF, w5
cp w2, w5
bra z, L2
mov #-1, w0
pop.d w4
return
L2:
push TBLPAG
mov W0, NVMADRU
mov W1, NVMADR
mov W4, NVMCON
push SR
mov #0xE0, W0
ior SR
mov #0x55, W0
mov W0, NVMKEY
mov #0xAA, W0
mov W0, NVMKEY
bset NVMCON, #WR
nop
nop
L3: btsc NVMCON, #WR
bra L3
clr w0
pop SR
L4: pop TBLPAG
pop.d w4
return
/* DATA EEPROM Write Routines */
_WriteEE:
push w4
bclr SR, #Z
mov #EE_WORD_WRITE_CODE, W4
cp w3, #1
bra z, L5
mov #EE_ROW_WRITE_CODE, W4
cp w3, #16
bra z, L5
pop w4
mov #-1, w0
return
L5: push TBLPAG
mov W1, TBLPAG
push W2
L6: tblwtl [W0++],[W2++]
dec w3, w3
bra nz, L6
mov W1, NVMADRU
pop W2
mov W2, NVMADR
mov W4, NVMCON
push SR
mov #0xE0, W0
ior SR
mov #0x55, W0
mov W0, NVMKEY
mov #0xAA, W0
mov W0, NVMKEY
bset NVMCON, #WR
nop
nop
L7: btsc NVMCON, #WR
bra L7
clr w0
pop SR
pop TBLPAG
pop w4
return
.end
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/)
Powered by Discuz! X3.2