Thanks, i'll try MCP23017.
I know what going on wrong with the code...
3 things been observed :
1. I do not put "$" to determine the address in HEX
2. Before initializing MCP23016, it need to have short delay ( i use 50ms ) otherwise the whole program will not work.
3. The code should be I2CWrite SDA,SCL,Address,CtrlDir1,[00] not I2CWrite SDA,SCL,CtrlDir1,Address,[00]. This is confusing because the manual shows the address come after Control, but it does not work.
It works fine after the correction.
I need help to evaluate my second code.
I use GP1 as input and GP0 as output.
However this is what happened :
Input Triggered | Output Respond
----------------+-----------------
GP1.0 | No Respond
GP1.1 | GP0.0
GP1.2 | GP0.1
GP1.3 | GP0.2
GP1.4 | GP0.3
GP1.5 | GP0.4
GP1.6 | GP0.5
GP1.7 | GP0.6
GP0.7 never respond at all.
Anyone can help ?
Code:
INCLUDE "modedefs.bas"
'*****STARTUP*****************************************************************
TRISA=%00000
TRISB=%00000000
'*****PORT Setup**************************************************************
SDA VAR PORTA.1 'O Serial Data
SCL VAR PORTA.2 'O Serial Clock
'*****Constant****************************************************************
CtrlRW1 CON 00 'Set1
CtrlRW2 CON 01 'Set2
CtrlDir1 CON 06 'Set1
CtrlDir2 CON 07 'Set2
'**VARIABLES******************************************************************
Address VAR BYTE 'Address size
Set VAR BYTE 'Temporary place to put Data
Address=$40 'Set MCP23016 address as 01
Set=$00 'Clear Temporary Storage
'*****INITIALIZING MCP23016 **************************************************
Pause 50
I2CWrite SDA,SCL,Address,CtrlDir1,[00] 'Set as Output
Pause 10 'Delay 10ms
I2CWrite SDA,SCL,Address,CtrlDir2,[$FF] 'Set as Input
Pause 10 'Delay 10ms
Start :
I2CRead SDA,SCL,Address,CtrlRW2,[Set] 'Read from input, put in Set
Pause 10 'Delay 10ms
I2CWrite SDA,SCL,Address,CtrlRW1,[Set] 'Write data into Set
Pause 10 'Delay 10ms
GoTo Start
Bookmarks