decimal input on portB


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: decimal input on portB

    Yes, you could use the BRANCH command as you have described, "BRANCH PORTB [dog, cat,fish]".
    That being said, I don't think I would use it that way.

    The BRANCH command has the following syntax, "BRANCH Index,[Label{,Label...}]"

    One issue in using the BRANCH command this way is that using a byte variable or Port Alias for the "Index" means you can have 256 possible values (0-255).
    Which might require you to create 256 Labels and add them to the Label list in the BRANCH command.
    The "Index" is just a number pointing to the list of "Labels" in the BRANCH command. E.g. BRANCH Index, [Label_0, Label_1, Label_2, ...]
    If Index = 0 then the program will Branch to Label_0, if Index = 1 then the program will Branch to Label_1, etc.

    If you are using the value of PORTB, there can be up to 256 different values which would make for one very long Branch command.
    "BRANCH Index,[Label_0, Label_1,... Label_255]"

    If it were me I would do something like this.

    Code:
    myPortB var byte
    
    myPortB = PORTB
    
    if myPortB = 1 then GOTO Label_1
    if myPortB = 2 then GOTO Label_2
    
    etc.
    
    Label_1:
        'Do something
        
    Label_2:
        'Do something
    This gives you the power to pick and choose which values of PORTB you want to act on.

    You could also replace the GOTO portion above with GOSUB, which will jump to the Label_x, then at the end of your subroutine (Label_x) the "Return"
    command will cause the program to return back to the next instruction after the GOSUB.

    Code:
     
    if myPortB = 1 then GOSUB Label1
    if myPortB = 2 then GOSUB Label2
    etc.
    
    Label_1:
        'Do something
        return
        
    Label_2:
        'Do something
        return
    You could similarly use the Select Case command.
    Regards,
    TABSoft

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: decimal input on portB

    This wouldn’t be needed if shift shifts in zero values which I think it does:
    Code:
    SWVAR2 = SWVAR & %00001111 'Mask off bits 7:4 to 0, Only get bits 3:0

Similar Threads

  1. Decimal variable input with HSERIN command
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 28th April 2013, 14:14
  2. PORTB.3 Input not working as expected.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2013, 09:58
  3. Replies: 6
    Last Post: - 12th March 2011, 13:11
  4. portb input problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th February 2011, 15:18
  5. Decimal value
    By leonel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th April 2005, 16:39

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