Question about the SHIFTOUT expression
Buck Rogers
Posts: 2,187
in BASIC Stamp
Hello!
I'm in the process of constructing one of my 'gee-wiz' contraptions and I'm wondering about something, the end result of it is to display the receiving activity on a 2 line display, (The Parallax one). But the part is supposed to be receiving data sent to it from the stamp via that expression. I had thought of including this code:
' SHIFTOUT.BS2 ' This program uses the SHIFTOUT command to interface to the 74HC595 shift ' register as an 8-bit output port. The '595 requires a minimum of three ' inputs: data, clock, and latch. See the figure in the SHIFTOUT command ' description in the manual for wiring information. SHIFTOUT automatically ' handles the data and clock, pulsing the clock to shift data bits into the ' '595. An extra step (pulsing the latch input) is required to move the ' shifted bits in parallel onto the '595's output pins. Note: this code does ' not control the output-enable or reset lines of the '595. This means that ' before the BASIC Stamp first sends, the '595's output latches are turned ' on and may contain random data. In critical applications, you should hold ' output-enable high (disabled) until the BASIC Stamp can take control. ' {$STAMP BS2} ' {$PBASIC 2.5} Dpin PIN 0 ' data pin to 74HC595 Clk PIN 1 ' shift clock to 74HC595 Latch PIN 2 ' latch 74HC595 outputs counter VAR Byte Setup: LOW Latch ' initialize latch output ' This loop moves the 8-bit value 'counter' onto the output lines of the ' '595, pauses, then increments counter and repeats. The data is shifted ' MSB first so that the MSB appears on pin QH and the lsb on QA. Changing ' MSBFIRST to LSBFIRST causes the data to appear backwards on the outputs. Main: DO SHIFTOUT Dpin, Clk, MSBFIRST, [counter] ' send the bits PULSOUT Latch, 1 ' transfer to outputs PAUSE 100 ' Wait 0.1 seconds counter = counter + 1 ' increment counter LOOP END
Or at least the relevant parts, it would be stuffed in between the code that does the sample gathering from the part in question, one of my programmed PAL chips, that blob would send stuff into the part via the selected shift register. The sample gathering stuff I can post on request.
Mascot away.
Comments
Hello!
Okay as promised here since someone will ask, is both of the ones that I know work. First one up:
That one was the second of the sixth series of programs. Next is the final and seventh:
And those are it. I'm still doing the proverbial pacing about, and stuff to ponder how to insert that shift function into the middle of either one.
Mascot still away.
Why not put that SHIFTOUT code into a subroutine? With the BS2, you're forced to use a global value to send, so give it a reasonable name.
In the body of your code you'd do this:
Of course, the 10 would be replaced by a value that comes out of the body of your program.
Buck,
StampWorks is always a good reference.
https://www.parallax.com/package/stampworks-experiment-kit-manual-and-code/
Experiment #23 on page 140 of the PDF uses the 595.
I assume P15 is a Parallax Serial LCD.
What is on P12, P13, and P14?
It's better to name the I/O pins that just use their numbers.
I agree!
Hello!
Normally yes. However I believe I wrote the entire series of which they are the last ones, during an overnight programming run, normally I do name those pins. Typically Twelve is optional, Thirteen and Fourteen are input lines. However I ended up tracking down and buying a serial port device from Micro Center, and am now sending it to a Palm Pilot using an app written by a (sadly now closed) outfit over in an area of Illinois that's roughly in the area where Chicago is.
Buck,
I honestly think the Propeller (1) is the best choice for you, since it can easily support multiple serial devices at once and even provide a simple User Interface.
https://www.parallax.com/package/an013-gui-graphics-series-menus-and-messaging-with-the-propeller-window-manager-framework/