找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

AT24C02做的I2C通信仿真问题,高手进!!

[复制链接]
admin 发表于 2012-9-2 14:33:13 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
预想的是P3.0口输出低电平,可是仿真结果是P3.7输出了高电平,高手解答下怎么回事,不盛感激~~!!!

#include<reg52.h>
#define uchar unsigned char
sbit scl=P2^0;
sbit sda=P2^1;
void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=50;y>0;y--);
}
void start()
{
sda=1;
delay(1);
scl=1;
delay(1);
sda=0;
delay(1);
scl=0;
delay(1);
}
void stop()
{
sda=0;
delay(1);
scl=1;
delay(1);
sda=1;
delay(1);
scl=0;
delay(1);
}
void response()
{
uchar i;
scl=1;
delay(1);
while((sda==1)&&(i<255))
i++;
scl=0;
delay(1);
}
void write(uchar dat)
{
uchar i,temp;
temp=dat;
scl=0;
delay(1);
for(i=0;i<8;i++)
{
temp=temp<<1;
sda=CY;
delay(1);
scl=1;
delay(1);
scl=0;
delay(1);
}
}
uchar read()
{
uchar i,j,k;
scl=0;
delay(1);
sda=1;
delay(1);
for(i=0;i<8;i++)
{
scl=1;
delay(1);
j=sda;
delay(1);
k=(k<<1)|j;
scl=0;
delay(1);
}
return k;
}
void main()
{
sda=1;
delay(1);
scl=1;
delay(1);
start();
write(0xa0);
response();
write(1);
response();
write(0xfe);
response();
stop();
delay(100);
start();
write(0xa0);
response();
write(1);
response();
start();
write(0xa1);
P3=read();
stop();
while(1);
}

5_118819_37bafcc488b2cba.png
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-25 04:33 , Processed in 0.055344 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表