8051 ports.. again

Hi,

i just checked that on power up all ports on 8051 are configured as output ports and you have to wirte FFh to each one to configure them as input.

my question is, if you have to write an output of FFh to any output port, then doesn't that convert it to an input port immediatly? and of so, how do i write all 1's to an output port if i need to?

another thing..

i know that all the ports are bit addressable. but is each bit in a particular port eg. port 0 also bit addressable as individual input output or does the entire port get configured as either input of output.

thanks fellows. will give the group loads of credit if this thing works!

cheers al

Reply to
Aliasger
Loading thread data ...

On a (standard...) 8051 there is no such thing as an input/output configuration. The port is input and output at the same time (called "quasi bidirectional"), but the output function can only pull the port to 0 with an open drain. The 1 state is formed by a pull-up current source. So if you write a 1 to the port, it outputs a 1, but it can be pulled low by an external drive. If you write a 0 to the port, the output will be pulled hard low by th eopen drain. The pull-up current is around 50uA. The 0-1 transition is pulled 'hard' to 1 for 2 clock cycles, to overcome any capacitive delay, and then released again to weak pull up.

I suggest you go read the datasheet of the 8051. It is all explained in great detail, including the schematics of the I/O port pins.

Meindert

Reply to
Meindert Sprang

In article , Meindert Sprang writes

Also, the ports are all set to 0xFF at power up, you do not need to write to them to use them as inputs.

Port 0 does not have any internal pullups so you may need to provide them externally.

--
Tim Mitchell
Reply to
Tim Mitchell

Tim Mitchell wrote in news:BJpZ7nTLua3$ snipped-for-privacy@tega.co.uk:

Not "may", "do" if you want Port 0 pins to do something other than sit at zero.

--
- Mark ->
--
Reply to
Mark A. Odell

aliasger snipped-for-privacy@hotmail.com (Aliasger) wrote in news: snipped-for-privacy@posting.google.com:

Where did you hear this? Certainly not in the MCS-51 Users Manaul that Intel has for *free* on their website.

All SFR's that are an integral of 8 bytes, e.g. 0x80, 0x88, 0x90 etc. are bit addressable.

Since there is no true input or output mode configuration (this is critical to understand when working with 8051s, please read Intel's MCS-51 Users Manual) you can use some of the bits as input and some as output. The entire port does not need to be used exclusively as input or output.

--
- Mark ->
--
Reply to
Mark A. Odell

In article , Mark A. Odell writes

As inputs, yes, but you don't need pullups if using them as outputs.

--
Tim Mitchell
Reply to
Tim Mitchell

Tim Mitchell wrote in news:QAzNZlqjvd3$EA$ snipped-for-privacy@tega.co.uk:

Since when? Explain to me how open-collector outputs can drive a one without a pull-up? Port 0 can only drive ones without pull-ups when used as a address/data bus.

--
- Mark ->
--
Reply to
Mark A. Odell

Tim Mitchell wrote in news:QAzNZlqjvd3$EA$ snipped-for-privacy@tega.co.uk:

Wait, why as inputs? Even that doesn't make sense. If some other logic drives the input to a one, then the pull-up would add nothing. No, on Port

0 you need pull-ups for expected output operation but do not need them when Port 0 is an input port fed by a driving source capable of driving the pins high.

Please see page 3-6 of the Intel MCS-51 User's Manual. Note Figure 4, sub-figure A. When not being used as address/data the top FET is not enabled and you have your basic open-collector I/O pin.

--
- Mark ->
--
Reply to
Mark A. Odell

In article , Mark A. Odell writes

Errr.... I think we are arguing at cross purposes here. Everything you have said is true, but there are some input/output uses you haven't considered.

I said that you "may" need pullups, because if you are using Port 0 as open collector drivers, say to drive an LED display connected to Vcc or something like that, you don't need pullups. To switch the output between Vcc and 0, yes you would need pullups.

If you are using Port 0 as inputs with some device connected which pulls low, like a push switch connected to ground, then you will need external pullups. If the connected device outputs a voltage, like a logic gate or something, then no, you don't need a pull up.

The original poster sounded a bit new to the 8051 so I didn't want to make blanket statements about always needing pullups. But this discussion has probably confused him even more.

--
Tim Mitchell
Reply to
Tim Mitchell

Tim Mitchell wrote in news:GUfIc60See3$ snipped-for-privacy@tega.co.uk:

But you already have one, the LED to VCC acts as a pull-up.

How can a switch pull low to ground without having a pull-up on the otherside? Since it must, you don't need a pull up on Port 0. I'm being a bit semantic here, I realize.

Right. The OP should just stick a 10k resistor pack on Port 0 and be done with all of this.

--
- Mark ->
--
Reply to
Mark A. Odell

Mark ..Tim..

Thanks for your info, but there is still one thing i can't understand. I'll use this example;

We know that to configure as input each port has to have FFh written to it.

Now suppose I have a port I'm using as an output port, eg. P1. And now I execute these instructions at startup:

  1. Mov P1,#FFh
  2. Mov P1,#01h

So I'm assuming that after instruction 1 P1 is now an input port and will not output 01h in my next instruction. In that case how do I output FFh at any port without causing problems.

Am I right? or just completly off track? :-(

- Ali

Reply to
Aliasger

P1 will look like a 1 if you write a 1 to it. There's a weak internal pullup resistor that pulls it high.The reason that bit CAN (not must) be used as an input is that something external can pull the bit down.

Reply to
Gary Kato

There is no 'configure as input' function. Pins can ALWAYS be read, and NFETs will ALWAYS drive low, if asked to.

Take a look at

formatting link
Pages 4-6, and esp fig 5.

The generic 8051 does NOT have a DataDirectionRegister, it is what's called a Quasi-Open Drain port (soft PFETS / Stronger NFET).

Newer 80C1's have 4 modes on the pins, for more options, set with

2 bits per pin.

-jg

Reply to
Jim Granville

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.