How do I get the internal EEPROM to store CORRECTLY into ALL loactions when using 18F series PICs?


A lot of debate on does it work, or doesn't it work? on this topic.

Yes, it DOES work. You need...

1. PBP Version 2.45 or later.
2. MPASM version v03.70 or later (part of MPLAB v6.50).

Typical Command Line to execute your compilation...

PBPW -p18F252 Myfile -ampasmwin

Nothing special in your program... use DATA, READ and WRITE commands just as you do for all your other 12 and 16 series PICs. If you don't believe me, here's a test program for you to run...

Code:
	'	Program ETEST.BAS
	'	=================
	'	Writes incrementing values to internal EEPROM
	'	until Doomsday (or until EEPROM wears out!)

	'
	'	Hardware Defines
	'	================
		'
		' 	LCD Display
		'	-----------
	Define LCD_DREG PORTC	' Port for LCD Data
	Define LCD_DBIT 4	' Use upper 4 bits of Port
	Define LCD_RSREG PORTC	' Port for RegisterSelect (RS) bit
	Define LCD_RSBIT 3	' Port Pin for RS bit
	Define LCD_EREG PORTC	' Port for Enable (E) bit
	Define LCD_EBIT 0	' Port Pin for E bit
	Define LCB_BITS 4	' Using 4-bit bus
	Define LCD_LINES 2	' Using 2 line Display
	Define LCD_COMMANDUS 2000
				' Command Delay (uS)
	Define LCD_DATAUS 50	' Data Delay (uS)

	'
	'	EEPROM Presets
	'	==============
	Data @0,0,1,2,3,4,5,6,7,8,9
	Data 10,11,12,13,14,15,16,17,18,19
	Data 20,21,22,23,24,25,26,27,28,29
	Data 30,31,32,33,34,35,36,37,38,39
	Data 40,41,42,43,44,45,46,47,48,49
	Data 50,51,52,53,54,55,56,57,58,59
	Data 60,61,62,63,64,65,66,67,68,69
	Data 70,71,72,73,74,75,76,77,78,79
	Data 80,81,82,83,84,85,86,87,88,89
	Data 90,91,92,93,94,95,96,97,98,99
	'
	Data 100,101,102,103,104,105,106,107,108,109
	Data 110,111,112,113,114,115,116,117,118,119
	Data 120,121,122,123,124,125,126,127,128,129
	Data 130,131,132,133,134,135,136,137,138,139
	Data 140,141,142,143,144,145,146,147,148,149
	Data 150,151,152,153,154,155,156,157,158,159
	Data 160,161,162,163,164,165,166,167,168,169
	Data 170,171,172,173,174,175,176,177,178,179
	Data 180,181,182,183,184,185,186,187,188,189
	Data 190,191,192,193,194,195,196,197,198,199
	'
	Data 200,201,202,203,204,205,206,207,208,209
	Data 210,211,212,213,214,215,216,217,218,219
	Data 220,221,222,223,224,225,226,227,228,229
	Data 230,231,232,233,234,235,236,237,238,239
	Data 240,241,242,243,244,245,246,247,248,249
	Data 250,251,252,253,254,255


	'
	'	Software Variables
	'	------------------
	CounterA var BYTE	' Address Pointer
	CounterL var WORD	' Loop Counter
	DataA var BYTE		' Read Data from/to EEPROM
	DataB var BYTE		' Expected Data from EEPROM
	DataOffset var BYTE

	'
	'	Program Constants
	'	-----------------
	MaxEEPROM con 255	' Top address limit of EEPROM

	'
	'	Initialise Program 
	'	------------------
	TRISC=%00000000
	CounterL=0
	Pause 1000
	'
	'	Load Offset
	'	-----------
Loop:
	Read 0,DataOffset
	'
	'	Read and Verify EEPROM Bank (256 Bytes)
	'	---------------------------------------
	LCDOut $FE,1,"Reading=",#CounterL
	Pause 500		' Need this to see above message
	For CounterA=0 to MaxEEPROM
		Read CounterA,DataA
		DataB=CounterA+DataOffset
		If DataA<>DataB then 
			LCDOut $FE,1,"Error Loop=",#CounterL,$FE,$C0
				'
				' Displays EEPROM Address, Expected Data, Read Data
				'
			LCDOut "$",HEX2 CounterA," E=$",HEX2 DataB," R=$",HEX2 DataA
			Pause 1000
			endif
		Next CounterA
	'
	'	Increment DataOffset and write-Out EEPROM
	'	-----------------------------------------
	CounterL=CounterL+1
	LCDOut $FE,1,"Writing=",#CounterL
	DataOffset=DataOffset+1
	For CounterA=0 to MaxEEPROM
		DataA=CounterA+DataOffset
		Write CounterA,DataA
		Next CounterA
	Goto Loop		' Do it forever

	End
If it doesn't work for you, check the versions of PBP and MPASM you're running... MPASM is FREE (a component part of MPLAB), so download and install the latest version regularly from the Microchip website.

Just a brief note on the operation of the above test program. If you Power-OFF your PIC whilst running this program during the WRITE cycle where it's filling the EEPROM with new values, the EEPROM contents will of course be corrupted. When you next Power-On, some values will be correct, and some will not be correct (the errors which will display accordingly on the LCD). Allow the program to complete it's READ cycle, it will then write-out a fresh EEPROM page which should then be read without error.

Melanie