新人求助··········c程序问题
时间:10-02
整理:3721RD
点击:
为什么我调用初始化程序chushihua()就出现错误,从主函数中把chushihua()去掉就显示没有错误?小弟刚学单片机没多久,真心希望得到各位牛人帮助。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sda=P2^0;
sbit sdl=P2^1;
void delay0()
{ ; ;}
void chushihua()
{
sda=1;
sdl=1;
delay0();
}
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
{
for(y=100;y>0;y--)
{ }
}
}
void start()
{
sda=1;
delay0();
sdl=1;
delay0();
sda=0;
delay0();
}
void stop()
{
sda=0;
delay0();
sdl=1;
delay0();
sda=1;
delay0();
}
void respons()
{
uchar i;
sdl=1;
delay0();
while((sda==1)&&(i<250))i++;
sdl=0;
delay0();
}
void write_bite(uchar date)
{
uchar j,temp;
temp=date;
sdl=0;
delay0();
for(j=0;j<8;j++)
{
temp=temp<<1;
sda=CY;
delay0();
sdl=1;
delay0();
sdl=0;
delay0();
}
sda=1;
delay0();
}
uchar read_bite()
{
uchar i,j,k;
sdl=0;
delay(20);
sda=1;
delay(20);
for(i=0;i<8;i++)
{
sdl=1;
delay(20);
j=sda;
k=(k<<1)/j;
sdl=0;
delay(20);
}
return k;
}
void main()
{
chushihua();
uchar a;
start();
write_bite(0xa0);
respons();
write_bite(3);
respons();
write_bite(0xfe);
respons();
stop();
delay(200);
start();
write_bite(0xa0);
respons();
write_bite(3);
respons();
start();
write_bite(0xa1);
respons();
a=read_bite();
stop();
P1=a;
while(1);
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sda=P2^0;
sbit sdl=P2^1;
void delay0()
{ ; ;}
void chushihua()
{
sda=1;
sdl=1;
delay0();
}
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
{
for(y=100;y>0;y--)
{ }
}
}
void start()
{
sda=1;
delay0();
sdl=1;
delay0();
sda=0;
delay0();
}
void stop()
{
sda=0;
delay0();
sdl=1;
delay0();
sda=1;
delay0();
}
void respons()
{
uchar i;
sdl=1;
delay0();
while((sda==1)&&(i<250))i++;
sdl=0;
delay0();
}
void write_bite(uchar date)
{
uchar j,temp;
temp=date;
sdl=0;
delay0();
for(j=0;j<8;j++)
{
temp=temp<<1;
sda=CY;
delay0();
sdl=1;
delay0();
sdl=0;
delay0();
}
sda=1;
delay0();
}
uchar read_bite()
{
uchar i,j,k;
sdl=0;
delay(20);
sda=1;
delay(20);
for(i=0;i<8;i++)
{
sdl=1;
delay(20);
j=sda;
k=(k<<1)/j;
sdl=0;
delay(20);
}
return k;
}
void main()
{
chushihua();
uchar a;
start();
write_bite(0xa0);
respons();
write_bite(3);
respons();
write_bite(0xfe);
respons();
stop();
delay(200);
start();
write_bite(0xa0);
respons();
write_bite(3);
respons();
start();
write_bite(0xa1);
respons();
a=read_bite();
stop();
P1=a;
while(1);
}
自己顶下
自己解决了··
chushihua();
uchar a;
这两个换一下位置就行了,变量定义放在调用程序前面。虽然不知道为什么要这样
这是编译器所规定的,不同的编译器规定不同,在GCC里面编译,这种写法是被允许的
原来这样子,谢谢哦。
Content不懂....