lookup2?


Closed Thread
Results 1 to 5 of 5

Thread: lookup2?

  1. #1
    Join Date
    Feb 2006
    Location
    france
    Posts
    47

    Default lookup2?

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    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:
    Code:
    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...
    Code:
    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 ;-)

  3. #3
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default Lookup2

    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
    Last edited by jonas2; - 28th February 2009 at 10:12.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    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...
    Code:
    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.
    Code:
    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.

  5. #5
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. LOOKUP2 please help
    By emilhs in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 12th May 2009, 23:13
  2. need help! to beginner
    By emilhs in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 6th May 2009, 18:44
  3. Kind of "customisable" LOOKUP(2), possible?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th May 2009, 19:45
  4. Lookup2 & Lookdown2
    By saladlee in forum Serial
    Replies: 1
    Last Post: - 4th February 2008, 20:41
  5. PIC 16F84A and 7segment LED dispay
    By select in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st November 2007, 21:01

Members who have read this thread : 0

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