!- -------------------------------------------
!- -    Compile this source using the tool   -
!- -            CBM program studio           -
!- -------------------------------------------
!- read datasheet of the MCP23008 before using
!- -------------------------------------------
1 REM USE THE MCP23008 IO EXPANDER
2 REM B7,6,5 ARE INPUT (BUTTONS)
3 REM B4,3,2,1,0 ARE OUTPUT (LED)
4 REM ---------------
5 I=64:REM IO-EXPANDER I2C ADDRESS
6 A=0:REM I2C VARIABLE
7 SYS 29000:REM ACTIVATE WEDGE
12 GOSUB 1000:REM INIT IO
14 REM ----------------
20 !I2CAW,I:!I2CPU,9:!I2CST:REM PREP
30 !I2CAR,I:!I2CGL:!I2CST:REM READ
40 PRINT A
50 !I2CAW,I:!I2CPU,9:!I2CPU,1:!I2CST:REM WRITE
60 FOR L=0TO100:NEXTL:REM DELAY
70 !I2CAW,I:!I2CPU,9:!I2CPU,0:!I2CST:REM WRITE
80 FOR L=0TO100:NEXTL:REM DELAY
90 GOTO 20
1000 REM ---------------
1001 REM INITIALIZE IO
1005 PRINT"initialize io"
1010 REM SET IO DEFINITIONS
1011 !I2CAW,I   :REM ADDRESS DEVICE
1012 !I2CPU,0   :REM IODIR REG
1013 !I2CPU,224 :REM 0=OUT,1=IN
1014 !I2CST     :REM STOP I2C
1021 !I2CAW,I   :REM I2C ADDRESS
1022 !I2CPU,6   :REM IODIR REG
1023 !I2CPU,255 :REM ENABLE PULLUP
1024 !I2CST     :REM STOP I2C
1031 !I2CAW,I   :REM I2C ADDRESS
1032 !I2CPU,5   :REM IOCON REG
1033 !I2CPU,32  :REM DISABLE AUTO INC
1034 !I2CST     :REM STOP I2C
1050 RETURN