Re: high/low of 14 numbers
Hi,
If all you need to do is "peak detect" (and not actually sort the values) then something like this might work
Code:
Values VAR BYTE[14] ' Array to store the 14 values, array is indexed 0-13.
HighValue VAR BYTE ' Highes value found
LowValue VAR BYTE ' Lowest value found
i VAR BYTE
Temp VAR BYTE
HighValue = 0
LowValue = 255
For i = 0 to 13
Temp = Values[i]
IF Temp > HighValue THEN HighValue = Temp ' Found new high value
IF Temp < LowValue THEN LowValue = Temp ' Found new low value
NEXT
LCDOUT $FE, 1 , "Low: ", #LowValue, " High: ", #HighValue
You can skip using the Temp variable and index the array directly if you want but it'll produce slightly larger code.
/Henrik.
Re: high/low of 14 numbers
Thanks for the help Henrik. I don't understand your code so I have some questions/comments:
1. I am still using 2.50. Is the top line (Values VAR BYTE[14]) wanting to use arraywrite? I'm assuming your code, if written out, would be Values.1, Values.2......
2. I already store the 14 byte sized variables into D1, D2, D3....D14. Could this be a direct substitution?
3. Your code states "Values[i]." The "i" would be 14 in this case?
4. Last question. When you put a # before the lowvalue and highvalue, what exactly is that doing?
Re: high/low of 14 numbers
Hi,
Quote:
1. I am still using 2.50. Is the top line (Values VAR BYTE[14]) wanting to use arraywrite? I'm assuming your code, if written out, would be Values.1, Values.2......
No, it does declare an array but it does not use ARRAYWRTITE or ARRAYREAD so you should be fine. The individual values in the array are accessed like Values[0], Values[1] and so on.
Quote:
2. I already store the 14 byte sized variables into D1, D2, D3....D14. Could this be a direct substitution?
Not directly, no. But if you don't want to re-write your code you can create aliases for each of your variables to actually use the declared array
Code:
Values VAR BYTE[14]
D1 VAR Values[0]
D2 VAR Values[1]
D3 VAR Values[2]
'...and so on.
This way, when you assign a value to D3 it'll actually be stored in the array.
Quote:
3. Your code states "Values[i]." The "i" would be 14 in this case?
No, i is a variable which is used as the index in the FOR-NEXT loop. First time thru the loop i is 0 so it will access the first value in the array, next time thru the loop i is 1 so it will access the second value in the array and so on. Remember that arrays are indexed starting at 0 so Value[0] is the first value, Value[13] is the 14th value.
Quote:
4. Last question. When you put a # before the lowvalue and highvalue, what exactly is that doing?
It converts the value to readable ASCII text, it's the same as using the DEC modifier.
/Henrik.
Re: high/low of 14 numbers
Thanks for the help Henrik! It works very well! One question - Is there an advantage to using # instead of DEC?
Re: high/low of 14 numbers
No, not that I know of. With DEC you can specify the number of digits, like DEC3 or print signed numbers with SDEC but as far as I know # is the same as DEC.
/Henrik.