Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2014
    Posts
    63

    Default Working with HEF

    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:

    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. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,204

    Default Re: Working with HEF

    Quote Originally Posted by mpgmike View Post

    Code:
    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
    Code:
    
    
    BANKSEL _Cyls
    movf _Cyls,w  
    BANKSEL PMDATL
    movwf PMDATL
    clrf      PMDATH  ? ;  a write is 1 word


    does writecode not work for these chips ?
    Last edited by richard; - 16th August 2017 at 10:13. Reason: a few typos
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Apr 2014
    Posts
    63

    Default Re: Working with HEF

    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.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,204

    Default Re: Working with HEF

    have a look at this

    saves 1 to 32 vars to hef
    Attached Files Attached Files
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Apr 2014
    Posts
    63

    Default Re: Working with HEF

    Many thanks. I'm back from a week long business trip and am getting back in the groove of things.

Similar Threads

  1. HEF (High Endurance Flash) What to do?
    By mehmetOzdemir in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th June 2016, 06:25
  2. SERIN Not Working, SEROUT Working
    By cc1984 in forum Serial
    Replies: 11
    Last Post: - 26th October 2010, 19:16
  3. SHIFTOUT is not working
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th August 2010, 22:56
  4. Anyone working with the MRF24J40MA's?
    By JD123 in forum Off Topic
    Replies: 4
    Last Post: - 18th April 2010, 03:49
  5. Working with money
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 25th July 2007, 22:46

Members who have read this thread : 21

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts