'{$STAMP BS2p} ' {$PBASIC 2.5} '*********************************************************** '** ** '** I2C Routines for the Basic Stamp BS2p ** '** Controlling RLY08 I2C LCD Display ** '** ** '** Copyright 2006 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Chris Clarke - Jan 2006 ** '** ** '*********************************************************** Key VAR Byte addr VAR Byte ver VAR Byte states VAR Byte SCL CON 1 ' I2C clock SDA CON 0 ' I2C data ALL_ON CON 100 RELAY1_ON CON 101 RELAY2_ON CON 102 RELAY3_ON CON 103 RELAY4_ON CON 104 RELAY5_ON CON 105 RELAY6_ON CON 106 RELAY7_ON CON 107 RELAY8_ON CON 108 ALL_OFF CON 110 RELAY1_OFF CON 111 RELAY2_OFF CON 112 RELAY3_OFF CON 113 RELAY4_OFF CON 114 RELAY5_OFF CON 115 RELAY6_OFF CON 116 RELAY7_OFF CON 117 RELAY8_OFF CON 118 Main: ver = 255 addr = $70 PAUSE 500 ' Wait for the display to go through its power up routine DO WHILE (ver = 255) 'searchs through all possible addresses on the I2C bus for the RLY08 DEBUG CLS,CRSRXY,0, 0," RLY08 @ 0x", HEX addr I2CIN SDA, addr,0, [ver] IF(ver = 255) THEN addr = addr + 2 IF (addr = $80) THEN addr = $70 PAUSE 100 LOOP MainLoop: IF(ver = 255) THEN GOTO main 'if response is lost we go back to searching I2CIN SDA, addr,0, [ver] I2CIN SDA, addr,1, [states] I2COUT SDA, addr, 0, [RELAY1_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY2_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY3_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY4_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY5_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY6_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY7_ON] GOSUB show_rly08_status I2COUT SDA, addr, 0, [RELAY8_ON] GOSUB show_rly08_status PAUSE 200 I2COUT SDA, addr, 0, [ALL_OFF] GOSUB show_rly08_status PAUSE 200 GOTO MainLoop ' Loop show_rly08_status: I2CIN SDA, addr,1, [states] DEBUG HOME, " RLY08 addr = 0x", HEX addr, " Version = ", DEC ver, " Relay States = ", DEC states, " " PAUSE 100 RETURN