; ***********************************************************************
; EE_WRITE_BYTE - Routine to write a byte to ee ram 
; Adress in W, byte MUST be in EE_Byte

EE_WRITE_BYTE
        BANK2                   ; select bank2
        MOVWF   EEADR           ; setup adress
        BANK0                   ; 
        MOVF    EE_Byte,W       ; get byte
        BANK2
        MOVWF   EEDATA          ; setup byte to write
        BSF     STATUS,RP0      ; bank3 !!
        BCF     EECON1,EEPGD    ; set to data ee ram
        BSF     EECON1,WREN     ; enable writes
        DISABLE_IRQ             ; disable irq's
        
        MOVLW   H'55'           ; required sequence !!
        MOVWF   EECON2
        MOVLW   H'AA'
        MOVWF   EECON2
        BSF     EECON1,WR       ; begin write procedure
        
        ENABLE_IRQ              ; enable irq's again
        
        BCF     EECON1,WREN     ; disable writes ( does not affect current write cycle )
        
        BANK0                   ; reset to bank0
        ; wait for the write to complete before we return
        BTFSS  PIR2,EEIF        ; wait for interrupt flag to be set
        GOTO   $-1               
        ; clear interupt bit and write enable bit
        BCF    PIR2,EEIF        ;clear eewrite irq flag

        RETURN

; ***********************************************************************
; EE_READ_BYTE - Routine to read a byte from ee ram 
; Adress in W, byte will be delivered in W
EE_READ_BYTE
        BANK2
        MOVWF   EEADR           ; put in adress reg.
        BSF     STATUS,RP0      ; bank3 !!
        BCF     EECON1,EEPGD    ; set to read data memory
        BSF     EECON1,RD       ; set bit to read
        BCF     STATUS,RP0      ; bank2 !!
        MOVF    EEDATA,W        ; move data to W
        BANK0                   ; Reset to BANK0 !
        RETURN                  ; and return

