You are on page 1of 22

CHAPTER 10

Logic circuits
Chapter summary
This chapter introduces electronic circuits and devices that are associated
with digital rather than analogue circuitry. These logic circuits are used
extensively in digital systems and form the basis of clocks, counters, shift
registers and timers.
The chapter starts by introducing the basic logic functions (AND, OR,
NAND, NOR, etc.) together with the symbols and truth tables that describe
the operation of the most common logic gates. We then show how these
gates can be used in simple combinational logic circuits before moving
on to introduce bistable devices, counters and shift registers. The chapter
concludes with a brief introduction to the two principal technologies used
in modern digital logic circuits, TTL and CMOS.

Electronic Circuits: Fundamentals and applications. 978-1-138-82892-6. © Mike Tooley.


Published by Taylor & Francis. All rights reserved.

TOOLEY 9781138828926 PAGINATION.indb 187 22/04/2015 11:32


10 Logic circuits

Solution
In order to operate the lamp, switch A and either
switch B or switch C must be operated. The truth
table is shown in Fig. 10.8.

Logic gates
Logic gates are circuits designed to produce the
basic logic functions, AND, OR, etc. These circuits
are designed to be interconnected into larger,
more complex, logic circuit arrangements. Since
these circuits form the basic building blocks of all
digital systems, we have summarized the action
of each of the gates in the next section. For each Figure 10.8 See Example 10.1
gate we have included its British Standard (BS)
symbol together with its American Standard (MIL/
ANSI) symbol. We have also included the truth
tables and Boolean expressions (using ‘ + ’ to
denote OR, ‘·’ to denote AND, and ‘−’ to denote
NOT). Note that, while inverters and buffers each
have only one input, exclusive-OR gates have two Figure 10.9 Symbols and truth table for a buffer
inputs and the other basic gates (AND, OR, NAND
and NOR) are commonly available with up to eight
inputs.

Buffers (Fig. 10.9)
Buffers do not affect the logical state of a digital
signal (i.e. a logic 1 input results in a logic 1 output Figure 10.10 Symbols and truth table for an
whereas a logic 0 input results in a logic 0 output). inverter
Buffers are normally used to provide extra current
drive at the output but can also be used to AND gates (Fig. 10.11)
regularize the logic levels present at an interface.
AND gates will only produce a logic 1 output
The Boolean expression for the output, Y, of a
when all inputs are simultaneously at logic 1. Any
buffer with an input, X, is:
other input combination results in a logic 0 output.
Y=X The Boolean expression for the output, Y, of an
AND gate with inputs, A and B, is:
Inverters (Fig. 10.10)
Y=A∙B
Inverters are used to complement the logical
state (i.e. a logic 1 input results in a logic 0 OR gates (Fig. 10.12)
output and vice versa). Inverters also provide
OR gates will produce a logic 1 output whenever
extra current drive and, like buffers, are used
any one, or more, inputs are at logic 1. Putting
in interfacing applications where they provide a
this another way, an OR gate will only produce
means of regularizing logic levels present at the
a logic 0 output whenever all of its inputs are
input or output of a digital system. The Boolean
simultaneously at logic 0. The Boolean expression
expression for the output, Y, of a buffer with an
for the output, Y, of an OR gate with inputs A and
input, X, is:
B is:
Y=X
Y=A+B

190

TOOLEY 9781138828926 PAGINATION.indb 190 22/04/2015 11:32


10 Logic circuits

Figure 10.11 Symbols and truth table for an AND Figure 10.13 Symbols and truth table for a NAND
gate gate

Figure 10.12 Symbols and truth table for an OR Figure 10.14 Symbols and truth table for a NOR
gate gate
NAND gates (Fig. 10.13)
NAND (i.e. NOT-AND) gates will only produce a
logic 0 output when all inputs are simultaneously
at logic 1. Any other input combination will
produce a logic 1 output. A NAND gate, therefore,
is nothing more than an AND gate with its output
inverted! The circle shown at the output denotes Figure 10.15 Symbols and truth table for an
this inversion. The Boolean expression for the exclusive-OR gate
output, Y, of a NAND gate with inputs A and B is:
Y=A∙B
Combinational logic
NOR gates (Fig. 10.14) By using a standard range of logic levels (i.e.
NOR (i.e. NOT-OR) gates will only produce a logic voltage levels used to represent the logic 1 and
1 output when all inputs are simultaneously at logic 0 states) logic circuits can be combined in
logic 0. Any other input combination will produce order to solve complex logic functions.
a logic 0 output. A NOR gate, therefore, is simply
an OR gate with its output inverted. A circle is Example 10.2
again used to indicate inversion. The Boolean A logic circuit is to be constructed that will
expression for the output, Y, of a NOR gate with produce a logic 1 output whenever two or more
inputs, A and B, is: of its three inputs are at logic 1.
Y=A+B
Solution
Exclusive-OR gates (Fig. 10.15) This circuit could be more aptly referred to as a
Exclusive-OR gates will produce a logic 1 output majority vote circuit. Its truth table is shown in
whenever either one of the inputs is at logic 1 and Fig. 10.16. Fig. 10.17 shows the logic circuitry
the other is at logic 0. Exclusive-OR gates produce required.
a logic 0 output whenever both inputs have the
Example 10.3
same logical state (i.e. when both are at logic 0 or
both are at logic 1). The Boolean expression for Show how an arrangement of basic logic gates
the output, Y, of an exclusive-OR gate with inputs (AND, OR and NOT) can be used to produce the
A and B is: exclusive-OR function.

Y=A∙B+B∙A
191

TOOLEY 9781138828926 PAGINATION.indb 191 22/04/2015 11:32


10 Logic circuits

is applied to it in order to change its state (or until


the supply is disconnected).

R-S bistables
The simplest form of bistable is the R-S bistable.
This device has two inputs, SET and RESET,
and complementary outputs, Q and Q . A logic 1
applied to the SET input will cause the Q output
to become (or remain at) logic 1 while a logic
1 applied to the RESET input will cause the Q
output to become (or remain at) logic 0. In either
Figure 10.16 See Example 10.2 case, the bistable will remain in its SET or RESET
state until an input is applied in such a sense as to
change the state.
Two simple forms of R-S bistable based on cross-
coupled logic gates are shown in Fig. 10.19.
Fig. 10.19(a) is based on NAND gates while
Fig. 10.19(b) is based on NOR gates.

Figure 10.17 See Example 10.2

Solution
In order to solve this problem, consider the
Boolean expression for the exclusive-OR function: Figure 10.18 See Example 10.3

Y = A ⋅B +B ⋅ A

This expression takes the form:


Y = P + Q where P = A ⋅ B and Q = B ⋅ A
A ⋅ B and Q = B ⋅ A can be obtained using
two two-input AND gates and the result (i.e. P
and Q) can then be applied to an OR gate with
two inputs. A and B can be produced using
inverters. The complete solution is shown in
Fig. 10.18.

Bistables
The output of a bistable has two stable states
(logic 0 or logic 1) and, once set in one or other
of these states, the device will remain at a
particular logic level for an indefinite period until
reset. A bistable thus constitutes a simple form
of ‘memory cell’ because it will remain in its
Figure 10.19 R-S bistables using cross-coupled
latched state (whether set or reset) until a signal
NAND and NOR gates
192

TOOLEY 9781138828926 PAGINATION.indb 192 22/04/2015 11:32


10 Logic circuits

The simple cross-coupled logic gate bistable has J-K bistables


a number of serious shortcomings (consider what
would happen if a logic 1 was simultaneously J-K bistables have two clocked inputs (J and K),
present on both the SET and RESET inputs!) and two direct inputs (PRESET and CLEAR), a CLOCK
practical forms of bistable make use of much (CK) input, and outputs (Q and Q). As with R-S
improved purpose-designed logic circuits such as bistables, the two outputs are complementary
D-type and J-K bistables. (i.e. when one is 0 the other is 1, and vice versa).
Similarly, the PRESET and CLEAR inputs are
invariably both active low (i.e. a 0 on the PRESET
D-type bistables input will set the Q output to 1 whereas a 0 on
The D-type bistable has two inputs: D (standing the CLEAR input will set the Q output to 0).
variously for ‘data’ or ‘delay’) and CLOCK (CLK). Tables 10.4 and 10.5 summarize the operation of
The data input (logic 0 or logic 1) is clocked a J-K bistable, respectively, for the PRESET and
into the bistable such that the output state only CLEAR inputs and for clocked operation.
changes when the clock changes state. Operation
is thus said to be synchronous. Additional Table 10.4 Input and output states for a J-K
subsidiary inputs (which are invariably active bistable (PRESET and CLEAR inputs)
low) are provided which can be used to directly Inputs Output Comments
set or reset the bistable. These are usually PRESET CLEAR QN+1
called PRESET (PR) and CLEAR (CLR). D-type
0 0 ? Indeterminate
bistables are used both as latches (a simple form
0 1 0 Q output changes to 0
of memory) and as binary dividers. The simple
(i.e. Q is reset) regardless
circuit arrangement in Fig. 10.20 together with the of the clock state
timing diagram shown in Fig. 10.21 illustrate the 1 0 1 Q output changes to 1
operation of D-type bistables. (i.e. Q is set) regardless
of the clock state
1 1 See Enables clocked operation
below (refer to Table 10.5)
Note: The preset and clear inputs operate regardless of the
clock

Table 10.5 Input and output states for a J-K


bistable (clocked operation)
Figure 10.20 D-type bistable operation
Inputs Output Comments
J K QN+1

0 0 QN No change in state of
the Q output on the next
clock transition
0 1 0 Q output changes to 0
(i.e. Q is reset) on the
next clock transition
1 0 1 Q output changes to 1
(i.e. Q is set) on the next
clock transition
1 1 QN Q output changes to the
opposite state on the
next clock transition
Figure 10.21 Timing diagram for the D-type Note: QN+1 means ‘Q after next clock transition’ while QN
bistable means ‘Q in whatever state it was before’

193

TOOLEY 9781138828926 PAGINATION.indb 193 22/04/2015 11:32


10 Logic circuits

J-K bistables are the most sophisticated and the next stage. Note that all data transfer occurs
flexible of the bistable types and they can be on the falling edge of the clock pulse.
configured in various ways including binary
dividers, shift registers and latches. Example 10.4
Fig. 10.22 shows the arrangement of a four-stage A logic arrangement has to be designed so that
binary counter based on J-K bistables. The timing it produces the pulse train shown in Fig. 10.27.
diagram for this circuit is shown in Fig. 10.23. Devise a logic circuit arrangement that will
Each stage successively divides the clock input generate this pulse train from a regular square
signal by a factor of two. Note that a logic 1 input wave input.
is transferred to the respective Q-output on the
Solution
falling edge of the clock pulse and all J and K
inputs must be taken to logic 1 to enable binary A two-stage binary divider (based on J-K bistables)
counting. can be used together with a two-input AND gate
as shown in Fig. 10.26. The waveforms for this
Fig. 10.24 shows the arrangement of a four- stage
logic arrangement are shown in Fig. 10.28.
shift register based on J-K bistables. The timing
diagram for this circuit is shown in Fig. 10.25.
Note that each stage successively feeds data to

Figure 10.22 Four-stage binary counter using J-K bistables

Figure 10.23 Timing diagram for the four-stage binary counter shown in Fig. 10.22

194

TOOLEY 9781138828926 PAGINATION.indb 194 22/04/2015 11:32


10 Logic circuits

Figure 10.24 Four-stage shift register using J-K bistables

Figure 10.27 See Example 10.4

Figure 10.25 Timing diagram for the four-stage


shift register shown in Fig. 10.24

Figure 10.28 Waveforms for the logic


arrangement shown in Fig. 10.26

Figure 10.26 See Example 10.4

195

TOOLEY 9781138828926 PAGINATION.indb 195 22/04/2015 11:32


11 Microprocessors

Many microprocessors designed for control and Table 11.1  Binary, denary and hexadecimal
instrumentation applications make use of an 8-bit Binary Denary Hexadecimal
data bus and a 16-bit address bus. Others have (base 2) (base 10) (base 16)
data and address buses which can operate with 0000  0 0
as many as 128-bits at a time. 0001  1 1
The largest binary number that can appear on an 0010  2 2
8-bit data bus corresponds to the condition when 0011  3 3
all eight lines are at logic 1. Therefore the largest 0100  4 4
value of data that can be present on the bus at 0101  5 5
any instant of time is equivalent to the binary 0110  6 6
number 11111111 (or 255). Similarly, the highest 0111  7 7
address that can appear on a 16-bit address
1000  8 8
bus is 1111111111111111 (or 65,535). The full
1001  9 9
range of data values and addresses for a simple
1010 10 A
microprocessor of this type is thus:
1011 11 B
Data from 00000000
1100 12 C
to 11111111 1101 13 D
Addresses from 0000000000000000 1110 14 E
to 1111111111111111 1111 15 F

Data representation
a $ symbol before a hexadecimal number or add
Binary numbers – particularly large ones – are an H to the end of the number. For example, 64
not very convenient. To make numbers easier means decimal ‘sixty-four’; whereas $64 means
to handle we often convert binary numbers to hexadecimal ‘six-four’, which is equivalent to
hexadecimal (base 16). This format is easier decimal 100. Similarly, 7FH means hexadecimal
for mere humans to comprehend and offers the ‘seven-F’, which is equivalent to decimal 127.
advantage over denary (base 10) in that it can be
converted to and from binary with ease. The first Example 11.1
16 numbers in binary, denary and hexadecimal Convert hexadecimal A3 into binary.
are shown in Table 11.1. A single hexadecimal
character (in the range zero to F) is used to Solution
represent a group of four binary digits (bits). This From Table 11.1, A = 1010 and 3 = 0011. Thus
group of four bits (or single hex character) is A3 in hexadecimal is equivalent to 10100011 in
sometimes called a nibble. binary.
A byte of data comprises a group of eight bits.
Thus a byte can be represented by just two Example 11.2
hexadecimal (hex) characters. A group of 16 Convert binary 11101000 binary to hexadecimal.
bits (a word) can be represented by four hex
characters, 32 bits (a double word by eight hex Solution
characters, and so on). From Table 11.1, 1110 = E and 1000 = 8. Thus
The value of a byte expressed in binary can be 11101000 in binary is equivalent to E8 in
easily converted to hex by arranging the bits in hexadecimal.
groups of four and converting each nibble into
hexadecimal using Table 11.1.
Note that, to avoid confusion about whether a
number is hexadecimal or decimal, we often place
206

TOOLEY 9781138828926 PAGINATION.indb 206 22/04/2015 11:32


11 Microprocessors

Data types alive by means of a small battery. This battery-


backed memory is used to retain important data,
A byte of data can be stored at each such as the time and date.
address within the total memory space of a
When expressing the amount of storage provided
microprocessor system. Hence one byte can be
by a memory device we usually use Kilobytes
stored at each of the 65,536 memory locations
(Kbyte). It is important to note that a Kilobyte of
within a microprocessor system having a 16-bit
memory is actually 1,024 bytes (not 1,000 bytes).
address bus.
The reason for choosing the Kbyte rather than the
Individual bits within a byte are numbered from 0 kbyte (1,000 bytes) is that 1,024 happens to be
(least significant bit) to 7 (most significant bit). In the nearest power of 2 (note that 210 = 1,024).
the case of 16-bit words, the bits are numbered
The capacity of a semiconductor ROM is usually
from 0 (least significant bit) to 15 (most significant
specified in terms of an address range and
bit).
the number of bits stored at each address.
Negative (or signed) numbers can be represented For example, 2 K × 8 bits (capacity 2 Kbytes),
using two’s complement notation where the 4 K × 8 bits (capacity 4 Kbytes), and so on. Note
leading (most significant) bit indicates the sign that it is not always necessary (or desirable) for
of the number (1 = negative, 0 = positive). For the entire memory space of a microprocessor to
example, the signed 8-bit number 10000001 be populated by memory devices.
represents the denary number −1.
The range of integer data values that can be
represented as bytes, words and long words are
The microprocessor
shown in Table 11.2. The microprocessor central processing unit
(CPU) forms the heart of any microprocessor
or microcomputer system computer and,
Data storage
consequently, its operation is crucial to the entire
The semiconductor ROM within a microprocessor system.
system provides storage for the program code as The primary function of the microprocessor is that
well as any permanent data that requires storage. of fetching, decoding and executing instructions
All of these data are referred to as non-volatile resident in memory. As such, it must be able to
because they remain intact when the power transfer data from external memory into its own
supply is disconnected. internal registers and vice versa. Furthermore,
The semiconductor RAM within a microprocessor it must operate predictably, distinguishing, for
system provides storage for the transient data example, between an operation contained within
and variables that are used by programs. Part of an instruction and any accompanying addresses
the RAM is also used by the microprocessor as of read/write memory locations. In addition,
a temporary store for data while carrying out its various system housekeeping tasks need to be
normal processing tasks. performed including being able to suspend normal
It is important to note that any program or data processing in order to respond to an external
stored in RAM will be lost when the power device that needs attention.
supply is switched off or disconnected. The only The main parts of a microprocessor CPU are:
exception to this is CMOS RAM, which is kept (a) registers for temporary storage of addresses
Table 11.2  Data types and data;
(b) an arithmetic logic unit (ALU) that performs
Data type Bits Range of values
arithmetic and logic operations;
Unsigned byte  8 0 to 255
(c) a unit that receives and decodes instructions;
Signed byte  8 −128 to +127
and
Unsigned word 16 0 to 65,535 (d) a means of controlling and timing operations
Signed word 16 −32,768 to + 32,767 within the system.
207

TOOLEY 9781138828926 PAGINATION.indb 207 22/04/2015 11:32


11 Microprocessors

Table 11.3 A simple example program immediately to the interrupt. In the case of a
Address Data Assembly Comment maskable interrupt, the processor’s response
code will depend upon whether interrupts are currently
2002 DB FF IN A, (FFH) Get a byte from enabled or disabled (when enabled, the CPU
Port A will suspend its current task and carry out the
2002 2F CPL Invert the byte requisite interrupt service routine).
2003 D3 FE OUT (FEH), A Output the byte The response to interrupts can be enabled
to Port B
or disabled by means of appropriate program
2005 C3 00 20 JP 2000 Go round again instructions. In practice, interrupt signals may be
generated from a number of sources and since
each will require its own customized response a
mechanism must be provided for identifying the
source of the interrupt and calling the appropriate
interrupt service routine. In order to assist in this
task, the microprocessor may use a dedicated
programmable interrupt controller chip.

A microcontroller system
Fig. 11.11 shows the arrangement of a typical
microcontroller system. The sensed quantities
(temperature, position, etc.) are converted to
Figure 11.10 (a) Flowchart for the example corresponding electrical signals by means of
program and (b) the eight bytes of program code a number of sensors. The outputs from the
stored in memory sensors (in either digital or analogue form) are
passed as input signals to the microcontroller.
to remember mnemonics. The flowchart for the The microcontroller also accepts inputs from the
program is shown in Fig. 11.10(a). user. These user-set options typically include
The program occupies a total of eight bytes of target values for variables (such as desired room
memory, starting at a hexadecimal address of temperature), limit values (such as maximum
2000 as shown in Fig. 11.10(b). You should also shaft speed) or time constraints (such as ‘on’ time
note that the two ports, A and B, each have and ‘off’ time, delay time, etc.).
unique addresses; Port A is at hexadecimal The operation of the microcontroller is controlled
address FF and Port B is at hexadecimal by a sequence of software instructions known as
address FE. a control program. The control program operates
continuously, examining inputs from sensors, user
Interrupts
settings and time data before making changes to
A program that simply executes a loop indefinitely the output signals sent to one or more controlled
has a rather limited practical application. In most devices.
microprocessor systems we want to be able to
The controlled quantities are produced by the
interrupt the normal sequence of program flow
controlled devices in response to output signals
in order to alert the microprocessor to the need
from the microcontroller. The controlled device
to do something. We can do this with a signal
generally converts energy from one form into
known as an interrupt. There are two types of
energy in another form. For example, the
interrupt; maskable and non-maskable.
controlled device might be an electrical heater
When a non-maskable interrupt input that converts electrical energy from the AC mains
is asserted, the processor must suspend supply into heat energy, thus producing a given
execution of the current instruction and respond temperature (the controlled quantity).

214

TOOLEY 9781138828926 PAGINATION.indb 214 22/04/2015 11:32


11 Microprocessors

In most real-world systems there is a requirement The output port signals can be connected to a
for the system to be automatic or self-regulating. number of devices, including:
Once set, such systems will continue to operate XXLED indicators (both individual and multiple bar
without continuous operator intervention. The types);
output of a self-regulating system is fed back XXLED seven-segment displays (via a suitable
to its input in order to produce what is known interface);
as a closed-loop system. A good example of a XXmotors and actuators (both linear and
closed-loop system is a heating control system rotary types) via a suitable buffer/driver or a
that is designed to maintain a constant room dedicated interface;
temperature and humidity within a building XXrelays (both conventional electromagnetic
regardless of changes in the outside conditions. types and optically couple solid-state types);
In simple terms, a microcontroller must produce XXtransistor drivers and other solid-state
a specific state on each of the lines connected switching devices.
to its output ports in response to a particular
combination of states present on each of the Input devices
lines connected to its input ports (see Fig. 11.11). Input devices supply information to the computer
Microcontrollers must also have a central system from the outside world. In an ordinary
processing unit (CPU) capable of performing personal computer, the most obvious input device
simple arithmetic, logical and timing operations. is the keyboard. Other input devices available on
The input port signals can be derived from a a PC are the mouse (pointing device), scanner,
number of sources, including: and modem. Microcontrollers use much simpler
input devices. These need be nothing more
XXswitches (including momentary action
than individual switches or contacts that make
push-buttons);
and break, but many other types of device are
XXsensors (producing logic-level compatible
also used including many types of sensor that
outputs);
provide logic-level outputs (such as float switches,
XXkeypads (both encoded and unencoded types).
proximity detectors, light sensors, etc.).

Figure 11.11  A microcontroller system with typical inputs and outputs


215

TOOLEY 9781138828926 PAGINATION.indb 215 22/04/2015 11:32


11 Microprocessors

It is important to note that, in order to be microcontroller systems often use much simpler
connected directly to the input port of a output devices. These may be nothing more than
microcontroller, an input device must provide LEDs, piezoelectric sounders, relays and motors.
a logic compatible signal. This is because In order to be connected directly to the output
microcontroller inputs can only accept digital port of a microcontroller, an output device must,
input signals with the same voltage levels as once again, be able to accept a logic compatible
the logic power source. The 0 V ground level signal.
(often referred to as VSS in the case of a CMOS Where analogue quantities (rather than simple
microcontroller) and the positive supply (VDD in the digital on/off operation) are required at the
case of a CMOS microcontroller) is invariably 5 V output a digital-to-analogue converter (DAC) will
± 5%. A level of approximately 0 V indicates a logic be needed. All of the functions associated with
0 signal and a voltage approximately equal to the a DAC can be provided by a single integrated
positive power supply indicates a logic 1 signal. circuit. As with an ADC, the output resolution of a
Other input devices may sense analogue DAC depends on the number of bits and 8, 10 and
quantities (such as velocity) but use a digital 12 bits are common in control applications.
code to represent their value as an input to the
microcontroller system. Some microcontrollers Interface circuits
provide an internal analogue-to-digital converter Finally, where input and output signals are not
(ADC) in order to greatly simplify the connection logic compatible (i.e. when they are outside the
of analogue sensors as input devices, but where range of signals that can be connected directly
this facility isn’t available it will be necessary to to the microcontroller) some additional interface
use an external ADC which usually takes the form circuitry may be required in order to shift the
of a single integrated circuit. The resolution of the voltage levels or to provide additional current
ADC will depend upon the number of bits used drive. Additional circuitry may also be required
and 8-, 10- and 12-bit devices are common in when a load (such as a relay or motor) requires
control applications. more current than is available from a standard
logic device or output port. For example, a
Output devices common range of interface circuits (solid-state
Output devices are used to communicate relays) is available that will allow a microcontroller
information or actions from a computer system to be easily interfaced to an a.c. mains-connected
to the outside world. In a personal computer load. It then becomes possible for a small
system, the most common output device is the microcontroller (operating from only a 5 V d.c.
flat-screen display. Other output devices include supply) to control a central heating system
printers and modems. As with input devices, operating from 240 V a.c. mains.

Figure 11.12  An analogue input signal can be connected to a microcontroller input port via
an analogue-to-digital converter (ADC)
216

TOOLEY 9781138828926 PAGINATION.indb 216 22/04/2015 11:32


11 Microprocessors

Figure 11.13  An analogue output signal can be produced by connecting a digital-to-analogue converter
(DAC) to a microcontroller output port

Practical investigation Outputs (Port 82H)


Logic 1 = LED ‘off’
Objective
Logic 0 = LED ‘on’
To investigate the operation of a Z80 Note that in order to illuminate an LED the logic 1
microprocessor using a simulator to run a simple input must be inverted in order to produce a logic
assembly language program. 0 output. Hence it will be necessary to read the
byte from port 80H, invert (i.e. complement) it,
Simulator and then output it to port 82H.
Oshonsoft Z80 Simulator or similar Integrated The program is to continue to run, detecting
Development Environment (IDE). The the state of the input switches and turning the
Oshonsoft IDE can be downloaded from appropriate LEDs on, until such a time as all of the
www.oshonsoft.com. Alternatively, a Z80 input switches are set to the ‘off’ position. If this
development system with resident assembler and situation is detected the program is to halt.
I/O ports can be used (note that port addresses
used in the Practical Investigation may need to be Procedure
modified in order to agree with those available).
Start the Z80 Simulator (see Fig. 11.14) then
select Tools and Assembler and enter the
System configuration and
assembly language code shown in Fig. 11.15.
required operation
When complete select File and Save your
For the purposes of this investigation we shall assembly language source code with a suitable
assume that the system has eight input switches name (e.g. switch.asm).
connected to port address 80H and eight LED Next select Tools and Assemble. Correct any
indicators connected to output port address errors in the assembly language source code
82H. The LEDs are to be operated from their and repeat the process until the source code
corresponding input switches on the following assembles without error. Save the final assembly
basis: code and then quit the assembler in order to
Inputs (Port 80H) return to the main IDE screen.
Switch ‘on’ = logic 1 Select File and Load Program and then select
Switch ‘off’ = logic 0 the object code (switch.obj) that has just been
produced by the assembler. You will then need

217

TOOLEY 9781138828926 PAGINATION.indb 217 22/04/2015 11:32

You might also like