90 likes | 219 Views
ECT 357. Ch 20 EEPROM. Today’s Quote: Conscience is God’s built-in warning system. Be very happy when it hurts you. Be very worried when it doesn’t. And herein do I exercise myself, to have always a conscience void to offense toward God, and toward men. Acts 24:16. EEPROM.
E N D
ECT 357 Ch 20 EEPROM
Today’s Quote: Conscience is God’s built-in warning system. Be very happy when it hurts you. Be very worried when it doesn’t. And herein do I exercise myself, to have always a conscience void to offense toward God, and toward men. Acts 24:16
EEPROM The 256 byte Data EEPROM is readable and writable during normal operation over the entire VDD range. The data memory is not directly mapped in the register file space. Instead, it is indirectly addressed through the Special Function Registers (SFR).
EEPROM Registers EECON1: used for EEPROM control and status EECON2: not a physical register, used for unlock mechanism to previous inadvertent writes EEDATA: Data of EEPROM being written to or read from EEPROM address EEADR: Address of EEPROM reading from or writing to PIR2: EEIF flag signals write completion
EEPROM Initialization 1. Clear EECON1 in the Initial Subroutine.
EEPROM Write Sequence MOVLF 0x00,EEADR ;load address movff ADRESH,EEDATA ;load data bsf EECON1,WREN ;enable writes bcf INTCON,GIEH ;disable interrupts MOVLF 0x55,EECON2 ;unlock code 1 MOVLF 0xaa,EECON2 ;unlock code 2 bsf EECON1,WR ;write to EEPROM bsf INTCON,GIEH ;re-enable interrupts Wait: btfss PIR2,EEIF ;wait for write to finish bra Wait ;takes 4 ms bcf PIR2,EEIF ;clear EEPROM flag bcf EECON1,WREN ;disable writes
EEPROM Read Sequence MOVLF 0x00,EEADR ;load address bsf EECON1,RD movf EEDATA,W ;copy data to WREG
EEPROM Interrupts The EEPROM mechanism has the ability to generate interrupts upon completion of an EEPROM write. The registers associated with this are: IPR2, EEIP PIR2, EEIF PIE2, EEIE