Announcement

Collapse
No announcement yet.

Accessing HEF

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing HEF

    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:

    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
    What am I missing?

  • #2
    This is working but to be really useful you need to implement a block structure of say 32 14bit words that you can erase and rewrite as required
    individual words can be read but the whole block must be erased and rewritten to modify an individual word.

    strangely the pbp [ver 3.010.4] MOVE macros fail to load the PMDAT latches correctly so its done longhand , I have not investigated why

    Code:
    '****************************************************************
    '*  Name    : hef_Test.PBP                                   *
    '*  Author  :                                                   *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    :                                                   *
    '*  Version :                                    *
    '*  Notes   : PIC16F1619                                        *
    '*          : hef TEST                                          *
    '****************************************************************
    
    
    
    
    
    
    
    #CONFIG
        __config _CONFIG1,  _FOSC_INTOSC & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
        __config _CONFIG2,  _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_ON
        __config _CONFIG3,  _WDTCPS_WDTCPS6 & _WDTE_OFF & _WDTCWS_WDTCWS100 & _WDTCCS_LFINTOSC
    #ENDCONFIG
    
     define      OSC             32
    
    ; --- *** Oscillator  *** ---------------------------------------------------
    OSCCON = %11110000           ;8 MHz, 4X PLL Enabled, 32 MHz
    TRISA  = %11011011
    TRISC  = 255
    ANSELA = 0
    ANSELC = 0
    
    
    
    LED    VAR  PORTA.5  ' Assign name "LED" to  
    
    'LCD defines begin here  
        DEFINE LCD_BITS 4  'defines the number of data interface lines (4 or 8)
        DEFINE LCD_DREG PORTB 'defines the port where data lines are connected to
        DEFINE LCD_DBIT 4  'defines the position of data lines for 4-bit interface (0 or 4)
        DEFINE LCD_RSREG PORTC 'defines the port where RS line is connected to
        DEFINE LCD_RSBIT 2  'defines the pin where RS line is connected to
        DEFINE LCD_EREG PORTC  'defines the port where E line is connected to
        DEFINE LCD_EBIT 1  'defines the pin where E line is connected
        DEFINE LCD_RWREG PORTC ' LCD read/write port
        DEFINE LCD_RWBIT 0 ' LCD read/write pin bit
        DEFINE LCD_COMMANDUS 1500  'defines the delay after LCDOUT statement
        DEFINE LCD_DATAUS 50   'delay in micro seconds
    'END of LCD DEFINES
    
    Cyls        var     WORD
    RESULT      var     WORD
    
    
    Cyls = 12340
    Pause 500       ' LCD initialize time
    lcdout $FE,1,"ready "
    Pause 2000
    
    lcdout $FE,1,"WRITING " ,#Cyls
    
    GOSUB Write_HEF
    
    READCODE $1F80,  RESULT
    
    lcdout $FE,$C0,"read " ,#RESULT
    
    
    
    
    
    STOP
    
    Write_HEF:
    ASM
        BANKSEL PMADRH
        MOVLW    1Fh
        MOVWF   PMADRH                        
        MOVLW    80h
        MOVWF   PMADRL                        
        BCF     PMCON1,CFGS
        BSF     PMCON1,WREN
        BSF     PMCON1,LWLO
       ;MOVE?BA  _Cyls            ; BYTE MACRO'S FAIL HERE
        ;MOVE?AB  PMDATL           ;      "
        ;MOVE?BA  _Cyls+1          ;      "
        ;MOVE?AB  PMDATH           ;      "
        ;MOVE?BB   _Cyls,  PMDATL  ;    AND THESE TOO FAIL
        ;MOVE?BB   _Cyls+1,PMDATH  ;      "
        ;MOVE?WW   _Cyls,  PMDATL  ; WORD MACRO FAILS HERE
        BANKSEL    _Cyls
        movf _Cyls,w
        BANKSEL  PMDATL
        movwf PMDATL
        BANKSEL _Cyls
        movf _Cyls+1,w
        BANKSEL PMDATH
        MOVWF    PMDATH
        ;L?CALL UnlockHef    ; unnecessary here
        BANKSEL PMCON1
        BCF     PMCON1,LWLO
        L?CALL UnlockHef
        BANKSEL PMCON1
        BCF     PMCON1,WREN
        RST?RP
        RETURN
    UnlockHef
        BANKSEL PMCON2
        MOVLW   55h
        MOVWF   PMCON2
        MOVLW   0AAh
        MOVWF   PMCON2
        BSF     PMCON1,WR                    
        NOP
        NOP
        RETURN
    endasm
    Last edited by richard; 08-16-2017, 09:56 PM.

    Comment


    • #3
      data sheet is a bit of a mystery
      High-Endurance Flash Data Memory (HEF):

      - 128 B of nonvolatile data storage

      - 100K erase/write cycles
      later on is says 1024 bytes for 16f1619

      but start addr is still 1f80

      Code:
      PIC16(L)F1615/9 8,192 1FFFh 1F80h-1FFFh
      
      Note 1: High-endurance Flash applies to low byte of each address in the range.
      how can you only write to the low byte ?
      Attached Files

      Comment


      • #4
        a version that saves 1 to 32 vars to hef
        Attached Files

        Comment


        • #5
          Thank you very much.

          Comment

          Working...
          X