Shop OBEX P1 Docs P2 Docs Learn Events
DIR command — Parallax Forums

DIR command

Armored CarsArmored Cars Posts: 172
edited 2004-10-25 15:14 in BASIC Stamp
Can DIR be used as a contant or variable such as in these examples?
(Assume that DIRA is less than 255)

IF DIR20=1 GOTO test

LOOKUP DIRA [noparse]/noparse

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-25 14:42
    The DIR registers (DIRS, DIRA, DIRB, DIRC, DIRD, DIR0 ... DIR15) are variables that specify where a pin is an output (when bit is 1) or an input (when bit is 0). You would not normally use them in code the way you suggest. Perhaps you meant

    IF (IN20 = 1) THEN Test
    LOOKUP INA, [noparse][[/noparse] ... ], result

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-10-25 15:14
    It sounds like you are trying to say: "If pin 20 is an output, then GOTO Test". Is that what you're trying to say?

    If so, I'm not sure you can use the DIRxx variables that way. In 'native PIC' you could, but I don't think PBasic supports that. Note the INPUT/OUTPUT state of a pin is changed by several instructions. SEROUT will automatically make a pin an output before use. HIGH or LOW will make it an output. INPUT MyPin will obviously make it an input.

    The easiest solution to this would be to keep a local WORD variable, update it with what you *want* the states to be, then assign that variable to the DIR register to update them, and read your local variable for the state.
Sign In or Register to comment.