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.30. IF …THEN … ELSE … ENDIFSyntax : IF Comparison THEN Instruction : { Instruction }or…IF Comparison THEN Instruction : { Instruction } : ELSE Instructionor…IF Comparison THENInstructionELSEInstructionENDIFOverview :Operators :Example 1 :Evaluates the comparison and, if it fulfils the criteria, executes expression.If comparison is not fulfilled the instruction is ignored, unlessan ELSE directive is used, in which case the code after it is implementeduntil the ENDIF is found.When all the instruction are on the same line as the IF-THEN statement,all the instructions on the line are carried out if the condition isfulfilled.Comparison is composed of variables, numbers and comparators.Instruction is the statement to be executed should the comparisonfulfil the IF criteriaSYMBOL LED = PORTB.4Var = 3LOW LEDIF Var > 4 THEN HIGH LED : DELAYMS 500 : LOW LEDIn the above example, VAR is not greater than 4 so the IF criteria isn’tfulfilled. Consequently, the HIGH LED statement is never executedleaving the state of port pin PortB.4 low.However, if we change the value of variable VAR to 5, then the LEDwill turn on for 500ms then off, because VAR is now greater than 4, sofulfils the comparison criteria.A second form of IF, evaluates the expression and if it is true then thefirst block of instructions is executed. If it is false then the secondblock (after the ELSE) is executed. The program continues after theENDIF instruction.65Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!