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.

how to write into EEPROM of AT89s8252 in C language

Status
Not open for further replies.

dnarenderreddy

Junior Member level 2
Joined
Jan 2, 2006
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,742
how to write data into eeprom

hello every body , this is narender

i am struggling to write into the internal EEPROM of AT89s8252. i need to write a floating point type number into EEPROM. how do u do this. iam using C language and Keil u vison to write the program.

can anyone help me out with this pleasee.


thanks in advance
narender
 

how to write into eeprom

Hi

Is it a serial EEProm ? Then

1. Write a driver for that
2. Write a simple interface function to pass a pointer to your float variable.

Thx+
 

how to write narender in arabic

Hi,
Folow is code write/read data from eeprom (89S8252):
// Keil ver 7.00 Complier
#include <AT898252.H>
void Read_eeprom_in(unsigned int num)
{
char* data_onchip=(char *)&BDisplay7seg; //Pointer to Save Data
int i,j,k;
k=(num/64)+1;
for(j=0;j<k;j++)
{
WMCON|=0x08; //Enable on-chip eeprom
for(i=0;i<64;i++)
eeprom_buffer=data_onchip[64*j+i];
WMCON&=0xf7; //Disable on-chip eeprom
data_onchip=(char*)&BDisplay7seg;
for(i=0;i<64;i++)
data_onchip[64*j+i]=eeprom_buffer;
}
}

void Write_eeprom_in(unsigned int num)
{
char* data_onchip=(char *)&BDisplay7seg; //Pointer to Save Data
unsigned int i,j,k;
char ch;
k=(num/64)+1;
for (i=0;i<NUM_SERIAL;i++)
data_onchip=Buffer_comm;

for(j=0;j<k;j++)
{
for(i=0;i<64;i++)
eeprom_buffer=data_onchip[64*j+i];
WMCON|=0x18; //Enable on-chip eeprom and write to on-chip eeprom
data_onchip=(char *)&BDisplay7seg;
for(i=0;i<64;i++)
{
data_onchip[64*j+i]=eeprom_buffer;
do
{
ch=WMCON&0x02;
}
while(ch!=0x02);
}
WMCON&=0xe7;//Disable write to on-chip eeprom, Disable on-chip eeprom
}
 
  • Like
Reactions: MRAMA

    MRAMA

    Points: 2
    Helpful Answer Positive Rating
89s8252 eeprom

You may be able to modify this for floating point. Trying to do a modified vers to work with AT89S8253, but no joy yet. Anyone done this?. OK with 8252 though.

void write_eeprom_byte (unsigned int adr, unsigned char val)
{
WMCON |= (EEMEN_ | EEMWE_); // enable EEPROM and set write bit
DelayMs (10);
XBYTE[adr] = val; // write value
while ((WMCON & EERDY_) == 0) // wait until value programmed
DelayMs (10);
WMCON &= ~(EEMWE_ | EEMEN_); // disable EEPROM and write strobe
}
///////////////////////////////////////////////////////////////////

unsigned char read_eeprom_byte (unsigned int adr)
{
unsigned char v;

WMCON |= EEMEN_; // enable EEPROM
v = XBYTE[adr]; // read value
WMCON &= ~EEMEN_; // disable EEPROM
return (v);
}
///////////////////////////////////////////////////////////////////

// write_eeprom_word
// Inputs: unsigned addr 0x000-0x7ff
// int dataword (16 bit length)
// Output:
// calls: write_eeprom_byte()
// Called by:
void write_eeprom_16(unsigned int addr, unsigned int dataword){
char i;
char *ptr = & dataword;

for (i=0; i<sizeof (dataword); i++){
write_eeprom_byte (addr + i, *ptr);
ptr ++;
}
}
///////////////////////////////////////////////////////////////////

// read_eeprom_word
// Inputs: unsigned addr 0x000-0x7ff
// Output: int read dataword (16 bit length)
// Called by: write_eeprom_word()
unsigned int read_eeprom_16 (unsigned int addr){
char i;
unsigned dataword;
char *ptr = & dataword;


for (i=0; i<sizeof (dataword); i++){
*ptr = read_eeprom_byte (addr + i);
ptr ++;
}
return dataword;
}

Added after 3 minutes:

Forgot to mention. You will need some sort of delay routine to replace DelayMs if you do not have it.
 

    V

    Points: 2
    Helpful Answer Positive Rating
write into eeprom

Trying to do a modified vers to work with AT89S8253, but no joy yet. Anyone done this?

Reply: Testing with AT89S8253 on internal eeprom read/write. Because AT89S8253 is using different EEPROM control register from AT89S8252, it seems we need to change WMCON to EECON. Code below writes a single byte to internal EEPROM at address 0x0700 with a value 0x39 (ASCII 9).

Code:
/*
********************************************************************************************************************
Description:   Testing a program to write internal eeprom data and read it back and displayed
mcu = Atmel AT89S8253 at Vdd=3.3 matching CM60010ACT6 1.8" color LCD module
Date:             4 Nov 2006 ongoing
Programmer:  John Leung
Internet:        [url]www.TechToys.com.hk[/url]
********************************************************************************************************************
*/
#include <REG8253.H>
#include <absacc.h>

unsigned char buf[32];

void ieem_WrByte(unsigned int adr, unsigned char val);
unsigned char ieem_RdByte(unsigned int adr);

unsigned char k;

void main (void)
{
   ieem_WrByte(0x0700, 0x39);
   k=ieem_RdByte(0x0700);
   while(1){
     ;
   }
}

/*
********************************************************************************************************************
* Write a single byte to internal eeprom at the address adr 
********************************************************************************************************************
*/
void ieem_WrByte(unsigned int adr, unsigned char val)
{
	EECON|= (EEMEN_ | EEMWE_); 	// EEPROM Access Enable. Redirects MOVX | EEPROM Write Enable 
	XBYTE[adr] = val;           // write value
	while ((EECON & RDY_) == 0) // wait until value programmed by monitoring the RDY_ flag in EECON register
	 							// RDY_=0 means programming is still in progress
	EECON &= ~(EEMWE_ | EEMEN_);// disable EEPROM and write strobe 
}


/*
********************************************************************************************************************
* Read a single byte from internal eeprom specified by the address adr
********************************************************************************************************************
*/
unsigned char ieem_RdByte (unsigned int adr) 
{ 
	unsigned char v; 

	EECON |= EEMEN_; 	// enable EEPROM
	v = XBYTE[adr];    
	EECON &= ~EEMEN_; 	// disable EEPROM
	return (v); 
} 

/*
********************************************************************************************************************
* Write a page of 32 bytes from buffer buf to internal eeprom with starting address specified by adr_start
* Page write at 4ms instead of 4*32ms! A much faster mode for writing large chuck of data
********************************************************************************************************************
*/
void ieem_WrPage(unsigned int adr_start, unsigned char *buf)
{
	//TBD
}


Program verified by Atmel ISP downloader software since there is a Window displaying the internal eeprom data.

However, it seems not possible to reload another program to Flash but retaining eeprom data at the same time! We need to erase them all if using the isp downloader software! My previous intention was to use the internal eeprom to store some sort of icon or font so that I could use two different programs, one for font download, and the other for font display to save program space. Otherwise, I need to use all flash space to store icons and fonts for graphical LCD!

However, AT89S8253 is a nice device. It works from Vdd=3.3 to 5.5V w/o switching to LS part like before.

John Leung
 

eeprom addressing c code language

u can use union in C
to convert float to 4 (i think) bytes array
so u can store the data char by char to the EEprom

the same union can be in use to retrieve the float

yuv
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top