Loading...

Writing To EEPROM Memory

Writing to EEPROM Memory

In order to write data to EEPROM location, programmer must first write address to EEADR register and data to EEDATA register. Only then is it useful to set WR bit which sets the whole action in motion. WR bit will be reset, and EEIF bit set following a writing what may be used in processinginterrupts. Values 55h and AAh are the first and the second key whose disallow for accidental writing to EEPROM to oecur. These two values are written to EECON2 which serves only that purpose, to receive these two values and thus prevent any accidental writing to EEPROM memory. Program lines marked as 1, 2, 3, and 4 must be executed in that order in even time intervals. Therefore, it is very important to turn off interrupts which could change the timing needed for executing instructions. After writing, interrupts can be enabled again .Example of the part of a program which writes data OxEE to first location in EEPROM memory could look something like the fallawing:


bcf STATUS, RP0 ;bank0, because EEADR is at 09h
movlw 0x00   ;address of location being written to.
movwf EEADR   ;address being transferred to EEADR
       
movlw 0xEE   ;WRİTE THE vALUE 0xEE
movwf EEDATA   ;data goes to EEDATA Register
bsf STATUS, RP0 ,BANK1 because EEADR is at 09h
bsf INTCON, GIE ;all interrupts are disabled
bcf EECON1, WREN ;writing Enabled
movlw 55h    
       
movwf EECON2   ;first key 55h -->EECON2
movlw AAh    
movwf EECON2   ;second key AAh --> EECON2
bsf EECON1, WR ;initializes wirting
bsf INTCON, GIE ;interrupts are enabled

it is recommended that WREN be turned off the whole time except when writing data to
EEPROM, so that possibility of accidental writing would be minimal. All writing to EEPROM will automatically clear a location prior to writing a new.


Keywords : Pic, Assembler, Assembly, Writing, Reading, From, EEPROM, Memory
Writer : delon  |
3 Mar 2006 Fri   
|  6.395 Views
No Comments