Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 6207|回復: 1
打印 上一主題 下一主題

想請問srf08更改address的問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2009-2-16 15:07:16 | 顯示全部樓層 回帖獎勵 |倒序瀏覽 |閱讀模式
我是使用PIC16F877A

  i2c_start();                    
  i2c_write(0xA0);
  i2c_write(0xAA);
  i2c_write(0xA5);
  i2c_write(0xE2);
  i2c_stop();
更改位址的方法我是按照他的說明

可是修改完以後 我把兩個srf08串起來使用
第二個出現的值都是65535
以下是第二個的接收
我是直接用第一個接收的方式 只是把位址改掉而已
不知道是不是有錯誤的地方
  i2c_start();                    //initate start condition
  i2c_write(0xE2);                //device address
  i2c_write(0x00);                //register address
  i2c_write(0x51);                //set units to centimeters
  i2c_stop();
  delay_ms(105);                  //wait for returning ping
  i2c_start();                    //initiate a new start condition
  i2c_write(0xE2);                //device address
  i2c_write(0x02);                //address of high byte register
  i2c_start();
  i2c_write(0xE1);                //device address but read
  for (i=0;i<17;i++)
  {
  range[i] = i2c_read(1);         //read first byte and shift left
  range[i] = range[i] << 8;
  if(i<16)
  range[i] += i2c_read(1);           //read second byte and add to 1st
  else
  range[i] += i2c_read(0);
  }
  i2c_stop();
  for (i=0;i<17;i++)
  {
   printf("range in centimeters = %lu\n\r", range[i]);
  }

謝謝進來看以及回答的各位<(_ _)>
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-19 21:32 , Processed in 0.199088 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表