This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing to eeprom

Hi all,
Hope someone can explain what I am doing wrong. I have the following problem.
I am using a AT89C51ED2 micro and running PK51 8.01.
I want to write a variable to and read a variable from eeprom.
I have done a search on the Keil web site and have gained some
advance, but, I can read data from eeprom (V:0x00 - V:????).
When I write to eeprom I see it going into xdata and not the eeprom (v-data).
Is this correct?

Also the EEBUSY flag is never set (EECON bit '0')

Maybe (hopefully) I'm doing something wrong somewhere and someone will spot it.

Below I include my test program.

#include <at89c51xd2.h>
#include <absacc.h>


void WriteEEPROM (unsigned int adr, unsigned char val) small
	{
	  EA = 0;
	  EECON = 0x02;        						// enable EEPROM and set write bit
	  XBYTE[adr] = val;
	  while(EECON & 0x01)						// wait untill programmed
	  	{
		}
	  EECON = 0x00;        						//  disable EEPROM
	  EA = 1;
	}

unsigned char Read_EEPROM (unsigned char adr) small
	{
	unsigned char v;

	EA = 0;
	EECON = 0x02;    						//  enable EEPROM
	v = XBYTE[adr];
	EECON = 0x00;    						//  disable EEPROM
	EA = 1;
	return (v);
	}



unsigned char v;
unsigned char f;

void main (void)
	{
	while (1)
		{
		v = Read_EEPROM(0x00);
		f = v*2;
	  	WriteEEPROM (0x10, f);         // write 9 to EEPROM address 0x001
		}
	}

I am only using Dscope, so I can't comment on it working or not working on a live system.
Thanks in advance for any responses

Kind regards
John Garrelts

0