8051 Interfacing: Interfacing To 8051 I/O Ports
8051 Interfacing: Interfacing To 8051 I/O Ports
It is always best connecting the switch to ground with a pull-up resistor as shown in
the "Good" circuit. When the switch is open, the 10k resistor supplies very small
current needed for logic 1. When it is closed, the port pin is short to ground. The
voltage is 0V and all the sinking current requirement is met, so it is logic 0. The 10k
resistor will pass 0.5 mA (5 Volt/10k ohm). Thus the circuits waste very little current
in either state. The drawback is that the closure of switch gives logic 0 and people
like to think of a switch closure gives logic 1. But this is not a matter because it is
easy to handle in software.
Fair circuit:
The "Fair" circuit requires that the pull-down resistor be very small. Otherwise, the
pin will rise above 0.9V when the resistor passes the 1.6mA sinking current. When
the switch is closed, the circuit waste a large current since virtually no current flows
into the pin. The only advantage is that a switch closure gives logic 1.
Poor circuit:
In the "Poor" circuit, the logic 1 is stable when the switch is closed. But when the
switch is open, the input floats to a noise-sensitive high rather than a low. An open
TTL pin is usually read as logic 1 but the pin may picks up noise like an antenna.
To conclude, driving a TTL input should always consider current sinking (pulling
input to 0V).
LED ON I/O PORTS:
Since TTL outputs is designed to feed multiple TTL inputs, they are good at current
sinking but poor at current sourcing. The Standard TTL can sink up to 16mA and
source 250uA. The LS logic family can sink 8mA and source 100uA. The 8051 port
pin can sink 1.6mA (3.2mA for port 0) and source 60uA. Therefore, if you drive
significant current, try to arrange your circuits to use current sinking.
Unlike diodes, Light-emitting diodes have a forward voltage drop from 1.7 to 2.5
volts and most of them flow a forward current 20mA.
Poor circuit: since the TTL output can't source above 1mA so the LED will be very
dim.
Fair circuit: The LED will conduct heavily at about 2V and the extra 3V has to be
dropped in the TTL circuitry. This causes high power dissipation in the TTL or the
LED fails.
Good circuit: The resistor limits the current. The resistance can be calculated by
assuming its voltage is about 2.5V and the TTL output is 0.9V. For 2.2V LED, 1.9V is
across the resistor so the 220ohm would limit the current to 8.6mA (1.9/220). For
1.7V LED, 2.4V is across the resistor so it would limit the current to 10.9mA
(2.4/220). The resistor should not less than 100ohm or the LED would fail.
CODE EXAMPLE
ASSEMBLY LANGUAGE :
SETB P1.0
; input pin.
LOOP:
JB P2.0, LOOP ; not grounded then stay in loop
CLR P0.0 ;To clear pin P0.0 when P1.0 is at 0 v
C LANGUAGE:
BIT button p1.0 / * Using BIT keyword for p1.0 definition*/
BIT LED p2.0
void main ( )
{
while (1) {
LED = button ; /* Note LED=button is wrong */
}
}
In A, NPN transistor (say a BC337 or BC338) is being used to control a relay with a 5
V coil. Series base resistor R1 is used to set the base current for Q1, so that the
transistor is driven into saturation (fully turned on) when the relay is to be
energized. That way, the transistor will have minimal voltage drop, and hence
dissipate very little power as well as delivering most of the 5V to the relay coil.
How do work out the value of R1?.
Let us say RLY1 needs 50mA of coil current to pull in and hold reliably, and has a
resistance of 24 Ohms so it draws this current from 5V. Our BC337/338 transistor
will need enough base current to make sure it remains saturated at this collector
current level. To work this out, we simply make sure that the base current is greater
than this collector current divided by the transistors minimum DC current gain hFE.
So as the BC337/338 has a minimum hFE of 100 (at 100mA), we'll need to provide it
with at least 50mA/100 = 0.5mA of base current.
In practice, you give it roughly double this value, say 1mA of base current, just to
make sure it does saturate. So if your resistance will be
TTL Logic High Voltage (Min) /1ma ( 1K approx)
EXAMPLE
(SPJ SIDE51):
1.
void main() {
while (1) {
P0 = P1; /* Note P1=P0 will not work
}
}
2.
voided main() {
char port_value;
while (1) {
port_value = P1;
P0 = port_value;
}
}
USING ULN
Home
8051 Interfacings
8051 Downloads
About Me
Contact Me
Get a free website at Webs.com