Symbol Reserved1 = b0 ; used for the bit variables indicated below
Symbol bitnc = bit0
Symbol Lite = bit1
Symbol bitD7 = bit2
Symbol bitD6 = bit3
Symbol bitD5 = bit4
Symbol bitD4 = bit5
Symbol bitE = bit6
Symbol bitRS = bit7
; MCP23008 Registers
SYMBOL IODIR = $00 ; direction register
SYMBOL IOCON = $05 ; control register
SYMBOL GPIO = $09 ; 8-bit port register
SYMBOL MCP23008 = $40 ; i2c slave address
SYMBOL SEQ_OP = $20
Initialisation:
HI2cSetup I2CMASTER, MCP23008, I2CSLOW, I2CBYTE ; this can be i2cfast later
HI2COUT IODIR, ($00) ' set the direction register pins as outputs
HI2COUT IOCON, (SEQ_OP) ' set to keep writing to the same register - don't auto inc register address
HI2COUT GPIO, ($00) ' clear outputs which also sets register for sending further data
b0 = $33 : Gosub SendB0AsInitByte
b0 = $33 : Gosub SendB0AsInitByte
b0 = $32 : Gosub SendB0AsInitByte
b0 = $28 : Gosub SendB0AsCommandByte
b0 = $0C : Gosub SendB0AsCommandByte
b0 = $06 : Gosub SendB0AsCommandByte
b0 = $01 : Gosub SendB0AsCommandByte
Pause 2
MainProgram:
b0 = $80 : Gosub SendB0AsCommandByte
b0 = "L" : Gosub SendB0AsDataByte
b0 = "i" : Gosub SendB0AsDataByte
b0 = "n" : Gosub SendB0AsDataByte
b0 = "e" : Gosub SendB0AsDataByte
b0 = " " : Gosub SendB0AsDataByte
b0 = "1" : Gosub SendB0AsDataByte
b0 = $A0 : Gosub SendB0AsCommandByte
b0 = "L" : Gosub SendB0AsDataByte
b0 = "i" : Gosub SendB0AsDataByte
b0 = "n" : Gosub SendB0AsDataByte
b0 = "e" : Gosub SendB0AsDataByte
b0 = " " : Gosub SendB0AsDataByte
b0 = "2" : Gosub SendB0AsDataByte
Do : Loop
SendB0AsInitByte:
Pause 15
SendB0AsCommandByte:
bitRS = 0 ; Send byte as a command
SendB0AsDataByte:
bitD4 = bit4 ; Send msb first
bitD5 = bit5
bitD6 = bit6
bitD7 = bit7
bitE = 1
b1 = b0 ; b1 holds msb with E set
bitE = 0 ; b0 holds msb with E clear
HI2cOut b1, ( b1, b0 )
bitD4 = bit0 ; Send lsb second
bitD5 = bit1
bitD6 = bit2
bitD7 = bit3
bitE = 1
b1 = b0 ; b1 holds lsb with E set
bitE = 0 ; b0 holds lsb with E clear
HI2cOut b1, ( b1, b0 )
bitRS = 1 ; ready to send data byte next time
Return