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.
Bookmarks