Controlling 8051 output port

Thread Starter

majoritical

Joined Nov 20, 2007
12
Hi guys,

I am trying to switch between various outputs on port 1 of an 8051, based on

data the 8051 receives from an external EPROM.

Now regardless of what I do, a LED connected to P1.0 is constantly high.

I even sent a low to it by changing the microcontroller code, but its still high.

How exactly do I controll the port 1 outputs. Sample code and (or)

schematics will be highly appreciated.

My code is available on request.

Thanks a bunch in advance!!!!
 

beenthere

Joined Apr 20, 2004
15,819
You will have to be more clear. Vanilla 8051's do not have ports, just address and data lines. Your microprocessor is probably based on an 8051 core, but we don't know what it is.

If you just used the output line to drive the LED with no current limiting, then that line is bad now. It's a good idea to understand all the hardware before using it.
 

Thread Starter

majoritical

Joined Nov 20, 2007
12
I'm using an Atmel AT89C51ED2. I'm trying to drive the LED's from port 1 (if thats right??).

Basically the LED's are for testing, to see if my code is working well. If that works, i intend on using some drivers to 'drive' a relay from the microcontroller.

Hope that clarifies things a bit.
 

Caveman

Joined Apr 15, 2008
471
This is a general statement without reading your processor's datasheet (which you should do. Yes, all of it!).

You need to make sure that the port is set to be an output first. This is typically done using an direction register. Then you have to drive the port register low.
 

mrmeval

Joined Jun 30, 2006
833
It's odd compared to other atmel products.

http://www.atmel.com/dyn/resources/prod_documents/doc4235.pdf

AT89C51RD2/ED2 I/O ports (P1, P2, P3, P4, P5) implement the quasi-bidirectional output that is common on the 80C51 and most of its derivatives. This output type can be used as both an input and output without the need to reconfigure the port. This is possible because when the port outputs a logic high, it is weakly driven, allowing an external device to pull the pin low. When the pin is pulled low, it is driven strongly and able to sink a fairly large current. These features are somewhat similar to an open drain output except that there are three pull-up transistors in the quasi-bidirectional output that serve different purposes. One of these pull-ups, called the "weak" pull-up, is turned on whenever the port latch for the pin contains a logic 1. The weak pull-up sources a very small current that will pull the pin high if it is left floating. A second pull-up, called the "medium" pull-up, is turned on when the port latch for the pin contains a logic 1 and the pin itself is also at a logic 1 level. This pull-up provides the primary source current for a quasi-bidirectional pin that is outputting a 1. If a pin that has a logic 1 on it is pulled low by an external device, the medium pull-up turns off, and only the weak pull-up remains on. In order to pull the pin low under these conditions, the external device has to sink enough current to overpower the medium pull-up and take the voltage on the port pin below its input threshold.

The third pull-up is referred to as the "strong" pull-up. This pull-up is used to speed up low-to-high transitions on a quasi-bidirectional port pin when the port latch changes from a logic 0 to a logic 1. When this occurs, the strong pull-up turns on for a brief time, two CPU clocks, in order to pull the port pin high quickly. Then it turns off again. The DPU bit (bit 7 in AUXR register) allows to disable the permanent weak pull up of all ports when latch data is logical 0.

The quasi-bidirectional port configuration is shown in Figure 5-1.
 

TechSpec

Joined Jul 9, 2007
12
8051 processors dont have direction registers. You simply set the port to 1 or 0 by P1.1=0 or P1.1=1, at the same time you can read the port aswell.
Driving a led is simple, just add resistor in series and pull cathode low.
 
Top