Datasheet

dsPIC30F2011/2012/3012/3013
DS70139G-page 58 © 2010 Microchip Technology Inc.
EXAMPLE 6-5: DATA EEPROM BLOCK WRITE
6.4 Write Verify
Depending on the application, good programming
practice may dictate that the value written to the mem-
ory should be verified against the original value. This
should be used in applications where excessive writes
can stress bits near the specification limit.
6.5 Protection Against Spurious Write
There are conditions when the device may not want to
write to the data EEPROM memory. To protect against
spurious EEPROM writes, various mechanisms have
been built-in. On power-up, the WREN bit is cleared;
also, the Power-up Timer prevents EEPROM write.
The write initiate sequence and the WREN bit together
help prevent an accidental write during brown-out,
power glitch, or software malfunction.
MOV #LOW_ADDR_WORD,W0 ; Init pointer
MOV #HIGH_ADDR_WORD,W1
MOV W1
,
TBLPAG
MOV #data1,W2 ; Get 1st data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data2,W2 ; Get 2nd data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data3,W2 ; Get 3rd data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data4,W2 ; Get 4th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data5,W2 ; Get 5th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data6,W2 ; Get 6th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data7,W2 ; Get 7th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data8,W2 ; Get 8th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data9,W2 ; Get 9th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data10,W2 ; Get 10th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data11,W2 ; Get 11th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data12,W2 ; Get 12th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data13,W2 ; Get 13th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data14,W2 ; Get 14th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data15,W2 ; Get 15th data
TBLWTL W2
,
[ W0]++ ; write data
MOV #data16,W2 ; Get 16th data
TBLWTL W2
,
[ W0]++ ; write data. The NVMADR captures last table access address.
MOV #0x400A,W0 ; Select data EEPROM for multi word op
MOV W0
,
NVMCON ; Operate Key to allow program operation
DISI #5 ; Block all interrupts with priority <7 for
; next 5 instructions
MOV #0x55,W0
MOV W0
,
NVMKEY ; Write the 0x55 key
MOV #0xAA,W1
MOV W1
,
NVMKEY ; Write the 0xAA key
BSET NVMCON,#WR ; Start write cycle
NOP
NOP