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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerThe ELSE is optional. If it is missed out then if the expression is falsethe program continues after the ENDIF line.Example 2 :IF X & 1 = 0 THENA = 0B = 1ELSEA = 1ENDIFIF Z = 1 THENA = 0B = 0ENDIFA third form of IF, allows the ELSE to be placed on the same line asthe IF: -IF X >= 10 THEN HIGH LED1 : ELSE LOW LED2Notice that there is no ENDIF instruction. The comparison is automaticallyterminated by the end of line condition. So in the above example,if X is greater or equal to 10 then LED1 will illuminate, otherwise,LED2 will illuminate.The IF statement allows any type of variable, register or constant tobe compared. A common use for this is checking a Port bit: -IF PORTA.0 = 1 THEN HIGH LED: ELSE LOW LEDAny commands on the same line after THEN will only be executed ifthe comparison if fulfilled: -IF VAR = 1 THEN HIGH LED : DELAYMS 500 : LOW LEDNotes : A GOTO command is optional after the THEN: -IF PORTB.0 = 1 THEN LABELIn fact, the THEN is also optional, however code is more understandablewith the THEN in place. Consider the following two lines of code.IF VAR = 1 THEN VAR = 10andIF VAR = 1 VAR = 10Both lines produce the same result, but the second line is a bit easierto understand. The decision is yours to make whether to use theTHEN part of the constructor not.66Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!