Hello,
OK I managed to contact the MCP23017en I2C.
For now, the test program the LED lights of the 2 ports following a counter made by the software in the 16F877.
I have a small question.
When feeds it off, the LED of port B are all lit and the rest for + / - 30sec (while the PIC is running without problem) and then everything works normally.
If I reflash the PIC everything is OK, the problem happens only when switched on.
As if it would take some time for it to MCP23017 syncronise with I2C.
Here is the code used
adcon1=7 'pour que les entrées analogique du port A soient digitale
trisa=0 'pour que RA3 soit une entrée et les autres des sorties
trisb=0 'pour que tout le port B soit des entrées
trisc=0 'pour que tout le port C soit des entrées
'initialisation de LCD
'debut code specifique 877
DEFINE LCD_DREG PORTD 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTD 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit
DEFINE LCD_EREG PORTD 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD '
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us
'***definition des variable pour I2C***
DEFINE I2C_HOLD 1
DEFINE I2C_SCLOUT 1
define I2C_SDA PORTa.0
DEFINE I2C_SCL PORTa.1
Define I2C_SLOW 1 'At this clock speed this needed to be added to make it work.
sda var porta.0 'sda est sur le porta.0
scl var porta.1 'scl est sur le porta.1
Addr var byte
j var byte
i var byte
'================================================= =====================================
'************* DEFINITION DU PORT A ET DU PORT B ***************
' Port A Registers (8 Bit Mode)
IODIRA con $00 ' Port A Direction Bit Control Reg (suivant datasheet)
IOLATA con $0A ' Output Latch Reg (suivant datasheet)
'Port B Registers (8 Bit Mode)
IODIRB con $10 ' Port B Direction Bit Control AReg (suivant datasheet)
IOLATB con $1A ' Output Latch Reg (suivant datasheet)
debut:
lcdout $FE,1, "TEST MCP23017 " ;affichage ecran acceuil
lcdout $FE,$C0, "V 1.3" ;affichage ecran acceuil
pause 1000 ;pause pour ecran acceuil
i2cwrite sda,scl,$40,[IODIRA,0]
i2cwrite sda,scl,$40,[IODIRb,0]
pause 100
'i2cwrite sda,scl,$40,[Ipola,255]
lcdout $FE,1, "Debut"
for i=1 to 255
i2cwrite sda,scl,$40,[iolata,i]
i2cwrite sda,scl,$40,[iolatb,i]
lcdout $FE,$C0,"i=",#i
pause 100
next i
lcdout $FE,1, "Fin"
goto debut
end
Thank you for your help
Claudy
Bookmarks