Lestroso
http://www.fasasoftware.com
- Code: Select all
' Test leds program for MCP23017 By FasaSoftware
' www.fasasoftware.com
' Flash Leds Output on MCP ADRESS MCP TO 000 port gpio a-b and ADRESS MCP TO 111 port gpio a-b
Const Device = CB220
Set I2c 9,8
' Register Definitions (Bank = 0)
#define IODIRA 0x00
#define IODIRB 0x01
#define IOPOLA 0x02
#define IOPOLB 0x03
#define GPINTENA 0x04
#define GPINTENB 0x05
#define DEFVALA 0x06
#define DEFVALB 0x07
#define INTCONA 0x08
#define INTCONB 0x09
#define IOCONA 0x0A
#define IOCONB 0x0B
#define GPPUA 0x0C
#define GPPUB 0x0D
#define INTFA 0x0E
#define INTFB 0x0F
#define INTCAPA 0x10
#define INTCAPB 0x11
#define GPIOA 0x12
#define GPIOB 0x13
#define OLATA 0x14
#define OLATB 0x15
#define MCP_0_write 0b01000000 'ADRESS MCP TO 000
#define MCP_1_write 0b01001110 'ADRESS MCP TO 111
Dim I2cresult As Byte
' Set up MCP23017 I/O direction
I2cstart
I2cresult = I2cwrite(MCP_0_write) 'WRITE TO ADDRESS MCP 000
I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
I2cresult = I2cwrite(0b00000000) 'Set To Out leds
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_0_write)
I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
I2cresult = I2cwrite(0b00000000) 'Set To Out leds
I2cstop
' Test output
I2cstart
I2cresult = I2cwrite(MCP_1_write) 'WRITE TO ADDRESS MCP 111
I2cresult = I2cwrite(IODIRA) 'CALL REGISTER DIRECTION PIN iodira
I2cresult = I2cwrite(0b00000000) 'Set To Out leds
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_1_write)'WRITE TO ADDRESS MCP 111
I2cresult = I2cwrite(IODIRB)'CALL REGISTER DIRECTION PIN iodirb
I2cresult = I2cwrite(0b00000000) 'Set To Out leds
I2cstop
Do
Delay 500
I2cstart
I2cresult = I2cwrite(MCP_0_write)
I2cresult = I2cwrite(GPIOA)
I2cresult = I2cwrite(0b0000000) 'set off led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_0_write)
I2cresult = I2cwrite(GPIOB)
I2cresult = I2cwrite(0b0000000)'set off led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_1_write)
I2cresult = I2cwrite(GPIOA)
I2cresult = I2cwrite(0b0000000)'set off led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_1_write)
I2cresult = I2cwrite(GPIOB)
I2cresult = I2cwrite(0b0000000)'set off led
I2cstop
Delay 500
I2cstart
I2cresult = I2cwrite(MCP_0_write)
I2cresult = I2cwrite(GPIOA)
I2cresult = I2cwrite(0b11111111)'set on led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_0_write)
I2cresult = I2cwrite(GPIOB)
I2cresult = I2cwrite(0b11111111)'set on led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_1_write)
I2cresult = I2cwrite(GPIOA)
I2cresult = I2cwrite(0b11111111)'set on led
I2cstop
I2cstart
I2cresult = I2cwrite(MCP_1_write)
I2cresult = I2cwrite(GPIOB)
I2cresult = I2cwrite(0b11111111)'set on led
I2cstop
Loop