PDA

View Full Version : Working with HEF



mpgmike
- 16th August 2017, 09:34
I am working with a PIC16F1619 that uses High Endurance Flash instead of the conventional EEPROM. I have pored over the data sheet as well as AN1673, a MicroChip Application Note specifically on the PIC16F1XXX processors and the HEF (AN1673 includes a .c and .h file with everything coded in C). Anyways, here's what I got so far:



Cyls var byte
Start:
GOSUB Write_HEF
GOSUB Read_HEF


Write_HEF:
ASM
BANKSEL PMADRH
MOVF 0Fh,W
MOVWF PMADRH ;PMADRH = $0F, 1st HEF Address is 0F80h
MOVF 80h,W
MOVWF PMADRL ;PMADRL = $80
BCF PMCON1,CFGS
BSF PMCON1,WREN
BSF PMCON1,LWLO
MOVIW _Cyls
MOVWF PMDATL

ENDASM
GOSUB UnlockHef
@ BCF PMCON1,LWLO
GOSUB UnlockHef
@ BCF PMCON1,WREN
RETURN


Read_HEF:
ASM
BANKSEL PMADRL ; Select Bank for PMCON registers
MOVLW 0x80h ;
MOVWF PMADRL ; Store LSB of address
MOVLW 0x0F ;
MOVWF PMADRH ; Store MSB of address
BCF PMCON1,CFGS ; Do not select Configuration Space
BSF PMCON1,RD ; Initiate read
NOP
NOP
MOVF PMDATL,W ; Get LSB of word
MOVWF _Cyls ; Store in user location
MOVF PMDATH,W ; Get MSB of word
MOVWF _b0 ; Store in user location
ENDASM
RETURN


UnlockHEF:
asm
BANKSEL PMCON2
MOVLW 55h
MOVWF PMCON2
MOVLW AAh
MOVWF PMCON2
BSF PMCON1,WR ; set WR bit
NOP
NOP
endasm
RETURN


What am I missing?

richard
- 16th August 2017, 11:10
Cyls var byte
Start:
GOSUB Write_HEF
GOSUB Read_HEF


Write_HEF:
ASM
BANKSEL PMADRH
MOVLW 1Fh
MOVWF PMADRH ;PMADRH = $1F, 1st HEF Address is 1F80h
MOVLW 80h
MOVWF PMADRL ;PMADRL = $80
BCF PMCON1,CFGS
BSF PMCON1,WREN
BSF PMCON1,LWLO
???? MOVIW _Cyls see below
MOVWF PMDATL

ENDASM
GOSUB UnlockHef
@ BCF PMCON1,LWLO
GOSUB UnlockHef
@ BCF PMCON1,WREN
RETURN



What am I missing?

start here I think
1st HEF Address is 0x1F80h not 0x0f80


MOVIW _Cyls
this won't work that's an indirect load of wreg but a fsr has not been loaded or selected



BANKSEL _Cyls
movf _Cyls,w
BANKSEL PMDATL
movwf PMDATL
clrf PMDATH ? ; a write is 1 word



does writecode not work for these chips ?

mpgmike
- 20th August 2017, 03:16
Richard, that is obvious when you work with Assembly a bit more regularly than I do. Thank you. I'm on a business trip right now, but should be able to try it later this week.

richard
- 21st August 2017, 02:26
have a look at this

saves 1 to 32 vars to hef

mpgmike
- 22nd August 2017, 18:16
Many thanks. I'm back from a week long business trip and am getting back in the groove of things.