
- •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 6
Circuit Components
This chapter covers the most common general-purpose circuit components often found in microcontroller boards. Some simpler circuit devices such as diodes, LEDs, and logic gates, were discussed in chapter 5. Here we mention other common components including power supplies, switches, clocks and timers, flip-flops, decoders, seven-segment displays, and liquid crystal displays (LCDs). Other components sometimes found in microcontroller-based digital circuits are not discussed either because of their simplicity (buzzers and relays), their passive nature (connectors, adapters, batteries, and wiring), or their specialized features (motors, digital-to-analog and ana- log-to-digital converters, and memory).
6.0 Power Supplies
Standard logic circuits usually require a power source of +5 VDC. One possible source of +5 VDC is in one or more batteries. A D- cell battery generates 1.5 volts, so three of them can be connected in series to produce 4.5 VDC. An alternative power source can be from the standard wall outlet. Household electrical service in the United States is in the form of 110 volt AC (alternating current) power. Actually, 110 volts is the root mean square value of a sine wave that oscillates 60 times per second from about +155 volts to about -155 volts. The circuitry required to convert 110 VAC into 5 VDC is known as a power supply.
To obtain +5 VDC from 110 VAC requires scaling down the voltage and converting alternating current to direct current. In addition, most power supplies include a voltage regulator component that ensures that the circuit voltage is exactly +5 volts. The circuit in Figure 6-1 (in the following page) is a regulated 5-VDC power supply. The transformer reduces the household voltage from 110 to about 12 VAC. The diodes rectify the input to an oscillating signal of about +12 VDC. The 100mF electrolytic capacitor smoothes out the oscillation producing a largely DC voltage with little ripple. The 7805 is a voltage regulator that accepts an input voltage from about 8 volts to about 35 volts and produces a constant 5V output. Voltage regulator ICs are Zener diodes with a precise, reverse-biased breakdown voltage.
95

96 |
Chapter 6 |
12.5V |
|
|
CENTER-TAPPED |
|
+5V DC |
TRANSFORMER |
|
|
|
REGULATED |
|
IN |
OUT |
|
|
|
OUTPUT |
+ 100mF |
78L05 |
0.1mF |
110V AC INPUT
Figure 6-1 Regulated +5 VDC Power Supply
The 7805 is usually mounted on a metal base with a drilled hole so that a heat sink can be attached to it. With a heat sink the 7805 can produce up to 1 amp output. Figure 6-2 shows a 7805 voltage regulator IC.
output
ground
input
Figure 6-2 7805 Voltage Regulator IC
6.1 Clocked Logic and Flip-flops
In the digital circuits considered so far the outputs are entirely determined by the inputs to these circuits. In other words, if the inputs change so do the outputs. However, we often need a digital component whose output remains unchanged even if there is a change in input, for example, to store a binary number. A flip-flop is such a circuit since it performs as a 1-bit memory that stores either the value 0 or 1.
6.1.1 The RS Flip-flop
A circuit is said to be bistable if it has two, and only two, stable states. For example, a toggle switch which can be either OPEN or CLOSED is a bistable device. In a sense the toggle switch has memory since it remains in any one of the two positions until changed.
A flip-flop is an electronic circuit with two stable states, since its output is either 0 or +5 VDC. In this context we say that a flip-flop is set if it stores a binary 1 and reset otherwise. The RS designation refers to the Reset and Set stages. The flip-flop can also be said to have memory since its output remains set or reset until it is intentionally changed. When the flip-flop output is 0 VDC it can be regarded as storing a logic 0 and when its output is +5 VDC as storing a logic 1.

Circuit Components |
97 |
Flip-flops can be constructed using primary logic gates. One possibility is using two NAND gates, as in Figure 6-3.
+5V |
|
|
|
|
1 |
|
|
Set |
5 |
7 |
Q |
2 |
|
|
|
|
|
|
|
|
3 |
|
|
Reset |
6 |
8 |
R |
|
4 |
|
|
Set |
Reset |
Q |
R |
H |
H |
no change |
|
L |
H |
H |
L |
H |
L |
L |
H |
L |
L |
disallowed |
|
|
|
|
|
+5V
Figure 6-3 NOR Gate-based RS Flip-flop
Recall from Chapter 5 that a NAND gate is equivalent to a negative logic OR gate; this makes the flip-flop easier to understand. Looking at Figure 6-3, first consider that the Set input is pulled low by flipping the switch counterclockwise and sending the input to ground. In this case the output of the upper gate (1) is forced high since the gate’s output goes high if either input 1 or input 2 is low. Since the Reset input to the lower gate is high (4), then neither input of the lower gate (3 or 4) is low and its output is low. Note that input 3 is low because the bubble on the lower OR gate inverts the value fed back from the upper OR gate. Now the feedback line from the lower gate (6) sends low to input 2 on the upper gate, which is inverted by the upper gate bubble. So both inputs to the upper gate are high, determining that the upper gate’s output remains high even when the Set input returns to a logic high, as would be the case if the switch were turned back to the neutral position. Thus, the Q output of the flip-flop stays high (and the inverted Q output remains low). When the flip-flop is in this state, it is set. The flip-flop is placed in the cleared state by momentarily pulling the Reset input low. This forces the lower gate’s output to be high and the upper gate’s to be low.
The action of the flip-flop in Figure 6-3 is consistent with the description of a device with two steady states, labeled Set and Reset, and controlled by two corresponding input lines. Once a device is in either state, it remains in that state until the opposite state is enabled, thus “remembering” its set or reset status. The rotary switch mechanism ensures that the device will have either two high input lines or one high and one low. The condition of two low input lines is not allowed in this flip-flop, as shown in the truth table.
All mechanical switches used in electronic devices contain a spring of some sort. It is this spring that maintains the switch’s contact in either position, but it also makes the switch electrically “bounce” whenever it is activated. Although the bounce only takes a few milliseconds, the logic level can change between high and

98 |
Chapter 6 |
low several times during this period. If an RS flip-flop is connected to the switch, the first contact switches the flip-flop and subsequent ones have no effect, thus effectively “debouncing” the switch.
6.1.2 Clocked RS Flip-flop
So far the circuits discussed are examples of combinatorial or asynchronous logic. If we ignore a few nanoseconds of propagation delay, in combinatorial circuits the outputs change as soon as the inputs change. Although in theory you can build complex logic circuits using combinatorial logic, it is more convenient to use clocked logic pulses to ensure high reliability and noise immunity. Circuits that use clocked impulses are said to use synchronous logic.
In synchronous circuits unconstrained changes in logic gate outputs are not allowed. Instead, the logic is designed so that logic level changes can progress through the circuitry one stage at a time under control of a clock. Between the clock pulses that cause changes to take place, the temporary state of the system is stored in memory elements or flip-flops.
In clocked or synchronous logic all the gates in the system change outputs at the same time. The output state of each gate depends only on the state of the gate inputs at the time of the clock pulse. In combinatorial circuits the gates may briefly “see” the wrong logic level and cause incorrect operation of the circuit. With clocked logic, the gate outputs “settle down” during the time between clock pulses so that only valid logic levels are present by the time the next clock pulse arrives.
The RS flip-flop in Figure 6-3 is not suitable for use in a clocked logic circuit because its output changes immediately whenever the Set or Reset inputs change. However, the circuit can be made into a clocked RS flip-flop by adding two NAND gates, as shown in Figure 6-4.
Set
Q
Reset |
R |
Clock
Figure 6-4 Clocked RS Flip-flop

Circuit Components |
99 |
In the clocked flip-flop of Figure 6-4 the Set and Reset inputs can change at any time, but those changes are ignored by the flip-flop except during the interval when the logic high of a clock pulse is present. During the clock pulse the state of the Set or Reset line is stored by the flip-flop.
6.1.3 The D Flip-flop
One of the objections to the flip-flops in Figures 6-3 and 6-4 is that there are two data input lines, labeled Set and Reset in the illustrations. One possible solution is to only use one of the inputs by connecting an inverter between the Set line and the Reset input. The circuits for a D Flip-flop are shown in Figure 6-5.
Data
Q
R
Clock
Figure 6-5 The D Flip-flop
The name D (or data) flip-flop originates in the fact that it contains a single data line. The D flip-flop is also called a transparent latch, or a D latch. In the D flip-flop the state of the input line, called the D input, is stored in the flip-flop when a clock pulse occurs. An advantage of this design is that the disallowed state (see Figure 6-3), in which both Set and Reset are simultaneously low, cannot be reached accidentally.
A flip-flop can be used for storing binary data. To visualize how this can be done, imagine four D flip-flops driven by the same clock signal. When the clock goes high, input data is loaded into the flip-flops and appears at the output. When the clock goes low, the output retains the data. For example, consider four data inputs, as follows:
D0 D1D2 D3 = 0101
When the clock signal goes high, these four bits are loaded into the D latches, resulting in the output:
Q0Q1Q2Q3 = 0101
This operation is represented in Figure 6-6.

100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chapter 6 |
||
|
D3 |
|
|
|
D2 |
|
|
|
D1 |
|
|
|
D0 |
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Clock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
D |
CLK |
|
D |
CLK |
|
D |
CLK |
|
D |
CLK |
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Q |
Q |
|
|
Q |
Q |
|
|
Q |
Q |
|
|
Q |
Q |
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Q3 |
|
|
|
Q2 |
|
|
|
Q1 |
|
|
|
Q0 |
|
|
Figure 6-6 4 Data Bits Stored in D Latches
In the 4-bit D latch of Figure 6-6 the output data is stored as soon as the clock goes low. For as long as the clock is low, the D values can change without affecting the Q values. The 7475 IC contains four D flip-flops and is called a quad bistable latch. This circuit is well suited for handling 4-bit data bits simultaneously (one nibble).
6.1.4 The Edge-triggered D Flip-flop
The D flip-flop or transparent latch is available in several versions in addition to the 7475. Although the pure D flip-flop is a useful IC, for some applications it has the drawback that outputs follow the D input during the entire time that the clock line is high. In some circuits it would be ideal to have a flip-flop that stores data at a unique point in time. The edge-triggered D-type flip-flop approaches this behavior. In this device, the flip-flop stores the state of the data line at the instant the clock signal makes a transition from low to high and ignores it otherwise. Figure 6-7 shows an edge-triggered D flip-flop.
Data
S |
|
Q |
|
Clock
R |
|
|
Q |
|
Figure 6-7 Edge-Triggered D Latch
The circuit in Figure 6-7 is sometimes called an RC differentiated clock input latch. In this case RC stands for the resistor/capacitor combination at the input of the D latch. By design, the RC time constant is made smaller than the clock’s pulse width. This determines that the capacitor fully charges when the clock goes high,

Circuit Components |
101 |
producing a narrow positive voltage spike across the resistor. Later, the trailing edge of the pulse results in a narrow negative spike, enabling the AND gates for a brief period. The effect is to activate the AND gates only during the positive spike; the negative spike does nothing in this circuit. The result is equivalent to sampling the value of D for an instant. At this point in time, D and its complement hit the flip-flop inputs, forcing Q to set or reset (unless Q is already equal to D).
6.1.5 Preset and Clear Signals
The use of flip-flops in digital circuits usually requires some way of placing the signals in a known state. In this sense a Preset signal is used to make sure that the Set line is high, and a Clear signal to make sure that the Reset line is high. Alternatively, these signals are referred to as Preset R and Preset S. Figure 6-8 shows how the Preset and Clear functions can be implemented in an RS flip-flop.
Preset
Data
S Q
Clock
R Q
Clear
Figure 6-8 Implementing Preset and Clear
The OR gates in the circuit of Figure 6-8 allow selectively setting the S or the R lines of the edge-triggered D flip-flop. The Preset and Clear signals are called asynchronous inputs since they activate the R or S lines of the flip-flop independently of the clock. The D input, on the other hand, is synchronous since it has an effect only when the clock edge signal is high. Figure 6-9 shows the electrical symbol for a positive edge-triggered flip-flop with active high Preset and Clear lines.
PR
D Q
CLK
CLR Q
Figure 6-9 D-Type Edge-triggered Flip-flop Symbol

102 |
Chapter 6 |
In the normal mode of operation, a D-type flip-flop has the Set and Clear inputs high (not active), so that a transition of the clock input from low to high (called a positive edge) clocks the value of D into Q and the inverse of D into not-Q. The clock transition is required; D can do anything it wants to, but nothing happens to Q and not-Q until a positive edge occurs on the clock line.
6.1.6 D Flip-flop Waveform Action
An easy way of understanding the interaction of the various signals in a clocked RS flip-flop is by means of a waveform diagram. The reference circuit is the one in Figure 6-8. This includes a clock signal, a data input line, Preset and Clear lines, Set and Reset input lines into the flip-flop, and Q and not-Q output lines. The signals are described as follows:
1.The clock signal (CLK) is a square wave that oscillates between a high and a low state. It provides a synchronized beat that coordinates the various digital devices present in the circuit.
2.The data signal is used as a single input line into the flip-flop. Setting the data signal high also sets high the flip-flop’s Set line. A low data signal makes the flip-flop Reset line high.
3.The Set signal or line is one of the two inputs into the flip-flop. The other one is the Reset line.
4.The Preset line is used to make the flip-flop set line active. The Clear signal has the effect of setting high the Reset line into the flip-flop.
5.The Q and not-Q lines provide the flip-flop output. Q is high if the Set line is high; otherwise the not-Q line is high.
Figure 6-10 is a waveform diagram for a clocked RS flip-flop.
|
|
|
Preset |
|
|
Clear |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set |
|
|
Reset |
|
|
CLK |
|
|
|
|
|
|
|
1 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
|
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
1 |
S |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
1
R
0
1
Q
0
1
Q
0
Figure 6-10 Waveform Diagram for Clocked RS Flip-flop