News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Help MCP23017

Started by Giuseppe MPO, Mar 07, 2021, 07:16 PM

Previous topic - Next topic

Giuseppe MPO


Hi,
maybe I'm too hard on my head, but I'm fighting with an MPC23017 and, so far I'm defeated.
The hardware connection has no problems because some answers from the chip come to me,
but I can't understand how it works to set the various input and output pins and then use them.
Can anyone help me with a little piece of code?

John Drew

Towlerg wrote some code to have a MCP23017 drive a LCD. I have a copy of that if it is of any interest.
Bit pressed for time at present. I can probably help if in no hurry.
John

SCV

If you post your code and a brief description of what you are trying to achieve, it would help us to help you.
Never used the MCP23017, but looks easy enough.

Tim.

Giuseppe MPO

I don't have a specific application, I was just trying to understand and test the operation of a MCP23017,
I simply put 8 LEDs on Port A and 8 switches on Port B.
In any case I solved, I did not understand the access to the registers,
now my little test program works perfectly.

Thank you


TRISC = %00000000

LATC.5 = 1
DelayMS 1000

$define I2C_SCL_Pin PORTC.3
$define I2C_SDA_Pin PORTC.4

Dim Var1 As Byte
Dim Var2 As Byte
Dim Ctrl As Byte

Symbol SDA = PORTC.4
Symbol SCL = PORTC.3

Ctrl = $40
Var1 = 0

I2COut SDA,SCL,Ctrl,0,[0x00] ' Porta A OUT
I2COut SDA,SCL,Ctrl,1,[0xFF] ' Porta B INP

Main: While
I2COut SDA, SCL, Ctrl,18, [Var1] ' Scrittura Porta A
I2CIn SDA, SCL, Ctrl,19, [Var2] ' Lettura Porta B
Inc Var1
HSerOut [Dec Var2,13]
DelayMS 500
NoCrt: Wend

John Drew

Great AGB. It's always better to solve a problem yourself, we learn more that way.
Cheers
John