Argh, won't let me add a comment.
Apparently I still hadn't understood how I'm supposed to set the register for IOCON.
Latest attempt, still no workie.
Code:#CONFIG __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF __config _CONFIG5, _CP_OFF & _CPD_OFF #ENDCONFIG DEFINE OSC 32 define CCP1_REG 0 ' Must clear unused CCP pins or else unpredictable results DEFINE CCP1_BIT 0 define CCP2_REG 0 DEFINE CCP2_BIT 0 DEFINE CCP3_REG PORTB DEFINE CCP3_BIT 5 define CCP4_REG 0 DEFINE CCP4_BIT 0 define CCP5_REG 0 DEFINE CCP5_BIT 0 ANSELA = %00000000 ANSELB = %00000000 ANSELC = %00000000 ANSELD = %00000000 ANSELE = %00000000 TRISA = %00000000 TRISB = %00000000 TRISC = %00000000 TRISD = %00000000 TRISE = %00001000 PinSCL2 VAR PortB.1 PinSDA2 VAR PortB.2 HPWM 3, 8, 1953 addr var byte : addr = %01000000 ' $40 IOCONAreg var byte : IOCONAreg = $0A ' Bank=0 IOCONBreg var byte : IOCONBreg = $0B ' Bank=0 IOCONdat var byte : IOCONdat = %00110000 ' Bank=0 'IOCONAreg var byte : IOCONAreg = $05 ' Bank=1 'IOCONBreg var byte : IOCONBreg = $15 ' Bank=1 'IOCONdat var byte : IOCONdat = %10110000 ' Bank=1 ' bit 7 0 = The registers associated with each port are separated into different banks. ' bit 6 0 = The INT pins are not connected. INTA is associated with PORTA and INTB is associated with PORTB ' bit 5 1 = Sequential operation disabled, address pointer does not increment. ' bit 4 1 = Slew rate disabled ' bit 3 0 = Disables the MCP23S17 address pins. ' bit 2 0 = Active driver output (INTPOL bit sets the polarity.) ' bit 1 0 = Active-low ' bit 0 Unimplemented: Read as ‘0’ I2CWRITE PinSDA2,PinSCL2,addr,IOCONAreg,[IOCONdat] I2CWRITE PinSDA2,PinSCL2,addr,IOCONBreg,[IOCONdat] IODIRAreg var byte : IODIRAreg = $00 ' Bank=0 'IODIRAreg var byte : IODIRAreg = $00 ' Bank=1 IODIRAdat var byte : IODIRAdat = %00000000 I2CWRITE PinSDA2,PinSCL2,addr,IODIRAreg,[IODIRAdat] 'set GPIOA all output IODIRBreg var byte : IODIRBreg = $01 ' Bank=0 'IODIRBreg var byte : IODIRBreg = $10 ' Bank=1 IODIRBdat var byte : IODIRBdat = %00000000 I2CWRITE PinSDA2,PinSCL2,addr,IODIRBreg,[IODIRBdat] 'set GPIOB all output OLATAreg var byte : OLATAdat var byte OLATBreg var byte : OLATBdat var byte LOOOP: OLATAreg = $14 : OLATAdat = %00000000 ' Bank=0 ' OLATAreg = $0A : OLATAdat = %00000000 ' Bank=1 I2CWRITE PinSDA2,PinSCL2,addr,OLATAreg,[OLATAdat] OLATBreg = $15 : OLATBdat = %00000000 ' Bank=0 ' OLATBreg = $1A : OLATBdat = %00000000 ' Bank=1 I2CWRITE PinSDA2,PinSCL2,addr,OLATBreg,[OLATBdat] pause 250 OLATAreg = $14 : OLATAdat = %11111111 ' Bank=0 ' OLATAreg = $0A : OLATAdat = %11111111 ' Bank=1 I2CWRITE PinSDA2,PinSCL2,addr,OLATAreg,[OLATAdat] OLATBreg = $15 : OLATBdat = %11111111 ' Bank=0 ' OLATBreg = $1A : OLATBdat = %11111111 ' Bank=1 I2CWRITE PinSDA2,PinSCL2,addr,OLATBreg,[OLATBdat] pause 250 GOTO LOOOP end





Bookmarks