Reading Array values into variables


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    >>4 => shift byte 4 position to the right. so you keep only the 4 high bits
    & $F => Bitwise and with hex F. so you keep only the 4 low bits

    everything is in the PBP manual section 4.17
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    It's no more difficult than copying data from a single variable to another.

    X VAR BYTE
    Y VAR BYTE

    X = 3
    Y = X

    You can state X = SSMAX(23), Y = SSMAX(34), etc,,.

    Since the resulting value will be a word, then use something like this;

    SSMAX(23) contains 83h
    SSMAX(34) contains 03h

    Result VAR WORD

    Result.LowByte = SSMAX(23) ' Place 83h into lowbyte
    Result.HighByte = SSMAX(34) ' Place 03h into highbyte
    HSEROUT [DEC Result] ' Print decimal value of 0383h = 899
    Last edited by Bruce; - 28th February 2005 at 04:29.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Red face Array values into Variables - into ONE variable..

    Seems like I should be able to figure this out, but I can't ...

    I have an array that contains 24 bits which equate to an altitude in tenths of meters.

    alt[1]
    alt[2]
    alt[3]


    I need to 1) display this, and 2) convert from meters to feet, so I need to stuff all these into a single variable which represents actual meters as opposed to tenths of meters, then convert to feet....

    Any ideas out there? They way I am doing it now is not working. I am just reading these into alt1, alt2, alt2, and showing them as #alt1, #alt2, #alt3... I get 13130 which may be 131.30 meters,(which would be about right) but I am not sure. I am also not sure how to make this a single variable ..

    Thanks !

    Tom

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Red face

    I have no answer, but I do see an immediate problem.

    A byte contains 8 bits, a word contains 2 bytes; that's a total of 16 bits.

    There is a way to do 32 bit math, I saw a section in the manual. You work with 2 separate words or something, I didn't pay much attention.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Page 33, 4.17.1 - Multiplication.

    Using * and **, / and //.

    Good luck!

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Question

    Exactly the problem.. I have 3 bytes that need to be put into one variable.. this is a 24 bit container that relates a number - the altitude in tenths of meters..

    How to get this into ONE variable I can work with is the first issue..

    Tom

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Wink

    Hi, Tom

    Let's have another view of the problem ...

    You get an altitude measurement, ...but what is your sensor ??? and mostly what is its precision ???

    I do not know lots of altitude sensors seriously able to give 1 cm on a hundred meters ... 1/10 000 precision, you sure ??? ... !!!

    May be a little look here could reduce your number sizes ...and simplify you work.

    24 and 32 bits arithmetics can be downloded from Melabs site ... if you really want to keep "ghost" centimeters !!!

    Alain

Similar Threads

  1. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  2. Array values changing
    By MyBuddy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th October 2009, 23:13
  3. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  4. Seeting array variables in For-Next loop
    By bcd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th October 2007, 07:01
  5. Putting values into an array
    By Vince in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd December 2003, 07:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts