Файл: Embedded Controller Hardware Design (Ken Arnold, 2001).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2658
Скачиваний: 0
163CHAPTER EIGHT
Basic I/O Interfaces
to another bit, such as the carry bit, which is very useful when sending and receiving information by a serial bit sequence. This is a useful way to transfer data and addresses between the processor and serial I/O and memory devices.
For example, to output eight bits to Port 1 the following instructions can be used:
MOV |
90h, A ; Accumulator is output to |
port 1 |
||
MOV |
P1, A |
; |
same as above, using the |
symbolic name for port 1 |
MOV |
P1,0ffh |
; |
Output FF hex (all ones) |
to port 1 |
It is also possible to output a single bit, as shown below:
CLR |
P1.0 |
; |
The |
LSB |
of |
Port |
1 |
is |
cleared (made equal to 0, ~0 Volts) |
SETB |
P1.0 |
; |
The |
LSB |
of |
Port |
1 |
is |
set (made equal to 1, ~5 Volts) |
Likewise, eight bits can be input into the accumulator, using:
MOV |
A, P1 |
; Acc<=port 1 |
Single bit input can be accomplished from Port one bit 1 to the carry bit:
MOV |
C, P1.1 ; Carry bit is loaded with the current state of P1.1 |
An input bit can also be used to control program flow:
JB |
P1.0, address ; Jump to address if bit P1.0 is 1, otherwise continue |
Monitor commands can also be used to access the I/O pins on the SDK:
#P1 |
allows direct R/W of port 1 |
#SB 92 allows observing and set/clr of P1.2 bit
Port 1 can be accessed one bit at a time in the bit addressable address space from 90h to 97h, which correspond to each of the eight bits of port 1. The MSB (P1.7) can be accessed at bit address location 97h. The entire port can be reset to zero by moving the value zero to location 90h executing the instruction:
MOV 90h,#0
The MSB (P1.7) could be set to logic one by setting bit number 97h executing the following instruction:
SETB 97h
164EMBEDDED CONTROLLER
Hardware Design
Bit P1.7 can be cleared to logic zero by executing the instruction CLR 97h. Likewise, a single input bit can be tested using a conditional jump instruc tion, such as: JB 90h,address which will jump to the address only if the LSB of Port 1 (P1.0) is high when the instruction is executed. You can easily observe this operation by using a logic probe or meter connected to pin 1 of the pro cessor chip, which is the LSB of Port 1 (P1.0). Normally the pin will be in the logic one state after reset, but executing the CLR 90h instruction will clear P1.0. I/O pins can also be input directly to another bit, such as the carry bit, which is very useful when sending and receiving information by a serial bit sequence. This is exactly how the data and addresses are sent and received between the processor and serial I/O and memory devices.
It’s important to recognize that some instructions modify the output latch, rather than the input pin. This applies to instructions that read-modify-write the output pins, such as ANDing the port with a constant value to mask certain bits. This is necessary because the I/O pins can serve as input or output. Pins which are to be used as inputs must be written with a logic one output first, so that an external device such as a switch to ground, can pull the line low.
If the pins were used directly, then a pin that was being used as an input but just happened to be low at the time that the logical AND operation was carried out, would become stuck low! By performing the logical AND with the out put register instead, the state of the input pin will not be affected.
The internal circuits for the I/O pin are shown in simplified form in the figure. The 8051 uses a modified open-drain output structure, which allows it to oper
ate as either input or output, or even both at the same time. It consists of a constant |
|||||||||||
current pull-up (current source), an |
|||||||||||
N-channel MOSFET switch as a pull- |
+V |
||||||||||
down device (FET sinks current). |
|||||||||||
Resistor |
|||||||||||
The FET is an active switch, so it can |
|||||||||||
IOH Sources |
|||||||||||
sink more current. That is why the |
In |
Current |
|||||||||
8051’s sink current is large compared |
Port |
||||||||||
Pin |
|||||||||||
to source. |
|||||||||||
Out |
Output |
||||||||||
The simplified I/O port circuit diagram |
IOL |
Sinks |
|||||||||
NMOS FET |
Current |
||||||||||
in Figure 8-1 shows a pull-up resistor |
|||||||||||
providing a weak current source, and a |
|||||||||||
FET pull-down capable of sinking more |
|||||||||||
current. The input pin can also be read |
Figure 8-1: Simplified I/O port circuit. |
||||||||||
165CHAPTER EIGHT
Basic I/O Interfaces
by the input buffer. This allows the pin to be used as either input or output. When using the pin as an input, the FET must be turned off by writing a one to the output pin. Then an external device, such as a switch connected between the pin and ground, will pull the input low when the switch is closed. When using one of these pins as an input, an external pull-up is usually not re quired, as the pin is pulled up internally.
While the simplified representation approximates the behavior of the circuit, in order to thoroughly understand how it behaves, we must go deeper. The diagram in Figure 8-2 shows a somewhat more accurate version of the circuit,
which is referred to as a “quasi- |
+V |
+V |
||
bi-directional” circuit. The pull-up |
Current |
|||
is actually a current source, which |
Source |
|||
can source one of two currents. |
“1” |
“0” |
||
When the output is static in the |
||||
Resistor |
||||
high state, the current source |
Transistor |
|||
Sources |
||||
provides about 50 microamperes |
OFF |
Switch |
Current |
|
of current to an external load. |
(open) |
ON |
||
(shorted) |
||||
When the output pin transitions
from one to zero, the FET switches on, sinking the source current and
the current from any output load to
ground. The switch is not perfect, and has some resistance, which causes the output voltage to rise somewhat above ground. If the current source is a resis tor, then the low-to-high output voltage transition would be very slow, due to the R-C time constant formed by the resistor and the load capacitance. Even with a small constant current source, the output voltage will ramp up slowly. The current source in the 8051 behaves differently on a zero-to-one transition. When the output pin transitions from zero to one, the current source provides a much higher current for a very short time, pulling the output voltage up quickly. Then the current source reverts to its lower value. This unique feature of the output addresses the slow rise time problem by lowering the time con stant during the zero-to-one transition, without requiring an external input device to sink more than 50 microamperes. A secondary benefit is that the pin circuitry does not have to be explicitly programmed as an input or output, as is the case with all other microcontroller families. This also means that the pin can be used alternately for input and output, like an open-collector or opendrain bus without concern for bus contention. This is useful for things like
166EMBEDDED CONTROLLER
Hardware Design
shared request lines and multiprocessor communication. The disadvantage to this type of I/O circuit is that it cannot source much current. The sink current is greater than the source current, but still less than other microcontrollers.
Output Current Limitations
The output low (sink) current for the 80C32 is limited to approximately15 milliamperes maximum. That is an absolute maximum specification value, meaning that output current in excess of this value can damage the device. Shorting a low output to the power supply would damage the device. In addition, the total sink current for an 8-bit port is limited to approximately 26 milliamperes. So if all the outputs of a port are low at the same time, they can only sink a little more than 3 milliamperes each.
On the other hand, the current source will not supply any more than about 50 microamperes under static conditions, so it cannot be destroyed by shorting an output to ground. The 80C32 current source also has an additional feature that improves input noise immunity. The current that must be sunk by an external device trying to pull the 80C32 pin low increases as it approaches ground during a one-to-zero transition. That means that weak low going noise pulses are less likely to cause an error.
Let’s examine a simple case, that of driving a LED which needs around 10 milliamperes to be clearly visible. In this case, we connect the LED and a resistor to limit the current between the power supply and the processor pin as shown in Figure 8-3.
+5 V
330 to
470 Ohms
80C32
Port 1 |
1 |
LED |
|
Bit 0 |
The LED will be off as long as the output pin is high. When the output pin goes low,
the output will sink current and the LED will turn on. LEDs have a relatively constant voltage (1.5 to 2 volts typical) across them when they are operating.
If the LED has 2 volts across it, then the resistor has the remaining 3 volts across it, then the current in the resistor and LED is 3 volts/330 ohms, or about 9 milliamperes. This will be enough current to light the LED, but it won’t be very bright. Also, the processor would only be capable of lighting a couple of LEDs. When more output current is required, other circuits can be used.
167CHAPTER EIGHT
Basic I/O Interfaces
+5 V
330 to
470 Ohms
80C32
CPU Pin
Sources
+Current
Turns
Transistor
ON
Port 1 |
|
Bit 0 |
Optional |
Base Current |
|
Limiting R |
LED Typically Requires from 10–20 mA for
Full Brightness
Output
Sinks
Current
Figure 8-4: NPN transistor for greater load current.
Figure 8-4 shows how an NPN transistor can be used to amplify the current from the processor’s output. The processor’s output source current and transistor gain limit the potential load current. A special type of transistor, called a Darlington transistor, has a very high current gain, on the order of thousands. The CPU’s output high current is multiplied by the transistor’s gain, allowing much more current to flow in the load.
In this case, the 50 microampere source current is multiplied by the transistor gain, allowing more current to flow in the transistor collector, and hence the resistor and LED. When the output pin is high, the LED is on. For 8051 family parts, a current limiting resistor in series with the transistor base is not required, since the current source limits the base current. Other processor outputs will usually require the base resistor to limit the base current. The low source cur rent and transistor gain is a limiting factor in this case, along with the higher saturation voltage on the collector-emitter output of the Darlington transistor compared to a regular transistor. Note that the output voltage switched by the transistor is separate from the processor supply, so this circuit can also be used to switch much higher voltages, limited only by the transistor’s maximum collector voltage specification. Yet another approach, using a PNP transistor may be a better solution for high current loads.
This approach is shown in Figure 8-5. Using a PNP transistor so that the processor’s output greater output low sink current to turn on the transistor, allows a standard transistor to be used in place of a Darlington device. It also allows the output switch to control a grounded load, which the previous versions could not. For an output low current of 1.6 milliam peres (one standard TTL load) and a
Base Current |
+5 V |
|||
Limiting R |
Transistor |
|||
Port 1 |
1K to 4.7K |
|||
Sources |
||||
Bit 0 |
Current |
|||
CPU Pin |
toLoad |
|||
Sinks |
||||
Current |
330 to |
|||
Turns |
||||
470 Ohms |
||||
Transistor |
||||
NMOS FET |
ON when |
|||
Outpu LOW |
||||
LED |
||||
80C32
Figure 8-5: PNP transistor output driver.