2
\$\begingroup\$

is it possible to use 8051 microcontroller as input as well as output at a time? if i use particular pin as input and then how to make it as output as well.tell me please i born just now in microcontroller

\$\endgroup\$
  • \$\begingroup\$ Think, how would you implement such a thing in a hardware? And how would you use it? \$\endgroup\$ – Eugene Sh. Feb 18 '15 at 16:41
  • 1
    \$\begingroup\$ Do you mean using the same pin as an input at one time, then using it as an output at a different time? Trying to do both at the exact same time would not make much sense... unless you're afraid your output line is getting overdriven by some external driver. \$\endgroup\$ – darron Feb 18 '15 at 16:43
  • \$\begingroup\$ is it possible to write code that same pin act as input (i.e read something from input) and output the value what we have read on that pin by connecting led to it.?? \$\endgroup\$ – chakravarthi merugumalli Feb 18 '15 at 16:51
  • \$\begingroup\$ @chakravarthimerugumalli You could do that by briefly turning the pin into an input, reading the value, and then going back to being an output. If it's done fast enough you would not see the blinking of the LED. You might need a driver for the LED depending on how the voltages work out. \$\endgroup\$ – Spehro Pefhany Feb 18 '15 at 17:04
  • \$\begingroup\$ if i write "1" to output pin then pulldown transistor is in off state.so ,its logic value(5) same as when i write the "1" to input pin.buffers in the port structure will differentiate the input and output ?? or Instructions will make that?? \$\endgroup\$ – chakravarthi merugumalli Feb 18 '15 at 17:17
5
\$\begingroup\$

The original 8051 and 80C51 has so-called pseudo-bidirectional I/O pins- they are open drain, with internal pullups (some pins may require external pullup resistors). So, they don't have (or need) the direction registers you may be familiar with from more modern microcontroller families than the rather long-in-the-tooth MCS-51).

So to use a pin as an input you write a '1' to the particular bit and read the pin. Whatever is connected to the 'input' must be able to sink more current than the pullup delivers.

It is not possible to use a pin as an input if it is set to '0' (the pull down transistor is quite strong).

The source current capability of the pin when used as an output is limited to what the pullup can deliver (though there is a 'strong' source transistor that comes on briefly when the pin is switched from '0' to '1' in order to charge stray capacitance connected to the pin quickly.

Edit :

Here is the bidirectional port image which might help beginners and others like me who just added an image to this wonderful answerenter image description here

Edit: The above is a simplified view that was added know my answer, I will leave it as it may be useful, but for a more complete view, check this more recent answer.

\$\endgroup\$
  • \$\begingroup\$ is it compulsory to declare the port pins as input or output at the beginning of program or can we declare any where we want? (inthe middle of the code can i initalize that pins as input or output) \$\endgroup\$ – chakravarthi merugumalli Feb 18 '15 at 17:05
  • \$\begingroup\$ You can change them at any time and as many times as you like, whether the pins are old-style pseudo-bidirectional or true push-pull CMOS bidirectional. \$\endgroup\$ – Spehro Pefhany Feb 18 '15 at 17:10
  • \$\begingroup\$ P.S. of course you should set them up before using them, normally at the start of your program, but you can subsequently change the mode as desired. \$\endgroup\$ – Spehro Pefhany Feb 18 '15 at 19:23
0
\$\begingroup\$

The older style 8051 microcontroller ports are not the same as other more modern microcontrollers which can often have mixed inputs and outputs on the same port. If I recall correctly the standard 8051 must have all pins of the same port either used as all inputs or all outputs, at any one time.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.