'*********************************************************** '** ** '** SRF08 Demonstration Software for the Basic Atom ** '** To change the SRF08 I2C address ** '** ** '** Copyright 2002 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Gerald Coe - April 2002 ** '** ** '*********************************************************** SRF08_NEW_ADDRESS Con 0xe2 ' Sonar I2C Address SDA Con P8 ' Define Data pin SCL Con P9 ' Define Clk pin CmdReg Con 0 ' Sonar Command register LightReg Con 1 ' Sonar Light sensor register RangeReg Con 2 ' Sonar 1st Range register Light Var Byte Range Var Word ' 16 bit variable for Range Main Gosub ChangeAddress ' Only call this once to change I2C address, with a single SRF08 connected. Loop i2cout SDA, SCL, SRF08_NEW_ADDRESS, CmdReg, [81] pause 66 i2cin SDA, SCL, SRF08_NEW_ADDRESS, LightReg, [Light, Range.HighByte, Range.LowByte] Serout S_OUT, i9600, ["SRF08 at 0x", HEX SRF08_NEW_ADDRESS, " - Light = 0x", HEX Light, ", Range = ", DEC03 Range, " cm, ", 13] ' Use terminal window goto Loop ' This subroutine will change the SRF08's I2C address to whatever you have set ' in the SRF08 Con statement above. Since we don't know what the current address ' of the SRF08, we use the General Broadcast address (00) to communicate with it. ' Make sure you only have one SRF08 connected when you do this. ' The new address is stored on the SRF08, so this only needs to be done once. ' I suggest you write the new address on a label on the SRF08. ChangeAddress i2cout SDA, SCL, 0, CmdReg, [0xA0] ' { i2cout SDA, SCL, 0, CmdReg, [0xAA] ' { Required Sequence to change Address i2cout SDA, SCL, 0, CmdReg, [0xA5] ' { i2cout SDA, SCL, 0, CmdReg, [SRF08_NEW_ADDRESS] ' Send new Address Return