Shop OBEX P1 Docs P2 Docs Learn Events
Can someone teach me the OUTS of DIRS? — Parallax Forums

Can someone teach me the OUTS of DIRS?

firestorm.v1firestorm.v1 Posts: 94
edited 2009-12-15 17:44 in BASIC Stamp
Ok, so after many moons of not having enough time, I finally dusted off my BS2 and started working with it.

I have an HD44780 LCD and am using Parallax's code to run my LCD (see prod #603-00006)

I an initially trying to get the thing working for now, but eventually will be switching to 8bit mode as I have more pins than I need and I just got done building an 14 pin single inline pin header cable for working with the LCD.

The issue I'm having is that I can't remember for the life of me if OUTS and DIRS are LSB-MSB or backwards, i.e. if I want pins 1-8 and 9,10,11 to be outs and the rest input: (say I'm sending 255 through an OUTS statement)

Is it like this:
DIRS=%1111111111100000
OUTS=%1111111100000000

or like this:
DIRS=%0000011111111111
OUTS=%0000000011111111


My LCD is hooked up as follows:

Pin 0-7 -> D0-7 on the LCD
Pin 8 -> E
Pin 9 -> RW
Pin 10 -> RS

Will setting DIRs affect me being able to manually set the pin state of E,RW,RS (or pin 16 later on for a ping sensor?)


Thanks for your time!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-14 16:48
    The pins are numbered according to the power of 2, so the value of pin 0 is 2^0 or 1. The value of pin 1 is 2^1 or 2. The value of pin 6 is 2^6 or 64. When you write the values in binary (with "%" in front), they're numbered from right to left, just like the powers of ten (thousands=10^3, hundreds=10^2, tens=10^1, ones=10^0).

    When you set DIRS (or any piece of it like DIRA or DIRL), you're just setting it at that very moment. If you use a statement (like HIGH / LOW / INPUT) that changes the mode of a specific I/O pin, that actually changes the specific bit in DIRS.
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2009-12-14 16:52
    Hey Mike, thanks for your reply. I want to make sure I understand clearly:

    Anytime I use the % symbol on OUTS, this means that the rightmost bit will always be pin 0, correct?

    e.g. OUTS=%10000 and OUTS =%10 don't matter in respect to pin 0, but the first example sends pin4 high while the second one sends pin 1 high.

    and with that said, if I don't use the binary operator % if I OUTS a number less than 255, I shouldn't have an issue colliding with the control pins for the LCD?

    Thank you for clarifying it, I just want to make sure I'm seeing it correctly. [noparse]:)[/noparse]
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-14 23:40
    If at first it's: OUTS = %1111111100000000

    and then you go and do: OUTS = %01

    you do not end up with the OUTS register = %1111111100000001

    what you get is the OUTS register = %0000000000000001
  • velociostrichvelociostrich Posts: 40
    edited 2009-12-15 00:51
    The % indicates that the numbers following it are in binary -- if you don't know that, Wikipedia has more than enough information -- and they're always big-endian.

    You can always refer to the documentation available through the help menu of Parallax's BASIC Stamp IDE.
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2009-12-15 05:33
    Hello Everyone:

    I think I have managed to confuse myself and in the process have confused all of you.

    I know how binary works and I did check the parallax documentation in the IDE however it was as clear as mud. (Seriously, search DIRS and tell me if there is anything that directly states whether or not DIRS is lsb-msb or msb-lsb?)

    The question is:

    If I send OUTS=%0011, this should set pins 0,1 as high and if I set OUTS as %1100, this should set pins 0 and 1 as low, 2 and 3 as high. If I OUTS, say 255, then pins 0-7 will be high, with the rest low, correct?

    Thank you all for your assistance.

    Edit:
    Another question which may be causing the confusion. If I set DIRS=%111000111 (should be pins 3-5 as outputs) and I OUTS=%1111 Does this mean that the pin states will be pins 0-3 high?

    Post Edited (firestorm.v1) : 12/15/2009 11:31:10 AM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-15 12:10
    Binary numbers are always understood as LSB lsb on the right, just like decimal numbers.

    25 is the same as 000000025·or 025 or 0000000000000000000025.






    Post Edited (PJ Allen) : 12/15/2009 12:16:39 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-15 17:44
    firestorm.v1 said...(trimmed)
    Hello Everyone:
    I think I have managed to confuse myself and in the process have confused all of you.
    Edit:
    Another question which may be causing the confusion. If I set DIRS=%111000111 (should be pins 3-5 as outputs) and I OUTS=%1111 Does this mean that the pin states will be pins 0-3 high?
    In that example pins 3-5 have been set to inputs, so regardless of how you set OUTS, that data will not appear on those pins.· Your OUTS example only affects pins 0-3 anyway.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    Check out the new Savage Circuits TV!
    ·
Sign In or Register to comment.