新手,學習I2C總線。
Build target 'Target 1'
compiling i2c總線學習.c...
I2C總線學習.C(18): warning C206: 'delay': missing function-prototype
I2C總線學習.C(51): error C231: 'delay': redefinition
I2C總線學習.C(51): error C231: 'delay': redefinition
Target not created
單片機源程序如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit sda=P2^0;
sbit scl=P2^1;
void delay1()
{
uint x,y;
for(x=5;x>0;x--)
for(y=5;y>0;y--);
}
void start()//起始信號
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop()//終止信號
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void response()//應答信號
{
uchar i;
scl=1;
delay();
while((sda==1)&&(i<250))
i++;
scl=0;
delay();
}
void delay()
{;;}
void init()//初始化
{
sda=1;
scl=1;
}
void wtite_byte(uchar date)
{
uchar i,temp;
temp=date;
scl=0;
delay();
for(i=0;i<8;i++)
{
temp=temp<<1;
sda=CY;
delay();
scl=1;
delay();
scl=0;
delay();
}
sda=1;
delay();
}
uchar read_byte()
{
uchar i,j,k;
scl=0;
delay();
scl=1;
delay();
for(i=0;i<8;i++)
{
scl=1;
delay();
j=sda;
k=(k<<1)|j;
scl=0;
delay();
}
return k;
}
void main()
{
init();
start();
write_byte(0xa0);
response();
write_byte(3);
response();
write_byte(0xfe);
response();
stop();
start();
write_byte(0xa0);
response();
write_byte(3);
response();
start();
write_byte(0xa1);
response();
P1=write_byte();
stop();
while(1);
}
|