' {$STAMP BS2} ' {$PBASIC 2.5} xp VAR Byte channel VAR Byte Readysingal CON 0 Chsel VAR Byte 'channel select ADCin VAR Word 'ADC reading X VAR Nib N9600 CON $4054 '9600 baud cs CON 11 'enable or disable A to D converter serDo CON 12 'serial data out p2 serDin CON 13 'serial data in p3 serclk CON 14 'serial Clock p4 'Software Handshaking Connection: SEROUT 16,84,[DEC 1,LF] SERIN 17,84,[DEC xp] IF xp <> (Readysingal) THEN Connection Main: SERIN 17,84,[DEC channel] IF (channel >7) THEN Shutdown LOW cs 'enable ADC LOOKUP channel, [142, 206,158,222,170,170,190,254],chsel ' Demical Resprentation of the binary code sent to the ADC 'See maunual of MAX186 to under what the commands are SHIFTOUT serDo, serclk, MSBFIRST,[chsel] 'send the channel data SHIFTIN serDin, serclk, MSBPOST ,[ADCin\12] 'the reading HIGH cs 'disable ADC SEROUT 16, 84, [DEC ADCin DIG 3,".", DEC ADCin DIG 2, DEC ADCin DIG 1, DEC ADCin DIG 0,LF ] 'print results to Matlab ' SEROUT 16, 84, [DEC4 ADCin] this line can be used instead if the perivous line presents formating error for Matlab 'Result will just be divided by 1000 in Matlab to get proper number HIGH cs 'disable GOTO Main END Shutdown: HIGH cs 'disable SEROUT 16, 84, ["Shutdown ",CR,LF] END END