SIMPLE question


Closed Thread
Results 1 to 8 of 8

Thread: SIMPLE question

  1. #1
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120

    Default SIMPLE question

    I am happy to be a member of that forum!!!!

    I have a SIMPLE question.
    I need to look at the 10 pins (portb.0-portb.7,porta.0,porta.1) in a loop and find the first pin that set 1.I need the simplest code to check that ports.

    Thanks
    Nikos

  2. #2
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Nikos

    I too am happy to be a member of this forum!!!

    You could alias each pin into a word variable.
    Then simply check the value of the whole word

    If w0 > 1 then
    etc etc
    endif

    or

    while w0 <> 0
    wend

    I guess there are lots of other ways but this came into my mind first.

    Hope this Helps

    Duncan

  3. #3
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    Good idea Duncan,

    But I want to find exactly the pin that is 1.
    When you say word(variable)that can have 10bits???

    Nikos

  4. #4
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Nikos

    A word is indeed 16bits, there is a great post by Melanie in the FAQ section I think, which describes how to address bits bytes words and arrays,

    but I think first it is worth taking the time to fully digest pages 21 to 24 of the PBP manual. Every minute taken will pay back in Spades. Settle back with a nice cool glass of retsina.... take your time.

    Just in case you do search for other info: a nybble is 4 bits but PBP does not access these directly.

    Cheers and good luck

    Duncan

  5. #5
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi again,

    I did not answer your question fully,

    you can determine which bit in the word variable that has been set by its value.

    if w0 = 8 this is the same as %0000000000001000

    so if you aliased say portb.1 to bit <3> in the word then you would know that when w0 = 8 portb.1 = 1

    etc etc

    Duncan

    Its many years since i had a glass of retsina.. but you know I can still smell it even now

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, N'Geron

    you can use:

    Code:
    For I = 0 to 7
    
    IF PORTA.0[I] = 1 THEN Bail_out
    
    NEXT I
    
    For I = 0 to 1
    
    IF PORTB.0[I] = 1 THEN Bail_out
    
    NEXT I

    In simple words, you add the value I to the "Base address" that is PORTA.0 ... same for PortB

    You have it "officially written" in the 2.50 Manual, at th REPEAT --- UNTIL Command page !!!

    Alain

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    Duncan,

    What I was thinking...

    portA PORTB
    % 00000000 / 00001000

    <0> PORTB.0 <1>PORTB.1 .... <8>PORTA.0
    Let's say that this is my word that Contains PORTA+PORTB that I have to check.
    The followings are correct???
    ----------------------------------------------
    w0 var word
    L var byte
    H var byte

    L = PORTB
    H = PORTA
    w0.LowByte = L
    w0.HighByte = H

    If w0 > 1 then
    I WILL READ THE w0
    endif

    ---------------------------------------------------

    Thanks
    Nikos

    Retsina,Summer,Sea and Sun

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ngeronikolos View Post
    Duncan,

    What I was thinking...

    portA PORTB
    % 00000000 / 00001000

    <0> PORTB.0 <1>PORTB.1 .... <8>PORTA.0
    Let's say that this is my word that Contains PORTA+PORTB that I have to check.
    The followings are correct???
    ----------------------------------------------
    (w0 var word
    L var byte
    H var byte

    L = PORTB
    H = PORTA
    w0.LowByte = L
    w0.HighByte = H

    If w0 > 1 then
    I WILL READ THE w0
    endif

    ---------------------------------------------------

    Thanks
    Nikos

    Retsina,Summer,Sea and Sun
    If that is what you want to do, you could use Darrel's trick with EXT

    Code:
    @PORTS = PORTA
    PORTS VAR WORD EXT  ; PORTS = PORTB:PORTA
    
    ; in middle of program
    
    if PORTS > 1 then ....
    (Don' t forget to mask the unused bits of PORTA if they might not be 0)
    Last edited by paul borgmeier; - 5th February 2008 at 18:30.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. Stupid simple question.....
    By chien_fu in forum mel PIC BASIC
    Replies: 18
    Last Post: - 23rd February 2010, 13:21
  2. Simple Timer question
    By jimseng in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th September 2009, 23:12
  3. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 01:43
  4. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 22:02
  5. really simple adcin question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 21st April 2006, 09:06

Members who have read this thread : 1

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