'__Free running ADC to serial output (c) P J Finch April 1997____________ Rx VAR IN0 ' IN pin0 RS232 received data Tx CON 1 ' OUT pin1 RS232 transmitted data RTS VAR IN2 ' IN pin2 RS232 RTS flow control CTS CON 3 ' OUT pin3 RS232 CTS flow control SCLK CON 9 ' OUT pin9 MAX186 serial clock input CS CON 10 ' OUT pin10 MAX186 chip select line DIN CON 11 ' OUT pin11 MAX186 serial data input SSTRB VAR IN12 ' IN pin12 MAX186 conversion status flag DOUT CON 13 ' IN pin13 MAX186 serial data Result VAR word ' 12 bit ADC result word Control VAR byte ' Control byte for MAX186 Channel VAR byte ' Analog input channel lo VAR byte ' Low byte of Result word hi VAR byte ' High byte of Result word '__Main__________________________________________________________________ DIRH=%00001111 ' p15-12=input, p11-8=output DIRL=%10011010 ' p7,4,3,1=output, p6,5,2,0=input high CS ' Start with a blank sheet low SCLK ' not CS and SCLK low checkcom: low CTS ' assert CTS low - linked to RTS on plug if RTS=1 then checkcom ' RTS high - no plug present loop: gosub acquire gosub send goto loop '__Acquire________________________________________________________________ Acquire: for Channel = 0 to 7 gosub A2DC write Channel*2,Result/256 write Channel*2+1,Result&255 next return '__Send___________________________________________________________________ Send: for Channel= 0 to 7 read Channel*2,hi read Channel*2+1,lo Result=256*hi + lo if Result>$800 then neg 'Positive number serout Tx, 32+$4000,[dec Result] goto either neg: 'Negative number serout Tx, 32+$4000,["-", dec 4096-Result] either: if Channel=7 then skpcom serout Tx, 32+$4000,[","] skpcom: next serout Tx, 32+$4000,[13,10] return '__A2DC___________________________________________________________________ A2DC: ' Control=1xxx1110, where xxx=channel : MAX186 Control byte ' 1 XXX 0 1 10 ' start, channel #, bipolar, single-ended, internal clock ' xxx = channel.bits 021 Control = %10000110 | ((Channel & %110) << 3) | ((Channel & %1) << 6) low CS ' Activate MAX186 'Clock out Control byte shiftout DIN, SCLK, MSBFIRST, [Control\8] EOC: ' Wait for end of conversion if SSTRB=0 then EOC 'Clock in 12 bits of Result Result=0 shiftin DOUT, SCLK, MSBPOST, [Result\12] high CS ' Deactivate MAX186 return '_________________________________________________________________________