Datasheet
PICkit™ 3 Debug Express
DS41370C-page 60 © 2009 Microchip Technology Inc.
For more information on the data EEPROM memory see Section 7.0 of the
PIC18F45K20 Data Sheet (DS41303).
FIGURE 3-51: DATA EEPROM WRITE
3.10.3 Exploring the Lesson 10 Source Code
The Lesson 10 program writes all 256 bytes of the data EEPROM memory, writing each
location with value = 255 – address. For example, the EEPROM byte at address 0x09
is written with value 0xF6 = 246.
Once all locations have been written, the program ends in an infinite while(1) loop.
3.10.4 Build and Run the Lesson 10 Code with PICkit 3 Debug Express
Build and program the Lesson 10 project, then Run the application in the debugger.
The EEPROM memory may be viewed in the MPLAB IDE by selecting view >
EEPROM.
As the EEPROM memory window does not update with changed EEPROM byte values
during debugging, it is necessary to select Debugger > Read
to see the current
contents of the data EEPROM memory. However, doing so will cause a program Reset.
void EEPROM_Write(unsigned char address, unsigned char databyte)
{ // writes the "databyte" value to EEPROM at the address given
// location in "address".
EECON1bits.EEPGD = 0; // Set to access EEPROM memory
EECON1bits.CFGS = 0; // Do not access Config registers
EEDATA = databyte; // Load EEDATA with byte to be written
EEADR = address; // Load EEADR with address of location to write.
EECON1bits.WREN = 1; // Enable writing
INTCONbits.GIE = 0; // Disable interrupts
EECON2 = 0x55; // Begin Write sequence
EECON2 = 0xAA;
EECON1bits.WR = 1; // Set WR bit to begin EEPROM write
INTCONbits.GIE = 1; // re-enable interrupts
while (EECON1bits.WR == 1)
{ // wait for write to complete.
};
EECON1bits.WREN = 0;
}
// Disable writing as a precaution.
Note: The EEPROM window in the MPLAB IDE does not update with new
EEPROM values during debugging.