0% found this document useful (0 votes)
69 views

EEPROM - To Write Some Initial Value To The Memory and Read Back (Test Bed For Testing Nonvolatile RAM of 8583)

This code provides functions to write to and read from EEPROM memory locations using I2C communication. It initializes the EEPROM by writing an ON value to the control register. It then writes a value to location 0x01, reads it back, and displays the value on an output port. The code contains functions for I2C start, stop, write and read operations to interface with the EEPROM.

Uploaded by

axeray
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

EEPROM - To Write Some Initial Value To The Memory and Read Back (Test Bed For Testing Nonvolatile RAM of 8583)

This code provides functions to write to and read from EEPROM memory locations using I2C communication. It initializes the EEPROM by writing an ON value to the control register. It then writes a value to location 0x01, reads it back, and displays the value on an output port. The code contains functions for I2C start, stop, write and read operations to interface with the EEPROM.

Uploaded by

axeray
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

10.

EEPROM – To write some initial value to the memory and


read back(test bed for testing Nonvolatile
RAM of 8583)

Connections : To be made as mentioned in the I2C code.

Source Code :

#include<reg52.h>

sbit buzz = P0^6;

sbit SCL = P0^5;

sbit SDA = P0^4;

#define EEPROM_WRITE 0xA2

#define EEPROM_READ 0xA3

#define EEPROM_OFF 0x80

#define EEPROM_ON 0x00

#define LOC1 0x02

#define LOC2 0x00

#define NO_ACK 0

unsigned int j;

void write_EEPROM(unsigned char loc, unsigned char dat);


unsigned char read_EEPROM(unsigned char loc);

void start(void);

void stop(void);

unsigned char read(bit ack);

bit write(unsigned char dat);

bit in;

void delay(unsigned int del) {

while(del--)

void start(void)

SDA = 1;

SCL = 1;

delay(100);

SDA = 0;

SCL = 0;

void stop(void)

SDA = 0;
SCL = 1;

delay(100);

SDA = 1;

SCL = 0;

bit write(unsigned char dat)

unsigned char mask;

bit ack = 0;

for(mask = 0x80; mask; mask >>= 1)

if(dat & mask)

SDA = 1;

else

SDA = 0;

SCL = 1;

SCL = 0;

SDA = 1;

SCL = 1;

ack = SDA;

SCL = 0;

return(ack);
}

unsigned char read(bit ack)

unsigned char temp = 0x00, g;

for(g = 0; g < 8; g++)

SCL = 1;

temp <<= 1;

if(SDA)

temp |= 0x01;

SCL = 0;

if(ack)

SDA = 0;

SCL = 1;

delay(100);

SCL = 0;

SDA = 1;

else

{
SDA = 1;

SCL = 1;

SCL = 0;

//P2 = 8;

return(temp);

void main (void) {

unsigned char val;

buzz = 1;

SCL = 0;

start();

if(!(write(EEPROM_WRITE))) {

if(!write(EEPROM_OFF)) {

start();

if(!write(EEPROM_WRITE)) {

if(!write(LOC1)) {

if(!(write(LOC2))) {

start();

if(!write(EEPROM_WRITE)) {
if(!write(CONTROL_REG))
{

if(!
write(EEPROM_ON))

P1 = 0x00;

stop();

while(1) {

start();

if(!write(EEPROM_WRITE)) {

if(!write(LOC1)) {

start();

if(!write(EEPROM_READ)) {

val = read(NO_ACK);

P1 = 0x01;

stop();
P2 = val ;

Output : A value is written into locations 0x00 and 0x01 of the EEPROM and is
read back and displayed on the BCD decoder based display. Writing

and reading can also be one page at a time (in this case,1 page being

8 bytes)

You might also like