to floating it, to gnd it, to Vcc with a resistor, or what?

thanks
Posted on 2003-10-23 07:00:58 by dion
Unused port pins should never be left floating.

They can be grounded or pulled high, if configured as inputs.
You can also configure them as outputs, and output either a "0" or a "1" to them.
Posted on 2003-10-23 11:45:52 by VVV
If current usage is an issue, tie them off to ground.

Regards, P1 :cool:
Posted on 2003-10-23 13:11:14 by Pone
thanks for replies...

VVV: how about if the port is bidi, act as input/output?

Pone: to ground it? the current? yes, i am confuse about the related issue.

afaik, i read somewhere that when a uC is having trouble so that it's executions was stuck somewhere, all the pins (addr/data) tend to be stuck at low. nah, at that moment, if someone let it be on for sometime, the chip heat would raise faster than the normal operation. thats why i am got confused with this matter.

another condition would be latch up. i ever experience one with a 8051 that one of its pin is stuck high. yes, i was made a mistake that day :( but i would know, what made it latch up(please correct me if it is not), is it because i gnd it for sometime, or i short it to 5V, or i short it to 12V?

thanks
Posted on 2003-10-24 06:11:19 by dion
Hi Dion.
If you can config these pins as outputs - do it and left float.
If this impossible you can connect these pins to resistors (10KOm+), another pin of R connect to Vcc. It works in any case (input/output/bidirect), but may required a some power.
Posted on 2003-10-24 06:53:55 by MikDay
If the port pins are bidirectional, most microcontrollers (8051 family NOT included) will have a Data Direction Register, where you can define the pin as input or output. Upon RESET, the pins are generally defined as ALL inputs, to avoid any possible problems. Then your program must write to the Data Direction Register and define as outputs the pins that need to be outputs.

If you define the pin as an input, you must either ground it or connect it to Vcc (pullup not required).
If you define the pin as an output, you just write either a 0 or a 1 to it and it will be in a stable state (you do not necessarily need to write anything to the port if you don't care about the state, since the port latch register will contain either 0 or 1, it will not be undefined). This is the approach I prefer, since it involves no external connection.

The ports on the 8051 are open drain outputs, with internal pullups (except port 0, which does not have pullups in normal operation, strong pullups for ext. memory access). There is no Data Direction Register. Upon RESET, the port latches are initialized to 1 (all transistors OFF).
The port pins are both inputs and outputs. If unused, these are best GROUNDED, because if by mistake you output a 1, nothing will happen, since the output is only pulled high by a pullup (resistor), there is no transistor turned on.
If you output a 0, the transistor will just short to ground something that is already grounded. With a grounded input, it's less likely it'll pick up noise (than with a pullup).
Or, you can actually leave them unconnected, since the pullups will pull them high (this does not apply to port 0, it needs pullups).
Or you can just output 0's to the unused port pins. That way they are "grounded", without an external connection (works for port 0, too).

I suspect your 8051 burned because you either :
a) connected a pin to 5V and then forced the output to 0; that turned on the transistor, which was now connected directly between 5V and GND.
b) or, maybe the input was accidentally connected to 12V, which alone could have caused a latchup.
Posted on 2003-10-24 12:17:28 by VVV

If you output a 0, the transistor will just short to ground something that is already grounded. With a grounded input, it's less likely it'll pick up noise (than with a pullup).



connected a pin to 5V and then forced the output to 0; that turned on the transistor, which was now connected directly between 5V and GND


these two statement is contradict, which one is true?
:confused:
Posted on 2003-10-25 03:08:31 by dion
The first is true if you follow VVV's design advice.

The second is one possible guess as to what happened to the 8051 you burned out.
Posted on 2003-10-27 17:20:26 by tenkey
The two statements do not contradict each other.

Take a look at the picture. The pin can be used as an input when the transistor is OFF, which means you set the output to a "1" by writing a "1" to the port latch. Now the pullup pulls the pin high and you read a "1", but you can safely ground the pin to input a "0". The gate output is read when you do a port read.

If the transistor is ON it shorts the pin to GND. If you short the pin to GND externally you just help the transistor, by diverting most of its current to your external short. In other words you "connect to GND something already connected to GND".

The output latch is the one that turns on the transistor. For a "0" written to the latch the transistor is ON and it pulls the pin to ground, for a "1", it's OFF and the pullup pulls the pin to "1". When you do a port write, you write to the latch.
Therefore, the latch can be in the "1" state, but when you read the pin it can be in a "0" state, pulled LOW by something else in the circuit.

Now consider connecting the pin to +5V. The transistor has the collector connected to +5V and the emitter is grounded, so it's between +5V and GND, with nothing to limit the current, that is, "directly between +5V and GND".
If you now output a "0", you turn on the transistor and it will just cook.
Posted on 2003-10-28 11:58:33 by VVV
thanks so much again, got it :grin:
Posted on 2003-10-30 05:22:22 by dion