PDA

View Full Version : Array comparison



Travin77
- 30th March 2006, 04:39
I have an array that is 12 spaces long. I am trying to compare the second space of the array ( array[1] ) to a numerical value. The array contains ascii characters and numbers ( numbers in this case ). When array[1] is equal to or greater than 6, I want to make a pin go high. This is the code I am using:

if array[1] >= 6 then
high portb.7
endif

When I do this, it makes the pin high no matter what. I know for sure that array[1] is not greater than 6 because I can see what value it is on an lcd. Any ideas as to what I am doing wrong? Thanks for any help.

sougata
- 30th March 2006, 06:07
Hi there,

IF you are using



LCDOUT, array[1]


and it is displaying 6 on your LCD screen it essensially means that it is definately not a 6 but an ASCII representation of 6 which is decimal 54. So check it out.

IF you are using



LCDOUT, DECarray[1]


then it is a "6" and something else makes your port high. Why not include an else in your IF-ENDIF routine that turns of the bit when it is not greater than 6.

As I always yell on this forum that a more bit of code is needed. For example how are you transferring values or getting values into an array. If by serial in and hyperterminal then it is definately "ASCII"