Shop OBEX P1 Docs P2 Docs Learn Events
Question about the SHIFTOUT expression — Parallax Forums

Question about the SHIFTOUT expression

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

  • Buck RogersBuck Rogers Posts: 2,185
    edited 2024-08-26 11:15

    Hello!
    Okay as promised here since someone will ask, is both of the ones that I know work. First one up:

    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
     T2400       CON     396
     T9600       CON     84
     T19K2       CON     32
    LcdBaud CON T2400
    
    'TX  PIN 15
    
    
    'PL0  PIN     0    '
    'PL1  PIN     1    '
    LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
    LcdBLon         CON     $11             ' backlight on
    LcdBLoff        CON     $12             ' backlight off
    LcdOff          CON     $15             ' LCD off
    LcdOn1          CON     $16             ' LCD on; cursor off, blink off
    LcdOn2          CON     $17             ' LCD on; cursor off, blink on
    LcdOn3          CON     $18             ' LCD on; cursor on, blink off
    LcdOn4          CON     $19             ' LCD on; cursor on, blink on
    '
    '
      X VAR Word
      Z VAR Word
      Z1 VAR Word
      Z2 VAR Word
      X2 VAR Word
    SEROUT 15, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
    
     PAUSE 5
    
    'FOR X=1 TO 192
    SERIN 14, LcdBaud, [Z]
    'DEBUG Z, X
    SEROUT 12, LcdBaud, [Z]
    SEROUT 15, LcdBaud, [Z]
    'PULSOUT 14,50
    'PULSOUT 14, X
    SEROUT 15, LcdBaud, [X]
    SEROUT 12, LcdBaud, [X]
    'PAUSE 250
    Z1=Z -128
    X2=Z1 +128
    SERIN 14, LcdBaud, [Z]
    SERIN 13, LcdBaud, [Z2]
    SEROUT 12, LcdBaud, [Z1]
    SEROUT 15, LcdBaud, [Z1]
    SEROUT 12, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [Z]
    
    'DEBUG Z1, X
    'NEXT
    

    That one was the second of the sixth series of programs. Next is the final and seventh:

    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
     T2400       CON     396
     T9600       CON     84
     T19K2       CON     32
    LcdBaud CON T2400
    
    'TX  PIN 15
    
    
    'PL0  PIN     0    '
    'PL1  PIN     1    '
    LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
    LcdBLon         CON     $11             ' backlight on
    LcdBLoff        CON     $12             ' backlight off
    LcdOff          CON     $15             ' LCD off
    LcdOn1          CON     $16             ' LCD on; cursor off, blink off
    LcdOn2          CON     $17             ' LCD on; cursor off, blink on
    LcdOn3          CON     $18             ' LCD on; cursor on, blink off
    LcdOn4          CON     $19             ' LCD on; cursor on, blink on
    '
    '
      X VAR Word
      Z VAR Word
      Z1 VAR Word
      Z2 VAR Word
      X2 VAR Word
    SEROUT 15, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
    
     PAUSE 5
    
    'FOR X=1 TO 192
    SERIN 14, LcdBaud, [Z]
    'DEBUG Z, X
    SEROUT 12, LcdBaud, [Z]
    SEROUT 15, LcdBaud, [Z]
    'PULSOUT 14,50
    'PULSOUT 14, X
    SEROUT 15, LcdBaud, [X]
    SEROUT 12, LcdBaud, [X]
    'PAUSE 250
    Z1=Z -128
    X2=Z1 +128
    SERIN 14, LcdBaud, [Z]
    SERIN 13, LcdBaud, [Z2]
    SEROUT 12, LcdBaud, [Z1]
    SEROUT 15, LcdBaud, [Z1]
    SEROUT 12, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [Z]
    
    'DEBUG Z1, X
    'NEXT
    

    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.

  • JonnyMacJonnyMac Posts: 9,101
    edited 2024-09-09 15:54

    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.

    Shift_It:
      SHIFTOUT DPin, SClk, MSBFIRST, [soValue]
      PULSOUT Latch, 1
      RETURN
    

    In the body of your code you'd do this:

      soValue = 10
      GOSUB Shift_It
    

    Of course, the 10 would be replaced by a value that comes out of the body of your program.

  • GenetixGenetix Posts: 1,754

    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.

    ' Define I/O Pins
    SerialLCD PIN 15
    Something1 PIN 12
    Something2 PIN 13
    Something3 PIN 14
    
  • JonnyMacJonnyMac Posts: 9,101

    StampWorks is always a good reference.

    I agree! :D

  • @Genetix said:
    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.

    ' Define I/O Pins
    SerialLCD PIN 15
    Something1 PIN 12
    Something2 PIN 13
    Something3 PIN 14
    

    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.

  • GenetixGenetix Posts: 1,754

    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/

Sign In or Register to comment.