11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler5.3. BRANCHSyntax : BRANCH Index, [Label1 {,...Labeln }]Overview :Operators :Cause the program to jump to different locations based on a variableindex. On a PIC device with only one page of memory.Index is a constant, variable, or expression, that specifies the addressto branch to.Label1,...Labeln are valid labels that specify where to branch to.Example : DEVICE 16F84DIM index as BYTEStart: index = 2 ‘assign index a value of 2‘jump to label 2 (Lab_2) because index = 2BRANCH index,[Lab_0, Lab_1, Lab_2]Lab_0: index = 2 ‘index now equals 2GOTO StartLab_1: index = 0 ‘index now equals 0GOTO StartLab_2: index = 1 ‘index now equals 1GOTO StartThe above example we first assign the index variable a value of 2,then we define our labels. Since the first position is considered 0 andthe variable index equals 2 the BRANCH command will cause theprogram to jump to the third label in the brackets [Lab2].Notes :BRANCH is similar to the ON x GOTO command found in other BA-SICs. It’s useful when you want to organise a structure such as: -IF Var = 0 THEN GOTO Lab_0IF Var = 1 THEN GOTO Lab_1IF Var = 2 THEN GOTO Lab_2' Var =0: go to label "Lab_0"' Var =1: go to label "Lab_1"' Var =2: go to label "Lab_2"You can use BRANCH to organize this into a single statement: -BRANCH Var, [Lab_0 , Lab_1, Lab_2]This works exactly the same as the above IF...THEN example. If thevalue is not in range (in this case if Var is greater than 2), BRANCHdoes nothing. The program continues with the next instruction..The BRANCH command is primarily for use with PIC devices thathave one page of memory (0-2047). If larger PIC’s are used and yoususpect that the branch label will be over a page boundary, use theBRANCHL command instead.See also :BRANCHL25Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!