This is example how to interfacing MCS-51 with I2C EEPROM 24LC256 which is 265K-Bits EEPROM.Software program with KEIL C51 and I use EEPROM from Microchip company.

The Microchip Technology Inc. 24AA256/24LC256/
24FC256 (24XX256*) is a 32K x 8 (256K bit) Serial
Electrically Erasable PROM, capable of operation
across a broad voltage range (1.8V to 5.5V). It has
been developed for advanced, low power applications
such as personal communications or data acquisition.
This device also has a page-write capability of up to 64
bytes of data. This device is capable of both random
and sequential reads up to the 256K boundary. Functional
address lines allow up to eight devices on the
same bus, for up to 2M bit address space.
ADDRESS SEQUENCE BIT ASSIGNMENTS
The buttom figure is the schematic to use in this example.Note that,pin A0-A2 was connected to ground becuase we only use one EEPROM in this example.So in the software we must define A2 - A0 is "0" in control byte(see above figure).
AT89S8252 used for this example becuase I have the ISP development board AT89 Dev which easy to develop with ATMEL ISP devices without any programmer.

Here is the main loop for this example.For full source code program with KEIL C51 you can download at the buttom of this page.
//---------------------------------------
// Example read and write DS1307
// KEIL C51 v7.5
// www.sixca.com
//---------------------------------------
#include<reg8252.h>
#include<stdio.h>
#include<24LC256.h>
#include<serial.h>
#include<delay.h>
//---------------------------------------
// Main program
//---------------------------------------
void main(void)
{
unsigned char EData;
InitSerial(); // Initialize serial port
putchar(0x0C); // clear hyper terminal
WriteBYTE(0x0000,0x55);DelayMs(5);// Delay for write cycle time
WriteBYTE(0x0001,0x22);DelayMs(5);// Delay for write cycle time
WriteBYTE(0x0002,0x77);DelayMs(5);// Delay for write cycle time
WriteBYTE(0x0003,0x88);DelayMs(5);// Delay for write cycle time
EData = ReadBYTE(0x000);// read back
printf("Addr 0x0000 : %02bX\r\n",EData); // display data
EData = ReadBYTE(0x001);// read back
printf("Addr 0x0001 : %02bX\r\n",EData); // display data
EData = ReadBYTE(0x002);// read back
printf("Addr 0x0002 : %02bX\r\n",EData); // display data
EData = ReadBYTE(0x003);// read back
printf("Addr 0x0003 : %02bX\r\n",EData); // display data
while(1);
}
From the above example after intialize serial port the CPU will clear screen of Hyper terminal then write data 4 byte.After write for each byte we must insert delay for write cycle time
which this delay time not same for differrent manufacture see data sheet for each manufacture in this example use 5 mS for Microchip 24LC256 .
 |
|
|