IF command error.

zorgloub

Member
Hello to the Team,
I'm confused... !
After a period of programming hiatus, I'm back at it.
I don't understand the error in my simple IF command!??

Thanks

Code:
          #Picaxe 08M2

;                __ __
;         Vcc  o|  U  |o  Gnd
;         C.5  x|Rx Tx|x  C.0
;    _Set C.4  >|     |>  C.1
;  _Pulse C.3  >|     |>  C.2  _OUT
;                -----

;*** Pins I/O ***********************
Symbol _SET   = C.4 : Input _SET
Symbol _PULSE = C.3 : Input _PULSE
Symbol _OUT   = C.2 : Output _OUT

;*** Variables **********************
Symbol Measure = W1  ; Successive measurements

;-------------------------------------------------------------

DO
  If _SET = 0 Then
    Gosub Normal ; C.4 = LOW = 0
  Else ; C.4 = High = 1
    Gosub Inverse
  End if
LOOP
;====================================
; SUB-ROUTINES
;====================================

NORMAL:    ; ...
…
…
return
;---------------------------------------------------------

INVERSE:    ; ; ...
…
…
return

; ================================
 

AllyCat

Senior Member
Hi,

"C.4" represents a Port.Pin Number, which can be proved by "printing" it, e.g. by running SERTXD("C.4= ",#C.4) in the simulator. Thus the condition IF 4 = 0 THEN ... will always "fail" (i.e. take the ELSE path).

To READ the level on the pin, you need to use the "Pin" syntax, i.e. IF pinC.4 = 0 THEN : .... : ENDIF , and select a (different) suitable Symbol name.

Cheers, Alan.
 

zorgloub

Member
Hi AllyCAt,

Indeed, it works with IF PinC.4 = 0. :))

What do you mean by "use another suitable symbol name"?
Is the name "_Set" a problem?

If I try, for example with : Symbol _XYZ = C.4 : Input _XYZ

I still get the error with

IF _XYZ = 0 and also with IF _XYZ = Low


BUT also this:

Symbol _SET = pinC.4 : input _SET
IF _SET = 0 then ...

Finally:
Error corrected as follows:


Symbol _SET = pinC.4 : Input C.4
If _SET = 0 Then

Thankssssss
 
Last edited:

AllyCat

Senior Member
Hi,

You need different Symbol names for "Reading" and "Writing" these pins (where both might be possible). So it should be Symbol _XYZ = pinC.4 which will perform the correct substitution. You can use any symbol names that you find convenient, the _ prefix is not normally required (provided that you avoid "Reserved Words" for symbol names). For example, you might use "Output" and "Input" symbol names for C.4 , e.g. : Symbol oSET = c.4 : Symbol iSET = pinC.4 . Probably better to avoid R(ead) and W(rite) prefixes (or suffixes) because W might be needed to mark Word variables. ;)

Cheers, Alan.
 

zorgloub

Member
Thank you Alan,

I appreciate and embrace the concept of lower case "i" and "o" identifiers in front of capitalized port names.

Example: oSERVO, iSET, iPULSE, ...,

@++
 

AllyCat

Senior Member
Hi,

Note that the "pin" qualifier is required only where the "number" (Symbol name) can apply to both Input and Output instructions or values. For most specific Input commands, you still need to use the generic ("output") symbol name, for example: PULSIN C.4 (e.g. oSET)..... , COUNT C.4 ..... , or READADC C.4 .... , etc. I believe the "pin_" is mainly used in the "Conditional" Instructions or structures such as: IF .. THEN , CASE .. SELECT and BRANCH/ON .. GOTO , etc., but I think the Compiler (Syntax Check) will "Warn" you if the "pin_" is used in error.

Cheers, Alan.
 
Top