Strange compile for a 16F628A


+ Reply to Thread
Results 1 to 9 of 9

Thread: Strange compile for a 16F628A36 days old

  1. #1
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    57
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    152.82 MB

    0 Not allowed!

    Default Strange compile for a 16F628A

    I can't understand why the context save/restore wants to save eeprom data, which causing a huge effect that the writing is not synchronized.

    This is the rough program that I started.
    Code:
    '****************************************************************
    '*  Name    : FlowCTRL.Bas                                      *
    '*  Author  : Fulvio                                            *
    '*  Notice  : Copyright (c) 2019 Creative Commons Shared Alike  *
    '*          : All Rights Reserved                               *
    '*  Date    : 9/10/2019                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    $define WANTWDT 0                   ' Set if wanting the Watchdog
    $define PULSEPERLT  470             ' pulse per liter value
    
    Device = 16F628A
    Xtal 4
    On_Hardware_Interrupt GoTo Isr
    $if WANTWDT
    Declare Watchdog = On
    $endif
    
    $ifdef WANTWDT
    $undef WDT_OFF
    $define WDT_OFF WDT_ON
    $endif
    
     Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, BOREN_OFF, LVP_OFF, _
     CPD_OFF, CP_OFF
    
    Symbol SetBtn PORTB.0
    Symbol DIGIT0 = PORTB.1
    Symbol DIGIT1 = PORTB.2
    Symbol CTRL = PORTB.3
    Symbol IN0PIN 4                     ' input 0 pin definition
    Symbol IN1PIN 5                     ' input 1 pin definition
    Symbol IN0 PORTB.IN0PIN             ' encoder first input
    Symbol IN1 PORTB.IN1PIN             ' encoder second input
    Symbol MASK (1< 0 Then              ' as long as ticks is above zero
          Dec ticks                     ' decrease it
        Else
          ticks = 100                   ' or reset it to maximum
          Set zeroX
        End If
        If Setprsd = 1 Then             ' when a press on SET is valid
          If prevticks > 20 Then        ' count for a period
            Clear Setprsd               ' if long enough
            Set pressed                 ' set the flag
          Else
            Inc prevticks               ' else keep counting
          End If
        End If
        If Entprsd = 1 Then             ' when a press on SET is valid
          If Entticks > 20 Then        ' count for a period
            Clear Entprsd               ' if long enough
            Set EnterOK                 ' set the flag
          Else
            Inc Entticks               ' else keep counting
          End If
        End If
      End If
      If TMR1IF = 1 Then                ' if the pulse is counting
        Clear CTRL                      ' stop when reaching zero
      End If
      If INTF = 1 Then                  ' Enter was pressed
        INTF = 0
        If EnterBtn = 0 Then
          Entprsd = 1
          Clear Entticks
        End If
      End If
      If RBIF = 1 Then                  ' Verifying if the inputs are changed
        If SetBtn = 0 Then              ' checking input button
          Set Setprsd
          Clear prevticks
        End If
        newenc = PORTB & MASK
        If oldenc = newenc Then Gray_out
        @Btfss   newenc,IN1PIN          ' is the second bit causing Interrupt?
        GoTo    Gray_out                ' no, don't care
        @Btfsc   oldenc,IN1PIN          ' raising edge ?
        GoTo    Gray_out                ' no, don't care
        @Btfsc   newenc,IN0PIN          ' is the first bit set?
        GoTo    Gray_inc                ' yes, increment counter
    Gray_dec:
          If encpos <> 0 Then           ' test whether is not zero
            Dec encpos                  ' decrease the counter
            GoTo    Gray_out            ' and go out
          End If
    Gray_inc:
          If encpos < 10 Then
            Inc encpos                  ' increase the counter
          End If
    Gray_out:
        oldenc = newenc                 ' oldenc = newenc, for the next round
        Clear RBIF
      End If
      Context Restore
    
      Sub display_digit
     Clrwdt
      tempval = value / 10
      inpbuf[0] = tempval
      If dot1 = 1 Then
        inpbuf[0] = tempval + 15
      End If
      inpbuf[1] = value - tempval * 10
      If dot2 = 1 Then
        inpbuf[1] = tempval + 15
      End If
    EndSub
    
    Sub chckinp
      Clear pressed
      inpbuf[0] = 25
      inpbuf[1] = 25
      tempval = 1
      Do
        display_digit
        inpbuf[tempval] = encpos + 15
        If pressed = 1 Then
          Clear pressed
          Clear tempval
        End If
      Loop
    EndSub
    
    DigitMask: LData     $c0            ' 0                index 0
    LData                $f9            ' 1                index 1
    LData                $a4            ' 2                index 2
    LData                $b0            ' 3                index 3
    LData                $99            ' 4                index 4
    LData                $92            ' 5                index 5
    LData                $82            ' 6                index 6
    LData                $f8            ' 7                index 7
    LData                $80            ' 8                index 8
    LData                $90            ' 9                index 9
    LData                $ff            ' BLANK            index 10
    LData                $bf            ' DASH             index 11
    LData                $89            ' H                index 12
    LData                $ab            ' n                index 13
    LData                $af            ' r                index 14
    LData                $40            ' 0 dotted         index 15
    LData                $79            ' 1 dotted         index 16
    LData                $24            ' 2 dotted         index 17
    LData                $30            ' 3 dotted         index 18
    LData                $19            ' 4 dotted         index 19
    LData                $12            ' 5 dotted         index 20
    LData                $2,            ' 6 dotted         index 21
    LData                $78            ' 7 dotted         index 22
    LData                $0,            ' 8 dotted         index 23
    LData                $10            ' 9 dotted         index 24
    LData                $7f            ' BLANK dotted     index 25
    LData                $3f            ' DASH dotted      index 26
    LData                $9,            ' H dotted         index 27
    LData                $2b            ' n dotted         index 28
    LData                $2f            ' r dotted         index 29
    I never expected to save anything on EEPROM, I don't understand the compiler doing such attempt. Without context I can manage the thing properly.

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,332
    Thumbs Up
    Received: 40
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    I just tried to compile your code and got an error because the label Isr is missing (On_Hardware_Interrupt goto Isr
    Where is the interrupt routine?

    Charlie

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,309
    Thumbs Up
    Received: 28
    Given: 7
    Total Downloaded
    801.38 MB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    Hi,
    Even if I put in Isr it still does not compile, there are errors
    TICKS
    ZEROX
    SETPRDS
    PREVTICKS
    PRESSED
    ENTPRDS
    ENTEROK
    ENTTICKS all not declared.
    There is also an issue around where Symbol MASK is.

    Regards,
    Bob

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,341
    Thumbs Up
    Received: 289
    Given: 139
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    Context Save and Restore will not save or restore internal eeprom data itself, however, if any of the eeprom commands are used within the interrupt, it will save the relevant SFRs used for reading and writing eeprom.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    57
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    152.82 MB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    OK, I didn't suspect to had missing something. Therefore the files are available here. It can be noted on the assembly, that the context save will write to EEPROM

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,341
    Thumbs Up
    Received: 289
    Given: 139
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    The context Save and Restore are saving the SFRs used in reading flash memory.

    The interrupt handler is using the Lread command which reads flash memory and uses several SFRs to do so, therefore these need to be saved so that the main program code is not destroyed. For example, the program's Context Save Asm is:
    Code:
        movlw _High__Context_Store & 0XFF
        movwf FSR          ; Load FSR with the address of _High__Context_Store     
        bsf STATUS,5
        movf EEADR,W
        movwf INDF         ; Save EEADR
        incf FSR,F
        movf EECON1,W     
        movwf INDF         ; Save EECON1
        incf FSR,F 
        movf EECON2,W   
        movwf INDF         ; Save EECON2
        incf FSR,F
        movf EEDAT,W       ; Save EEDAT
        movwf INDF
        incf FSR,F
        bcf STATUS,5
        movf Pbs_Var0,W
        movwf INDF         ; Save compiler system variable Pbs_Var0
        incf FSR,F 
        movf Pbs_Var0H,W  
        movwf INDF         ; Save compiler system variable Pbs_Var0H
        incf FSR,F
        movf Pbs_Var1,W
        movwf INDF         ; Save compiler system variable Pbs_Var1
        incf FSR,F
        movf PP8,W
        movwf INDF         ; Save compiler system variable PP8
        incf FSR,F
        movf PP8H,W      
        movwfINDF        ; Save compiler system variable PP8H
    This is pointing the FSR register to the Save\Restore stack address. It then saves SFRs; EEADR, EECON1, EECON2 and EEDAT. These are all used to read flash memory in the Lread command. It then saves the compiler system variables used in the interrupt; Pbs_Var0, Pbs_Var0H, Pbs_Var1, PP8, and PP8H.

    The Restore does the opposite and loads the SFRs and variables with the data saved from them at the beginning, then exits the interrupt. The FSRSAVE, SSAVE and WSAVE variables are saved before the interrupt is called, so also need to be restored.

    Code:
        movlw _High__Context_Store & 0XFF
        movwf FSR           ; Load FSR with the address of _High__Context_Store 
        movf INDF,W 
        bsf STATUS,5
        movwf EEADR         ; Restore EEADR    
        incf FSR,F
        movf INDF,W
        movwf EECON1         ; Restore EECON1
        incf FSR,F
        movf INDF,W
        movwf  EECON2         ; Restore EECON2
        incf FSR,F
        movf INDF,W
        movwf EEDAT          ; Restore EEDAT
        incf FSR,F
        movf INDF,W
        bcf STATUS,5
        movwf Pbs_Var0       ; Restore compiler system variable Pbs_Var0
        incf FSR,F
        movf INDF,W
        movwf Pbs_Var0H      ; Restore compiler system variable Pbs_Var0H
        incf FSR,F
        movf INDF ,W
        movwf Pbs_Var1       ; Restore compiler system variable Pbs_Var1
        incf FSR,F
        movf INDF ,W
        movwf PP8            ; Restore compiler system variable PP8
        incf FSR,F
        movf INDF,W
        movwf PP8H           ; Restore compiler system variable PP8H
        movf FSRSAVE,W
        movwf  FSR            ; Restore FSR
        movf SSAVE,W
        movwf STATUS        ; Restore STATUS
        swapf WSAVE,F
        swapf WSAVE,W       ; Restore WREG
        retfie              ; Exit the interrupt
    Technically, the restore is going through the motions of writing because EEDAT is reloaded with its original contents, however the unlock sequence is not carried out so it does not write. But, I may change the order of these so EEDAT is saved/restored first.
    Last edited by top204; 15th September 2019 at 21:23.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    57
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    152.82 MB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    I understood what save and restore were doing. I didn't get the reason why these operations are necessary, until you clarified that it is involving many SFRs. The worry has come when trying to simulate the program. Uninterrupted warnings saying that writing to EEPROM don't wait the time to complete one cycle.
    As far as nothing is related outside the ISR, I skipped to use the save/restore function. Therefore to go back to a reasonable condition I might opt to set an array in RAM rather than fetching from flash memory and reinstate the save/restore function. After all the program doesn't consume many variables.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,341
    Thumbs Up
    Received: 289
    Given: 139
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    Actually looking at the code more thoroughly, the compiler is saving and restoring some SFRs that it does not need too with standard 14-bit core devies, so I'll make the changes in the compiler and create a new uploader.

    Standard 14-bit core devices use the Retlw mnemonic to store flash memory data, or the dt for tables. However, the compiler is looking for a 14-bit core device only, which includes the enhanced 14-bit core types as well, and these use the EECON SFRs for true flash memory reads. I'll change the Lread and Cread commands to examine if the device is an enhanced 14-bit core as well, because this is what most of teh other parts of the compiler does because microchip also screwed up on the newer devices, instrad of giving them a brand new architecture and getting rid of RAM and page banks altogether, they made it even more complex!

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,341
    Thumbs Up
    Received: 289
    Given: 139
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: Strange compile for a 16F628A

    I've always prided myself on being a man of my word, so download the version 3.7.2.6 of Proton and it does not save/restore the EECON SFRs with standard 14-bit core devices if Cread, Lread or Cread X are used within an interrupt handler.

    Thanks for inadvertently pointing out this slight anomaly.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Midi 16f628a
      By bvbart in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 3rd July 2010, 10:52
    2. interrupt on a 16F628A
      By starter in forum Proton Plus Compiler v3
      Replies: 8
      Last Post: 27th March 2009, 15:35
    3. 16f628a analouge in
      By emmertex in forum Proton Plus Compiler v3
      Replies: 3
      Last Post: 1st October 2005, 06:23
    4. 16F628 vs 16F628A
      By david in forum The Lounge
      Replies: 8
      Last Post: 27th September 2005, 08:22
    5. 16F628A 04/p
      By Lester in forum Wanted and For Sale
      Replies: 0
      Last Post: 15th April 2004, 15:27

    Members who have read this thread : 44

    Actions :  (Set Date)

    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