Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

write and read from eeprom using c (mplab ide)

Status
Not open for further replies.
Use this routine

Code:
unsigned char ReadEeprom(unsigned int badd )
	{
	EEADR = (badd & 0x0ff);
  	CFGS = 0;
	EEPGD = 0;
	RD = 1;
	return ( EEDATA );              // return with read byte
	}

void WriteEeprom( unsigned int badd,unsigned char bdata )
	{
	EEADR = (badd & 0x0ff);
  	EEDATA = bdata;
  	EEPGD = 0;
	CFGS = 0;
	WREN = 1;
	GIE = 0;  // if used remember re-enable, interrupts cannot be on
	0x55;
	0xAA;
	WR = 1;
	while(WR);
	//GIE = 1;  // if used remember re-enable
	WREN = 0;
	}

This writes / reads into internal eeprom
 
Last edited:
Code:
{	
		delay(10000);

		while(location_enter==0)			//loop until location_enter flag is set
		{
		lcd_goto(0);						//set the lcd cursor to location 0		
		send_string("Choose User     ");	//display string
		lcd_goto(20);						//set the lcd cursor to location 20
		send_string("User ");				//display string
		lcd_goto(25);						//set the lcd cursor to location 25
		send_char(0x30 + location);			//display character (numerical digit which started from 0x30 or zero)
		if(!But1)							//if SW1 is pressed
			{	
				while(!But1);				//waiting for release
				if (location<5)				//if location is not reaching 5
				location++;					//increment by 1
				else
				location=1;					//reset back to 1
			}
		else if(!But2)						//if SW2 is pressed
		{		
			while(!But2);					//wait for release
			if (location>1)					//if location is not reaching 1
			location--;						//decrement by 1
			else
			location=5;						//reset back to 5			
		}
		else if(!But3)						//if SW3/Confirm is pressed
			{
				while(!But3);
				mem = 0x10 + location;				//waiting for release
				store_eeprom(mem,location); [B]//<<<<--------- this one,[/B]
				AddNew(location);			//function call for add new fingerprint into database at desired location
			}
		}
	}

Code:
void view_user(void)
{
	lcd_clr();						//clear lcd
	lcd_goto(0);     				//set the lcd cursor to location 0
	mem = 0x10;
	send_string("User 1 2 3 4 5 ");	//display string
	lcd_goto(24);					//set the lcd cursor to location 20
	unsigned char x;
	mem = 0x10;  [B]//<<<<----- memory location[/B]
	for(x=1; x<6; x++)		//loop 5 times for 5 days
	{	send_char(0x20);	//display " "
		mem = mem ++;
		TEMP=get_eeprom(mem);	//retrieve marking[B] <<<---- will read the eeprom[/B]
		send_char(TEMP);	//display marking
	}
	delay(500000);
	lcd_clr();			
}


Code:
//store data into specified location in EEPROM
void store_eeprom(unsigned char location,unsigned char data)
{
	EEPROM_WRITE(location,data);		//write data 
	while(WR)							//wait until it finish
	continue;
}

//access EEPROM to retrieve data
unsigned char get_eeprom(unsigned char mem)
{
	unsigned char value;
	value= EEPROM_READ(mem);		//read eeprom and assign the data to variable 
	return value;						//return data
}


can u check it... i`m not really know about c :eek:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top