PDA

View Full Version : HEX value o/p to PC and arrays



Christos_K
- 22nd August 2005, 20:34
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!

CocaColaKid
- 22nd August 2005, 20:46
Have you tried using HEX2 variable?



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.

CocaColaKid
- 22nd August 2005, 20:49
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.

rhino
- 22nd August 2005, 21:19
array1 var byte[4]
...


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


I think this may work better.

array1 var byte[3]
...


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

CocaColaKid
- 22nd August 2005, 21:24
oops, missed those ones :o

rhino
- 22nd August 2005, 21:27
Honest mistake.... right on otherwise!

CocaColaKid
- 22nd August 2005, 22:54
I copy and pasted and didn't notice those errors.

Bruce
- 22nd August 2005, 23:04
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.

rhino
- 22nd August 2005, 23:07
Good catch Bruce.... I see my mistake!

CocaColaKid
- 22nd August 2005, 23:29
lol, Bruce, shouldn't it be array1 and not array? :o Caught you too!

Bruce
- 22nd August 2005, 23:35
Ya got me......;o]

Christos_K
- 22nd August 2005, 23:46
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!!!

CocaColaKid
- 23rd August 2005, 00:00
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.

Bruce
- 23rd August 2005, 01:10
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.