Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] Input and Output Pins of 8051

Status
Not open for further replies.

ddnair

Junior Member level 1
Joined
Aug 25, 2014
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
128
Hai friends,
I have used 8051 from college days...and I know that a port can be made as input (P0=0xff) or output (0x00).
My doubt is that , can we make a pin as both input and output in a single program?
Eg : If I interface I2c with 8051 to write and read values in EEPRom....,in this case we are writing to SDA and also reading from SDA( so it acts as both input and output)...I am in a confusion about this....please clarify the doubt .
 

On the 8051 pins that have a 1 written to them can be used as inputs. Ports 1, 2 & 3 will then have internal pullup resistors pulling them high, and can be pulled low by the external device. Port 0 does'nt have internal pullups, so it's pins would be "open drain" when a 1 is written to them, and would need external pullups to be used as an output. A Pin can be used as both an input and output as long as everything attached to it is not in conflict with pulling the pin low.
 

Thank you FenTrac.
I am well aware of whatever you replied. As you told , a pin can be used as both input and output ,... But my doubt is that, in a single program can we assign it as both input and output ?
 

Yes. it can be both an input and output. With the 8051, unlike some other microcontrollers, the pins are not "defined" as inputs or outputs. The program just reads and writes to them. If a program reads from it, it is an input. If a 1 was not written to it before the read, it will be read as a zero, because the 8051 is pulling it low, so, it is required that a 1 is written first so that it is not conflicting with an external device trying to put a logic 1 on the pin. It uses the "open collector" ("open drain") bus concept. Interfaces like I2C are working in the same way, using a pullup resistor, so the line can be bidirectional.
 

Hi,

You need to better describe what you want to do.

Do you want to switch between input and output?
Or do you want to use it a as input and output at the same time?

A push-pull output is not useful as an input.
An input can maximally act with a pullup as output.

An open-drain or open-collector can be used as input and output at the same time.
Many open-drain outputs can be con enter together (with a pullup) and each if them can sense the state as an input, and everyone can output a "low". All without the problem of causing short circuit.

Klaus
 

I think the folks above covered it pretty well. But another way of looking at it is that once you have written a 0 as an output, it is no longer useful as an input. Because your inputs must sink pin current, they are active low.

That said you could use a pair of 74xxx244's and 74xxx373/4 and a pair of bits from another port to expand your IO from 10 to 16; add more 244/373 pairs and bits or mux to control enables to keep expanding. Or if you have an sm/i2c or spi port just add a port expander.
 

only one condition for 8051 ports. make a port bit to be in 1 level , before you read that bit as input.

as long as you meet that condition you can mix i/p and o/p direction for 8051 portbits.

but in practice , it is very difficult. since you have no control on extern signal which may be 0 or 1.

if you have made port bit as 0(as output) , and suddenly the external source apply a 1 in that pin , then your 8051 is finished, port burns.
so better not to mix the i-p and o-p in the same pin of 8051.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top