Accessing Portion of Input Port


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2008
    Posts
    39

    Default Accessing Portion of Input Port

    I have PortA on an 18F8722 defined as an input port , and I want to read 3 of these pins at once. Say I want to read 0,3,5 and use the input in an IF statement is this possible?

  2. #2
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    You can check for a state on all 3 pins with one if statement if thats what you mean

    Code:
    if porta.0=1 and porta.3=1 and porta.5=0 then
    
    endif
    In that example 0 and 3 must be high and 5 must be low to execute the code in the if statement

  3. #3
    Join Date
    Aug 2008
    Posts
    39


    Did you find this post helpful? Yes | No

    Default

    I know I can do it that way I was just looking to do it with out the and satements... so I can say something like:

    Code:
    IF PortA135 = $6h then
    
    endif

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Frozen001 View Post
    I know I can do it that way I was just looking to do it with out the and satements... so I can say something like:
    Code:
    IF PortA135 = $6h then
    endif
    IF ( PortA AND %00101001 ) = $29 (in this case all bits must be logic high) THEN whatever

    Or are you talking about pulling out PortA. bits 1, 3, and 5 (or whatever) and putting them in temp. bits 0,1,2 ???
    Last edited by skimask; - 24th October 2008 at 15:51.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    That is also possible. You can use the bit AND operator (&).

    Code:
    if (porta & %00010101)=%00010101 then
    The purpose of (porta & %00010101) is to strip out the unwanted information. Only the bit where you see a 1 will be kept from porta. Then you compare that with the value you are looking for

    Edit: Looks like skimask got there before me!

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Edit: Looks like skimask got there before me!
    MMMMWWWWAAAAHAAAAAA!!!!!!
    (don't know if you guys do much for Halloween over there or not...but there it is )

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    (don't know if you guys do much for Halloween over there or not...but there it is )
    Have you seen half my threads?!?! I dont think many people celebrate it here but i sure do Its my fave time of the year

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do a little morphing this time of year too.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2931&stc=1&d=122486118 8">
    Attached Images Attached Images  
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Is that going to be your new avatar for next week?

    Thinking about it, i should get an avatar for halloween!

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Is that going to be your new avatar for next week?

    Thinking about it, i should get an avatar for halloween!
    I can not figure out how to up load an animated avatar. But that is what I was thinking.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Your limited to 19.5K so that one is too big. Im sure someone here has an animated avatar already

Similar Threads

  1. Input and Output on same Port
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th November 2008, 18:46
  2. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Can defines be changed with port input?
    By Archangel in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 22:50
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43

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