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?
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?