
- •Table of Contents
- •Preface
- •Additional Material
- •Basic Electronics
- •1.0 The Atom
- •1.1 Isotopes and Ions
- •1.2 Static Electricity
- •1.3 Electrical Charge
- •1.4 Electrical Circuits
- •1.5 Circuit Elements
- •1.6 Semiconductors
- •Number Systems
- •2.0 Counting
- •2.1 The Origins of the Decimal System
- •2.2 Types of Numbers
- •2.3 Radix Representations
- •2.4 Number System Conversions
- •Data Types and Data Storage
- •3.0 Electronic-Digital Machines
- •3.1 Character Representations
- •3.2 Storage and Encoding of Integers
- •3.3 Encoding of Fractional Numbers
- •3.4 Binary-Coded Decimals (BCD)
- •Digital Logic, Arithmetic, and Conversions
- •4.0 Microcontroller Logic and Arithmetic
- •4.1 Logical Instructions
- •4.2 Microcontroller Arithmetic
- •4.3 Bit Manipulations and Auxiliary Operations
- •4.4 Unsigned Binary Arithmetic
- •4.5 Signed Binary Arithmetic
- •4.6 Data Format Conversions
- •Circuits and Logic Gates
- •5.0 Digital Circuits
- •5.1 The Diode Revisited
- •5.2 The Transistor
- •5.3 Logic Gates
- •5.4 Transistor-Transistor Logic
- •5.5 Other TTL Logic Families
- •5.6 CMOS Logic Gates
- •Circuit Components
- •6.0 Power Supplies
- •6.1 Clocked Logic and Flip-flops
- •6.2 Clocks
- •6.3 Frequency Dividers and Counters
- •6.4 Multiplexers and Demultiplexers
- •6.5 Input Devices
- •The Microchip PIC
- •7.0 The PICMicro Microcontroller
- •7.1 PIC Architecture
- •Mid-range PIC Architecture
- •8.0 Processor Architecture and Design
- •8.1 The Mid-range Core Features
- •8.2 Mid-Range CPU and Instruction Set
- •8.3 EEPROM Data Storage
- •8.4 Data Memory Organization
- •8.5 Mid-range I/O and Peripheral Modules
- •PIC Programming: Tools and Techniques
- •9.0 Microchip’s MPLAB
- •9.1 Integrated Development Environment
- •9.2 Simulators and Debuggers
- •9.3 Programmers
- •9.4 Engineering PIC Software
- •9.5 Pseudo Instructions
- •Programming Essentials: Input and Output
- •10.0 16F84A Programming Template
- •10.1 Introducing the 16F84A
- •10.2 Simple Circuits and Programs
- •10.3 Programming the Seven-segment LED
- •10.4 A Demonstration Board
- •Interrupts
- •11.0 Interrupts on the 16F84
- •11.1 Interrupt Sources
- •11.2 Interrupt Handlers
- •11.3 Interrupt Programming
- •11.4 Sample Programs
- •Timers and Counters
- •12.0 The 16F84 Timer0 Module
- •12.1 Delays Using Timer0
- •12.2 Timer0 as a Counter
- •12.3 Timer0 Programming
- •12.4 The Watchdog Timer
- •12.5 Sample Programs
- •LCD Interfacing and Programming
- •13.0 LCD Features and Architecture
- •13.1 Interfacing with the HD44780
- •13.2 HD44780 Instruction Set
- •13.3 LCD Programming
- •13.4 Sample Programs
- •Communications
- •14.0 PIC Communications Overview
- •14.1 Serial Data Transmission
- •14.2 Parallel Data Transmission
- •14.4 PIC Protocol-based Serial Programming
- •14.5 Sample Programs
- •Data EEPROM Programming
- •15.0 PIC Internal EEPROM Memory
- •15.1 EEPROM Devices and Interfaces
- •15.2 Sample Programs
- •Analog to Digital and Realtime Clocks
- •16.0 A/D Converters
- •16.1 A/D Integrated Circuits
- •16.2 PIC On-Board A/D Hardware
- •16.3 Realtime Clocks
- •16.4 Sample Programs
- •Index

Circuits and Logic Gates |
|
|
85 |
A |
A |
|
A |
|
Y |
Y |
Y |
B |
B |
|
B |
AND |
|
OR |
XOR |
|
A |
Y |
|
|
|
NOT |
|
A |
A |
|
A |
|
|
||
|
Y |
Y |
Y |
B |
B |
|
B |
NAND |
|
NOR |
XNOR |
Figure 5-10 Logic Gate Symbols
5.4 Transistor-Transistor Logic
Transistor-Transistor Logic is a class of digital circuits built from bipolar transistors and resistors. TTL is used in a popular family of integrated circuits originally developed by Texas Instruments in 1962. These are known as the 7400 series of ICs. Components of the 7400 family are used in computers, industrial controllers, music synthesizers, and electronic test and measurement instruments. TTL provided a low-cost digital option to the expensive analog methods of the day.
TTL integrated circuit are available to perform the following functions:
1.logic gates such as AND, OR, NAND, NOR, and XOR
2.flip-flops
3.latch elements
4.counters and adders
5.shift registers
6.timing circuits
7.data bus drivers and buffers
8.display drivers
9.multifunction logic
10.memory
11.programmable logic arrays

86 |
Chapter 5 |
The TTL logic gates require a 5-volt DC power supply regulated to within 5% (5V ± 0.25V). They are available in a variety of packages. For prototyping and manually built applications the most-used package is the dual inline package (DIP). DIP integrated circuits have 14, 16, 20, 24, 28, or 40 pins arranged in a row along two sides of a rectangular plastic package containing the silicon chip. The ground pin is usually the last in the first row. For example, pin 7 of a 14-pin DIP. The 5-volt power pin is usually the highest numbered pin. For example, pin 14 on the 14-pin DIP. The pins in a DIP package are spaced 0.1" apart. DIP components are mounted on a printed circuit board by inserting the pins through a set of holes and then soldering the pins in place. Figure 5-11 shows two integrated circuits in a DIP package.
notch |
dot |
|
mark |
pin 1
Figure 5-11 Dual Inline Packaged (DIP) Integrated Circuits
One objection to DIP packages is that they become too large if more than 40 pins are required. The pin grid array (PGA) is one solution to this problem. PGAs are square packages with an array of pins coming out of the bottom. Microprocessors are sometimes implemented in PGAs. Surface mount technologies are often used in commercial electronic boards, since they allow fitting more circuitry into a smaller space. The pins on surface mount packages are bent out horizontally and soldered to the top surface of the board. In surface mount ICs the pin spacing is .05 inch or less. But surface mount packages are difficult to handle outside of commercial production, since the smaller pins spacing require special soldering irons and inspection microscopes. For non-manufactured projects, such as the ones in this book, the
DIP is the most suitable.
In the present context we discuss TTL logic gates furnished as integrated circuits constructed using semiconductor electronics. The part number of logic gate ICs is in the format 74XXX, where XXX refers to the specific gate implementation.
5.4.1 Inverter Gates
IC number 7404 is a hex inverter. Here the term hex refers to the six inverters included in the circuit. Figure 5-12 shows the schematics of the 7404 hex inverter.
+5V |
|
|
|
|
|
|
|
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
In |
Out |
|
|
|
7404 |
|
H |
L |
|
|
|
|
|
|
|
L |
H |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
GND |
|
Figure 5-12 7404 TTL Hex Inverter IC

Circuits and Logic Gates |
87 |
The function of a given logic gate can be shown in a truth table, such as the one in Figure 5-12. The truth table lists the outputs (high or low) for the given inputs (also high or low).
5.4.2 The AND Gate
The 7408 is an AND gate that includes four individual gates per package. The 7408 AND gate and its truth table are shown in Figure 5-13.
+5V
|
|
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In1 |
In2 |
Out |
|
|
|
|
|
|
|
|
|
|
|
L |
L |
L |
|
|
|
|
|
7408 |
|
|
|
|
L |
H |
L |
|
|
|
|
|
|
|
|
|
|
|
|
H |
L |
L |
|
|
|
|
|
|
|
|
|
|
|
H |
H |
H |
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GND
Figure 5-13 7408 Quad 2-input AND Gate
The AND gate in Figure 5-13 is described as quad 2-input. Four individual AND gates are contained in the circuit and each one has two input lines. The gate logic corresponds to the Boolean AND: if both inputs are high, then the output is high, otherwise the output is low. If the input lines are designated as A and B, and the output as Y, then the AND operation can be expressed in the equation:
Y = A• B
In this case the dot operator represents the AND function, not arithmetic multiplication.
5.4.3 The NAND Gate
A variation of the AND gate is the 7400 NAND gate. In this case the AND operation is replaced with the inverted AND, or NAND. Thus, if both inputs are high, the output is low, otherwise the output is high. The 7400 NAND gate is shown in Figure 5-14.
+5V
|
|
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In1 |
In2 |
Out |
|
|
|
|
|
|
|
|
|
|
|
L |
L |
H |
|
|
|
|
|
7400 |
|
|
|
|
L |
H |
H |
|
|
|
|
|
|
|
|
|
|
|
|
H |
L |
H |
|
|
|
|
|
|
|
|
|
|
|
H |
H |
L |
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GND
Figure 5-14 7400 Quad 2-input NAND Gate

88 |
Chapter 5 |
Note that in the NAND gate of Figure 5-14, the AND symbol has been replaced with the NAND symbol as in Figure 5-10. The logic equation for the NAND gate is the combination of the AND and NOT operations, as follows:
Y = A• B
Here the vertical bar over the equation’s right-hand side indicates negation.
5.4.4 The OR Gate
The 7432 OR gate performs the Boolean OR of the two input lines. If either line A or line B is high, then line Y is high, otherwise line Y is low. Figure 5-15 is a diagram of the 7432 quad 2-input OR gate.
+5V
|
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In1 |
In2 |
Out |
|
|
|
|
|
|
|
|
|
|
L |
L |
L |
|
|
|
|
7432 |
|
|
|
|
L |
H |
H |
|
|
|
|
|
|
|
|
|
|
|
H |
L |
H |
|
|
|
|
|
|
|
|
|
|
H |
H |
H |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GND
Figure 5-15 7432 Quad 2-Input OR Gate
The equation of the OR operation with two inputs is:
Y = A + B
The plus sign in the previous equation indicates the Boolean OR operation, not arithmetic addition.
5.4.5 The NOR Gate
Another version of the OR gate is the 7402 NOR quad 2-input NOR gate. Here the Boolean OR is negated, as shown in Figure 5-16.
+5V
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
|
In1 |
In2 |
Out |
|
|
|
|
|
|
L |
L |
H |
|
|
|
7402 |
|
L |
H |
L |
|
|
|
|
|
|
|
H |
L |
L |
|
|
|
|
|
|
H |
H |
L |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
GND
Figure 5-16 7402 Quad 2-input NOR gate

Circuits and Logic Gates |
89 |
The equation for the NOR gate consists of negating the inputs of the OR gate, as follows:
Y = A + B
The gates shown in this section contain two input lines, labeled A and B. Logic gates are also available that contain more than two inputs, for example, the 7410 is a three 3-input NAND gate. Other logic gates with 3, 4, and 8 inputs are available. For example, the 7410 is a three 3-input NAND gate, the 7420 a two 4-input NAND gate, and the 7430 is a single 8-input NAND gate.
5.4.6 Positive and Negative Logic
The gates discussed so far assume that logic high is regarded as true and logic low as false. This is called positive logic. If we were to invert these assumptions so that logic high is regarded as true and logic low as false we would have a system based on negative logic. In this case the AND and the OR functions would be exchanged in regards to positive logic.
Digital circuit designers can often reduce the number of required integrated circuits by switching between positive and negative logic. For example, if an extra AND gate is available but the circuit requires an OR gate, the AND gate can be used by assuming negative logic. Circuit diagrams can be shown to use positive or negative logic by the position of the inverting circles. By convention, a circle on the input lines indicates negative logic and positive logic if it is placed on the output line. Figure 5-17 shows the equivalent circuits for gates using positive and negative logic.
POSITIVE |
NEGATIVE |
LOGIC |
LOGIC |
=
=
=
Figure 5-17 Circuit Symbols for Positive and Negative Logic Gates
The position of the inverting circles in the circuit diagrams is consistent with the notion that inverting the inputs changes the gate function. Thus, a negative logic AND gate functions as an OR gate and vice versa. In this manner a circle on the input line is read as the signal on that line being active low. An active low signal is asserted as true when it is electrically low. For example, the output of the 2-input NAND gates of Figure 5-14 is low when inputs A and B are both high, as shown in the

90 |
Chapter 5 |
circuit truth table. But the NAND gate can also be interpreted as a negative logic OR gate as in Figure 5-17. The one logic operation that is the same in negative or positive logic is NOT, as also shown in Figure 5-17.
An alternative explanation of positive and negative logic can be based on the truth table for the Boolean OR, as follows:
A |
B |
| |
Y |
-------- |
|
| |
----- |
T |
T |
| |
T |
T |
F |
| |
T |
F |
T |
| |
T |
F |
F |
| |
F |
In binary form and positive logic the OR truth table is as follows:
A |
B |
| |
Y |
-------- |
|
| |
---- |
1 |
1 |
| |
1 |
1 |
0 |
| |
1 |
0 |
1 |
| |
1 |
0 |
0 |
| |
0 |
If we now invert the binary values in the second table, the results are as follows:
A |
B |
| |
Y |
-------- |
|
| |
----- |
0 |
0 |
| |
0 |
0 |
1 |
| |
0 |
1 |
0 |
| |
0 |
1 |
1 |
| |
1 |
Note that the last truth table matches that of the AND function. Thus, by inverting the truth table for the logical OR we produced the truth table for logical AND, validating the previous assertion that a negative logic AND gate is equivalent to an OR gate.
5.4.7 The XOR Gate
The last elementary logic gate is called the XOR or exclusive OR gate. In the XOR function the output is high if the inputs have opposite values, otherwise the output is low. Figure 5-18 shows the 7486 quad 2-input XOR gate and the corresponding truth table.
+5V
14 |
13 |
12 |
11 |
10 |
9 |
8 |
|
|
|
|
|
|
|
|
In1 |
In2 |
Out |
|
|
|
|
|
|
L |
L |
L |
|
|
|
7486 |
|
L |
H |
H |
|
|
|
|
|
|
|
H |
L |
H |
|
|
|
|
|
|
H |
H |
L |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
GND
Figure 5-18 7486 Quad 2-input XOR gate

Circuits and Logic Gates |
91 |
Since an XOR gate’s output is high if the inputs are different it can serve as a difference detector for logic levels. The following equation expresses the XOR relationship for two inputs (labeled A and B) and one output (labeled Y).
Y = A B
The logic symbol for XOR is the symbol for OR (+) enclosed in a circle. The XOR function can also be expressed in terms of Boolean OR and AND operations, as in the following equation:
Y = ( A• B) + ( A• B)
Figure 5-19 is the circuit diagram for the XOR gate constructed from OR, AND, and NOR gates.
A
Y
B
Figure 5-19 XOR Gate Circuit Diagram
Note in the XOR truth table in Figure 5-18 that if one of the inputs is forced high, then the gate functions as an inverter for the other input. Also, note in the truth table for the NOR gate (Figure 5-16) that if both inputs are low or high, then the circuit also functions as an inverter. If the inputs of a NOR gate are tied together the gate performs as an inverter. Often a circuit designer can take advantage of these identities in order to use an available gate for a function other than the one originally intended, thus saving having to use an additional IC.
5.4.8 Schmitt Trigger Inverter
Digital signals used in operating electronic devices consist of pulses. Conceptually, the pulses instantly fluctuate between a high and a low voltage level, ideally generating a square waveform. But signal noise in a circuit often contaminates the waveform into a non-rectangular shape. This noise can be the cause of circuit problems. For example, consider a plot of output voltage versus input voltage for a simple inverter, as shown in Figure 5-20.

92 |
Chapter 5 |
Volts input
5
1.4 volts
3
1
Volts output
1 |
3 |
5 |
Figure 5-20 TTL Input and Output Voltage
In Figure 5-20 you notice that as the input voltage is raised from zero, the output voltage stays high. However, when the input voltage reaches about 1.4 volts (dashed line in Figure 5-20) the output switches sharply from high to low. Now suppose there is noise on the input line and that this noise causes the voltage to go above 1.4 volts and then below this value. In this case, the inverter’s output may also switch its logic state several times during the transition period following the voltage fluctuations.
One common solution to this problem is based on a property of physical systems called hysteresis. Although the term derives from a Greek work meaning deficiency, it can also be related to “history.” In this sense hysteresis refers to the property of an object that does not instantly follow the forces applied to it, but reacts “historically” to these forces. In other words, the new state depends on the object’s immediate history. Adding hysteresis to a circuit’s input makes it so that the point at which the output changes state depends on the current state of the output. For example, if output is high, it does not go low until the input voltage is raised above 1.7 volts. On the other hand, once the output goes low it will not change back to high until the input falls below 0.9 volt. This “lag” before changing to a new state makes the output much less susceptible to being inadvertently switched by noise. Figure 5-21 shows a plot of the input versus the output currents on a circuit with hysteresis.
Volts input
5 |
|
|
3 |
|
|
1 |
|
|
|
|
Volts |
|
|
output |
1 |
3 |
5 |
Figure 5-21 Effect of Hysteresis in an Inverter Circuit