PDA

View Full Version : lookup2?



jonas2
- 27th February 2009, 10:50
Hello

I have trouble understanding the instruction lookup2
You can explain this example
thank you


datat var byte
datac var byte[40]

FOR j = 0 TO 39
LOOKUP2 datac[j],[65,48,56,66,52,67,68,60,50,69,70,71,72,54,62,73,49 ,74,75,57,76,53,61,77,78,51,79,80,55,81,82,69],datat
datac[j] = datat
next j

HenrikOlsson
- 27th February 2009, 12:57
Hi,
The FOR-NEXT loop uses variable j as its "counter" but then, in the Lookup2 command, you try to lookup the value that has the index of datac[j]. In other words Lookup2 returns the value in the list that datac[j] "points to".

When this code is run the first time all 40 bytes in the datac array i 0 so you will lookup the same value 40 times in a row and fill the array with that value (65). Next time around, you try to lookup the 65th value in the table but since the table doesn't have 65 entries Lookup2 won't return anything and therefor leave datat unchanged.

Does that make sense?

How about this:

LOOKUP2 j,[65,48,56,66,52,67,68,60,50,69,70,71,72,54,62,73,49 ,74,75,57,76,53,61,77,78,51,79,80,55,81,82,69],datat
datac[j] = datat
Or, for that matter...

LOOKUP2 j, [65,48,56,66,52,67,68,60,50,69,70,71,72,54,62,73,49 ,74,75,57,76,53,61,77,78,51,79,80,55,81,82,69], datac[j]
Untested but should work ;-)

jonas2
- 28th February 2009, 09:24
Hello

I am beginning to understand this instruction, but I thought it was for
make the conversion.

There are 40 bytes of digital data (0123456789) has just saved to the eeprom data and each is compared
in the table and Lookup2 not return anything and therefor datat left unchanged.
and so on for 40 bytes.
And if he finds it changes datat to be written to eeprom.
And if I want that every 40 bytes of a change is saved
This way:
1st byte is a 1 is written in eeprom, R
2nd is a 2 bytes will be written in eeprom in S

40th is a 8 bytes will be written in eeprom in Z

How can I do to create my table

Thank you

HenrikOlsson
- 28th February 2009, 11:36
Hi,
I'm really sorry but you've lost me completely....

With Lookup and Lookup2 nothing is compared to anything. They both retrieve the value in the list that the index-variable points to and puts that value in the varible specified after the list itself.

So...

i VAR Byte
j VAR Byte
i = 0
Lookup2 i, [10, 20, 30, 40, 50], j 'This will return 10 in variable j

i=3
Lookup2 i, [10, 20, 30, 40, 50], j 'This will return 30 in variable j

i=10
Lookup2 i, [10, 20, 30, 40, 50], j 'This will leave j unchanged since there's only 5 entries in the list.


If you want to look/search for a specific value in the list you can use Lookdown and/or Lookdown2 instead.

i VAR Byte
j VAR Byte
i = 20
Lookdown i, [10, 20, 30, 40, 50], j 'This will return 1 in variable j

i=50
Lookdown i, [10, 20, 30, 40, 50], j 'This will return 4 in variable j

i=12
Lookdown i, [10, 20, 30, 40, 50], j 'This will leave j unchanged since 12 is not present in the list.


I'm sorry if this is of no help to you but I simply don't understand the question :-/

/Henrik.

jonas2
- 28th February 2009, 12:26
Hi


It is not easy to speak English.
I seek an example of a table, I must write to eeprom serial
digital data from 0 to 9
But I want to encrypted the data before writing it in'eeprom
Example:
111122233334444 = 55556666777788889999

That will:

abcdefghijklmn? ABCDEFGHIJKLMNOPRSTU

or other means of encrypted data

Thank you