Access pin using index


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Couldn't we use LOOKUP for this??

    my_var = port A

    Lookup my_var,[0,1,2,3,4,]pin_pressed



    wouldn't pin_presed now hold the pin that was triggered?
    Victor

  2. #2
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by victorf57 View Post
    Couldn't we use LOOKUP for this??

    my_var = port A

    Lookup my_var,[0,1,2,3,4,]pin_pressed



    wouldn't pin_presed now hold the pin that was triggered?
    Victor
    From what is written in the manual:

    "LOOKUP B0,[“Hello!”],B1 ' Get character number B0 from string to variable B1"

    So if you lookup portA then you will have a value equal to the bit rank of the bits that are set. I only need to find the first bit set when reading the PORTA register from LSB to MSB.
    With LOOKUP, if the bits 0 and 2 are set, portA will be = 5, that is not the pin_pressed.
    (It will will return the value of the 5th constant).

    The only way I found till now is to use redundant code like:
    if porta.0 = 0 then
    pin = 0
    Goto bypass
    endif
    if porta.1 = 0 the
    pin = 1
    Goto bypass
    endif
    ...etcetera

    That's not nice but it works

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    That's not nice but it works
    This may not be any nicer, and I'm not even sure if it'll work...but...

    Code:
    temp var byte
    pin var byte
    
    pin = 0 : temp = porta     'initial pin to zero and save porta to temp
    loop: pin = pin + 1 : if (temp.0[pin] <> 0) AND (pin <> 4) then loop
    got_pin:    'when you get here, if pin = 5 then porta.0 thru porta.3 <> 0

  4. #4
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    This may not be any nicer, and I'm not even sure if it'll work...but...

    Code:
    temp var byte
    pin var byte
    
    pin = 0 : temp = porta     'initial pin to zero and save porta to temp
    loop: pin = pin + 1 : if (temp.0[pin] <> 0) AND (pin <> 4) then loop
    got_pin:    'when you get here, if pin = 5 then porta.0 thru porta.3 <> 0
    This seems to be the way to index the pin registers.
    In fact before checking the replies on the forum (and your reply) I've tried the tutorial from BRUCE where he is using:
    SYMBOL TRIGGERED_PIN = PORTA

    Then

    IF (TRIGGERED_PIN.0[index] == 0) THEN
    ...

    and it worked fine I'm very happy.

  5. #5
    sheepdog's Avatar
    sheepdog Guest


    Did you find this post helpful? Yes | No

    Default

    You have substituted arrogance for intelligence
    Time enough
    nostromo signing off

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sheepdog View Post
    You have substituted arrogance for intelligence
    Time enough
    nostromo signing off
    Even I disagree with that statement...(who would've thunk that eh? )

    I think he substituted something that you think MIGHT have worked for him with something that DID work for him.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

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