Shop OBEX P1 Docs P2 Docs Learn Events
output vs. dir — Parallax Forums

output vs. dir

basicstampedebasicstampede Posts: 214
edited 2007-01-16 02:50 in BASIC Stamp
What is the difference between the following?

1.··High 4

2.· Out4 =1
···· Output 4

3.· Out4 = 1
···· Dir4 = 1

Is there a subtle difference between case 2 and 3 above or are they identical?

·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-16 02:29
    You first have to realize, that the PIC pins have this neat property. They can be output or input, and the output data is latched. So, the question arises, when a pin is set as an input, where does the output latch send its data? Well, it just holds it, it doesn't actually connect to the pin when the pin is set for input.

    This means that the I/O pins have a register, which indicates for each pin whether it's an INPUT or an OUTPUT. They have a SECOND register, which is where the output states of the pins are stored. If a pin is set as INPUT, then it's output state value is not sent anywhere.

    So: 1. HIGH 4 -- this makes I/O pin 4 into an OUTPUT, and then sets the value to HIGH.

    2. Out4 = 1 ' This sets the value of the output latch to 1
    Output 4 ' This sets I/O pin 4 to an output -- which routes that earlier '1' to the output pin.

    3. Out4 = 1
    Dir4 = 1 ' This all does the same as #2 above.
  • KatyBriKatyBri Posts: 171
    edited 2007-01-16 02:50
    Here is some info from the PBasic IDE Help Files-

    The BS1 has 16 bytes (8 words) of RAM space arranged as shown in the table below. The first word, called PORT, is used for I/O pin control. It consists of two bytes, PINS and DIRS. The bits within PINS correspond to each of the eight I/O pins on the BS1. Reading PINS effectively reads the I/O pins directly, returning an 8-bit set of 1's and 0's corresponding to the high and low state of the respective I/O pin at that moment. Writing to PINS will store a high or low value on the respective I/O pins (though only on pins that are set to outputs).

    attachment.php?attachmentid=74121
    562 x 85 - 5K
Sign In or Register to comment.