我的c语言源程序是这样的 为什么不对啊??
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SDA=P2^0;
sbit SCL=P2^1;
void Delay(uint x)
{
uchar i;
while(x--)
for(i=0;i<120;i++);
}
void start() //起始信号
{
SDA=1;
Delay(5);
SCL=1;
Delay(5);
SDA=0;
Delay(5);
}
void stop() //终止信号
{
SDA=0;
Delay(5);;
SCL=1;
Delay(5);
SDA=1;
Delay(5);
}
void respons() //应答信号
{
uchar i;
SDA=1;
Delay(5);
while((SDA==1)&&(i<250))i++;
SCL=0;
Delay(5);
}
void init() //初始函数
{
SDA=1;
SCL=1;
}
void write_byte(uchar date) //写一个字节
{
uchar i,temp;
temp=date;
SCL=0;
Delay(5);
for(i=0;i<8;i++)
{
temp=temp<<1;
SDA=CY;
Delay(5);
SCL=1;
Delay(5);
SCL=0;
Delay(5);
}
SDA=1;
Delay(5);
}
uchar read_byte() //读一个字节
{
uchar i,j,k;
SCL=0;
Delay(5);
SDA=1;
Delay(5);
for(i=0;i<8;i++)
{
SCL=1;
Delay(5);
j=SDA;
k=(k<<1)|j;
Delay(5);
SCL=0;
Delay(5);
}
return k;
}
void write_add(uchar address,uchar dat) //往一个地址写入一个数据
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(dat);
respons();
stop();
}
uchar read_add(address) //读取一个地址的一个数据
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void main()
{
init();
write_add(1,0x55);
Delay(100);
P0=read_add(1);
while(1);
}
这是哪里错了? 求教
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SDA=P2^0;
sbit SCL=P2^1;
void Delay(uint x)
{
uchar i;
while(x--)
for(i=0;i<120;i++);
}
void start() //起始信号
{
SDA=1;
Delay(5);
SCL=1;
Delay(5);
SDA=0;
Delay(5);
}
void stop() //终止信号
{
SDA=0;
Delay(5);;
SCL=1;
Delay(5);
SDA=1;
Delay(5);
}
void respons() //应答信号
{
uchar i;
SDA=1;
Delay(5);
while((SDA==1)&&(i<250))i++;
SCL=0;
Delay(5);
}
void init() //初始函数
{
SDA=1;
SCL=1;
}
void write_byte(uchar date) //写一个字节
{
uchar i,temp;
temp=date;
SCL=0;
Delay(5);
for(i=0;i<8;i++)
{
temp=temp<<1;
SDA=CY;
Delay(5);
SCL=1;
Delay(5);
SCL=0;
Delay(5);
}
SDA=1;
Delay(5);
}
uchar read_byte() //读一个字节
{
uchar i,j,k;
SCL=0;
Delay(5);
SDA=1;
Delay(5);
for(i=0;i<8;i++)
{
SCL=1;
Delay(5);
j=SDA;
k=(k<<1)|j;
Delay(5);
SCL=0;
Delay(5);
}
return k;
}
void write_add(uchar address,uchar dat) //往一个地址写入一个数据
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(dat);
respons();
stop();
}
uchar read_add(address) //读取一个地址的一个数据
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void main()
{
init();
write_add(1,0x55);
Delay(100);
P0=read_add(1);
while(1);
}
这是哪里错了? 求教