programming eeprom

Thread Starter

akp007

Joined Jan 28, 2013
3
Dear all,
i need to write a code(c ) to perform the following task(external serial eeprom interfaced with 89c51 microcontroller)

1. to store a bulk data in the external serial eeprom (12345678965879486250,489657927800205087,.....)
2.to update eeprom periodically automatically
3.to compare incoming data(input to the microcontroller) with the data stored in the eeprom.
4.if the data matches,form a string of the matched data
4.send the string to the output ports
.............pls suggest some sample programs............please help
 

RamaD

Joined Dec 4, 2009
328
What is the size of the bulk data? Select an EEPROM which has a larger size than your requirement. Search for serial eeprom 8051 code. There are lots of code available.
You need to check the datasheet of the eeprom that you decide to use, and use the instruction codes in the datasheet.
 

Ian Rogers

Joined Dec 12, 2012
1,136
I've done software I2C for the 51 chipset....

It was done on SDCC!! Works though.
Rich (BB code):
#include<8052.h>
#include<stdio.h>

__sbit __at (0xB2) rs;	// Register select pin
__sbit __at (0xB3) rw;	// Read write pin
__sbit __at (0xB4) en;	// Enable pin
__sbit __at (0x91) scl;
__sbit __at (0x90) sda;

void I2Cinit()
	{
	P1 = 0xc0;	
	}

void aknowledge()	 //acknowledge condition
	{
	sda=0;
	scl=1;
	scl=0;
	sda=1;
	} 
	
void nack()	 	// not acknowledge condition
	{
	sda=1;
	scl=1;
	scl=0;
	scl=1;
	}
	
void start()	 //start condition
	{
	sda=1;
	scl=1;
	sda=0;
	scl=0;
	}
	
void rstart()	 //re-start condition
	{
	scl=0;
	sda=1;
	scl=1;
	sda=0;
	}
	
void stop()	 //stop condition
	{
	scl=0;
	sda=0;
	scl=1;
	sda=1;
	}
	
unsigned char read_byte()	//reading from EEPROM serially
	{
	unsigned int i;
	unsigned char reead=0;
	
	for(i=0;i<8;i++)
		{
		reead=reead<<1;
		scl=0;
		if(sda==1)
			reead++;
		scl=1;
		}
	scl=0;
	sda=1;
	return reead;	 //Returns 8 bit data here
	}
	
void send_byte(unsigned char value)	//send byte serially
	{ 
	unsigned int i;
	unsigned char send;
	send=value;
		
	for(i=0;i<8;i++)
		{
		scl=0;
		sda=send/128;	 //extracting MSB
		send=send<<1;	 //shiftng left
		scl=1;
		}
	scl=0;
	sda=1;
	}
	
void Write(unsigned char ch, int addr)
	{
	start();
	send_byte(0xA0);
	aknowledge();	
	send_byte((unsigned char)(addr>>8));
	aknowledge();
	send_byte((unsigned char)addr);
	aknowledge();	
	send_byte(ch);	//device address
	aknowledge();
	stop();
	}
		
int Read(int addr)
	{
	unsigned char ret;
	start();
	send_byte(0xA0);
	aknowledge();
	send_byte((unsigned char)(addr>>8));  // High addr
	aknowledge();
	send_byte((unsigned char)addr);  // low addr
	aknowledge();
	rstart();
	send_byte(0xA1);	//device read address
	aknowledge();
	ret=read_byte();
	nack();				// stop reading
	stop();
	return ret;
	}
void delayus(int x)
	{
	while(x--);		
	}
void delayms(int x)
	{
	while(x--)
		delayus(97);
	}

void lcd_command(unsigned char comm) // function to send command to LCD
	{
	P2=comm;
	en=1;
	rs=0;
	rw=0;
	delayms(1);
	en=0;
	}

void lcd_ini() //Function to inisialize the LCD
	{
	lcd_command(0x38);	//8-bit 2 row LCD
	lcd_command(0x0C);	//Display on, cursor off
	lcd_command(0x80); //force cursor to the beginning of 1st line
	}

void lcd_data(unsigned char disp) // function to send only single data on LCD
	{
	P2=disp;
	en=1;
	rs=1;
	rw=0;
	delayms(1);
	en=0;
	}

void lcd_dataa(unsigned char *disp) // function to send strings to LCD
	{
	int x;
	for(x=0;disp[x]!=0;x++)
		{
		lcd_data(disp[x]);
		}
	return;
	}
	
	
void main()
	{
	int x,j;
	I2Cinit();
	lcd_ini();	
	lcd_command(0x80);
	lcd_dataa("WRITE=");
	for(x=0;x<10;x++)
		{
		Write(x+48,x);
		lcd_data(x+48);
		delayms(5);
		}
	lcd_command(0xC0);
	lcd_dataa(" READ=");
	for(x=0;x<10;x++)
		{
		j = Read(x);
		lcd_data(j);
		}
	for(;;){}
	}
 
Top