This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Difference in Working of INPUT & OUTPUT Register

P2DIR &=~BIT1;
P2IN |=BIT1;

P2DIR &=~BIT1;
P2OUT|=BIT1;

When i am using pin1 of port 2 as an input pin ,the above two statements Will give me same Result.

Why this Happens?

  • Ashish Sundriya said:
    P2DIR &=~BIT1;
    P2OUT|=BIT1;

    If you want it as an Output then write; P2DIR |= BIT1; P2OUT |= BIT1; otherwise P2OUT does nothing.

  • Ashish Sundriya said:

    P2DIR &=~BIT1;
    P2IN |=BIT1;

    P2DIR &=~BIT1;

    P2OUT|=BIT1;

    When i am using pin1 of port 2 as an input pin ,the above two statements Will give me same Result.

    Why this Happens?

    "P2DIR &=~BIT1;" makes Bit-1 of Port-2 an input pin.

    "P2IN |=BIT1;" does not make any sense.

    "P2OUT|=BIT1;" has nothing to do with P2IN.

  • If the pin is configured as an input you can write to the P2OUT register as well. The result depends on other configurations of that pin. If a pull up/down resistor is enabled you change it's function to up or down by changing the P2OUT bit. If not, you just set the P2OUT value which will appear when setting that pin to an output again.

    P2IN is a READ ONLY register. You should not write any value to it, since it results in increased current consumption during the write process.

    Dennis

**Attention** This is a public forum