Two Bit request (sic)


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    24

    Default Two Bit request (sic)

    I've read through the help files and the manual anad I'm SURE it can be done but I just cant seem to find out how. I'm confusing PICBASIC with VHDL in that what I want to do is this;

    I have 2 INPUT pins on a PIC which are pulled high, these then go to a switch which can pull EITHER bit of low, so the truth table is;

    BIT A BIT B Port "MODE"
    0 1 1
    1 0 2
    1 1 3

    What I want to be able to do is define MODE as two bits of a port so that I can use it as a variable to defire a series of CASE statement to select an option and thence jump to a subroutine.

    It's a cheap way of getting 3 funtions out of two pins. Anyone any ideas how I can do this. I guess the VHL instatiation would be sort of MODE=PORTA[0 TO 1] or something like that, but HOW to do it in PB??

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Lots of ways to do this, here’s one:

    If the pins are two adjacent pins of a port (for example portA.2 and porta.3) then you could use a bit mask and then shift the bit to the right as needed. So, using A.2 and A.3 it would be:
    Code:
    MODEval= PortA & %00001100
    MODEval = MODEval >> 2
    This will give you a value of MODE from 0-3.

    Also, you would even skip the shift and just use the CASE to check for values of 4, 8, and 12.

    And, if the pins are not consecutive, you can still use a bit mask and then check the values:
    Code:
    MODEval = PortA & %10001000
    SELECT CASE MODEval
    	CASE 8
        		Statement... 
    	CASE 128 
        		Statement...
    	CASE 136 
        		Statement...
    	{CASE ELSE 
        		Statement...}
    END SELECT
    HTH,
    SteveB

  3. #3
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks for the rapid reply. I've used this method before many times,and probably will in this case too, so couldn't believe I missed it =-) nvm.

    No all I gotta do if figure out how to attach 4 swiches per port. It's a LONG time since I did any programming and I forget a lot of the techniques involved (happens when you get old).

    Thanks Steve that was a great help.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  3. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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