; ***************************************************************************
; Read EEPROM Address 0x00 and copy to counter variable
; ***************************************************************************
ReadEE
movlw 0x00 ; Address in EEPROM
movwf EEADR ; Data Memory Address to read
bcf EECON1, EEPGD ; Point to DATA memory
bcf EECON1, CFGS ; Access EEPROM
bsf EECON1, RD ; EEPROM Read
movff EEDATA, counter ; EEDATA --> Counter
retlw 0x00
; ***************************************************************************
; Write value of variable counter into EEPROM address 0x00
***************************************************************************
WriteEE
movlw 0x00 ; Address
movwf EEADR ; Data Memory Address to write
movf counter,W;
movwf EEDATA ; Data Memory Value to write
bcf EECON1, EEPGD ; Point to DATA memory
bcf EECON1, CFGS ; Access EEPROM
bsf EECON1, WREN ; Enable writes
bcf INTCON, GIE ; Disable Interrupts
movlw 55h ;
movwf EECON2 ; Write 55h
movlw 0AAh
movwf EECON2 ; Write 0AAh
bsf EECON1, WR ; Set WR bit to begin write
bsf INTCON, GIE ; Enable Interrupts
Eeloop btfss PIR2,EEIF ; Is int bit on ie WRTDONE
bra Eeloop ; continue
bcf PIR2,EEIF ; reset interupt
bcf EECON1, WREN ; Disable writes on write complete (EEIF set)