View Single Post
  #4   Spotlight this post!  
Unread 16-12-2003, 02:22
IrisLab's Avatar
IrisLab IrisLab is offline
Mentor
AKA: Dave Page
#1466 (Webb School)
Team Role: Mentor
 
Join Date: Dec 2003
Location: Knoxville, Tennessee
Posts: 33
IrisLab will become famous soon enough
Re: read/write EEPROM on 18F8520

Couple of questions...

1. Can you explain addrH, addrL, and data a little more? For readEE, are these the locations of the high and low byte in the EEPROM where you want to write? What are typical values for these addresses, if so? For writeEE same thing?

2. I read in another thread that you (or someone) is developing a copyCat (?) where you'd record user input into the EEPROM. How big (bytes) is the EEPROM? Do you have sample code for the CopyCat?

I'm new to the forum...so I hope I'm asking the right questions in the right place.

Thanks!


Quote:
Originally Posted by Random Dude
[Edit] As to why they claim you only have 255 bytes? I don't know. There appears to be nothing in there at all. And I can write to bytes >0xFF so not really sure
[/edit]

This should suit you needs:

Code:
unsigned char readEE(unsigned char addrH,unsigned char addrL)  {
  	EEADRH = addrH;
 	EEADR =addrL;

    	  
  	EECON1bits.EEPGD =0;
  	EECON1bits.CFGS =0;
  	EECON1bits.RD =1;


    	return EEDATA;
}

void writeEE(unsigned char addrH,unsigned char addrL,unsigned char data)
{
  	EEADRH = addrH;
  	EEADR =addrL;
  	EEDATA = data;

  	  	//following as per spec. sheet
  	EECON1bits.EEPGD =0;
  	EECON1bits.CFGS =0;
  	EECON1bits.WREN =1; 
 	INTCONbits.GIE = 0;
  	EECON2 = 0x55;
  	EECON2 = 0xAA; 
 	EECON1bits.WR = 1;
  	INTCONbits.GIE = 1;
  	EECON1bits.WREN = 0;
}