Shop OBEX P1 Docs P2 Docs Learn Events
How to put lowbyte of a Word to a Byte variable? — Parallax Forums

How to put lowbyte of a Word to a Byte variable?

basicstampedebasicstampede Posts: 214
edited 2008-08-29 19:58 in General Discussion
BS2 code:

rawValue VAR Word
ledValue VAR Byte
ledValue = rawValue.lowbyte·

How do I do the line

ledValue = rawValue.lowbyte

in SX/B?

That is, all I want is the lowbyte of a Word variable and store it into a Byte (so I can display it to 8 LEDs).

Thanks.

Comments

  • RS_JimRS_Jim Posts: 1,771
    edited 2008-08-29 14:30
    try this:

    rawVal· VAR tmpW1

    ledVal· VAR tmpB1

    ledVal = rawVal_lsb

    Radio Shack Jim
  • basicstampedebasicstampede Posts: 214
    edited 2008-08-29 14:42
    Radio Shack Jim, thanks a lot.· That works!!!

    Excerpt from my code:

    LEDs PIN RC OUTPUT

    tmpW1 VAR Word
    tmpB1 VAR Byte
    rawValue VAR tmpW1
    ledValue VAR tmpB1

    IF rawValue > 255 THEN
    ··· ledValue = 255
    · ELSE
    ··· ledValue = rawValue_lsb
    · ENDIF
    ·
    · LEDs = ledValue


    Where did you find out about the _lsb operator?· I've searched the Help Index, but don't find it there.·

    And what others are there?· e.g.

    Which of these would be allowed:

    rawValue_msb
    rawValue_lownib(0)
    rawValue_lownib(1)
    rawValue_lownib(2) etc.
    ·
  • BeanBean Posts: 8,129
    edited 2008-08-29 15:27
    SX/B does not have nibble variables. So no those won't work.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • basicstampedebasicstampede Posts: 214
    edited 2008-08-29 15:34
    Thanks Bean.·

    I wonder where Radio Shack Jim found about the _lsb operator?

    I don't see any mention of it anywhere.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-29 19:58
    On page 109 of the early released material from "Practical SX/B" you'll find: "When defining words like this the compiler also provides aliases for the low- and high-bytes of the word, in this case those aliases would be tmpSetting_LSB and tmpSetting_MSB."

    I'll make sure that the creation of _LSB and _MSB aliases makes it into the help file as well.

    You can learn a great deal about SX/B by looking through a list file of a compiled program; you can do it in the editor by pressing Ctrl-L; this will show you all the internal variables, constants, and how your variables are organized (including automatic aliases) and how you code compiles. SX/B takes a bit more work than the BS2, and there's not as much material yet for spoon feeding, but the effort is worth it with the power you gain from using the SX.

    Post Edited (JonnyMac) : 8/29/2008 8:03:47 PM GMT
Sign In or Register to comment.