• PicŪ Basic


  • Ewrite with interrupt

    Normally the interruption bit must be disabled before writing to the EEPROM. However this method can reduce the time that the GIE is disabled. I modified the Ewrite original code for disabling the interrupts while a data is being writing to the eeprom memory like the Microchip method. This disabling time becomes really shorter.
    This code is for PIC18 only.
    Code:
    '****************************************************************
    '*  Name    : EwriteNew.inc                                     *
    '*  Author  : [Alberto Freixanet]                               *
    '*  Notice  : Copyright (c) 2015 [AFreixanet]                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 04/09/2015                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : New Ewrite command with interrupts included       *
    '*          : Takes care of Watchdog too                        *
    '*          : For PIC18 only!                                   *
    '****************************************************************
    
    '-------------------------------------------------------------------------------
    
    #ifdef EWRITE#REQ
    
        #Disable EWrite                 ' Bypass the compiler's EWRITE library subroutine
    
        GoTo OverEwrite                 ' Go to over this routine      
    
    $if _core <> 16
        $error "Ewrite modified command is for 18F devices only!"
    $endif
    
    $if _eeprom = 0
        $error "This PIC have not eeprom memory!"
    $endif
    
    Asm
    $if _eeprom > 256
    __EEWRITE_
        Clrf EEADRH,0
    __EEWRITE_W_
        Movwf EEDATA,0
    $else
    __EEWRITE_
    __EEWRITE_W_
        Movwf EEDATA,0
    $endif
    EndAsm
    
        EECON1 = 0                      ' Acces to eeprom memory
        '===========================================================================
        EECON1bits_WREN = 1             ' E2p write sequence start.
    
        #ifdef __INTERRUPTS_ENABLED
        PRODH = INTCON 
        INTCONbits_GIE = 0              ' Clear the GIE bit
        PIE2Bits_EEIE = 0               ' Clear enable eeprom interrupt (not used)
        #endif
    
        EECON2 = $55
        EECON2 = $AA
        EECON1bits_WR = 1
    
        ' Restore interrupt flag (if it was enabled)
        #ifdef __INTERRUPTS_ENABLED
        If PRODH.7 = 1 Then
            INTCONbits_GIE = 1          ' Reenable GIE
        EndIf
        #endif
    
        #ifdef WatchDog_Req
        Clrwdt
        #endif
    
        ' Wait for write to complete
        While EECON1bits_WR = 1 : Wend
        EECON1bits_WREN = 0             ' E2p write sequence end.
        '===========================================================================
    Asm
    $if _eeprom > 256
        Infsnz EEADR,F,0
        Incf EEADRH,F,0
    $else
        Incf EEADR,F,0
    $endif
    EndAsm
        Return
    OverEwrite:
    #endif  
    '-------------------------------------------------------------------------------
    2015/11/06 This feature is included in the new version 3574 of the PDS.
    Thank's Les.
    Alberto
    New_EWRITE.zip
  • Recent Activity

    xldaedalus-432

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    xldaedalus Yesterday, 23:49 Go to last post
    tumbleweed-20435

    Watchdog timer

    Thread Starter: joesaliba

    I have a code that basically looks for four input and four outputs, depends on various timing and input conditions. I use interrupt and some delays...

    tumbleweed Yesterday, 19:54 Go to last post