标题:
大神看看我这I2C总线程序编译错误 怎么回事?
[打印本页]
作者:
wps10025
时间:
2020-9-10 11:27
标题:
大神看看我这I2C总线程序编译错误 怎么回事?
新手,学习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);
}
作者:
wps10025
时间:
2020-9-10 11:28
说delay未定义,看不懂了,怎么没定义
作者:
wps10025
时间:
2020-9-10 12:10
我找到错误地方了
是delay函数要放在最上边,下面的函数可以调用。次序翻了,不能编译。
也希望初学者以此为鉴。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1