Shop OBEX P1 Docs P2 Docs Learn Events
Binary operators in SX/B — Parallax Forums

Binary operators in SX/B

bennettdanbennettdan Posts: 614
edited 2007-06-26 01:26 in General Discussion
I have read the help file but would like to know if I am correct.
I have a LTC 1298 and it returns two different·variables of bytes the upper 4 and the lower 8.
What the question I have is I want to combine these into a word then convert theis number to a decimal number.
When you add say Variable1 and Variable2 like this I should get this?
Word = 11110000 + 00001111
Word·= 11111111
Or
Word = 00010000 + 00010000
Word = 00100000
Is this Correct?

Then how do I make this bianry # into a decimal #·so I can display it in hyperterminal?
Thanks and hope this makes sense...
·

Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-25 17:14
    You can move two bytes to a word like this:

    wordVal = byteValLow, byteValHigh
    



    I found an old LTC1298 program on my PC; I've updated and attached it -- but didn't take time to test yet (please let me know if you find a problem).

    Post Edited (JonnyMac) : 6/25/2007 5:35:38 PM GMT
  • bennettdanbennettdan Posts: 614
    edited 2007-06-25 23:45
    Thanks for the program Jon.

    Question about the code if you dont mind are these because you are passing data between subroutines? Does it work if you dont use them?
    '
    ' Subroutine / Function Declarations
    '

    DELAY_MS SUB 1, 2
    TX_BYTE SUB 1
    TX_STR SUB 2
    TX_HEX2 SUB 1

    RD_1298 FUNC 2, 1
  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-25 23:52
    I'm not sure I understand your question... Subroutine and functions should be declared in SX/B so that the compiler can check your passed parameters. If you remove the declarations then the compiler will complain when you attempt to use on of the subs or funcs.
  • bennettdanbennettdan Posts: 614
    edited 2007-06-26 00:11
    JonnyMac,
    I dont have my code here with me right now but I will upload it tonight I did not Use any Delcarations and SX/B compiler compiled with no errors. I have two subroutines one for Channel 1 and the other is for Channel 2.
    But I do know that if I try to use more than two subroutines that it will not let it compile maybe this is what you are talking about?
    And if it helps I am using the Gosub in my main loop. I just read in the help file it is not needed anymore.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-26 00:24
    If you use GOSUB then you don't need the declarations for subroutines; that said, using declarations as in my program is the suggested (by me, and I'm writing a book on SX/B <grin>) method -- again, this lets the compiler check for usage errors.

    You can see that I have just one Function for reading the ADC and you pass the channel to it; what I've done (versus your program) is conserved code space. It may not matter for this program, but as you projects get more sophisticated code space conversation will become important.

    Post Edited (JonnyMac) : 6/26/2007 12:28:50 AM GMT
  • bennettdanbennettdan Posts: 614
    edited 2007-06-26 01:26
    I see what you mean I am use to PLC programming with a large Memory area to play with. Thanks again.
Sign In or Register to comment.