I'm working with a PIC16F1619 which doesn't have an "EEPROM", but instead uses High Endurance Flash (HEF). I have spent considerable time with the data sheet as well as AN1673, a MicroChip Application Note specifically on the HEF & PIC16F1XXX processors. It would be grand if I could save one single variable to the HEF that can be retrieved at start-up. Here's what I have:
What am I missing?
Code:
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
Comment