Shop OBEX P1 Docs P2 Docs Learn Events
Outs, ins, dirs — Parallax Forums

Outs, ins, dirs

ArchiverArchiver Posts: 46,084
edited 2001-05-26 20:23 in General Discussion
On 25 May 01 at 17:14, tim@t... wrote:

> ...I used DIRS = 1 to set all the ports to output and assumed they all
> go low.

DIRS = 1 sets only I/O 0 to output and all other I/O pins to input.
To set all I/O pins to output: DIRS = $FFFF, or DIRS =
%1111111111111111.

> Using the TOGGLE command, everything works per design.
> My resulting code took up 19% of the memory (I'm using a BS2e and
> assume that is 19% of a 2k slot)
>
> If, however, I use the OUTS command with a binary list on 1's and
> 0's (a 1 lights the segment), it won't work unless I toggle a few
> ports first.

The TOGGLE command not only toggles the OUT value for the I/O pin,
it also sets the pin's DIR value to 1. So you are making the pin an
output because the TOGGLE command was used.

> I would have expected that use of OUTS = 1 would
> initially turn on all segments and the OUTS = 0 would turn them all
> off.

Note that the OUT value has no practical effect if the DIR value is
zero. Note further that OUTS = 1 sets I/O pin 0's output latch to 1
and all other output latches to 0.

Regards,

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-05-25 18:14
    I'm still new at this.

    I hooked up an 8 segment LED. I turn on the segments one by one,
    then turn them back off in reverse order. I then turn them all on
    and toggle them on/off for several iterations, then proceed to count
    from 0 - 9. I'm using a common cathode (Radio Shack) LED.

    I first coded this by using the TOGGLE command.

    I used DIRS = 1 to set all the ports to output and assumed they all
    go low.

    Using the TOGGLE command, everything works per design.
    My resulting code took up 19% of the memory (I'm using a BS2e and
    assume that is 19% of a 2k slot)

    If, however, I use the OUTS command with a binary list on 1's and 0's
    (a 1 lights the segment), it won't work unless I toggle a few ports
    first. I would have expected that use of OUTS = 1 would initially
    turn on all segments and the OUTS = 0 would turn them all off.
    However, these statements appear to be ignored and the first
    statements that have any effect are the TOGGLE. Once I have used
    TOGGLE on the ports, then using DIRS works okay.
    IE DIRS = %1100000000000000 will turn on two segments.

    Obviously, I'm not understanding what is going on. Can someone
    explain it? If I can use the DIRS statements, my memory requirement
    drops to less than 9%. I'm trying to learn how to write good,
    concise code.

    Thanks!

    Tim
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-25 18:19
    The DIRS command sets the ports to either input or output.

    The TOGGLE command just inverts the current state of the PIN -- if it was
    high, it goes low and vice versa. Good for flashing an LED, etc..., but you
    don't really know what state it is in -- not a good choice for some things.

    Try using HIGH x or LOW x to turn on or off the pins as needed, where x is
    the number of the PIN you are messing with.

    Original Message

    > I first coded this by using the TOGGLE command.
    >
    > I used DIRS = 1 to set all the ports to output and assumed they all
    > go low.
    >
    > Using the TOGGLE command, everything works per design.
    > My resulting code took up 19% of the memory (I'm using a BS2e and
    > assume that is 19% of a 2k slot)
    >
    > If, however, I use the OUTS command with a binary list on 1's and 0's
    > (a 1 lights the segment), it won't work unless I toggle a few ports
    > first. I would have expected that use of OUTS = 1 would initially
    > turn on all segments and the OUTS = 0 would turn them all off.
    > However, these statements appear to be ignored and the first
    > statements that have any effect are the TOGGLE. Once I have used
    > TOGGLE on the ports, then using DIRS works okay.
    > IE DIRS = %1100000000000000 will turn on two segments.
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-25 19:27
    OUT command is the background state of a pin. To see a pin high ou low
    and not as an input (high impiedance) you need ALSO to command DIR to be
    an output. Remember also that DIRS=1 will only put in output mode just
    the P0. To put ALL pins as outputs and in high state you will need these
    2 commands:
    DIRS= 65535 (16 bit decimal value to set ALL pins as outputs)
    OUTS= 65535 (16 bit decimal value to set high ALL pins)

    The toggle command when used will set the correspondent DIRx to be an
    output (1) and this still setted after the command.
    ACJacques

    tim@t... wrote:
    >
    > I'm still new at this.
    >
    > I hooked up an 8 segment LED. I turn on the segments one by one,
    > then turn them back off in reverse order. I then turn them all on
    > and toggle them on/off for several iterations, then proceed to count
    > from 0 - 9. I'm using a common cathode (Radio Shack) LED.
    >
    > I first coded this by using the TOGGLE command.
    >
    > I used DIRS = 1 to set all the ports to output and assumed they all
    > go low.
    >
    > Using the TOGGLE command, everything works per design.
    > My resulting code took up 19% of the memory (I'm using a BS2e and
    > assume that is 19% of a 2k slot)
    >
    > If, however, I use the OUTS command with a binary list on 1's and 0's
    > (a 1 lights the segment), it won't work unless I toggle a few ports
    > first. I would have expected that use of OUTS = 1 would initially
    > turn on all segments and the OUTS = 0 would turn them all off.
    > However, these statements appear to be ignored and the first
    > statements that have any effect are the TOGGLE. Once I have used
    > TOGGLE on the ports, then using DIRS works okay.
    > IE DIRS = %1100000000000000 will turn on two segments.
    >
    > Obviously, I'm not understanding what is going on. Can someone
    > explain it? If I can use the DIRS statements, my memory requirement
    > drops to less than 9%. I'm trying to learn how to write good,
    > concise code.
    >
    > Thanks!
    >
    > Tim
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-26 20:23
    --- In basicstamps@y..., tim@t... wrote:
    > I'm still new at this.
    >
    > I hooked up an 8 segment LED. I turn on the segments one by one,
    > then turn them back off in reverse order. I then turn them all on
    > and toggle them on/off for several iterations, then proceed to
    count
    > from 0 - 9. I'm using a common cathode (Radio Shack) LED.
    >


    Thanks for the inputs! Steve helped me grasp reality and understand
    the errors of my ways.

    Now things work as they should and I now understand why they do and
    why they didn't before. Operator error was a major factor!

    Thanks!

    Tim
Sign In or Register to comment.