testing bits


Closed Thread
Results 1 to 3 of 3

Thread: testing bits

  1. #1
    Join Date
    Mar 2004
    Posts
    74

    Default testing bits

    I have 4 switches connected to port b, I am reading in the state of the switches ok but need some help in exicuting code depending wich switches are pressed. At present I am doing 16 if then statements, ( 1 for each of the possible outputs). Is there an easier more efficiant way of doing this?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Look at the BRANCH or BRANCHL commands.
    Code:
    Main:
       PortVal = PORTB & %00001111 ' Assumes lower 4-bits
       ' Or
       ' PortVal = PORTB >> 4 ' Assumes upper 4-bits
       BRANCH PortVal, [Nada, itsA, itsB, itsC, etc,,]
       GOTO MAIN
    
    Nada:  ' PortVal returned 0
       GOTO Main
    
    itsA:  ' PortVal returned 1
       do something
       GOTO Main
    
    itsB: ' PortVal returned 2
       do something else
       GOTO Main
    
    itsC: ' PortVal returned 3
       do something else
       GOTO Main
    Much easier than 16 IF THENs.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce
    I have decided to tackle it a compleatly different way. I have identical circuits and wanted to send serial commands from one to the other depending on which input had changed state to change state on the corresponding output of the other micro. I am now reading the port, checking if it has changed since last checked, if it has I send the value out PortA serialy. The other end just takes the serial information and sends it directly to PortB.
    I am learning a great deal from this project and I thank you for your help. My next part in this project I am going to tackle is ack from the receiving unit, and retries on no ackon the Tx end.

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. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. PIC's ports individual bits manipulation - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 27th February 2007, 22:34
  4. Need clever way to convert 10 bits to 8 bits
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd September 2005, 15:13
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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