Professional Documents
Culture Documents
Source Code :
#include<reg52.h>
#define NO_ACK 0
unsigned int j;
void start(void);
void stop(void);
bit in;
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 ack = 0;
SDA = 1;
else
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
SCL = 1;
ack = SDA;
SCL = 0;
return(ack);
}
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);
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)