_param1 syntax: SX48
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
·
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
__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...
·
Problem solved.
I love this forum!
~ 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:
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
·
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:
to read something like this:
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
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:
You'll need to define these variables:
And, finally, the definition:
Lots to look at and digest - I really appreciate the help - thanks, you guys!
~ Laura