HEX value o/p to PC and arrays


Closed Thread
Results 1 to 14 of 14
  1. #1
    Christos_K's Avatar
    Christos_K Guest

    Default HEX value o/p to PC and arrays

    Hi all. I was wondering how can I send to the terminal of my PC using MAX232 the hex value of a variable.

    hserout [dummydata] will give me the the dec value..Any ideas.

    Also a question about Arrays.

    I want to create an array with byte values in it and read and write to it. Will this be correct:

    Array1 var byte[4]
    .
    ....
    .
    for i=0 to 3
    array[i]=i
    i=i+1
    next i

    will this give the following result??
    array1[0]=0
    array1[1]=1
    array1[2]=2
    array1[3]=3

    Thanx!

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Have you tried using HEX2 variable?

    Code:
    hserout [HEX2 dummydata]
    The 2 after HEX is the number of digits. You can also use DECx for decimal and BINx for binary with x being the number of digits to display.
    Last edited by CocaColaKid; - 22nd August 2005 at 20:52.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Code:
    array1  var  byte[4]
    ...
    
    
    for i = 0 to 3
    array[i]=i
    next i
    Your code i believe will screw up the for...next loop because you will be changing the value of i.

  4. #4
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Lightbulb

    Quote Originally Posted by CocaColaKid
    Code:
    array1  var  byte[4]
    ...
    
    
    for i = 0 to 3
    array[i]=i
    next i
    I think this may work better.
    Code:
    array1  var  byte[3]
    ...
    
    
    for i = 0 to 3
    array1[i]=i
    next i
    Last edited by rhino; - 22nd August 2005 at 21:23.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    oops, missed those ones

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Talking

    Honest mistake.... right on otherwise!

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I copy and pasted and didn't notice those errors.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Christos_K
    Also a question about Arrays.

    I want to create an array with byte values in it and read and write to it. Will this be correct:

    Array1 var byte[4]
    .
    ....
    .
    for i=0 to 3
    array[i]=i
    i=i+1
    next i

    will this give the following result??
    array1[0]=0
    array1[1]=1
    array1[2]=2
    array1[3]=3

    Thanx!
    The value of i is automatically incremented by the for next loop, so just remove the i=i+1.

    This will give you the results you're looking for.

    Array1 var byte[4] ' declare a 4-byte array

    for i=0 to 3 ' index array elements 0 to 3 (4 total)
    array[i]=i
    next i

    Array elements start at 0, and end at the declared size-1. I.E. Array VAR BYTE[4] gives you
    4 byte sized elements in the Array that are indexed 0 to 3.

    If you do this;

    Array1 var byte[3]

    for i=0 to 3
    array[i]=i
    next i

    You'll end up placing the 3 in a RAM location outside your 3-byte array.
    Regards,

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

  9. #9
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Red face You are correct SIR!

    Good catch Bruce.... I see my mistake!

  10. #10


    Did you find this post helpful? Yes | No

    Default

    lol, Bruce, shouldn't it be array1 and not array? Caught you too!

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


    Did you find this post helpful? Yes | No

    Default

    Ya got me......;o]
    Regards,

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

  12. #12
    Christos_K's Avatar
    Christos_K Guest


    Did you find this post helpful? Yes | No

    Default

    Wow! Thanx for all your answers!! You have been more than helpful! Just one more quick one though...I was not aware of the HEX statement...
    If i want to store to Array1[2] the hex value 0x2A will it be
    Array[2] = HEX 2A

    or


    Array[2] = $2a (as it says on manual page 25) ????

    And if i want to compare the value store in Array[2] with 0x3F will it be

    if array[2] != $3F .....

    or

    if array[2] != hex 3F ???

    Thank you all again so much!!!

  13. #13


    Did you find this post helpful? Yes | No

    Default

    I would have to say using the $ method would be correct but I am by no means a guru on this subject. Hopefully one of the others with more knowledgeable can confirm this.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CocaColaKid
    I would have to say using the $ method would be correct but I am by no means a guru on this subject. Hopefully one of the others with more knowledgeable can confirm this.
    Absolutely.

    HEX, BIN, and DEC modifiers are only available when used with the commands that support these modifiers like HSEROUT, DEBUG, SEROUT2, and a few others.
    Regards,

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

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