
- •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

Chapter 5
Circuits and Logic Gates
In Chapter 1 we covered basic electronics and elementary circuit components such as resistors, capacitors, inductors, transformers, and simple semiconductors. In this chapter we expand these topics and introduce new ones so as to provide a basic background in digital electronics and in the electronic circuits that are often used in microcontroller-based systems. The chapter also contains information on some of the simpler electronic devices often found in electronic circuit boards, such as diodes, LEDs, and logic gates. Chapter 6 covers other circuit components including switches, seven-segment displays, LCDs (liquid crystal displays), buzzers, motors, and flip-flops.
5.0 Digital Circuits
Digital circuits are the basic building blocks from which microprocessors, microcontrollers, computer systems, and virtually all digital electronic devices are constructed. These building blocks are essential and perform elementary functions. A single device can contain thousands of these primitive components. Knowing about these elementary building blocks is necessary if you are to design or program digital circuitry.
Understanding these components requires viewing them at the proper level of abstraction. To understand a simple digital device you must know how the simpler transistors that make up the device operate. To understand how a shift register works it is useful to visualize it in term of the logic gates from which it is built. Similarly, once you understand how counters and registers work it is easy to grasp how a complex large-scale integrated circuit, such as a serial port, operates.
Fortunately, at any given level of abstraction, it is not necessary to consider every single device of that class, because knowing about one or two representative devices is usually sufficient. For example, once you understand the operation of a few different logic gates you can assume that others work in a similar manner. So we start by explaining the basic facts about diodes and transistors, then we consider logic gates that are built from transistors, then the more complex circuits that are built from elementary logic gates, and so on.
77

78 |
Chapter 5 |
5.1 The Diode Revisited
Chapter 1 concluded with a brief discussion of diodes and p-type and n-type silicon junctions. The diode acts as a very useful one-way valve for electrical current and is one of the most powerful developments in semiconductor physics.
But in order to use the diode it is not necessary to comprehend the physical and electrical principles that make it work. Rather, the diode can be treated as a device made from two pieces of silicon and it has the property of passing current in one direction.
When a voltage is applied to the diode that makes the n-type end more positive than its p-type end, electrons flow from the n to the p direction, but not from the p to n direction. In this manner the diode behaves as a one-way filter that allows electrons to flow in one direction but not in the other one. Figure 5-1 shows the p-n junction in a diode and its electrical symbol.
+anode
p-type
symbol
n-type
-cathode
Figure 5-1 Diode Construction and Symbol
The general convention is that current flows from positive to negative, although in reality electrons flow from negative to positive. Benjamin Franklin is usually held responsible for this erroneous convention. Therefore, current in the diode in Figure 5-1 flows from the anode to the cathode, but not vice versa.
The electrical symbol for a diode, in Figure 5-1, resembles an arrow pointing in the direction of current flow. When the anode voltage of a diode exceeds the cathode voltage the diode is said to be forward-biased. A forward-biased diode acts like a short circuit. To prevent too much current from flowing a resistor is usually inserted in series with the diode, as in Figure 5-2.
Current
flow
+
-
Figure 5-2 Diode and Resistor in a Circuit

Circuits and Logic Gates |
79 |
y
I
x
|
V |
Avalanche |
Forward |
|
|
point |
breakover |
|
|
|
point |
Figure 5-3 I/V Plot in a Diode
The diode’s behavior can be also be represented by a curve that shows cur- rent-versus-voltage, sometimes called an I/V curve. If the voltage is represented on the abscissa of the Cartesian coordinate plane (x-axis) and current on the ordinate (y-axis), then the plot resembles the one in Figure 5-3.
In Figure 5-3 the current is non-linear; that is, it becomes very large if a positive voltage difference across the diode exceeds about 0.6 volts. This point is called the forward breakover point. If the diode is reverse-biased and the voltage is progressively increased, a point is reached in which the junction suddenly begins to conduct. This is called the avalanche point. The effect is similar to an internal short and the diode can be destroyed. Note that the I-V plot of a resistor is quite different from that of a diode. Since the resistor obeys Ohm’s Law its I/V curve would be a straight line.
The typical diode, such as the ones used in logic and display circuits, can handle a current of 10 to 20 milliamps. For a 5-volt supply a 300-ohm series resistor limits the current through the diode to a reasonable value.
5.1.1 The Light-Emitting Diode (LED)
One of the most useful types of diodes is an LED (light emitting diode). The LED produces light when it is forward-biased. The most common LEDs have a distinctive red color, although they may be amber, green, blue, or white.
The LED is a semiconductor device that emits incoherent light when for- ward-biased. The color of the light depends on the chemical composition of the semiconducting material. The first practical LEDs were developed in 1962. LEDs are

80 |
Chapter 5 |
used in many electronic devices to signal the presence of an electric current. Like any diode, the LED consists of a chip of semiconducting material impregnated with impurities to create a p-n junction. As is the case in all diodes, current flows easily from the p-side, or anode, to the n-side, or cathode, but not in reverse.
The first LEDs were made of gallium arsenide. Today LEDs are made of a variety of materials so as to produce light of different colors.
Advances in materials science have made possible the production of devices with ever shorter wavelengths, producing light in a variety of colors.
Because LEDs are diodes they light only with positive electrical polarity, that is, when forward-biased. When the polarity is reversed very little or no light is emitted by the LED. Figure 5-4 shows a typical LED.
Flat tab
-
+
Figure 5-4 A Typical LED
The correct polarity of a new LED can usually be determined by observing that the longest terminal is the anode. If the terminals have been altered, then it is risky to try to determine polarity by observing the LED’s internals. Although in most LEDs the larger internal tab is the cathode, there are others in which it is not. A more dependable clue to the LED’s polarity is the flat tab on the LED’s base, which indicates the cathode, as in Figure 5-4.
Ratings vary among the different sizes and types of LEDs. Most LEDs are rated to operate between 1.7 and 3.8 volts and at currents of 10 to 40 mA. The light-emitting capacity of an LED is measured in megacandela or mcd. Small commercial LEDs range from 10 to about 5000 mcd.
Once the LED’s ratings and circuit’s voltage are known it is necessary to calculate the value of the series resistor so that the current does not exceed the LED’s capacity. For example, the series resistor for wiring a commercial red LED rated at 2.6 VDC and 28 mA on a 5 volt circuit is calculated as follows:
STEP 1: Calculate the voltage across the resistor by subtracting the LED’s forward voltage from the supply voltage, in this case:
STEP 2: Apply Ohm’s Law to calculate the required resistor:
The electronic symbol for an LED is somewhat similar to that for a diode, as shown in Figure 5-5.