Shop OBEX P1 Docs P2 Docs Learn Events
INS OUT AND DIRS....omg — Parallax Forums

INS OUT AND DIRS....omg

???O? ???????O? ???? Posts: 18
edited 2009-06-28 21:15 in BASIC Stamp
Before you tell me to read the stamp manual or do a search. I can assure you that I am asking this very basic question as a last resort.· But I am sure this is also something I must understand before i move on, or worse smoke something.


So....here it goes.

What are ins, outs, and dirs, and how are they used?

Here is my understanding...this may or may not help.

INS. This are the actual state of the pin. can not be controlled internally.
Outs. This is the state at which you set the output
Dirs. this is setting each pin in or out.

Example.

OUTS=0
· DIRS=%1111111011111111
· '······ ··· fedcba9876543210

I have set all pins to out puts, except for pin 8. pin·8 is anout input. all output pins are low·until otherwise toggled in the code.

Am I close? am i hopeless?

can each out be addressed individually like the dirs?
is there a need to ever do anything with ins?



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DP
(ΜΟΛΩΝ ΛΑΒ&#917[noparse];)[/noparse]

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-27 14:09
    Hi , DIRS INS and OUTS are useful if you want to control or read several inputs/outputs simultaneously.

    The IO pins can be grouped in sets of 4
    > [noparse][[/noparse]DIRA | INA | OUTA ]·- [noparse][[/noparse]DIRB | INB | OUTB ]·- [noparse][[/noparse]DIRC | INC | OUTC ]·- [noparse][[/noparse]DIRD | IND | OUTD ]

    sets of 8
    > [noparse][[/noparse]DIRL | INL | OUTL ]·- [noparse][[/noparse]DIRH | INH | OUTH ]

    1 set of 16
    >[noparse][[/noparse]DIRS | INS | OUTS ]

    or as individual bits IN1 , OUT1 , IN2 , OUT2 etc

    The INS· can be read at any time·. Before OUTS has any effect you must set the DIR register.

    For example to set P0 P1 P2 and P3 to output and make P1 P2 and P3 high and P0 low simultaneously

    DIRA=%1111    'make P0 P1 P2 P3 outputs
    OUTA=%1110    'swich P1 P2 P3 high and P0 low
    

    This instruction is useful for controlling devices such as stepper motors and recently there was a post where this instruction was used to control traffic lights.

    Also useful for reading binary inputs say from a binary switch.

    Jeff T.
  • ???O? ???????O? ???? Posts: 18
    edited 2009-06-27 16:19
    Hey Jeff,

    Thank you,

    It sounds as if i was close. So if i set DirA= %1110 , i would be making pin3 an input. and then OUTA%1110 would not matter if written like OUTA%1111, pin 3 as an input can show only acutally state, and cannot be driven internally? which would be random unless pulled down or up correctly.

    In reallty, this whole thing would be the same as
    'intialize
    output 0
    out0 = 1
    output 1
    out1 = 1
    output 2
    out2 = 1
    input 3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DP
    (ΜΟΛΩΝ ΛΑΒ&#917[noparse];)[/noparse]
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-27 16:51
    Hi, in PBasic 1 = set to output , 0 = set to input . The least significant bit , bit 0 is indicated on the right of the binary notation (Red = bit 0·, Orange = bit 3 %1111)

    So your notation "DirA= %1110" is setting P0 to an input and P1 through P3 to output. Apart from that you seem ok with it.

    The DIR,IN and OUT instructions are a strong feature of PBasic.

    Jeff T.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-27 17:00
    You have the bits in the wrong order. %1110 means bit3 = 1, bit2 = 1, bit1 = 1, and bit0 = 0, so you want to set DirA = %0111 and OUTA = %0111 or %1111.

    INS (and all of its named pieces like INA/B/C/D) reflects the actual state of the I/O pins regardless of whether they're input or output mode. It's normally only useful if the I/O pins of interest are input mode. In other words, the INS bits are always connected to their corresponding I/O pins.

    OUTS (and all of its named pieces like OUTA/B/C/D) is a register and all 16 bits have a value you can set (and they stay at that value until changed by your program). You can test them if you want. They only affect the I/O pin if the pin is in output mode.
  • ???O? ???????O? ???? Posts: 18
    edited 2009-06-28 21:15
    Thank you for clearing that up·for me. I didnt want to get to far without understanding the "basics"tongue.gif !!

    I really appreciate your help!




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DP
    (ΜΟΛΩΝ ΛΑΒ&#917[noparse];)[/noparse]
Sign In or Register to comment.