打印
[ZLG-MCU]

关于CAT1025

[复制链接]
1292|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
linhai1986|  楼主 | 2010-2-2 22:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ADDR, sd, TE, AD, DDR
我用51模拟了I2C协议来读写CAT1025,但是读入的和写出的总不一样,查不出原因,麻烦各位帮我看看,先谢谢了,下面是我的子程序代码
void CAT1025_Write_Byte(unchar addr, unchar dat)
{
unchar cat_addr = 0xa0;
unchar i;

SCL = 0;   //start condition
SDA = 1;
delay2(5);
SCL = 1;
delay2(5);
SDA = 0;
SCL = 0;
delay2(5);

for(i=0; i<8; i++)      //send the cat1025 address
{
  if(cat_addr&0x80)SDA=1;
  else SDA=0;
  SCL = 1;
  delay2(5);
  cat_addr <<= 1;
  SCL = 0;
  delay2(5);
}

SDA = 1; //release bus
SCL = 1;  // ask from cat1025
delay2(5);
SCL = 0;
delay2(5);

for(i=0; i<8; i++) //send the cat1025 address
{
  if(addr&0x80)SDA=1;
  else SDA=0;
  SCL = 1;
  delay2(5);
  addr <<= 1;
  SCL = 0;
  delay2(5);
}

SDA = 1; //ask from cat1025
SCL = 1;
delay2(5);
SCL = 0;
delay2(5);

for(i=0; i<8; i++) //send the dat
{
  if(dat&0x80)SDA=1;
  else SDA=0;
  SCL = 1;
  delay2(5);
  dat <<= 1;
  SCL = 0;
  delay2(5);
}

SDA = 1; //ask from cat1025
SCL = 1;
delay2(5);     
SCL = 0;
delay2(5);

SDA = 0;
SCL = 1;
delay2(5);
SDA = 1;
delay2(100);
}

unchar CAT1025_Read_Byte(unchar addr)
{
unchar i;
unchar cat_addr;
unchar dat=0;

SCL = 0;  //start condition
SDA = 1;
delay2(5);
SCL = 1;
delay2(5);
SDA = 0;
SCL = 0;
delay2(5);

cat_addr = 0xa0;
for(i=0; i<8; i++)  // send the addr of cat1025
{
  if(cat_addr&0x80) SDA = 1;
  else SDA = 0;
  SCL = 1;
  delay2(5);
  SCL = 0;
  delay2(5);
  cat_addr <<= 1;
}

SDA = 1;    //ask from cat1025
SCL = 1;
delay2(5);
SCL = 0;
delay2(5);

for(i=0; i<8; i++)  //send the addr of dat
{
  if(addr&0x80) SDA = 1;
  else SDA = 0;
  SCL = 1;
  delay2(5);
  SCL = 0;
  addr <<= 1;
  delay2(5);
}

SDA = 1;  //ask from cat1025
SCL = 1;
delay2(5);
SCL = 0;

SDA = 1; // start condition
SCL = 1;
delay2(5);
SDA = 0;
SCL = 0;
delay2(5);

cat_addr = 0xa1;   // send the addr of cat1025
for(i=0; i<8; i++)
{
  if(cat_addr&0x80)SDA = 1;
  else SDA = 0;
  SCL = 1;
  delay2(5);
  SCL = 0;
  delay2(5);
  cat_addr <<= 1;
}

SDA = 1;   //ask from cat1025
SCL = 1;
delay2(5);
SCL = 0;
delay2(5);

for(i=0; i<8; i++)  //receive dat from cat1025
{
  SCL = 1;
  delay2(5);
  if(SDA) dat|=0x01;
  dat <<= 1;
  SCL = 0;
  delay2(5);
}


SDA = 0;    // stop condition
SCL = 1;
delay2(5);
SDA = 1;
delay2(5);
return dat;
}

相关帖子

沙发
juventus9554| | 2010-2-4 21:01 | 只看该作者
看不出啥毛病……

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

172

主题

1451

帖子

0

粉丝