#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x70
DATA_EE_ADDR
DATA_EE_DATA
dly0
dly1
EE_ADR
W_DATA
R_DATA
endc
org 0
nop
; intialise output ports
banksel ANSEL
movlw 0x00
movwf ANSEL
banksel ANSELH
movlw 0x00
movwf ANSELH
banksel TRISC
movlw 0xF0
movwf TRISC
movlw 0xF0
movwf DATA_EE_DATA
movlw 0x00
movwf DATA_EE_ADDR
; To WRITE into EEPROM
banksel EE_ADR
movlw 0x00 ; EE_ADDR
movwf EE_ADR ; move 0x00 into EE_ADR
movlw 0x12 ; Writes Hous data into EEPROM
movwf W_DATA ; Data to be written
call EE_WR ; Write routine for EE_Addr
; To READ from EEPROM
movlw 0x00 ; EE_ADDR
movwf EE_ADR ; move 0x00 into EE_ADR
call EE_RD ; Read EEPROM Addr 0
movwf R_DATA ; Write into Hyst High register
; -------------------------------------------------------------------------------------------------
;EE_WR EEPROM DATA WRITE SEQUENCE
; -------------------------------------------------------------------------------------------------
EE_WR
banksel EECON1 ; Select Bank of EECON1
btfsc EECON1,WR ; Wait for write
goto $-1 ; to complete
banksel EE_ADR ;
movf EE_ADR,W ;
banksel EEADR ; (0x10C) Select Bank of EEADR
movwf EEADR ; Data Memory Address to write
banksel W_DATA ;
movf W_DATA,W ; Register containing data to be stored
banksel EEDATA ; (0x10D)
movwf EEDATA ; Data Memory Value to write
bsf STATUS,RP0 ;
bcf EECON1,EEPGD ; Point to DATA memory
bsf EECON1,WREN ; Enable writes
bcf INTCON,GIE ; Disable INTs.
movlw H'55' ;
movwf EECON2 ; (0x18C) Write 55h
movlw H'AA' ;
movwf EECON2 ; (0x18C) Write AAh
bsf EECON1,WR ; Set WR bit to begin write
bsf INTCON,GIE ; Enable INTs.
bcf EECON1,WREN ; Disable writes
banksel PIR2 ;
btfss PIR2,EEIF ; Wait for interrupt flag to be set
goto $-1 ; Current line -1
bcf PIR2,EEIF ; Clear the EEWRITE interrupt flag
return ; return to caller
; -------------------------------------------------------------------------------------------------
; EE_RD EEPROM DATA READ SEQUENCE ;
; -------------------------------------------------------------------------------------------------
EE_RD ;
movf EE_ADR,W ;
banksel EEADR ;
movwf EEADR ; Data Memory Address to read
banksel EECON1 ;
bcf EECON1,EEPGD ; Point to Data memory
bsf EECON1,RD ; EE Read
banksel EEDATA ;
movf EEDATA,W ; W = EEDATA
banksel R_DATA ;
movwf R_DATA ; Move W into EE_BYTE
incf EE_ADR,f ; increment EE_Addr with 1
return ; Value now in W, to be used
; -------------------------------------------------------------------------------------------------
; WRITE routine to write data ;
; into EEPROM memory Hours ;
; -------------------------------------------------------------------------------------------------
WriteEE: ;
movwf W_DATA ; Writes Hous data into EEPROM
call EE_WR ; Write routine for EE_Addr
incf EE_ADR,f ; increment EE_Addr with 1
return ; return to caller
end