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.

Accessing the E2prom on the Atmel 89S8252 from C language

Status
Not open for further replies.

bobcat1

Advanced Member level 4
Advanced Member level 4
Joined
Jul 10, 2002
Messages
1,284
Helped
99
Reputation
198
Reaction score
34
Trophy points
1,328
Activity points
8,546
Accessing the E2prom on the Atmel 89S8252 from C language
This sample written on k*eil C compiler


p.s download only one file the 2nd was up loadded by mistek

enjoy


bobi
 

Other functions:

/****************************************************************************/
/* EEpromWrite(address, value) */
/****************************************************************************/
unsigned char EEpromWrite(unsigned int address, unsigned int value)
{
unsigned char err, LSB, MSB;
unsigned int b_addr;

b_addr = address * 2;

err = FALSE;

if (address > 0x03FF) err = TRUE; /* address out of range */
else
{
TR0 = 0; /* TR0: stop Counter T0 */
EA = 0; /* Disable All Interrups */

WMCON |= EEMEN; /* enable EEPROM accesses */
WMCON |= EEMWE; /* enable EEPROM writes */

LSB = value % 256; /* Calculate LSB byte */
XBYTE[b_addr] = LSB; /* Write LSB byte */
while (!(WMCON & WDTRST)); /* Wait for end of write EEPROM */

MSB = value / 256; /* Calculate MSB byte */
XBYTE[b_addr + 1] = MSB; /* Write MSB byte */
while (!(WMCON & WDTRST)); /* Wait for end of write EEPROM */

if (LSB != XBYTE[b_addr]) err = TRUE; /* Compare data */
if (MSB != XBYTE[b_addr + 1]) err = TRUE; /* Compare data */

WMCON ^= EEMWE; /* disable EEPROM writes */
WMCON ^= EEMEN; /* disable EEPROM accesses */

END_SAMP = 0; /* Seted after Nsamples reading */
sample_count = 0; /* Clear samples counter */

EA = 1; /* Enable All Interrups */
TR0 = 1; /* TR0: Run Counter T0 */
}

return(err);
}

/****************************************************************************/
/*EEpromRead(address) - Read 2 bytes from Internaal EEPROM */
/*Input: unsigned int address - addres of first byte to read */
/*Output: unsigned int value - value = MSB*256+LSB; */
/****************************************************************************/
unsigned int EEpromRead(unsigned int address)
{
unsigned int b_addr, value;

b_addr = address * 2;

EA = 0x00; /* Disable All Interrups */

WMCON |= EEMEN; /* enable EEPROM accesses */

value = XBYTE[b_addr + 1];
value *= 256;
value += XBYTE[b_addr];

WMCON ^= EEMEN; /* disable EEPROM accesses */

EA = 0x01; /* Enable All Interrups */

return value;
}
 

These uploads are useful, thanks guys.

Eskimo, I am new to C, but should'nt EEpromWrite be an unsigned int if you are writing 16 bits?.

Also is it a requirement to stop counter 0. What if an RTOS is using this?.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top