Specifications
BASIC Stamp II Application Notes
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 357
2
' lines of the '595, pauses, then increments counter and repeats.
' The data is shifted msb first so that the most-significant bit is
' shifted to the end of the shift register, pin QH, and the least-
' significant bit is shifted to QA. Changing 'msbfirst' to 'lsbfirst'
' causes the data to appear backwards on the outputs of the '595.
' Note that the number of bits is _not_ specified after the variable
' in the instruction, since it's eight, the default.
Again:
Shiftout DataP,Clock,msbfirst,[counter] ' Send the bits.
pulsout Latch,1 ' Transfer to outputs.
pause 50 ' Wait briefly.
counter = counter+1 ' Increment counter.
goto Again ' Do it again.
' LISTING 2. SHIFTIN FROM ADC0831
' Program: ADC0831.BS2
' This program demonstrates the use of the BS2's new Shiftin instruction
' for interfacing with the Microwire interface of the Nat'l Semiconductor
' ADC0831 8-bit analog-to-digital converter. It uses the same connections
' shown in the BS1 app note.
ADres var byte ' A-to-D result: one byte.
CS con 0 ' Chip select is pin 0.
AData con 1 ' ADC data output is pin 1.
CLK con 2 ' Clock is pin 2.
high CS ' Deselect ADC to start.
' In the loop below, just three lines of code are required to read
' the ADC0831. The Shiftin instruction does most of the work. Shiftin
' requires you to specify a data pin and clock pin (AData, CLK), a
' mode (msbpost), a variable (ADres), and a number of bits (9). The
' mode specifies msb or lsb-first and whether to sample data before
' or after the clock. In this case, we chose msb-first, post-clock.
' The ADC0831 precedes its data output with a dummy bit, which we
' take care of by specifying 9 bits of data instead of 8.
again:
low CS ' Activate the ADC0831.
shiftin AData,CLK,msbpost,[ADres\9] ' Shift in the data.
high CS ' Deactivate '0831.
debug ? ADres ' Show us the conversion result.
pause 1000 ' Wait a second.
goto again ' Do it again.
2: Using Shiftin & Shiftout










