把数据传进e2prom,再读取的,一直找不到问题,p1是流水灯口
#include<reg52.h>
#define uchar unsigned char
sbit sda=P2^0; //数据总线
sbit scl=P2^1; //时钟总线
void delay()
{ ; ; }
delay1()
{
uchar f;
for(f=1000;f>0;f--);
}
void start() //起始信号
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop() //停止信号
{
sda=1;
delay();
scl=0;
delay();
sda=1;
delay();
}
void response() //应答信号
{
uchar i=0;
scl=1;
delay();
while((sda==1)&&(i<250))
i++;
scl=0;
delay();
}
void write(date) //写入信号
{ uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
}
scl=0;
delay();
sda=1;
delay();
}
uchar read() //读出信号
{
uchar a,k;
scl=0;
delay();
sda=1;
for(a=0;a<8;a++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return k;
}
void init()
{
scl=1;
delay();
sda=1;
delay();
}
void main()
{
init();
start();
write(0xa0); //地址
response();
write(2); //内部地址
response();
write(5); //数据
response();
stop();
delay1();
start();
write(0xa0);
response();
write(2);
response();
start();
write(0xa1);
response();
P1=read();
response();
stop();
while(1);
}
|