Shop OBEX P1 Docs P2 Docs Learn Events
SX/B SHIFTOUT - Multiple data in one command? — Parallax Forums

SX/B SHIFTOUT - Multiple data in one command?

John KauffmanJohn Kauffman Posts: 653
edited 2007-08-07 00:33 in General Discussion
SX/B SHIFTOUT - Multiple data in one command
·
Is there a way in SX/B to have SHIFTOUT send multiple values?
·
PBASIC has option for multiple [noparse][[/noparse]OutputData {\Bits}
SHIFTOUT Dpin, Cpin, Mode, [noparse][[/noparse]OutputData {\Bits} {,OutputData {\Bits}...}]

SX/B seems to not have that option
SHIFTOUT DPin, CPin, ShiftMode, Value {\Count} {, SpeedMult}
·
I searched Parallax site for SX/B “shiftout multiple values” and got no applicable results.
(The SX/B {\Count} provides for sending other then 8 bits, but that is not the question.)
·
Specifically, what is the best way to translate the following PBASIC to SX/B?
SHIFTOUT PinData, PinClock, LSBFIRST, Datum1, Datum2, Datum3, Datum4

Thanks.
·
·

Comments

  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-06 10:25
    I asked about that a·while ago. It is set up for the BS2 but it appears that you need separate statements for SX/B.
  • BeanBean Posts: 8,129
    edited 2007-08-06 11:09
    John,
    This is similar to SEROUT in SX/B. Only one byte at a time.
    The best way to handle this is to make a subroutine to do the SHIFTOUT. Then call the subroutine for each byte that needs sent.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-06 11:31
    John,
    As Bean stated use subroutines like these for SEROUT but modify them for SHIFTOUT.


    'example to a Serial LCD
    

    TxPin  VAR RA.2  ' RA.2 pin used for Serial LCD
    

    Baud19200 CON "T19200"  ' Baud rate = 19200 - SW1 ON, SW2 ON
    

    ' ---------------------------------------------------
    ' Variables
    ' ---------------------------------------------------
    

    tmpB1  VAR Byte  ' work variables
    tmpB2  VAR Byte
    tmpB3  VAR Byte
    tmpB4  VAR Byte
    tmpW1  VAR Word
     
    PROGRAM Start
     
    ' -----------------------------------------------
    ' Subroutine Declarations
    ' -----------------------------------------------
    TX_BYTE  SUB  1, 2    ' transmit byte
    TX_STR   SUB  2, 4    ' transmit string
    Cents_Char1 SUB 0   ' Custom LCD character 1 (Cents Symbol)
    
     
    ' ------------------------------------------------
    ' Program Code
    ' ------------------------------------------------
    
     
    Start:
     
    'Initialize here
    HIGH TxPin
    PAUSE 100
    
     
     
    Main: 
     
    TX_STR LCD_CurOff
    TX_STR LCD_LightOn
    TX_STR LCD_CLS
    TX_STR "    50" 
    Cents_Char1
    TX_STR " Piece"
    TX_STR LCD_Cr
    TX_STR "Total = $"
    'More code....
     
    END
     
     
    ' ---------------------------------------------------
     
    ' Use: TX_BYTE theByte {, count}
    ' -- transmit "theByte" at "Baud19200" on "TxPin"
    ' -- optional "count" may be specified (must be > 0)
    SUB TX_BYTE
      tmpB1 = __PARAM1 ' save byte
      IF __PARAMCNT = 1 THEN ' if no count
      tmpB2 = 1 ' set to 1
      ELSE ' otherwise
      tmpB2 = __PARAM2 ' get count
      IF tmpB2 = 0 THEN ' do not allow 0
      tmpB2 = 1
      ENDIF
      ENDIF
      DO WHILE tmpB2 > 0 ' loop through count
        SEROUT TxPin, Baud19200, tmpB1 ' send the byte
        DEC tmpB2 ' decrement count
      LOOP
      ENDSUB
     
    ' ---------------------------------------------------
     
    ' Use: TX_STR [noparse][[/noparse]string | label] {, count {, offset }}
    ' -- "string" is an embedded string constant
    ' -- "label" is DATA statement label for stored z-String
    ' -- "count" is number of characters to send (0 is entire string)
    ' -- "offset" is offset from head of string (0 is head)
    SUB TX_STR
      tmpW1 = __WPARAM12 ' get offset+base
      tmpB3 = 0 ' do whole string
      IF __PARAMCNT >= 3 THEN ' count specified?
      tmpB3 = __PARAM3 ' -- yes, get count
      ENDIF
      IF __PARAMCNT = 4 THEN ' offset specified?
      tmpW1 = tmpW1 + __PARAM4 ' -- yes, update it
      ENDIF
      DO
        READ tmpW1, tmpB4 ' read a character
        IF tmpB4 = 0 THEN EXIT ' if 0, string complete
        TX_BYTE tmpB4 ' send character
        DEC tmpB3 ' update count
        IF tmpB3 = 0 THEN EXIT ' terminate if done
        INC tmpW1 ' point to next character
      LOOP
      ENDSUB
     
    ' ---------------------------------------------------
     
    SUB Cents_Char1
      TX_BYTE 249       ' define LCD Custom Character 1
      TX_STR LCD_Cents  ' LCD cents symbol
      TX_BYTE 1         ' display LCD Custom Character 1
      ENDSUB
     
     
    '====================================================
    ' User Data
    '====================================================
    LCD_CLS:
    DATA 12,10, 0
     
    LCD_Cr:
    DATA 13, 0
     
    LCD_CurOff:
    Data 22, 0
     
    LCD_LightOn:
    Data 17, 0
     
    LCD_LightOff:
    Data 18, 0
     
    LCD_Cents:
    DATA $04,$0E,$15,$14,$14,$15,$0E,$04, 0
    
     
    

    Post Edited (T&E Engineer) : 8/6/2007 11:37:09 AM GMT
  • John KauffmanJohn Kauffman Posts: 653
    edited 2007-08-06 13:59
    OK, I see how to send a literal string.

    But I'm having problems sending the contents of a byte size varible. What if you had these lines of code:
    Price VAR byte
    Price = 50
    And you wanted to get the value in Price to show up on the LCD?

    If I use: LCD_OUT 50 then I get the ASCII character #50 which is the numeral two.
    If I use: LCD_OUT Price then I still get the numeral two.

    In the end, I want the value of a byte size variable to show up on the screen as a number between 0 and 255. I think this would be a common need; your project senses or calculates a byte sized value and you want to use the LCD so the user can see that value

    Thanks.
  • JonnyMacJonnyMac Posts: 9,281
    edited 2007-08-06 14:15
    You need to do a decimal-to-ASCII conversion, John. I've attached a program from the book I'm working on that shows how to do it -- it's a bit long and may require some study. You'll need to update TX_BYTE to use SHIFTOUT instead of SEROUT.
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-07 00:33
    John,

    You may want to also take a look at this posting. Jon has code listed as SERIAL_LCD_DEMO.sxb and mine is LCD_Serial_RevE.sxb.

    They show how to·display numbers 0-99 (or more) to the LCD.

    http://forums.parallax.com/showthread.php?p=560786

    ·Bean also has a very good method that I am using in my current LCD project.

    http://forums.parallax.com/showthread.php?p=603003

    My project:

    http://forums.parallax.com/showthread.php?p=660476

    (code posted too).


    Post Edited (T&E Engineer) : 8/7/2007 12:40:18 AM GMT
Sign In or Register to comment.