#include <reg52.h>
sbit EECS = P2^0;
sbit EECLCK = P2^1;
sbit EEDATA = P2^2;
unsigned char data eecount,eetemp,eeval,wdata,dev_addr=0xa0;
unsigned char data c,d,flag;
unsigned int data u,eeadd,i,q;
void start(void)
{
EEDATA=1;
EECLCK=1;
EEDATA=0;
EECLCK=0;
}
void stop(void)
{
EEDATA=0;
EECLCK=1;
EEDATA=1;
EECLCK=0;
}
void add_data(void)
{
for(eecount=0;eecount<8;eecount++)
{
eetemp=(wdata&0x80);
if(eetemp==0)
EEDATA=0;
else
EEDATA=1;
EECLCK=1;
EECLCK=0;
wdata=wdata<<1;
}
EEDATA=1;
EECLCK=1;
EECLCK=0;
}
void eeread(void)
{
unsigned char data eread,rdata;
start();
wdata=dev_addr;
add_data();
wdata=eeadd;
add_data();
start();
wdata=(dev_addr | 0x01);
add_data();
EEDATA=1;
for(eread=0;eread<8;eread++)
{
EECLCK=1;
if(EEDATA==1)
rdata|=1;
else
rdata&=(0xfe);
if(eread != 7)
rdata<<=1;
EECLCK=0;
}
eeval=rdata;
EEDATA=1;
EECLCK=1;
EECLCK=0;
stop();
}
void eewrite(void)
{
start();
wdata=dev_addr;
add_data();
wdata=eeadd;
add_data();
wdata=eeval;
add_data();
stop();
for(u=0;u<300;u++);
}
void changeadd()
{
if(q == 256)
{
dev_addr = 0xa2;
c = 'B';
SBUF = 'b';while(!TI);TI = 0;
}
else if(q == 512)
{
dev_addr = 0xa4;
c = 'C';
SBUF = 'c';while(!TI);TI = 0;
}
else if(q == 768)
{
dev_addr = 0xa6;
c = 'D';
SBUF = 'd';while(!TI);TI = 0;
}
else if(q == 1024)
{
dev_addr = 0xa8;
c = 'E';
SBUF = 'e';while(!TI);TI = 0;
}
else if(q == 1280)
{
dev_addr = 0xaa;
c = 'F';
SBUF = 'f';while(!TI);TI = 0;
}
else if(q == 1536)
{
dev_addr = 0xac;
c = 'G';
SBUF = 'g';while(!TI);TI = 0;
}
else if(q == 1792)
{
dev_addr = 0xae;
c = 'H';
SBUF = 'h';while(!TI);TI = 0;
}
}
void main()
{
PCON=0x00;
TH1 = 0xfd;
TL1 = 0x00;
SCON=0x50;
TMOD=0x20;
TCON = 0x40;
PSW=0x00;
IP=0x02;
IE=0x92;
TH0=0xf2;
TL0=0x64;
TMOD=0x21;
P2 = 0x00;
TR0 = 1;
flag = 0;
c = 'T';
SBUF = 'R';while(!TI);TI = 0;
while(1)
{
if(flag == 1)
{
eeadd = 0;
dev_addr = 0xa0;
for(q=0;q<2048;q++)
{
eeval = c;
eewrite();
eeadd++;
changeadd();
SBUF = '.';while(!TI);TI = 0;
}
flag = 0;
}
if(flag == 2)
{
eeadd = 0;
dev_addr = 0xa0;
for(q=0;q<2048;q++)
{
eeread();
/* SBUF = ((eeadd/100)+48);while(!TI);TI = 0;
SBUF = (((eeadd%100)/10)+48);while(!TI);TI = 0;
SBUF = (((eeadd%100)%10)+48);while(!TI);TI = 0;
SBUF = '-';while(!TI);TI = 0;*/
SBUF = eeval;while(!TI);TI = 0;
eeadd++;
changeadd();
}
flag = 0;
}
}
}
void timer() interrupt 1 using 1
{
TR0=0;
TH0=0xf2;
TL0=0x64;
TR0=1;
}
void serial() interrupt 4 using 2
{
if(RI)
{
RI = 0;
d = SBUF;
if(d == 'W' || d == 'w')
flag = 1;
else if(d == 'R' || d == 'r')
flag = 2;
}
}
sbit EECS = P2^0;
sbit EECLCK = P2^1;
sbit EEDATA = P2^2;
unsigned char data eecount,eetemp,eeval,wdata,dev_addr=0xa0;
unsigned char data c,d,flag;
unsigned int data u,eeadd,i,q;
void start(void)
{
EEDATA=1;
EECLCK=1;
EEDATA=0;
EECLCK=0;
}
void stop(void)
{
EEDATA=0;
EECLCK=1;
EEDATA=1;
EECLCK=0;
}
void add_data(void)
{
for(eecount=0;eecount<8;eecount++)
{
eetemp=(wdata&0x80);
if(eetemp==0)
EEDATA=0;
else
EEDATA=1;
EECLCK=1;
EECLCK=0;
wdata=wdata<<1;
}
EEDATA=1;
EECLCK=1;
EECLCK=0;
}
void eeread(void)
{
unsigned char data eread,rdata;
start();
wdata=dev_addr;
add_data();
wdata=eeadd;
add_data();
start();
wdata=(dev_addr | 0x01);
add_data();
EEDATA=1;
for(eread=0;eread<8;eread++)
{
EECLCK=1;
if(EEDATA==1)
rdata|=1;
else
rdata&=(0xfe);
if(eread != 7)
rdata<<=1;
EECLCK=0;
}
eeval=rdata;
EEDATA=1;
EECLCK=1;
EECLCK=0;
stop();
}
void eewrite(void)
{
start();
wdata=dev_addr;
add_data();
wdata=eeadd;
add_data();
wdata=eeval;
add_data();
stop();
for(u=0;u<300;u++);
}
void changeadd()
{
if(q == 256)
{
dev_addr = 0xa2;
c = 'B';
SBUF = 'b';while(!TI);TI = 0;
}
else if(q == 512)
{
dev_addr = 0xa4;
c = 'C';
SBUF = 'c';while(!TI);TI = 0;
}
else if(q == 768)
{
dev_addr = 0xa6;
c = 'D';
SBUF = 'd';while(!TI);TI = 0;
}
else if(q == 1024)
{
dev_addr = 0xa8;
c = 'E';
SBUF = 'e';while(!TI);TI = 0;
}
else if(q == 1280)
{
dev_addr = 0xaa;
c = 'F';
SBUF = 'f';while(!TI);TI = 0;
}
else if(q == 1536)
{
dev_addr = 0xac;
c = 'G';
SBUF = 'g';while(!TI);TI = 0;
}
else if(q == 1792)
{
dev_addr = 0xae;
c = 'H';
SBUF = 'h';while(!TI);TI = 0;
}
}
void main()
{
PCON=0x00;
TH1 = 0xfd;
TL1 = 0x00;
SCON=0x50;
TMOD=0x20;
TCON = 0x40;
PSW=0x00;
IP=0x02;
IE=0x92;
TH0=0xf2;
TL0=0x64;
TMOD=0x21;
P2 = 0x00;
TR0 = 1;
flag = 0;
c = 'T';
SBUF = 'R';while(!TI);TI = 0;
while(1)
{
if(flag == 1)
{
eeadd = 0;
dev_addr = 0xa0;
for(q=0;q<2048;q++)
{
eeval = c;
eewrite();
eeadd++;
changeadd();
SBUF = '.';while(!TI);TI = 0;
}
flag = 0;
}
if(flag == 2)
{
eeadd = 0;
dev_addr = 0xa0;
for(q=0;q<2048;q++)
{
eeread();
/* SBUF = ((eeadd/100)+48);while(!TI);TI = 0;
SBUF = (((eeadd%100)/10)+48);while(!TI);TI = 0;
SBUF = (((eeadd%100)%10)+48);while(!TI);TI = 0;
SBUF = '-';while(!TI);TI = 0;*/
SBUF = eeval;while(!TI);TI = 0;
eeadd++;
changeadd();
}
flag = 0;
}
}
}
void timer() interrupt 1 using 1
{
TR0=0;
TH0=0xf2;
TL0=0x64;
TR0=1;
}
void serial() interrupt 4 using 2
{
if(RI)
{
RI = 0;
d = SBUF;
if(d == 'W' || d == 'w')
flag = 1;
else if(d == 'R' || d == 'r')
flag = 2;
}
}