• 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

    towlerg-21522

    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...

    towlerg Today, 15:45 Go to last post
    towlerg-21522

    PIC18F1330 PLL problem

    Thread Starter: rcurl

    I'm just starting out on a new project that uses a PIC18F1330. I haven't used this specific chip before, so I began by trying to blink an LED just...

    towlerg Today, 19:19 Go to last post
    towlerg-21522

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    towlerg Today, 15:59 Go to last post