'{$STAMP BS2} 'This is the sample program provided. 'It reads the voltage from two channels, alternating between them. CS CON 0 ' Chip select; 0 = active CLK CON 1 ' Clock to ADC; out on rising, in on falling edge. DIO_n CON 2 ' Data I/O pin _number_. config VAR Nib ' Configuration bits for ADC. AD VAR Word ' Variable to hold 12-bit AD result. startB VAR config.BIT0 ' Start bit for comm with ADC. sglDif VAR config.BIT1 ' Single-ended or differential mode. oddSign VAR config.BIT2 ' Channel selection. msbf VAR config.BIT3 ' Output 0s after data xfer complete. HIGH CS ' Deactivate ADC to begin. HIGH DIO_n ' Set data pin for first start bit. again: ' Main loop. FOR oddSign = 0 TO 1 ' Toggle between input channels. GOSUB convert ' Get data from ADC. DEBUG "channel ",DEC oddSign, ": ",DEC AD,CR ' Display data. PAUSE 500 ' Wait a half second. NEXT ' Change channels. GOTO again ' Endless loop. convert: config = config | %1011 ' Set all bits except oddSign. LOW CS ' Activate the ADC. SHIFTOUT DIO_n,CLK,LSBFIRST,[config\4] ' Send config bits. SHIFTIN DIO_n,CLK,MSBPOST,[AD\12] ' Get data bits. HIGH CS ' Deactivate the ADC. RETURN ' Return to program. RETURN ' Return to program.