Reading Inputs


Closed Thread
Results 1 to 4 of 4

Thread: Reading Inputs

  1. #1
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59

    Default Reading Inputs

    I would appreciate some help/advice with what seems a very simple problem, however I am just starting out in this branch of the hobby and I’m a raw beginner with buckets to learn!

    I wish to read the lower 5 bits of my PIC (16F628) which are connected to 5 simple (0 or 1) sensors and then deliver a conditional result to a PORTA pin with IF…THEN statements. As an example IF PORTB = %11100100 THEN etc etc. This seems OK but I would like to remove the upper 3 bits as they are not required. I can hold these three pins high, for example, so they are always a 1 but it would be nice to ‘isolate’ them out of the logic. Is there a way of doing this, please? I hope that’s clear but effectively I would like to end up with a statement which simply says, for example IF PORTB (or MyVar) = 00100 THEN etc etc
    How to do this, please

    Many thanks

    Adrian

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


    Did you find this post helpful? Yes | No

    Smile

    Welcome

    What you want is to mask the top three bits

    Code:
    MyVar=PORTB & %00011111 
    
    IF MyVar = %00000100 THEN
    EDIT: See section 4.17.4 of the manual
    Last edited by paul borgmeier; - 29th May 2007 at 13:42. Reason: added manual reference
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    yup,
    for reference about bit masking you could have a look at those
    http://en.wikipedia.org/wiki/Bitwise_operation
    http://en.wikipedia.org/wiki/Mask_(computing)

    Welcome here, and enjoy!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Reading inputs

    Thank you both for excellent information. Lots to learn but absorption rate very high at present!!!

    Adrian

Similar Threads

  1. Erratic analog inputs .
    By timseven in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th October 2009, 22:34
  2. Unable to get 2 inputs to work
    By rangerdoc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st June 2008, 03:16
  3. inputs on 12F675 (or for that matter any PIC)
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2007, 19:43
  4. Pot reading jumping like crazy!!!
    By champion in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th November 2006, 21:24
  5. Using portb as inputs PIC goes crazy
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th November 2005, 14:15

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