Shop OBEX P1 Docs P2 Docs Learn Events
Converting BS1 to BS2SX code — Parallax Forums

Converting BS1 to BS2SX code

Mike VR6Mike VR6 Posts: 1
edited 2004-12-08 01:41 in Learn with BlocklyProp
Hi, I am trying to run a piece of code, given in the applications PDF.· It is designed to use a Serial 8 bit ADC to to measurements from a potentiometer.· How do I translate the given code (In BS1) to BS2SX?· Is there any programs that are desgined to do this for me?· Thanks!

This is the code, designed for BS1:
' PROGRAM: ad_conv.bas
' BASIC Stamp program that uses the National ADC0831 to acquire analog data and
' output it via RS-232.
Symbol CS = 0
Symbol AD = pin1
Symbol CLK = 2
Symbol S_out = 3
Symbol data = b0
Symbol i = b2
setup: let pins = 255 ' Pins high (deselect ADC).
let dirs = %11111101 ' S_out, CLK, CS outputs; AD
' input.
loop: gosub conv ' Get the data.
serout S_out,N2400,(#b0,13,10) ' Send data followed by a return
' and linefeed.
pause 2000 ' Wait 2 seconds
goto loop ' Do it forever.
low CLK ' Put clock line in starting state.
low CS ' Select ADC.
pulsout CLK, 1 ' 10 us clock pulse.
let data = 0 ' Clear data.
for i = 1 to 8 ' Eight data bits.
let data = data * 2 ' Perform shift left.
pulsout CLK, 1 ' 10 us clock pulse.
let data = data + AD ' Put bit in LSB of data.
next ' Do it again.
high CS ' Deselect ADC when done.
return


Comments

Sign In or Register to comment.