cblock 0x70
ADDR
VALUE
endc
writeEEPROM macro reg, address
BSF STATUS, RP1 ;
BSF STATUS, RP0 ;Bank 3
BTFSC EECON1, WR ;Wait for
GOTO $-1 ;write to finish
BCF STATUS, RP0 ;Bank 2
banksel address
MOVF address, W
MOVWF EEADR
banksel reg
MOVF reg, W
MOVWF EEDATA
BSF STATUS, RP0 ;Bank 3
BCF EECON1, EEPGD ;Point to Data memory
BSF EECON1, WREN ;Enable writes
;Only disable interrupts
BCF INTCON, GIE ;if already enabled,
;otherwise discard
MOVLW 0x55 ;Write 55h to
MOVWF EECON2 ;EECON2
MOVLW 0xAA ;Write AAh to
MOVWF EECON2 ;EECON2
BSF EECON1, WR ;Start write operation
;Only enable interrupts
BSF INTCON, GIE ;if using interrupts,
;otherwise discard
BCF EECON1, WREN ;Disable writes bank0
BCF STATUS, RP1 ;
BCF STATUS, RP0 ;Bank 0
endm
readEEPROM macro address
BSF STATUS, RP1 ;
BCF STATUS, RP0 ;Bank 2
banksel address
MOVF address, W ;Write address bank2
MOVWF EEADR ;to read from
BSF STATUS, RP0 ;Bank 3
BCF EECON1, EEPGD ;Point to Data memory
BSF EECON1, RD ;Start read operation
BCF STATUS, RP0 ;Bank 2
MOVF EEDATA, W ;W = EEDATA
BCF STATUS, RP1
BCF STATUS, RP0
endm
setID
movlw B'00000100'
movwf counter
movlw 0x19
movwf ADDR
repeatID
call keyRelease
call keySelect ;takes in a letter
movwf VALUE
call KPHexToChar ;converts to character
call WrtLCD ;display on LCD
writeEEPROM VALUE, ADDR ;store the character in EEPROM
readEEPROM ADDR
call KPHexToChar
call WrtLCD
incf ADDR, F
decfsz counter, F
goto repeatID
endSetID
movlw 0x19
movwf ADDR
readEEPROM ADDR
call KPHexToChar
call WrtLCD
return