我用
单片机控制24c02但是发送一个字节后没有应答
#include<reg52.h>
sbit sda=P3^3;
sbit scl=P3^4;
sbit as=P1^0; //led
sbit d1=P1^1; //led
sbit d2=P1^2; //led
#define uint unsigned int
#define uchar unsigned char
delay(){;;}
init(){
sda=1;
delay();
scl=1;
delay();
}
start(){
sda=0;
delay();
scl=0;
delay();
}
stop(){
scl=0;
delay();
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
send(uchar x){
uchar i;
for(i=8;i>0;i--){
sda=(bit)x;
delay();
x<<=1;
scl=1;
delay();
scl=0;
delay();
}
sda=1;
delay();
}
respond(){
uchar i=0;
while((sda==1)&&(i<200))
i++;
if(sda==0) //如果led亮说明24c02有反馈
as=0;
}
uchar resive(){
uchar res,i;
for(i=8;i>0;i--){
res<<=1;
sda=1;
delay();
scl=1;
delay();
res=res+(uchar)sda;
scl=0;
delay;
}
}
fankui(){
sda=0;
delay();
scl=1;
delay();
scl=0;
delay();
}
main(){
d1=1;
d2=0;
init();
start();
send(0xA0);
respond();
stop();
d2=1;
while(1);
}
一周热门 更多>