Shop OBEX P1 Docs P2 Docs Learn Events
_param1 syntax: SX48 — Parallax Forums

_param1 syntax: SX48

Old_LadyOld_Lady Posts: 20
edited 2009-02-24 14:15 in General Discussion
Folks -

I'm a hardware person who is attempting to code on the 48SX.· I'm struggling with syntax here, if someone could help me out, that would be great.· I'm trying to copy a subroutine that would transmit a byte on my serial port, and I'm getting compile errors on the use of _PARAM1.· This is taken from an example code that Jon Williams wrote to read an A/D, the LTC1298.·(Here is his code:··http://forums.parallax.com/attachment.php?attachmentid=39238

(I'm trying to read an A/D as well, the LTC1864.· They are very similiar chips.)

Here is the sample code I'm copying right into my program:
'************************
' Use: TX_BYTE aByte
' -- transmits one byte to serial port

TX_BYTE:
· temp1 = __PARAM1····························· ' copy outgoing byte
· SEROUT TX, Baud, temp1
· RETURN
'************************

I can see that the _PARAM1 is under the HELP files as a SX/B variable.· Why does my compiler freak out on my use of this seemingly straightforward subroutine?· It says "INVALID PARAMETER "_PARAM1".· I copied the definition of the subroutine:
TX_BYTE·· SUB·· 1

I'm assuming that I will send it the byte that I want to have transmitted.· So what Jon calls "abyte" above is the what I want to have output from my circuit board to my PC's hyperterminal.· I'm calling the subroutine as follows:
TX_BYTE "H"

Sorry if this is super basic.·

~· Laura

·

Comments

  • BeanBean Posts: 8,129
    edited 2009-02-20 17:29
    Laura,
    __PARAM1 has TWO underscores in front of the word "PARAM1". I think that is the problem.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • Old_LadyOld_Lady Posts: 20
    edited 2009-02-20 17:32
    Thanks!
    Problem solved.

    I love this forum!

    ~ Laura
  • JonnyMacJonnyMac Posts: 9,412
    edited 2009-02-20 17:51
    Laura,

    You don't need the temporary variable in that routine -- after looking at the code generated for SEROUT the value transmitted is immediately moved into __PARAM1 which means you can do this:

    ' Use: TX_BYTE aByte
    ' -- transmits one byte to serial port
    
    SUB TX_BYTE
      SEROUT TX, Baud, __PARAM1
      ENDSUB
    
  • Old_LadyOld_Lady Posts: 20
    edited 2009-02-23 19:39
    Hi again -

    Thanks, Johnny Mac, for your reply.

    How about this:· When I read the data from my A/D, it will be in binary.· I am interested in showing that data on my hyperterminal screen, so I thought that I needed a binary to ascii converter routine.· But in your code where you read the A/D, you have a routine that looks like it converts a binary byte to Hex2 format, which you call text.· Will this routine display my A/D data in ASCII?· So that my manager will understand that my board is working correctly?· (He doesn't like reading binary.)

    Here is your code for the subroutine:

    ' Use: TX_HEX2 aByte
    ' -- sends "aByte" to host in HEX2 format (text)

    TX_HEX2:
    · temp2 = __PARAM1 ' copy byte
    · FOR temp3 = 1 TO 2 ' send two nibbles
    ··· temp4 = temp2 & $F0 ' get a nibble
    ··· SWAP temp4
    ··· IF temp4 < $A THEN
    ····· temp4 = temp4 + "0" ' convert to "0".."9"
    ··· ELSE
    ····· temp4 = temp4 + 55 ' convert to "A".."F"
    ··· ENDIF
    ··· TX_BYTE temp4 ' send to host
    ··· temp2 = temp2 << 4 ' position next nibble
    · NEXT
    · RETURN


    Thanks in advance for your help.· I'm really out of my comfort zone here... much happier in·my hardware world with lots of chips and caps and stuff.·

    ~ Laura
    ·
  • PJMontyPJMonty Posts: 983
    edited 2009-02-23 20:03
    Laura,

    I haven't read Jon's code, but your code certainly looks correct. Best way to know is to try it out and test it. You don't even need to build the hardware. Take your code and run it through SXSim to see what happens. You can force a value by doing something as simple as changing this line:

    temp2 = __PARAM1 ' copy byte
    



    to read something like this:

    temp2 = 15 ' For debugging only!
    



    You would want to test the boundary values such as 0, 1, 9, 10, 15, 16, 127, 128 and 255 to be sure your code handles the boundaries correctly. These are cases such as the smallest and biggest numbers, the first value with a letter, etc.

    Thanks,
    PeterM
  • JonnyMacJonnyMac Posts: 9,412
    edited 2009-02-23 20:11
    Laura,

    The SX uses binary internally but remember that binary, hexadecimal, and decimals are just sytems for representing values, hence:

    %1000 = 16 = $10

    -- the value is the same. Eggs are eggs whether you call them "huevos" or "eggs" -- right?

    I suspect you'd rather print the values in decimal format and SX/B 2.0 helps with the STR instruction. This (SX/B 2.xx) subroutine will print a value in decimal format:

    ' Use: TX_DEC value {, digits } 
    ' -- transmits "value" in DEC format
    ' -- "digits" MUST be specified with word values
    ' -- DEC3 or DEC5 format is used if "digits" not specified or invalid
    
    SUB TX_DEC
      dValue        VAR     tmpW1
      dDigits       VAR     tmpB1
      dIdx          VAR     tmpB2
      dChar         VAR     __PARAM1
    
      IF __PARAMCNT = 1 THEN                        ' byte w/o digits
        dValue = __PARAM1
        dDigits = 3
      ELSEIF __PARAMCNT = 2 THEN                    ' byte w/digits
        dValue = __PARAM1
        dDigits = __PARAM2
      ELSE                                          ' word w/digits
        dValue = __WPARAM12
        dDigits = __PARAM3
      ENDIF
    
      IF dDigits = 0 THEN                           ' validate digits
        dDigits = 5
      ELSEIF dDigits > 5 THEN
        dDigits = 5
      ENDIF
    
      STR nStr, dValue                              ' to decimal string
      dIdx = 5 - dDigits                            ' point to first char
    
      DO WHILE dIdx < 5
        TX_BYTE nStr(dIdx)
        INC dIdx
      LOOP
      ENDSUB
    


    You'll need to define these variables:

    tmpB1           VAR     Byte                    ' sub/func work vars
    tmpB2           VAR     Byte
    tmpW1           VAR     Word
    
    nStr            VAR     Byte (5) BANK           ' for STR and HEXSTR
    


    And, finally, the definition:

    TX_DEC          SUB     1, 3                    ' tx value in DEC format
    
  • JonnyMacJonnyMac Posts: 9,412
    edited 2009-02-23 20:15
    And in the event you want to print in binary or hex formats, here are better routines:

    ' Use: TX_BIN8 value
    ' -- prints value in BIN8 format
    
    SUB TX_BIN8
      binOut        VAR     tmpB1                   ' value to print
      binIdx        VAR     tmpB2                   ' bit index
    
      binOut = __PARAM1                             ' capture value
    
      FOR binIdx = 1 TO 8                           ' print 8 chars
        __PARAM1 = "0" + binOut.7                   ' convert bit7 to ASCII
        TX_BYTE __PARAM1                            ' print it
        binOut = binOut << 1                        ' shift to get next bit
      NEXT
      ENDSUB
    



    ' Use: TX_HEX2 value
    ' -- prints byte value HEX2 (00 .. FF) format
    ' -- packed BCD values will print 00 to 99
    
    SUB TX_HEX2
      hxWork        VAR     tmpB1
      hxNib         VAR     tmpB2
    
      hxWork = __PARAM1
    
      hxNib = hxWork & $F0                          ' isolate high nib
      SWAP hxNib                                    ' align for READ
      READ Hex_Digits + hxNib, hxNib                ' convert to ASCII
      TX_BYTE hxNib
      hxNib = hxWork & $0F                          ' isolate low nib
      READ Hex_Digits + hxNib, hxNib                ' convert to ASCII
      TX_BYTE hxNib
      ENDSUB
    
    Hex_Digits:
      DATA  "0123456789ABCDEF"
    
  • Old_LadyOld_Lady Posts: 20
    edited 2009-02-24 14:15
    Wow!
    Lots to look at and digest - I really appreciate the help - thanks, you guys!

    ~ Laura
Sign In or Register to comment.