Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Selecting I/O on the 8051

Status
Not open for further replies.

AceOfHearts

New Member
Hi there,

I am a little confused concerning how to select input and output on the 8051.

OK, upon reset, all the ports are input port. Right? And when the first 0 is written to the port, it becomes an output port....

Why is it that when I send a logic (be it 1 or 0) it outputs it, without me writing this iniitial 0 to configure it as an output port?

Suppose it is now an output port, and I now want to make it an input port so I need to send 1 to the port. But how does it know that I want to make it an input port, because it could just output it as a normal output logic?

Confused. Please help...
 
Last edited:
OK, upon reset, all the ports are input port. Right? And when the first 0 is written to the port, it becomes an output port....
No the ports do not get configured as input or output. They are bi-directional all the time. To use the port as an input write a 1 to it, whatever is providing the input (sensor, switch ect.) must pull the port pin low or let it float high to input the data.
 
The resolution of your problem involves the definition of the 8051 I/O port. It is a quasi-bi-directional output. The output stage of each pin on ports 1, 2, 3 has a strong n-channel pull down transistor and a very weak p-channel pull up tranistor. An 8051 output can sink several milliamperes of current in the zero state. The same output can source only 50 micramperes or so in the high state. Check the individual datasheets for the exact numbers. When the output data latch has a one written to it and it sources 50 microamperes, any external output can pull the weak p-channel transistor low without much trouble at all. This is radically different from the I/O ports on almost every other processor in the universe. Why was it done this way? In a word -- cost. In the early 1970's when the predecessor of the 8051 was designed the folks at Intel hit upon this technique to avoid having to use up valuable silicon real estate for a data direction register; it was an elegant solution at the time. With a little bit of care you can make the difference between the 8051 output stage and the alternative a complete don't care. A common base switch works really well in this application.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top