Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC EEPROM memory in hi-tech compiler

Status
Not open for further replies.

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,601
hi everybody.
i want to save a variable larger than one byte (int or lon int)
but it has code just for one byte. can anyone give any idea about this.
using a variable in eeprom is not useful for me.
thanks for your answers.
 

look at this page
**broken link removed**
 

Hi
I have done it before for only 2 byte variable (like integer)

here is the code
Code:
//-*************************************
//-************** EERead ***************
unsigned char EERead(unsigned char Addr)
{
	RP1=1;
	RP0=0;
	EEADR=Addr;
	RP0=1;
	EEPGD=0;
	RD=1;
	while(RD==1);
	RP0=0;
	return EEDATA;
}

unsigned int EERead_Db(unsigned char Addr)
{
    unsigned char RdByteLo,RdByteHi;
	unsigned int rddbtmp;
	RdByteHi = EERead(Addr);
	RdByteLo = EERead(Addr+1);
	rddbtmp = RdByteHi;
	rddbtmp = rddbtmp << 8;
	rddbtmp += RdByteLo;
	return(rddbtmp);
}

//-*************************************
//-************** EEWrite ***************
void EEWrite(unsigned char Data,unsigned char Addr)
{
	GIE=0;
	EEADR=Addr;
	EEDATA=Data;
	WREN=1;
	EECON2=0x55;
	EECON2=0xAA;
	WR=1;
	while(WR==1);
	EEIF=0;
	GIE=1;
}

void EEWrite_Db(unsigned int Data,unsigned char Addr)
{
    unsigned char WrByteLo,WrByteHi;
 	WrByteLo = Data;
 	WrByteHi = Data >> 8;
	EEWrite (WrByteHi,Addr);
	EEWrite (WrByteLo,Addr+1);
}

Don't gorget the helped me button :)

Added after 49 minutes:

Hi
You will need to call function named "EEWrite_Db" to write an integer to the EE. High order byte is saved in the address passed to the fn while low order byte is saved in the succeeding address.

For read purposes, you will just pass the address to the fn "EERead_Db" and you will get the data arranged as above.

P.S. : Db stands for Double Bytes.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top