James Wages
2017-08-04 04:21:40 UTC
I am trying to figure out how to WRITE data the initial EEPROM address on a 16F18854 using Assembly code. Sadly, the datasheet is lacking in terms of clarity:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001826B.pdf
Please open the datasheet PDF to page 153. Section 10.2 Data EEPROM Memory says, "Data EEPROM Memory consists of 256 bytes of user data memory. The EEPROM provides storage locations for 8-bit user defined data." If truly only "8-bit" then why is the NVMDATH:NVMDATL register pair (16-bits) required to WRITE to EEPROM? In other words, if truly 8-bit, am I allowed to WRITE to only to the Low Byte, NVMDATL?
Second related question...
The following is some ASM code I wrote. Does it look correct? Or have I written something wrong or out of sequence?
; ---------------
; WRITE to EEPROM
; ---------------
; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF")
; EEPROM Address Setup:
banksel NVMCON1 ; [Bank 16]
bsf NVMCON1, NVMREGS ; Access EEPROM.
bsf NVMCON1, WREN ; Allow Program/Erase.
movlw b'11110000' ; Address High Byte for WRITE to F000h.
movwf NVMADRH
clrf NVMADRL ; F000h = 11110000 00000000
; Data to WRITE to EEPROM address above:
movlw b'00000001' ; Low Byte data to WRITE
movwf NVMDATL
movlw b'10000000' ; High Byte data to WRITE
movwf NVMDATH
; Unlock Sequence (required for WRITE to EEPROM):
bcf INTCON, GIE ; Disable Interrupts (important)
; Next line not needed because WREN was already set to 1 above?
; bsf NVMCON1, WREN ; Enable WRITE/ERASE.
movlw 0x55 ; Put 55h into NVMCON2 register.
movwf NVMCON2
movlw 0xAA ; Put AAh into NVMCON2 register.
movwf NVMCON2
bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE.
bsf INTCON, GIE ; Re-enable Interrupts.
WRITEwater
btfsc NVMCON1, WR ; WRITE finished?
goto WRITEwater ; No. Loop.
goto MainProgram ; Yes.
Thank you,
James Wages
http://ww1.microchip.com/downloads/en/DeviceDoc/40001826B.pdf
Please open the datasheet PDF to page 153. Section 10.2 Data EEPROM Memory says, "Data EEPROM Memory consists of 256 bytes of user data memory. The EEPROM provides storage locations for 8-bit user defined data." If truly only "8-bit" then why is the NVMDATH:NVMDATL register pair (16-bits) required to WRITE to EEPROM? In other words, if truly 8-bit, am I allowed to WRITE to only to the Low Byte, NVMDATL?
Second related question...
The following is some ASM code I wrote. Does it look correct? Or have I written something wrong or out of sequence?
; ---------------
; WRITE to EEPROM
; ---------------
; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF")
; EEPROM Address Setup:
banksel NVMCON1 ; [Bank 16]
bsf NVMCON1, NVMREGS ; Access EEPROM.
bsf NVMCON1, WREN ; Allow Program/Erase.
movlw b'11110000' ; Address High Byte for WRITE to F000h.
movwf NVMADRH
clrf NVMADRL ; F000h = 11110000 00000000
; Data to WRITE to EEPROM address above:
movlw b'00000001' ; Low Byte data to WRITE
movwf NVMDATL
movlw b'10000000' ; High Byte data to WRITE
movwf NVMDATH
; Unlock Sequence (required for WRITE to EEPROM):
bcf INTCON, GIE ; Disable Interrupts (important)
; Next line not needed because WREN was already set to 1 above?
; bsf NVMCON1, WREN ; Enable WRITE/ERASE.
movlw 0x55 ; Put 55h into NVMCON2 register.
movwf NVMCON2
movlw 0xAA ; Put AAh into NVMCON2 register.
movwf NVMCON2
bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE.
bsf INTCON, GIE ; Re-enable Interrupts.
WRITEwater
btfsc NVMCON1, WR ; WRITE finished?
goto WRITEwater ; No. Loop.
goto MainProgram ; Yes.
Thank you,
James Wages
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist