Note that the sample program shown relates to sinking the current. The circuit this code is for has a common supply (PWM'd) to all the LEDS with the MCP23016 sinking to 0V to complete the circuit and turn on the LED.
Code:
'#################################################
'# For PICAXE-28X1, MCP23016 driving LEDS #
'#################################################
#picaxe 28x1
SetFreq m8
'#################################################
Init:
hi2csetup i2cmaster,%01000000,i2cfast_8,i2cbyte
'%0100 0 0 0 0 is the address with A0,A1,A2 all tied to 0V
'%0100 A2 A1 A0 RW - there is no explanation for the 6th bit being '1'
'If using multiple devices of different speeds on the bus,
'then use this line to change speed and remove the [%01000000] in the next line.
hi2cout [%01000000],6,($00,$00) 'IRDIR0,IRDIR1 set port direction register to output
'Note:- MCP23016 documentation indicates this register pair (06 & 07)
'defaults to all 1's (all Inputs) on Power On Reset.
'However if this register pair is not configured to all 0's (Outputs) there is no function when driving LEDS.
hi2cout $0A,($00,$00) 'IOCON0
IO_1:
hi2cout 0,(%01010101,%01010101) 'GPO,GP1 Turn on each alternate output
'A '0' bit to register 0 will turn ON current sink and a '1' will reverse to a current source
'i.e. the port is not actually turned on or off but rather it's direction is reversed
pause 1250
hi2cout 0,(%10101010,%10101010)
pause 250
hi2cout 0,(%01010101,%01010101)
pause 1250
hi2cout 0,(%10101010,%10101010)
pause 250
Goto IO_1 'Loop
Last edited: