Hey Dave, thanks man
you were right i made that mistake and i looked over and i couldn't catch it, you are having good eyes (i fixed it now).
but still there is no success. even i copy you code and deleted you usb codes line and compile it but i could not get it to work.
I connect all three address pin for my MCP to ground
I pulled up mcp reset pin with a 15K R
I pulled up SDA and SCL pin with two 1k R
portc.3 is my clock and portc.4 is my data
portc.7 is connected to an led just for test, so i know where i am in the program
and this is my codes
again thanks for your time
'* Notes : *
'* : *
'************************************************* ***************
'Includes
include "modedefs.bas"
'************************************************* ***************
'Definitions
DEFINE I2C_SDA PORTc,4
DEFINE I2C_SCL PORTc,3
define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50
'************************************************* ***************
'Variables
A var byte
Chip1 var byte
POT1 var word
POT2 var word
'************************************************* ***************
'Alias
CP VAR PORTc.3
DP VAR PORTc.4
'************************************************* ***************
'Initialization
'Pic 16f877A
adcon1=$02 'left justify A0 and A1
CCP1CON=0 'disable capture/compare
CCP2CON=0
CMCON=7 'disable comparater
option_reg.7=0 'portb pullups enabled
'set ports
trisa=%11111111
trisb=%00000000
trisc=%00000000
trisd=%00000000
'MCP 23017
chip1 = $40
IODIRA con $FF ' port A output
IODIRB con $FF ' port B output
IOCON con $3C ' Defining the MCP Bank as 0 and sequential disable
MCPA con $12
MCPB con $13
MCPAL con $14
MCPBL con $15
'Initialing MCP
i2cwrite dp,cp,$0A,chip1,[iocon]
i2cwrite dp,cp,$0B,chip1,[iocon]
i2cwrite dp,cp,$00,chip1,[iodira]
i2cwrite dp,cp,$01,chip1,[iodirb]
'IODIRA Con $00
'IODIRB con $00
'IPOLA con $00
'IPOLB con $00
'GPINTENA con $00
'GPINTENB con $00
'DEFVALA con $00
'DEFVALB con $00
'INTCONA con $00
'INTCONB con $FF
'IOCON con %00001000
'GPPUA con $00
'GPPUB con $00
'INTFA con $00
'INTFB con $00
'INTCAPA con $00
'INTCAPB con $00
'GPIOA con $00
'GPIOB Con $FF
'OLATA con $00
'OLATB con $FF)
'************************************************* **************
'Main Program
start:
portd =$00
portc.7=0
pause 500
portd = $ff
portc.7=1
pause 500
portc.7=0
pause 500
'I2CWRITE DataPin,ClockPin,Control,{Address,}[Value{,Value...}]{,Label}
I2CWRITE dp,cp,mcpa,chip1,[$FF] 'porta on
portc.7=1
pause 200
I2CWRITE dp,cp,mcpa,chip1,[$00] 'porta off
portc.7=0
pause 200
I2CWRITE dp,cp,mcpal,chip1,[$FF] 'porta on
portc.7=1
pause 200
I2CWRITE dp,cp,mcpal,chip1,[$00] 'porta off
portc.7=0
pause 200
I2CWRITE dp,cp,mcpb,chip1,[$FF] 'portb on
portc.7=1
pause 200
I2CWRITE dp,cp,mcpb,chip1,[$00] 'portb off
portc.7=0
pause 200
I2CWRITE dp,cp,mcpbl,chip1,[$FF] 'portb on
portc.7=1
pause 200
I2CWRITE dp,cp,mcpbl,chip1,[$00] 'portb off
portc.7=0
pause 200
goto start
end
Bookmarks