This is a trimmed down version of my code. And frankly, nothing is working. I'm not a hardware guy, so I can't tell if my setup is wired wrong. The guy I work with put it together for me. He's a professional so I'm not going to doubt him. But something, somewhere, isn't working.
Code:
;@ __CONFIG _HS_OSC & _WDT_OFF
DEFINE OSC 20
DEFINE ADC_BITS 10 '10-bit ADC
DEFINE I2C_SLOW 1
' Define used register flags
SSPIF VAR PIR1.3 ' SSP (I2C) interrupt flag
BF VAR SSPSTAT.0 ' SSP (I2C) Buffer Full
R_W VAR SSPSTAT.2 ' SSP (I2C) Read/Write
D_A VAR SSPSTAT.5 ' SSP (I2C) Data/Address
CKP VAR SSPCON.4 ' SSP (I2C) SCK Release Control
SSPEN VAR SSPCON.5 ' SSP (I2C) Enable
SSPOV VAR SSPCON.6 ' SSP (I2C) Receive Overflow Indicator
WCOL VAR SSPCON.7 ' SSP (I2C) Write Collision Detect
ADCGO VAR ADCON0.2 ' ADC GO /DONE bit: High to start. Automatically goes low when finished.
' Define constants
I2Caddress CON $12 * 2 ' Make our address twice the actual address (bit shifted left)
BUFFERSIZE CON $10 ' 16 Word addresses
BUFFERTOP CON BUFFERSIZE - 1 ' Top of Buffer
DATASIZE CON 20
' Allocate RAM
modLevel VAR WORD[BUFFERSIZE]' Modulation Level '32
dataout VAR BYTE[2] ' Data out array '18
result VAR WORD ' ADC result '2
Counter VAR BYTE ' Counter for Arrays '1
Iter VAR BYTE ' Generic Iterator '1
compHi VAR WORD ' Comparison Hi Value '2
compLo VAR WORD ' Comparison Lo Value '2
TempWord VAR WORD ' Swap Variable
' Initialize ports and directions
ADCON0 = $81 ' Clock /32
ADCON1 = $81 ' PORTA.0 analog
' TRISB.1 = 1 ' Pin for SDA
' TRISB.4 = 1 ' Pin for SCL
TRISB.1 = 0 ' Pin for SDA
TRISB.4 = 0 ' Pin for SCL
TRISA.2 = 1 ' Pin RA.2 for AN2
TRISA.3 = 0
TRISA.4 = 0
mainloop: ' Main program loop
'/////////////////////////////////////////////////////////////////////////////
'This is the portion I'm testing out
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
result = 512
result = result << 2
I2CWRITE PORTB.1, PORTB.4, $9C, [result.HIGHBYTE, result.LOWBYTE]
loopforfun:
GOTO loopforfun
'//////////////////////////////////////////////////////////////////////////////
Bookmarks