Arniepj - Tried your code and am now actually able to get a reading!!! It is off by about 200 mV but it might be because I am using a 4.096 Vref reference (were you using one?). I will play with this a little more to tweek it so that it is accurate and post the final code. What I have now that works is posted below. The other thing that I changed based on your code was going from an external to internal clock on the Control Byte for the chip.

Thanks a million!!!

(and thanks to you too, Steve!)


' Set compiler to use HS (20 mHz)
@ DEVICE HS_OSC
DEFINE OSC 20 'resonator frequency at 20 Mhz
ADCON1 = 7 ' Disable PORTA Analog

' Define the LCD Hookup parameters
' data pins D4-D7 are hooked to pins C.0-C.3, respectively
define LCD_DREG PORTC 'Data Port = PORTC
define LCD_DBIT 0 'Data starting bit = 0
define LCD_RSREG PORTC 'Register Select Port = PORTC
define LCD_RSBIT 4 'RS bit = PortC.4
define LCD_EREG PORTC 'Enable Port = PORTC
Define LCD_EBIT 5 'Enable Bit = PortC.5
define LCD_BITS 4 'LCD Bus Size = 4
define LCD_LINES 2 'Number of lines on LCD

Pause 1000 ' Wait for LCD to startup
Lcdout $fe, $80, "MAX1247"
lcdout $fe, $C0, "Example"
pause 1000
Lcdout $FE, 1 ' Clear LCD screen

'Variables for ADC
CB var byte
CB0 var Byte
CB1 var Byte
CB2 var Byte
CB3 var Byte

'Control Byte Setup:
' Bit 7: Start Bit = 1
' Bit 6: Channel Select Bit 2 (SEL2) -See Channel Selection Below
' Bit 5: SEL1
' Bit 4: SEL0
' Bit 3: UNI/BIP - 1=Unipolar 0=Bipolar
' Bit 2: SNGL/DIF - 1=Single Ended 0=Differential
' Bit 1: PD1 - Sets clock and power down mode
' Bit 0: PD0 - Sets clock and power down mode
' 00 - full power down
' 01 - fast power down
' 10 - internal clock mode
' 11 - external clock mode

'Channel Selection:
' SEL2 SEL1 SEL0
'CH0 0 0 1
'CH1 1 0 1
'CH2 0 1 0
'CH3 1 1 0

' To read channel 0 in Unipolar, single ended, internal clock mode,
' Control Byte (CB) = 10011110
CB0 = %10011110 'To read Channel 0
CB1 = %11011110 'To read Channel 1
CB2 = %10101110 'To read Channel 2
CB3 = %11101110 'To read Channel 3

' Set up MAX1247 4-channel 12-bit ADC
CLKpin var PORTA.0 'SPI clock pin
CSpin var PORTA.1 'DAC chip select
DINpin var PORTA.2 'Data in pin
DOUTpin var PORTA.3 'Data Out Pin

'set up Max1247 pins
TRISA.0 = 0 'CLKpin as output
TRISA.1 = 0 'CSpin as output
TRISA.2 = 0 'DIpin as output
TRISA.3 = 1 'DOpin as input

' ******** Declarations *******************************
Voltage1 var word
Voltage2 var word
Voltage3 var word
Voltage4 var word
SerialDataOut var byte ' Serial data out to Max1247 A/D
SerialDataIn var word ' Serial data in from Max1247 A/D
Indexer var byte ' Loop indexer for data in

' ********* Presets ****************************
SerialDataOut = cb0
SerialDataIn = 0
clkpin = 0 ' Clock signal
cspin = 0 ' Chip select: low selects
dinpin = 0 ' Serial data out
doutpin = 0 ' Serial data in

'******Main Program ********************************
DataOut:
gosub DataAcquisition 'Read data from Max1247
Voltage1 = SerialDataIn * 2 ' Convert data to voltage
Voltage2 = (SerialDataIn * 4)/10 ' Convert data to voltage
Voltage3 = (SerialDataIn * 4)/100 ' Convert data to voltage
Voltage4 = Voltage1 + Voltage2 + Voltage3 + 9 ' Convert data to voltage
lcdout $FE, $80, #Voltage4, " " ' Display data
SerialDataIn = 0
goto Dataout

'************ Data Acquisition ***************************
DataAcquisition:
for Indexer = 7 to 0 step -1 ' Output data,8 clock pulses
dinpin = SerialDataOut.0[Indexer] ' Output data port
pulsout clkpin,5 ' Output clock pulse
next Indexer ' Next data bit,next clock pulse

for Indexer = 1 to 12 ' Read data,12 clock pulses
SerialDataIn = SerialDataIn * 2 ' Shift each bit to the left
SerialDataIn = SerialDataIn + doutpin ' Data in port
pulsout clkpin,5 ' Output clock pulse
next Indexer ' Next data bit,next clock pulse

return

end