' Example program to test I2C-16IO (I2C 16 bits General Purpose Input/Output) unit. ' The program configures 8 bits PORT0 as inputs and 8 bits PORT1 as outputs. ' Output pins are toggle every 1 second ($55, $AA, $55, ...) ' Input pins are capture and display on debug terminal every 1 second. ' ' Note: This program was tested using PICAXE 28X-1 Firmware version 2 ' Setup: A2=0, A1=0, A0=0 ' ' Document: PCA9535 datasheet ' Updated: September 1, 2008 ' E-mail: support@gravitech.us ' Gravitech ' (C) Copyright 2008 All Rights Reserved '************************************************************ symbol I2C_ADDR = $40 ' I2C address symbol DATA_IN =b1 ' Input data symbol DATA_OUT = b2 ' Output data MAIN: PAUSE 1000 DATA_OUT = $55 ' Intialize output data i2cslave I2C_ADDR, i2cslow, i2cbyte writei2c 6,($FF,$00) ' Configure PORT 0 and PORT 1 ' P0.7 6 5 4 3 2 1 0 ' I I I I I I I I ' P1.7 6 5 4 3 2 1 0 ' O O O O O O O O writei2c 3, (DATA_OUT) ' Set output port to %01010101 AGAIN: PAUSE 1000 DATA_OUT = DATA_OUT ^ $FF ' Invert all of the bits i2cslave I2C_ADDR, i2cslow, i2cbyte writei2c 3, (DATA_OUT) ' Set output port to %10101010 writei2c (0) ' Set the pointer to REGISTER0 readi2c (DATA_IN) ' Read status of PORT0 sertxd ("PORT0 = ",#DATA_IN,CR,LF) ' Display status of PORT0 GOTO AGAIN END