Sunteți pe pagina 1din 301

Microprocessors and

Industrial Applications
Laboratory Manual

Model EBI-6810-40
HEATHKIT COMPANY, INC.
BENTON HARBOR, MICHIGAN 49022
595-5676-01

Copyright 1998, 1996


Heathkit Company, Inc.
All Rights Reserved
Printed in the United States of America

i i 1 CONTENTS

CONTENTS
Introduction to the Experiments
Parts List
Experiments
Experiment 1. Trainer Programming Fundamentals
Experiment 2. Microprocessor System Features
Experiment 3. Addressing Modes (Inherent, Immediate,
and Direct)
Experiment 4. Combined Addressing Mode Programming
Experiment 5. The Condition Code Register
Experiment 6. Program Branches
Experiment 7. Double Accumulator and Subroutine
Instructions
Experiment 8. Input/Output Operations
Experiment 9. Address Decoding
Experiment 10. Data Input
Experiment 11. Data Output
Experiment 12. Introduction to the Peripheral Interface
Adapter (PIA)
Experiment 13. Display Multiplexing Using the PIA
Experiment 14. I/O Control and Handshaking Using
the PIA
Experiment 15. Static RAM Interfacing
Experiment 16. Microprocessor/DAC Interfacing and
Applications
Experiment 17. A/D Converter Interfacing and
Applications
Experiment 18. A Microprocessor-Controlled Thermometer
Experiment 19. A Microprocessor-Controlled Photometer
Experiment 20. Microprocessor-Controlled Optical Counting,
Timing, and Motor Speed Measurement
Experiment 21. Linear Position Sensing Using Optical
Techniques
Experiment 22. Linear Position and Velocity Sensing Using
Magnetic Hall-Effect Devices
Experiment 23. Microprocessor Interfacing and Control of
Stepper Motors

iii
v
1-1
2-1
3-1
4-1
5-1
6-1
7-1
8-1
9-1
10-1
11-1
12-1
13-1
14-1
15-1
16-1
17-1
18-1
19-1
20-1
21-1
22-1
23-1

Appendix A Trainer Test Program

A-1

Appendix B Programming Worksheet

B-1

Appendix C MC68HC11A8 Technical Summary

C-1

Appendix D Data Sheets

D-1

INTRODUCTION TO THE EXPERIMENTS I

INTRODUCTION TO THE EXPERIMENTS


Many people believe that to learn by doing is to truly learn. You can
read about and study a topic, for example aviation, but it is not
until you've completed some actual flights that you know you can
fly! This is true of so many things including microprocessor
programming.
The importance of successfully completing the experiments contained in this manual cannot be overemphasized. Take your time in
performing (or even re-performing) these. They represent the
equivalent of your first few "flights."
This manual contains the experiments associated with the main
topics discussed in the textbook.
The first two experiments, entitled Trainer Programming Fundamentals, and Microprocessor System Features are designed to
provide an introduction to the fundamental concepts in Unit 2
(Microcomputer Basics) while acquainting you with the features
and operation of the ETW-3800 Microprocessor trainer.
Experiments 3 and 4 on Addressing Modes (Inherent, Immediate,
and Direct), and Combined Addressing Mode Programming, serve
to reinforce the main topics presented in Unit 3 (Addressing
Modes).
The next two experiments, 5 and 6, on The Condition Code Register
and Program Branches each concentrate on these two main areas
discussed in Unit 4 (Introduction to Programming).
The next two experiments are individually devoted to text units (7
and 8). These discuss the important topics of Double Accumulator
and Subroutine Instructions (7) and Input/Output Operations (8).
They are supported respectively by experiment 7 on Double Accumulator and Subroutine Instructions, and experiment 8 on Input I
Output Operations.
Experiments 9, 10, and 11 on Address Decoding, Data Input, and
Data Output, respectively serve to reinforce the important textbook concepts of designing and building general purpose interface
circuits to allow the MPU to communicate with the outside world.

V I INTRODUCTION TO THE EXPERIMENTS

Experiments 12,13, and 14 demonstrate the use and some applications of the PIA, or peripheral interface adapter chip. In many
ways a proper understanding of the capabilities of the PIA is
central to your ability to understand and design a wide variety of
MPU interface circuits.
Experiment 15 on Static RAM Interfacing shows you how to test,
and interface static RAM to a microprocessor. You will also learn
how data is stored in and then read back from memory circuits.
Experiments 16 and 17 explore some interesting techniques of data
conversion including digital-to-analog and analog-to-digital circuits and interfaces.
The remaining six experiments (18-23) are then presented to
demonstrate some of the endless possible applications and uses of
the interfacing concepts presented. These include an MPU-controlled thermometer, photometer, counter, timer, motor-speed measurement circuit, optical and Hall-effect linear positioning sensing
circuits, and a microprocessor interfacing circuit for the control of
a stepper motor.
We strongly advise you to take your time to completely perform,
and understand the contents of each of these experiments.

PARTS LIST I V

PARTS LIST
This is a list of all the parts you need to complete the experiments
in this Workbook. The key numbers in the parts list correspond to
the numbers in the parts pictorial. Some parts may be packaged in
envelopes. Except for this initial parts check, keep these parts in
their envelopes until they are called for in the experiments. In
some cases, the parts may be hard to identify once they are
separated from their labeled envelopes. For this reason, we advise
you to keep your parts separated and marked for easy identification.
Key No.

Part No.

Qty.

Description

RESISTORS

Al
Al
Al
Al
Al
Al
Al

6-470-12
6-101-12
6-102-12
6-332-12
6-103-12
6-471-12
6-472-12

8
1
2
1
2
8
1

47 Q (yellow-violet-black-gold)
100 Q. (brown-black-brown-gold)
1000 Q (brown-black-red-gold)
3300 Q (orange-orange-red-gold)
10 la/ (brown-black-orange-gold)
470 SI (yellow-violet-brown-gold)
4.7 kg/. (yellow-violet-red-gold)

1
1
1
1

10 kS2 potentiometer, .75 w


1 kS1 potentiometer, .75 w
50 52 potentiometer, .75 w
5 kS2 potentiometer, .75 w

1
1

.01 i.tF (103 m)


.1 .tF (104 m)

CONTROLS

A2
A2
A2
A2

10-1138
10-1141
10-1173
10-1216

CAPACITORS

A3
A3

21-185
21-192

SWITCHES/SWITCH COVERS

A4
A5
A5
A5
A5

64-910
462-1144
462-1145
462-1146
462-1147

4
1
1
1
1

SPST pushbutton
Black pushbutton switch cover*
White pushbutton switch cover*
Red pushbutton switch cover*
Blue pushbutton switch cover*

* NOTE: Each of the 4 colored switch covers will be placed on the SPST
pushbutton switches.

Go

VI l PARTS LIST

Key No. Part No.

Qty. Description

INTEGRATED CIRCUITS

NOTE: Integrated circuits are marked for identification in one of


the following ways:
1.
2.
3.
4.

Part number.
Type number.
Part number and type number.
Part number with a type number other than the one
listed.

Disregard any letters that precede or follow the numbers on an


IC.
B1
B1

442-22
442-751

1
1

B2
B3
B1
B1

442-752
442-783
443-13
443-36

2
1
2
1

B1
B1
B1
B1
B1
B1
B1

443-728
443-732
443-800
443-807
443-811
443-1014
443-1122

1
2
2
1
1
1
1

B1

443-1422

ALWAYS IDENTIFY AN IC BY THE


PART NUMBER OR THE TYPE NUMBER
NOTE: THE STYLE MAY BE SLIGHTL Y
DIFFERENT THAN SHOWN.

741 op amp
LM1408 or DAC0808 digital-toanalog converter
UGN3020 Hall-Effect device
LM35 temperature sensor
SM7475N bistable latch
SN7447N decoder/7-segment
driver
74LS00 quad NAND gate.
74LS30 8-input NAND gate
74LS27 3-input NOR gate
74LS42 decoder
74LS125 quad-tristate
68A21 PIA
ADC0809 analog-to-digital converter
TC5565 or equivalent 8K x 8
static RAM

PARTS LIST

Key No.

Part No.

Qty.

I VII

Description

MISCELLANEOUS

Cl
C2

C3
C4
C5
C6
C7
C8
C9

56-16
74-4
74-45
150-74
331-16
334-50
334-52
334-54
334-55
334-56
336-35
336-46
411-875
417-851
417-875
420-626
420-644
454-31
474-1
490-111

1
1
1
1
1
1
1
1
1
1
1
1
2
1
4
1
1
1
1
1

1N5231 5.1-volt zener diode


Roll of plastic tape
8" foam tape
Opto-interrupter module
0.035", 60/40 solder
#22 black wire roll
#22 red wire roll
#22 yellow wire roll
#22 green wire roll
12" blue wire
6" of 1/8" heat-shrink tubing
3" of 1/4" heat-shrink tubing
5082-7731 7-segment display
Opto-isolator
2N3904 NPN transistor
Stepper motor
DC motor
Sensor disk
Magnet
IC lifter

IMPORTANT: THE BANDED END OF


DIODES CAN BE MARKED IN A
NUMBER OF WAYS.
IFS

OR

PLASTIC

METAL

ti
BANDED END (CATHODE)

(;)

EXPERIMENT ONE - TRAINER PROGRAMMING FUNDAMENTALS 11 -1

EXPERIMENT 1
TRAINER PROGRAMMING
FUNDAMENTALS
Objectives:
1.

To acquaint the student with certain functions and capabilities of


the 8-Bit Microprocessor trainer.

2.

To demonstrate how to examine the contents of RAM and the


microprocessor registers including the accumulator, and program counter.

3.

To demonstrate how to program the MC68HC11 unit in the


microprocessor trainer to perform a simple task.

INTRODUCTION
This experiment introduces you to the basic functions of the 8-bit
microprocessor trainer system and the programming of the 68HC11
CPU. This is done by putting into practice the knowledge you
gained from studying the material in Unit 2 of the textbook.
Recall from your study of Unit 2 that a system with the hardware
and capabilities of your (68HC11-based) 8-bit microprocessor trainer
actually fits the definition of a true microcomputer. This is because
it contains memory, and other circuits as discussed in Unit 2. In
addition to these circuits, however, your trainer actually contains
many other useful circuits and features. Included among these is
an input/output (I/O) port, RS-232 interface, sonic logic probe,
serial communications interface, serial peripheral interface, and
analog-to-digital (A/D) converter. These trainer circuits indeed
qualify it as a microcomputer. As mentioned previously, however,
we refer to the trainer as an 8-bit "microprocessor" trainer because, in this course, we concentrate on the basic sections of the
microprocessor unit from a programmer's perspective.
Being new to the world of microprocessors, microprocessor programming, and especially the microprocessor trainer, you begin
this experiment by learning the most fundamental steps and
procedures involved in working with the trainer. This consists of

1 -2

I LABORATORY MANUAL

learning the basics such as how to turn it on, how to interpret the
liquid crystal display (LCD) contents, the function(s) of keys on the
21-key trainer keypad, etc. After you have familiarized yourself
with these basics, you are introduced to a simple program where
you use the microprocessor circuits, registers, and memory discussed in unit one. This program demonstrates the execution of
several instructions from the 68HC11 instruction set.

PROCEDURE
Refer to Figure 1-1 while you perform the following steps.
MPU CARTRIDGE
POWER SWITCH
DISPLAY
CPU STATUS INDICATORS
PROGRAM
(E'PROM CARTRIDGE)

8-LOGIC INDICATORS
TERMINAL BLOCK
LOGIC SWITCHES
TERMINAL BLOCK

BREADBOARD
LOGIC PROBE
LED INDICATORS

RS232 PORT

LOWER SIGNAL CONNECTOR


BLOCK

KEYBOARD

UPPER SIGNAL
CONNECTOR BLOCK

Figure 1-1

The ETW-3800 MPU trainer.

1.

Make sure the trainer's power switch is in the off position.


Then, with your trainer suitably positioned in front of you,
locate the 120 VAC power-cord on the back left-hand side of the
trainer. Plug this into a standard, grounded, 120 VAC wall
outlet.

2.

Identify the program cartridge and make certain it is plugged


into the shorter of the slots on the trainer's front panel (this is
the smaller of the two cartridges and should be plugged into
the right-hand slot).

EXPERIMENT ONE - TRAINER PROGRAMMING FUNDAMENTALS 1

3. Identify the MPU cartridge and make certain it is plugged into


the longer of the two slots on the trainer's front panel.
NOTE: The trainer is now ready to operate.
4. Locate and press the power (rocker) switch to the right. The
trainer should now be powered-up with the light-emittingdiode power indicator lit and the LCD display reading the
"reset logo":
Heathkit Ed. Systems
M68HC11 Trainer vx.xx
NOTE: x.xx = current version number.
5. Locate, press and release the Reset key in the keypad section
of the trainer. This ensures that the trainer is properly reset.
NOTE: The trainer should automatically reset itself during
power-up, however, it can always be reset after power-up by
pressing the Reset key. The Heathkit Educational Systems
reset logo is displayed after a system reset.
6. You will now initialize the first 16-bytes of RAM. To do this
locate, press, and release the I Blk (alternate of #5) key on the
trainer keypad. The display should show:
5
Start Address 0000H
7. Enter the start address of the lowest available byte in RAM by
entering 0000 (i.e., press 0 four times). The display should now
read:
Start Address 0000H
End Address 0000H
8. Enter the end address of the highest byte in RAM to be
initialized, 000F. This allows you to set the first 16 bytes of
RAM to a predetermined value, in this case FF. The display
should now show:
End Address 000FH
Byte = OOH

1 -3

1 -4 1 LABORATORY MANUAL
9.

Enter FF. The display now reads:


Byte = FFH
>_

10. Locate and press the Exm Mem key (alternate of #1). The
trainer display should read:
1
Look Address: 0000H
NOTE: At this point you could view the (hex) contents of any
address 0000-FFFF by entering its four-character hex address.
11. Examine the contents of the lowest memory location in RAM
by entering the address 0000. After entering the fourth 0 of the
address, the trainer display should change to:
Look Address
0000: FF
That is, the hex contents of this memory location is FF16.
Convert this hex number to the number systems indicated
below:
FF16 =

2=

8=

10.

12. Continue to examine the contents of the first 16 locations in


RAM by pressing the + key (alternate of List). This allows you
to view the contents of each successive memory location 0000
through 000F. Record the contents of each below.
Address

Contents Address

00

08

01

09

02

OA

03

OB

04

OC

05

OD

06

OE

07

OF

Contents

EXPERIMENT ONE - TRAINER PROGRAMMING FUNDAMENTALS 1

13. Press the Reset key. The display should return to the reset
logo.
14. Now press the Exm Reg key (alternate of #2). The display now
shows:
2
CCR = 00_ H
NOTE: The trainer is now displaying the contents of the 8-bit
Condition Code Register (CCR). The CCR is discussed later in
this course.
15. Press and release the + key. The display now shows:
CCR = 00 H
ACCB = 00 H
That is, the contents of the 8-Bit Accumulator B is 0016.
NOTE: Just as the + key can be used to advance the display up
to the next line; the key (next to the + key) can be used to
return the display back to the previous line.
16. Continue to press and release the + key and record (below) the
value of each register displayed:
CCR =

ACCB =

ACCA =
IX =

IY =

PC =
SP =
NOTE: The registers identified with an asterisk * above are
discussed in upcoming units of this course. For now, just think
of them as special purpose 8-bit registers like the accumulator
and program counter discussed in Unit 2.
17. Press the Reset key. The reset logo should be displayed.

1 -5

1 -6 I

LABORATORY MANUAL

18. Press the NMI (Non-Maskable Interrupt) key. Notice that the
reset logo appears in the display. The NMI function is similar
to the Reset function, however, there are differences (Interrupts are discussed in detail later in this course). One of these
differences is demonstrated in the next few steps of this
experiment.
19. Press the Exm Reg key (#2).
20. Again use the + key to look through the registers (CCR, ACCB,
etc.) as you did earlier in step 16. Record the contents of each
register below.
CCR =
ACCB =
ACCA =
IX =
IY =
PC =
SP =
Are the values recorded above the same as those recorded in
step 16?
(yes or no)
The register values viewed after pressing Reset in step 13 are
different than those obtained after pressing the NMI key
above. This is because the values of these registers change as
the MPU executes its operating system program contained in
ROM. One important difference between resetting the trainer
with the Reset key and the NMI key is that, whereas these
registers are reinitialized to 00 during a system reset (i.e.,
during power-up and after pressing the Reset key), they are
not re-initialized by pressing the NMI key. The register values
you recorded in this step above represent the saved contents of
each of these registers at the time the NMI key was pressed.
21. Press Reset.

EXPERIMENT ONE TRAINER PROGRAMMING FUNDAMENTALS I

22. To begin program data input, press the Exm Mem key. The
trainer display should read:
1
Look Address: 0000H
NOTE: The trainer is now ready to receive program data. This
data will be entered, byte by byte, into consecutively numbered address locations (beginning at 000016 ) If, while entering the program, you make a mistake and key-in the wrong
number, do not attempt to correct the error just remember,
or write down, the address of the error and continue programming. Any errors made during programming can be located
and corrected when you examine the program prior to running
it.
23. Press and release the Return key in the upper left corner of the
trainer key pad. The display should now read:
Look Address: 0000H
0000: xx
NOTE: xx means "don't care."
24. Key-in the Add to Accumulator program shown in Figure 1-2.
Notice that as you enter the second hex character of each
instruction, the display automatically scrolls up to reveal the
next memory location and its contents. The new program that
you are putting in is actually overwriting the memory register's
old contents.
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004

86
07
8B
OA
CF

LDAA
ADD
STOP

COMMENTS
Load accumulator A with...
07
Add to ACCA next byte...
OA
Stop program execution.

Figure 1-2
Add to Accumulator (ATA) program.

25. Press Reset.

1 -7

1 -8 I LABORATORY MANUAL

26. Study the ATA program in Figure 1-2. After running this
program what hex value would you expect accumulator A
(ACCA) to contain? Write your prediction below.
ACCA =

16

NOTE: Although the STOP at the end of a program tells the


MPU to quit executing, to see the STOP instruction located at
the end of the program (address 0004) after running the
program, you can instruct the MPU to "break" at the end of the
program. You can then use the Exm Reg (Examine Registers)
key to view the contents of ACCA (and the other registers) as
they were immediately after your program was executed. You
will learn how to insert a "break-point" for your program in the
next step of this experiment.
27. Locate, press, and release the Break (alternate of #7) key. The
display will show:
7
Break Address: 0000H
28. Watch the display as you enter the address of the last byte
(0004) of the Add to Accumulator program you entered in
Figure 1-2. The display should have momentarily shown:
Break Address 0004
Break added @ 0004
After this, the display should show:
Break added @ 0004H

29. Press the Go (alternate #3) key. The display should show:
>3
Go Address: 0000H
NOTE: The Go Address displayed above means that the MPU
will begin executing instructions at the address specified, that
is 0000. If you wanted to run a program beginning at some
other address, you could enter that address. Because your
program does, indeed, start at the Go Address displayed, you
may now run it.

EXPERIMENT ONE - TRAINER PROGRAMMING FUNDAMENTALS 1

30. Press the Return key. Notice the display. It should now show:
0004 CF
STOP
31. Examine the contents of the MPU registers, paying special
attention to the value in ACCA. To do this, press the Exm Reg
key and the + key (as before) to view the value of each register.
Record the value of ACCA below.
ACCA =
Does this agree with your prediction of ACCA given in step
26?
(yes or no)

DISCUSSION
Now that you have completed the Procedure section of this experiment, its time to review some of your accomplishments:
1. You have been acquainted with several basic trainer functions
and capabilities. These include Reset, NMI, Exm Mem, Exm
Reg, Go, I Blk, Break, Return, and the functions. As a review,
complete the list shown below by giving a brief description of
the full name or function of each trainer key.
Key Name Full Name/Function of Key
Reset
NMI
Exm Reg
Exm Mem
Go
I Blk
Break (Brk)
Return
+ key
key

1 -9

1 -1 0 1 LABORATORY MANUAL

2. You have seen how to examine the contents of RAM, and the
MPU registers including the accumulator, and program counter.
3. You have learned how to enter, analyze, and run a short
program.
In achieving the objectives listed at the beginning of the experiment you have not only put into practice the information contained
in Unit 2, but you have also acquired important practical knowledge by working with, and programming, a (MC68HC11) microprocessor-based system.
Finally, it should be pointed out that once you have completed an
experiment, and successfully accomplished its objectives to your
satisfaction, you can always go back and try changing things to see
"what happens if." Keep in mind that you can't do any harm* to the
trainer by anything you enter from the keypad. So go ahead, try out
your ideas, customize programs, explore, create, learn, enjoy!

" The worst you can do to the trainer from the keypad is "lock-it-up," or send it "off
into the weeds". All of these (same) conditions can be remedied by pressing Reset
or, if all else fails, turning the trainer off, waiting a few seconds, and then back on.

EXPERIMENT

Two - MICROPROCESSOR SYSTEM FEATURES 12-1

EXPERIMENT 2
MICROPROCESSOR SYSTEM
FEATURES
Objectives:
1. To introduce the operation and use of several common MPU
system features on the MPU trainer. These include Help,
SS (Single-Step), NMI (Non-Maskable Interrupt), W Reg
(Watch Register), W Loc (Watch memory Location), Save,
and Load.
2. To further demonstrate the use of the MPU accumulator.
3. To extend the students understanding of how the MPU
executes relatively simple programs.
INTRODUCTION
This experiment is done in three parts. It serves to further acquaint you with the operation of programming the 8-bit microprocessor trainer. You will learn to use several of the more advanced
system functions, as well as, put into practice, and continue to
develop, your understanding of microprocessor programming. Specifically, you will continue your study of a program involving the
MPU accumulator.
As a proper extension of Experiment 1, performing this experiment
helps you extend your understanding of the MPU trainer and
solidify your comprehension of the concepts presented in Unit 2 of
the textbook. As you progress through this experiment, take your
time to fully understand the information presented. This is important because the successful completion of future experiments will,
to some degree, depend upon your understanding of the concepts
presented in these earlier experiments.

2-2 I LABORATORY MANUAL

Part 1 - The Help, SS, and NMI Trainer Functions


PROCEDURE
1.

Apply power to the trainer by switching it on.

2.

Press and release the Reset key.

3.

Press and release the Help key. The display should read:
0 Single Step
>_

4.

Continue to press and release the Help key record each


message displayed next to its respective number below. The
first one is done as an example.
0 Single Step
1
2
3
4
5
6
7

8
9
A

5.

Press and release Reset.

6.

Enter the Trainer Feature Test (TFT) Program shown in Figure


2-1. Do this, as in Experiment 1, by pressing Exm Mem, the
start address (Return for 000016 ), then the hex contents.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005

86
OA
4A
2E
FD
CF

MNEMONICS/
CONTENTS
LDA
DECA
BGT
STOP

COMMENTS
Load ACCA with...
0A16
Decrement ACCA by 1.
Branch if Greater Than zero.
Offset branch back (-2).
Stop.

Figure 2-1
Trainer Feature Test Program (TFT) program.

EXPERIMENT

Two

MICROPROCESSOR SYSTEM FEATURES

7. Press and release NMI.


8. Press and release the SS (Single Step) key (alternate of 0) one
time. The display should read:
0
Step Address: 0000 H
NOTE: The display is now showing the default program start
address. If you wanted to begin single-stepping through a
program beginning at a different address, you could enter that
address at this point. Because the TFT program you entered
does begin at address 000016, you have two options to accomplish the same result:
A. You could enter 000016 by pressing the 0-key four times,
or,
B. You could simply press the Return key to start the program
at the default address of 000016 as displayed.
Because option B is more convenient you are directed to use it
in the next step.
9. Press and release the Return key. The display should read:
0000 86 OA
LDAA #0A
Notice that this is the first instruction in the TFT program.
The mnemonics LDAA means LoaD Accumulator A with the
number (#) 0A16. Keep in mind that this instruction will be
executed only after you press the SS key. You are instructed to
press SS next.
10. Press and release the SS key. The display should now read:
0002 4A
DECA
This instruction means DECrement (by 1) accumulator A. For
example, if the number in ACCA is OA before DECA is executed, it changes to (decremented to) 09 after the DECA
instruction is executed. Remember, at this time, ACCA contains the number OA as loaded by the execution of the previous
instruction.

2 -3

2-4 1 LABORATORY MANUAL


11. Examine the contents of ACCA by pressing and releasing the
Exm Reg key, and then the + key (twice) to scroll the display
to ACCA. Write the contents of ACCA in the space below.
ACCA =
12. Press and release the Reset key.
NOTE: As discussed in Experiment 1, the NMI key is similar
in function to the Reset key. That is, pressing NMI interrupts
any program or operation being performed by the trainer. NMI
is different from Reset, however, because, unlike a Reset, an
NMI does not affect the contents of the MPU registers.
13. Press and release the SS key.
14. Press and release the Return key.
15. Press and release the SS key twice. The display should now
read:
0003 2E FD
BGT FD
Having viewed the program steps located in RAM locations
0000 through 0002 with the SS function, the display now
shows the program instructions of the next location, 0003.
Although some of the instructions used in this program have
not been discussed in Unit 1, they are not difficult to understand. The BGT or "Branch if Greater Than zero" instruction
simply does what its name implies, that is, if the value present
in ACCA is greater than zero, program execution branches
(back in this case) a specified number of locations to another
address. In the case of the TFT program, the FDA tells the
MPU to go back 2 locations from the location of the next
instruction (i.e., from 0004 back to 0002). Notice that this puts
the program in what is referred to as a "loop." The "looping"
continues until the value in ACCA has been decremented to
zero. After ACCA has been decremented to zero, the program
continues to the next instruction after BGT that is, to STOP.
Branch instructions are discussed in more detail in Unit 4 of
the textbook.
16. Press and release the Exm Reg key.

EXPERIMENT

Two

MICROPROCESSOR SYSTEM FEATURES

17. Press and release the + key twice. Record the value of ACCA in
the space below.
18. Press and release the NMI key.
19. Press and release the SS key.
20. Press and release the Return key. The display should display
the same as in step #9.
NOTE: You are now ready to execute the program from its
beginning in the SS mode.
21. Record the display contents below as you press and release the
SS key exactly 6 times. The first one is done as an example.
SS key press Observed Display Contents
1

0002 4A
DEC A

At this point, estimate how many times the original value (OA)
contained in ACCA has been decremented. Record your estimate below.
ACCA decremented

times.

12 -5

2-6 I LABORATORY MANUAL


What value would you expect in ACCA at this time?
ACCA (anticipated) =

16

22. Press the Exm Reg key and then the + key twice to examine the
present value of ACCA. Record it's value below.
ACCA (actual) =

16

Does ACCA (anticipated) equal ACCA (actual)?

(yes/no)

23. Press and release the NMI key.


24. Press and release the SS key.
25. Press and release the Return key.
NOTE: You will now explore the slow-continuous SS program
execution by pressing and holding the SS key.
26. Press and hold the SS key until the display stops scrolling and
you see the STOP instruction displayed at the end of the TFT
program (approximately 25 seconds). Continue to press and
hold the SS key for about 5 seconds after STOP is displayed.
What value do you expect ACCA to contain now?
ACCA (expected) =
27. Press and release the NMI key.
28. Press the Exm Reg key and the + key twice to observe the
actual value of ACCA. Record this value below.
ACCA (observed) =
Do the values you recorded for ACCA (expected) and ACCA
(observed) agree?
(yes/no)
NOTE: Because you single stepped through the entire program in step #26, the original value of 0A16 placed in ACCA
should have been decremented ten times until ACCA = 0.

EXPERIMENT

Two MICROPROCESSOR SYSTEM FEATURES I 2-7

Part 2 The W Reg and W Loc Trainer Functions


Until now you have been single stepping through a program and
periodically checking the value of ACCA for its value. As you have
probably realized, this can be a time consuming process. There
must be a better way to run a program and automatically be alerted
when a certain register (e.g., the accumulator) reaches a particular
value of interest. That is, although the SS function provides a
useful way to analyze the step by step action of the TFT program,
for practical applications it would be desirable to be able to execute
the program at full speed and be automatically alerted when ACCA
reached zero.
You will now learn the operation of the "Watch" functions on the
MPU trainer. The W Reg, or Watch Register function allows you to
monitor a changing value contained in a particular register (e.g.,
ACCA or the program counter) for a specific value. When the value
of interest is reached in the register, the program will break. The
register and its contents are briefly displayed. The W Loc, or Watch
(memory) Location functions similarly, but with the contents of
memory locations instead of registers.
As you will see, one of the traits that distinguishes a programmable logic device (such as a computer) from a non-programmable
device (such as a simple calculator) is the ability to perform
repetitious calculations and automatically respond (as programmed)
to one or more changing quantities. The practical applications for
this characteristic of computers is virtually limitless. This is
apparent from all the microprocessor-based hardware available
today. For example, a typical microprocessor-based system may be
employed to perform highly repetitious tasks such as counting,
iterative calculation, or complex automated process control. In
applications such as these, the value of a particular MPU register
or memory location may become critical. The "watch" functions to
be demonstrated provide an effective way to monitor these values
automatically.

PROCEDURE
1. With the TFT program still entered from Part 1, Reset the
trainer.

2-8 I LABORATORY MANUAL


2. Press and release the W Reg (alternate of 8) key. The trainer
display should now read:
Watch Register:
CCR?
3. Press and release the 0 key seven times recording the top-most
line displayed in the spaces below.
0 Key Press Display Contents Observed
1
2
3
4
5
6
7
NOTE: You have now cycled through the registers. The "?"
displayed after each register name is interpreted as a prompt
asking you if you wish to "watch" that particular register for
a value of interest.
4. Press and release the 0 key twice so that ACCA? occupies the
bottom-most display line. The display should read:
ACCB?
ACCA?
NOTE: When looking through the W Reg "menu" it is the
bottom line that is selected to "watch" if desired. This is
demonstrated in the next few steps.
5. To set a particular value to "watch" ACCA for, press and
release the W Reg key once again. The display should now
read:
ACCB?
ACCA? = 00 H

EXPERIMENT

6.

Two MICROPROCESSOR SYSTEM FEATURES

Enter 00. Watch the display. After a moment the display


should read:
watch ACCA for 00
>_

7.

Press and release the SS key.

8.

Press and release the Return key.

9.

Carefully observe the display as you press and release the Go


key.

10. In the previous step the display should have briefly read:
LDAA #0A
ACCA = 00
NOTE: You can observe this brief message as many times as
you wish by re-running the program. The program can be rerun by entering NMI, SS, Return, and Go.
11. Press and release the Exm Reg key.
12. Press and hold the + key until the display scrolls to show the
contents of ACCA. Record the value observed below.
ACCA =
NOTE: By pressing and holding the + key, the display automatically scrolled upward. Most trainer function keys, if
pressed and held will continue their operation at a slow,
constant rate. These include +, , SS, Exm Reg, Exm Mem, W
Reg, and W Loc.
Regarding the W Reg function, lets briefly consider its workings. Simply stated you set a value (e.g., 00) to "watch" ACCA
for during the full speed execution of the TFT program. As you
saw earlier (Part 1) you could single-step through the program
ten times to decrement ACCA to zero. You also saw how to
check the value of any register using the Exm Reg key. This
was a time consuming process. However, in using the W Reg
function, the program could be run at full-speed and automati-

1 2-9

2-1 0 I LABORATORY MANUAL


cally stopped when ACCA reached zero. This is a much more
efficient way to monitor the contents of a register. One last
thing should be noted. All W Reg (and W Loc) values set are
cleared by pressing Reset, but not by NMI. Also, you can easily
check to see which registers are being watched as follows.
13. Press and release the NMI key.
14. Press and release the W Reg key.
15. Observe the display as you press and release the List key. All
"watched" registers, along with their current "watch" values
should be briefly displayed. If no registers are currently being
"watched," the message "no watch regs set" will be displayed.
NOTE: As mentioned, the W Loc or Watch Location function
works the same way for memory locations as W Reg does for
registers. That is, you can set a particular memory address to
be "watched" for a specific value and interrupt program execution when the value is reached.

Part 3 The Load and Save Functions


NOTE: The following steps require the ETC-128 Memory Module.
If you do not have this optional cartridge, please skip Part 3 and
proceed to the Discussion section.
Thus far, the programs you have been using have been relatively
short. If you accidentally erased a program you could simply reenter it without too much trouble. But what if you have a large
program? Obviously losing, and having to re-enter a rather large,
let's say 100 line, program would be a time consuming and tedious
task. Fortunately the ETW-3800 trainer has the capability to
permanently save your programs on an "Electrically Erasable
Programmable Read Only Memory" or EEPROM (also E2PROM)
cartridge. You will now learn to Save and Load programs.

PROCEDURE
1. Press and release NMI.
2.

Press the Exm Mem key.

EXPERIMENT TWO - MICROPROCESSOR SYSTEM FEATURES

3.

Press Return. The display should now read:


Look Address: 0000 H
0000: 86
This is the first line of the TFT program you entered earlier.
Continue checking the program as instructed in the following
step.

4.

Continue to check the first six RAM locations by pressing and


releasing the + key. The TFT program should still reside intact
at RAM locations 0000 to 0005. If it isn't intact, re-enter it as
before.

5.

With the TFT program properly entered, press and release the
NMI key.

6.

To save the program onto the EEPROM cartridge, press the


Save key (alternate of B). The display should read:
B
Source: 0000 H

7.

Enter the address of the first byte of the TFT program 0000.
The display should now read:
Source: 0000 H
# Bytes: 0000 H
NOTE: Count the total number of bytes in the program to be
saved. Notice that in a program beginning at address 0000, the
total number of bytes will be one greater than the address of
the last program byte. In the case of the TFT program (that you
will save), the address of the last byte is 0005, therefore, the
"# Bytes" to be saved is 0005 + 1, or 0006.

8.

Enter 0006. The display should change to:


# Bytes: 0006 H
File digit?
Notice that any time you "Save" a program on EEPROM you
must specify a "File digit" to save the program under. This
provides for a convenient way of labeling the program. A total
of 16 "File digits," 0-F16 may be used.

2 -1 1

2-1 2 I LABORATORY MANUAL

9.

Observe the display as you press the 0 key to save the TFT
program under "File digit" 0. The display will briefly read:
Copying...
Verifying Checksum
and then read:
Checksum= xxxx
>_
to indicate that the copy is complete. If, for some reason, the
copy does not occur correctly, an error message is displayed.

10. Press and release NMI.


11. Press and release the Save key.
12. Enter 0000.
13. Enter 03F916.
14. Enter "File digit" 1.
15. Record the contents of the display below.

Have the 03F9 bytes been effectively saved to EEPROM?


(yes/no)
Convert 03F916 to decimal.
03F916 =

10

16. Press and release NMI.


17. Press and release the Save key once again.
18. Enter 0000.
19. Enter 03FA. Record the contents of the display below.

EXPERIMENT

Two - MICROPROCESSOR SYSTEM FEATURES

Can a program containing 03FA bytes be saved using the


"Save" function?
(yes/no)
Why not?

Convert 03FA16 to decimal.


03FA16 =

10

What is the maximum number of bytes that can be saved using


the "Save" (to EEPROM) function?
bytes maximum.
20. Press and release NMI.
21. Now that you have investigated how programs can be saved,
its time to look at how they can be retrieved, or "loaded." With
the TFT program properly saved under "File digit" 0, change
all of the first six bytes 0000 to 0005 of RAM to FF16. To do this,
enter Exm Mem, Return, and entering FF six times.
22. Press and release NMI.
23. Now examine bytes 0000 through 0005 of RAM. Record their
value below.
Address

Contents

0000
0001
0002
0003
0004
0005
24. Does the TFT program reside at these first six locations
anymore?
(yes/no)
25. Press and release NMI.

12-1 3

2-14 I LABORATORY MANUAL

26. Press the Load key (alternate A). The display should read:
A
File digit?_
27. Enter the "File digit" you saved the TFT program under, i.e.,
0 watch the display. The display should have briefly read:
File digit?
copying to 0000 H
and then,
Checksum = xxxx
>_
xxxx should be same value displayed when program was saved
in step 9.
28. Now examine the first six RAM locations 000016-000516 as
before. Record their contents below.
Address

Contents

0000
0001
0002
0003
0004
0005
Has the TFT program been reloaded?

(yes/no)

DISCUSSION
Experiment 2 placed a strong emphasis on the MPU trainer and its
functions. Becoming familiar with these is important to your
overall understanding of, not only microprocessor programming
but, microprocessors in general. This is because many of the
trainer functions you have learned are directly or indirectly relatable right back to the MPU itself.

EXPERIMENT

Two - MICROPROCESSOR SYSTEM FEATURES 12-1 5

In conjunction with Experiment 1, this experiment has also emphasized several programming fundamentals related to topics
discussed in Unit 2 in the textbook. By this time you should be
becoming increasingly familiar with the idea of MPU registers as
specialized 8- or 16-bit memory locations. The discussion in Unit 2
concentrated on the accumulator as being representative of a
typical MPU register. The specifics concerning other MPU registers will be discussed later.

EXPERIMENT THREE - ADDRESSING MODES 13-1

EXPERIMENT 3
ADDRESSING MODES (Inherent,
Immediate, and Direct)
Objectives:
I. To demonstrate the characteristics, operation, and use of
the inherent, immediate, and direct addressing modes.
2. To provide a means of directly studying the execution of
simple programs as discussed in Unit 3 of the textbook.
3. To introduce and demonstrate the function and use of
several new instructions and the RPO (Return to Previous
Operation) key.

INTRODUCTION
In this experiment you will use the three addressing modes discussed in Unit 3. For your convenience and effective learning, the
experiment has been subdivided into three different parts. Each
part concentrates on a specific addressing mode.
Part 1, on the inherent addressing mode, contains a program
consisting of all inherent mode instructions. In this program, as in
the other programs in the experiment, you will see some new
instructions. These instructions, although not yet discussed, are
presented here and explained enough to build and develop your
understanding of the main topics of the experiment. In addition,
however, you will extend your "vocabulary" of MPU instruction
mnemonics.
Part 2 of the experiment presents an opportunity to investigate the
immediate addressing mode in a practical way. The program used
for this section is brief but effective. Again, by including the AND
instruction, you will gain additional instruction set experience.
Finally, the last section of the experiment, Part 3, serves to
reinforce your understanding of the direct addressing mode. As in
the other experiments, some new, but easy to learn, instructions
are included in the program used. These include the LDD, SUBD,
and STD instructions used in working with the 16-bit double
accumulator (ACCD).

3-2 I LABORATORY MANUAL


After you complete the experiment, as with any other experiment,
feel free to go back and change the programs, modify the procedures, etc. This type of individual exploring can lead to a greater
appreciation of the subject.

Part 1The Inherent Addressing Mode


PROCEDURE
1. Switch the trainer on press and release the Reset key. You
will now investigate the workings of the inherent (implied)
addressing mode. This is done using the Inherent Addressing
Mode Demonstration (IMD) program shown in Figure 3-1.
Notice that this program contains several new instructions. As
you will see, the IMD program is actually composed totally of
inherent addressing mode instructions. Although these particular instructions have not been formally discussed they are
easy to understand.
2.

Enter the IMD program shown in Figure 3-1.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F

4F
5F
4A
5A
4C
5C
4C
5C
40
50
01
01
01
01
01
CF

MNEMONICS/
CONTENTS
CLRA
CLRB
DECA
DECB
INCA
INCB
INCA
INCB
NEGA
NEGB
NOP
NOP
NOP
NOP
NOP
STOP

COMMENTS
Clear ACCA to all zeros
Clear ACCB to all zeros
Decrement ACCA (by 1)
Decrement ACCB (by 1)
Increment ACCA (by 1)
Increment ACCB (by 1)

Negate ACCA (2's complement)


Negate ACCB (2's complement)
No operation

Stop.

Figure 3-1

Inherent Addressing Mode Demonstration (IMD) program.

EXPERIMENT THREE - ADDRESSING MODES

NOTE: Remember, to enter a program beginning at address


0000, press and release Exm Mem, Return, and then the
instructions as shown in the Hex Contents column of Figure 31. When the last byte has been entered, press and release the
NMI key.
Also, at this point it is not a bad idea to save the IMD program
to E2PROM (as discussed in the last experiment). You should
get in the habit of saving any program that you wouldn't want
to re-enter in the event you lost it from RAM. Remember, to
save a program after it is entered, press Save, enter the start
address (e.g., 000016) enter the number of bytes (1 + last byte
in a program starting at 000016), and finally the file digit (0F) that you want to save the program under (make sure that
you don't have another program you want to keep already
saved under the same file digit, otherwise it will be overwritten).
3.

Press and release the SS key.

4.

Press and release the Return Key. The display should now
read:
0000 4F
CLRA
The CLRA, or CLeaR accumulator A, will be executed in the
inherent addressing mode. Notice in the IMD program that no
operand is specified. The operand is implied to be the contents
of ACCA.

5.

Execute the CLRA instruction by pressing and releasing the


SS key. The display should now read:
0001 5F
CLRB
Notice that the CLRB, or CLeaR Accumulator B, instruction
will also be executed in the inherent addressing mode. CLRB
works on accumulator B exactly as CLRA does on accumulator
A.

13-3

3-4

LABORATORY MANUAL

6.

Execute the CLRB instruction now by pressing and releasing


the SS key. The display should now read:
0002 4A
DECA

7.

Press and release the Exm Reg key to view the MPU registers.

8.

Press and release the + key twice to view the contents of ACCA
and ACCB. Record these values below.
ACCA =
ACCB =
Have both accumulator registers been cleared by executing the
CLR instructions in the inherent addressing mode?
yes
no)

9.

Press and release the + key 3 more times to view the contents
of the Program Counter (PC). Record its value below.
PC =
You will now see how the Return to Previous Operation (RPO)
key can be used to execute a program in sections while checking registers.

10. Press and release the RPO key (alternate of the Help key).
Notice that the display reads as it did in step 6, before the Exm
Reg key was pressed. RPO is a very useful function key. It can
be used at any point, after an Exm Mem, or Exm Reg, to return
to the program step where you left off. The RPO thus eliminates single-stepping from the beginning, or setting break/
watch points (as done previously).
11. You will now decrement ACCA and ACCB by executing the
DECA and DECB instructions. To do this, press and release SS
twice. The display should now show the next instruction to be
executed (after DECA, DECB).
0004 4C
INCA

EXPERIMENT THREE - ADDRESSING MODES 13 -5

12. The MPU decrements (or subtracts) by adding the 2's complement of the binary number to be subtracted (i.e., the subtrahend) from the original number. Perform the following binary
subtraction using this method.
ACCA = ACCB = 0016 = 000000002
0016 - 0116 = 000000002 - 000000012 = 000000002
+ 111111112 2's complement of subtrahend
2
16

calculated value in ACCA/ACCB

13. Press and release the Exm Register key.


14. Press and release the + key twice to examine the actual
contents of ACCA and ACCB. Record these values below.
ACCA (actual) =

16

ACCB (actual) =

16

Do the calculated and actual values for the accumulators


agree?
(yes/no)
At this point in the IMD program's execution both accumulators have been decremented (by 1) from their contents of 00.
This has resulted in their present contents of FF16.
15. Press and release the RPO key. This returns you back to the
IMD program. The display should read as before in step 11.
16. You will now increment both accumulators using the inherent
mode instructions INCA and INCB to respectively increase by
1 (or increment) the value contained in each. Press and release
the SS key twice. The display should now read:
0006 4C
INCA

3-6 1 LABORATORY MANUAL


The previously decremented contents of each accumulator
have now been incremented using the inherent mode instructions INCA and INCB. Notice again that the operand for these
instructions is implied to be the contents of each respective
accumulator. What value do you expect at present in each
accumulator?
ACCA =

16 ACCB =

16

17. Study the IMD program shown in Figure 3-1. What value will
each accumulator hold after the execution of the first 8 program bytes?
ACCA =

16

ACCB =

16

18. Press and release the SS key twice.


19. Press and release the Exm Reg key.
20. Examine the contents of ACCA and ACCB by pressing the +
key twice. Do the observed values agree with those predicted
above in step #17?
(yes/no)
21. Return to the previous program step, and execute the next two
instructions. Do this by entering RPO, and SS twice. The
display should read:
000A 01
NOP
The IMD program has now been executed through address OA.
The values previously contained in the accumulator (calculated in step #17) have each been "negated" with the inherent
mode instructions NEGA and NEGB . These "negate" instructions function to convert their (implied) operand (i.e., the
accumulator contents) to its 2's complement form. Convert the
contents of ACCA and ACCB calculated in step #17 to their 2's
complement form below.
ACCA (step #17) =

16 =

2's complement =

16 =

ACCB (step # 17) =


2's complement =

16 =
16 =

2
2

EXPERIMENT THREE - ADDRESSING MODES 13 - /

22. Examine the contents of ACCA and ACCB by pressing and


releasing Exm Reg, and the + key twice. Do the values observed agree with your 2's complement expectations written
above in step #21?
(yes/no)
23. Press and release the NMI key.
24. Check the IMD program to verify that it is correctly entered
if it is, press and release the Reset key.
25. Insert a break-point immediately before the 5 NOP instructions at address OA. Do this by entering Break, and then 000A.
26. Now run the IMD program at full speed by entering Go, and
then Return. The display should read:
000A 01
NOP
27. Examine and record the value of each MPU register (before the
NOPs) by entering Exm Reg and then using the + key to cycle
through all registers. Write each register's value below.
Before NOPs

After NOPs

CCR =
ACCB =
ACCA =
IX =
TY =
PC =
SP =
28. Press the Reset key to remove the break-point placed previously. Recheck your program using the Exm Mem key. Notice
that the instruction (01) at address 000A has probably changed.
If it has, change it back to 01. Press Reset.
29. Insert a new break-point immediately after the 5 NOP instructions at address OF. Do this by entering Break, and then 000F.

3-8 I LABORATORY MANUAL


30. Rerun the IMD program at full speed by entering Go, and
Return. The display should read:
000F CF
STOP_
31. Press the Exm Reg key and reexamine the value of each MPU
register as before in step #27. Record the value of each register
in the After NOPs column in step #27.
32. Compare the recorded contents (step #27) of each register
before and after the execution of the NOP instructions. Are all
values the same?
(yes/no)
If not, which are different?
Notice that all register values should be the same before the
execution of the NOP instructions as after except for the program counter (PC). By definition, the NOP instruction is a No
Operation. It does nothing except to advance the program counter.
NOP may be executed only in the inherent addressing mode.

Part 2The Immediate Addressing Mode


You will now concentrate on a simple program that demonstrates
the immediate addressing mode. As you learned in Unit 3, the
immediate addressing mode is similar to the inherent mode except,
in the immediate mode, the operand is not absent or implied but is
placed immediately after the instruction opcode.

PROCEDURE
1. Reset the trainer and enter the Immediate Addressing Mode
(IAM) program shown in Figure 3-2.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004

86
AA
84
55
CF

MNEMONICS/
CONTENTS
LDAA
ANDA
STOP

COMMENTS
Load ACCA with...
operand 1.
Logically AND with...
operand 2.
Stop.

Figure 3-2
Immediate Addressing Mode (IAM) program.

EXPERIMENT THREE - ADDRESSING MODES

Study the IAM program. You should be familiar with all but
the ANDA instruction. This is the "logical AND accumulator A
to memory" instruction. From your previous studies of digital
electronics, you should be familiar with the logical AND operation. In the IAM program, the result of a bit for bit logical AND
operation, between the contents of ACCA (operand 1) and
memory location 0003 (operand 2), is placed in ACCA. Both
instructions use the immediate addressing mode to address
their respective operands.
2.

Convert each operand in the IAM program to its binary equivalent below.
AA16 =
5516 =

3.

Logically AND each binary bit of operand 1 with each bit of


operand 2. Write the result in both binary and hexadecimal
below.
Result of ANDing operands above

Result of ANDing operands above

16

4.

If done correctly, the logical AND result calculated above


should be the same result obtained in ACCA after running the
IAM program. Before running it, however, you need to add a
break-point (Brk) at address 0004.

5.

Add a break-point at address 0004 by entering Brk, and then


0004.

6.

Run the IAM program by entering Go, and Return. (NOTE: You
could alternatively SS through the program and check the
intermediate values of ACCA using Exm key and RPO for
now just run the program as directed.) The display should
read:
0004 CF
STOP_

3-9

3-10 I LABORATORY MANUAL


7. Examine ACCA by entering Exm Reg, and + twice. What value
do you observe in ACCA?
ACCA =

16

Does this agree with the value you calculated in step #3?
(yes/no)
The results calculated and observed should both agree. In
performing the immediate mode logical AND of the two operands, the process of ANDing each corresponding bit should
result in zero. This can be seen by converting each operand to
its binary equivalent as you did in step #2. At this time you
should have a basic understanding of how the immediate
addressing mode operates. Simply stated, in the immediate
mode, the actual argument of operand is contained in the byte
immediately following the instruction, hence the name immediate addressing mode.

Part 3The Direct Addressing Mode


Recall from Unit 3 that the direct addressing mode is similar to the
immediate mode in that there is a separate instruction and an
operand involved. However, whereas in the immediate mode the
actual operand follows the instruction, in the direct addressing
mode it is the address of the operand that follows the instruction.
This (direct) addressing mode is, therefore, useful under circumstances in which the operand is a variable, or must be operated on
by more than one instruction. You will now experimentally verify
the action of the direct addressing mode.

PROCEDURE
1. Reset the trainer.
2.

Enter the Direct Mode Addressing (DMA) program shown in


Figure 3-3. After it is entered, press NMI.

EXPERIMENT THREE ADDRESSING MODES

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C

DC
07
93
09
DD
OB
CF
00
DC
00
78

MNEMONICS/
CONTENTS
LDD
SUBD
STD
STOP

COMMENTS
Load ACCD direct with...
operand 1 at address 07.
Subtract...
operand 2 at address 09.
Store ACCD...
at address OB.
Stop.
Operand 1 (high byte).
Operand 1 (low byte).
Operand 2 (high byte).
Operand 2 (low byte).
Reserved for difference (high byte).
Reserved for difference (low byte).

Figure 3-3
Direct Mode Addressing (DMA) program.

Although the DMA program involves a double accumulator


(formally discussed in Unit 7) keep in mind that working with
ACCD is the same as working with either of the single accumulators, except that ACCD is 16-bits wide instead of 8. Also
recognize that ACCD is simply composed of ACCA (as the high
byte), and ACCB (as the low byte).
The DMA program employs direct addressing to load the 16-bit
double accumulator (ACCD) with the value stored at address
07. The value stored at address 09 is then subtracted from the
contents of ACCD. The result of this subtraction (the subtrahend) is then placed back into ACCD. Finally, the STD instruction stores the contents of ACCD (the subtrahend) "directly" at
the address indicated in the next program byte after STD.
Notice that the program bytes following the instructions in the
DMA program are not operands, but the addresses of the
operands. You will now run the DMA program and see how it
works.
3. Check that you have entered the DMA program correctly. To do
this enter Exm Mem, Return, and then press and release the
+ key to look at each of the memory locations used for the
program (000016-000B16 ). Make any corrections necessary.
Press NMI.

3 -1 1

3-1 2

1 LABORATORY MANUAL

4. Single Step (SS) through address 0001 of the DMA program


and examine the contents of ACCD (i.e., ACCA and ACCB). To
do this enter SS, Return, SS, Exm Reg, and hit the + key twice.
Record the value of ACCD below.

ACCA
ACCB
High Byte (bits 8-15) of ACCD Low Byte (bits 0-7) of ACCD
5.

Press and release the RPO key.

6.

Single Step (SS) through address 0003 of the DMA program


and examine the contents of ACCD (i.e., ACCA and ACCB). To
do this press SS, Exm Reg, and + (twice). Record the value of
ACCD below.

ACCA
ACCB
High Byte (bits 8-15) of ACCD Low Byte (bits 0-7) of ACCD
Study the DMA program. Have the 16-bit contents of memory
locations 000916-000A16 been subtracted from the contents of
addresses 000716-000816?
(yes/no)
Into which register has the difference been placed?

If the DMA program were run completely, where else would


this difference (the subtrahend) be placed?
8.

Press and release the NMI key.

9.

Now run the complete DMA program at full-speed. To do this


press and release Go, and Return. Notice that after pressing
and releasing the Return key the program is run, but the
display does not change. This is because no break point has
been set. Remember that programs can be run at full-speed
with no break points, however, the display will not change to
indicate that the program has been run unless programmed to
do so.

EXPERIMENT THREE - ADDRESSING MODES

10. To view the contents of the registers or memory, press and


release the NMI key and then the appropriate "Exm" key.
Examine memory location 000C. Record its value below.
memory location 000C16 =
Is this the same value observed in ACCB in step #6?
(yes/no)
Have the contents of ACCD been stored directly?
(yes/no)
Remember that memory location 000C 16 was reserved for the
contents of ACCD after the subtraction. The value observed in
step #6 (i.e., the contents of ACCD) and the value at memory
location 000C should be the same.

DISCUSSION
This experiment has introduced you to some new instructions and
the RPO key. Included among the instructions were CLR, INC,
NEG, NOP, AND, LDD, SUBD, and STD. You saw how these
instructions can be used in working with ACCD the double
accumulator.
You have also worked with and used the main characteristics of the
inherent, immediate, and direct addressing modes. These addressing modes, discussed in Unit 3, are widely used and have many
applications throughout MPU programming. However, these are
not the only addressing modes possible. You will learn more about
the others in the remainder of the course.
Finally, you have gained experience in how programs are written
with instructions that use each of the addressing modes discussed.
To aid your understanding, these programs were intentionally
written to use predominantly one addressing mode. However, in
any given program, several addressing modes may be combined.
You will learn more about using more than one addressing mode in
your programs in the next experiment.

3-1 3

EXPERIMENT FOUR - COMBINED ADDRESSING MODE PROGRAMMING

EXPERIMENT 4
COMBINED ADDRESSING MODE
PROGRAMMING
Objectives:
1. To demonstrate how instructions using different addressing modes can be combined within a single program.
2. To introduce several new instructions and demonstrate
their use and operation in a program.
3. To provide an opportunity to write, analyze, edit, and run
a microprocessor program to illustrate how the use of
different addressing modes can affect the efficiency of a
program.

INTRODUCTION
Now that you have learned about and seen applications involving
the inherent, immediate, and direct addressing modes in separate
programs, it's time to investigate how these can be combined
within a single program. As you will see, in many programming
applications, two or more addressing modes can be used to accomplish a particular task more efficiently than would be otherwise
possible using only one mode.
At this point it is worth remembering that, although we speak of
using a particular addressing mode, it is how an instruction
addresses its operand that determines the addressing mode used.
Because certain instructions can address their operands in more
than one way, the same instruction may have several different
opcodes. This is the case with many instructions. For example, the
LDA (load accumulator) instruction can be used with not only the
immediate and direct modes as discussed, but also three other
modes, for a total of five different addressing modes.
In this experiment you will also have an opportunity to develop
your own program. This involves modifying the demonstration
program to make it more efficient. We use the term efficiency in
reference to the minimum number of bytes of code required to

4-1

4-2 I LABORATORY MANUAL


accomplish a certain task. For example, many different programs
could be written to add 10 numbers together. We consider the
program that uses the lowest, or minimum, number of bytes (to
accomplish the task) as the most efficient.
By developing your own programs and applying what you have
learned, you will discover that your understanding of the topics
and concepts presented are greatly enhanced. In fact, if you have
not already done so, you may find that creating programs can be a
very satisfying, fulfilling, and even enjoyable experience.

PROCEDURE
1. Enter the Addressing Mode Demonstration (AMD) program
shown in Figure 4-1. Remember, to do this, follow the usual
sequence, i.e., power-up the trainer, press Reset, Exm Mem,
Return, and then key-in the program as listed.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
0000
000E
000F

96
OC
43
98
OD
D6
OE
53
D8
OF
3D
CF
FF
02
FF
05

MNEMONICS/
CONTENTS
LDAA
COMA
EORA
LDAB
COMB
EORB
MUL
STOP

COMMENTS
Load ACCA (direct) with...
Operand 1 at address OC
l's complement ACCA
Exclusive OR ACCA with...
Operand 2 at address OD
Load ACCB direct with...
Operand 3 at address OE
l's complement ACCB
Exclusive OR ACCB with...
Operand 4 at address OF
Multiply ACCA`ACCB
Stop
Reserved for operand 1
Reserved for operand 2
Reserved for operand 3
Reserved for operand 4

Figure 4-1

Addressing Mode Demonstration (AMD) program.

2. Press and release the NMI key.


3. Check the program using the Exm Mem key correct any
errors.
4. Press and release the NMI key.

EXPERIMENT FOUR - COMBINED ADDRESSING MODE PROGRAMMING 14-3

5. Single Step (SS) through the AMD program. Do this by entering SS, the program's start address (or Return for start address 000016), and press and release the SS key to advance
program execution step-by-step. Examine and record the values indicated below. Do this using the SS, Exm Reg, and RPO
keys as demonstrated previously.
Display

Register Contents Observed

0000 96 OC
LDAA OC_
ACCA
0002 43
COMA
ACCA
0003 98 OD
EORA OD
ACCA
0005 D6 OE
LDAB OE
ACCA
0007 53
COMB
ACCB
0008 D8 OF
EORB OF
ACCB
000A 3D
MUL
ACCB
000B CF
STOP_
ACCA
ACCB
(double accumulator ACCD)
The AMD program is mainly composed of instructions that use
the direct addressing mode. The program works to load (directly) each 8-bit accumulator; take the
complement; exclusively OR (directly) the contents with the operand indicated;
and finally, multiply the resulting contents of the accumulators together.

4-4

1 LABORATORY MANUAL

The values that you observed and recorded above demonstrate


this description of how the program works. Starting at the
beginning, look at the display contents at address 0000. You
are already familiar with the LDAA instruction. This is being
executed in the direct addressing mode. As such, the byte (OC)
located at address 0001 (directly after the LDAA instruction)
gives the address of the operand to be loaded into ACCA.
Notice that, because the LDAA instruction was executed in the
direct mode, pressing SS advances the program to the program
byte after the address of the LDAA operand to 0002. Location 0002 contains the opcode for the l's complement ACCA
instruction. This instruction is executed in the inherent addressing mode and simply serves to take the l's complement of
the value in ACCA, and then store the (complemented) value
back in ACCA. The value loaded directly into ACCA was FF.
The l's complement (as you should recall) is formed by changing all l's to 0's and all 0's to l's in the binary form of a number.
Therefore, after the execution of the COMA instruction ACCA
should contain the l's complement of FF, or 00. Next, the
EORA, or "Exclusive OR accumulator A with memory" is
executed in the direct addressing mode. This instruction functions to accomplish a bit by bit exclusive OR (XOR) of accumulator A with the byte contained at the direct address (OD). The
value of the byte at the address is 02. Converting the content
of ACCA and memory location OD to binary gives:
ACCA = 00000000
byte at location OD = 00000010
XOR result = 00000010
This XOR result is placed back into ACCA . Notice that the
same operations are performed with ACCB (except the XOR
result is 00000101 = 5, instead of 00000010 = 2 as above).
Finally, the MUL or "multiply accumulators" serves to multiply the 8-bits of ACCA by the 8-bits of ACCB and place the
result (product) into the 16-bit double accumulator (ACCD). In
the AMD program, ACCA contains 02 and ACCB contains 05,
therefore, after executing the MUL instruction ACCD will
contain the product, 0A16. Because this number can be represented totally with a single byte, it is placed in the low byte
of ACCD (i.e. ACCB).

EXPERIMENT FOUR - COMBINED ADDRESSING MODE PROGRAMMING 14 -5

6.

Press and release the NMI key.

7.

Now SS back through the AMD program making certain that


you understand its workings. If there is something you do not
understand, go back and study the program and its description
above. To aid your understanding, complete the blanks below.
Accumulator A (ACCA) Operations
(AMD program lines 0000-0004)
operand 1 =
(address 000C)

16 =

l's complement of operand 1 =

Hexadecimal form of l's complement =


operand 2 =
(address 000D)

16

16 =

Exclusive OR Operation
l's complement of operand 1 =

Binary form of operand 2 =

Exclusive OR of operands =

final result ACCA


Accumulator B (ACCB) Operations
(AMD program lines 0005-0009)
Operand 3 =
(address 000E)

16 =

l's complement of operand 3 =

Hexadecimal form of l's complement =

16

Operand 4 =
(address 000F)

16 =

4-6 1 LABORATORY MANUAL


Exclusive OR Operation
l's complement of operand 3 =

binary form of operand 4

Exclusive OR of operands

final result ACCB


Multiplication of Final Accumulator Results
(AMD program line 000A)
binary form of final result ACCA =

binary form of final result ACCB =

ACCA x ACCB (product)

ACCD
8.

As you now know, the AMD program uses a combination of


addressing modes. Below is a list of instructions used in the
program. In the space next to each instruction, write the
addressing mode used in the AMD program.
AMD program instruction

addressing mode

LDAA
COMA
EORA
LDAB
COMB
E ORB
MUL
STOP
9.

You will now write a program to accomplish the same results


as the AMD program but more efficiently. Notice that the
AMD program requires a total of 16 program lines. Is there a
way in which it can be rewritten to accomplish the same

EXPERIMENT FOUR - COMBINED ADDRESSING MODE PROGRAMMING 4-7

results using less than 16 program lines? Modify the AMD


program to perform the same operations and employ the same
instructions. Write your program below. (Hint consider
using some instructions in different addressing modes.)
HEX
HEX
ADDRESS CONTENTS

MNEMONICS/
CONTENTS

COMMENTS

10. Load and run your program. Compare its results to the
original AMD program. Does your program load each accumulator, take its l's complement, Exclusive OR this with the
next operand, and finally multiply the resulting accumulator contents?
(yes/no)
If you answered no, go back and try using the immediate
addressing mode with the LDA, COM, and FOR instructions.
If you answered yes congratulations! You are well on your
way to becoming a true programmer.

4-8 1 LABORATORY MANUAL


DISCUSSION
By successfully performing this experiment you have accomplished
several things. First, you have seen how instructions that use
different addressing modes can be combined into a single program.
From now on you should be aware of the possibility of combining
addressing modes within a program. In fact, all but the simplest of
MPU programs usually require a combination of addressing modes
including those yet to be discussed (i.e., the extended, indexed,
and relative addressing modes covered in Units 4 and 5).
You have also worked with and seen the operation of several new
instructions. These include COMA, COMB, EORA, EORB, and
MUL.
Finally, you have had an opportunity to write, and run an MPU
program of your own design. Comparing this program to the
original AMD program, you saw how programs can be made more
efficient by carefully choosing the addressing mode with which to
execute program instructions.

EXPERIMENT FIVE - THE CONDITION CODE REGISTER 15-1

EXPERIMENT 5
THE CONDITION CODE REGISTER
Objectives:
I. To demonstrate the operation, use, and interpretation of
the MPU's Condition Code Register (CCR).
2.

To develop student understanding of the Condition Code


Register contents in terms of individual and combined flag
bit settings.

3.

To emphasize the meaning of the lower four CCR flag bits.

INTRODUCTION
In this experiment you will learn about a very important MPU
register the Condition Code Register, or CCR. As discussed in
Unit 4, this register monitors the results of each instruction
executed and sets certain condition code flag bits accordingly. For
example, if the execution of a program results in a negative
accumulator value, bit 3 of the CCR is set equal to 1. This CCR bit
corresponds to the N (negative) flag. Each of the other remaining
CCR bits or flags can be set (and reset or cleared) similarly. Figure
5-1 diagrams the bit by bit composition of the CCR.
7

0
S X HI N Z V C

CONDITION CODE REGISTER

CARRY/BORROW FROM MSB


OVERFLOW
ZERO
NEGATIVE
I-INTERRUPT MASK
HALF CARRY (FROM BIT 3)
X-INTERRUPT MASK
STOP DISABLE

Figure 5-1
The Condition Code Register (CCR).

These eight flags are arranged as a single byte in the CCR. Because
the lower four flags are by far more commonly involved in the
majority of MPU operations, we will concentrate on them (saving

5-2 I

LABORATORY MANUAL

discussion of the upper four bits for later). Notice that with four
bits, a total of sixteen different hexadecimal codes are theoretically possible (i.e., 24 = 16). That is, the execution of any given
program could affect one, or more than one CCR flag bit.
You can always check which CCR flag or flags have been affected
by examining the CCR register contents. This is done using the
Exm Reg key on the trainer. Because the trainer displays its
register values in hexadecimal, however, you must convert the
displayed CCR value to binary to have a clear look at exactly which
CCR flag bits are set. As you can see in Figure 5-1, the least
significant bit or LSB of the CCR is the C flag. The most significant
bit of the CCR is the S flag. The other flags fall between. For
example, suppose that the execution of a program set the CCR
equal to OB16. Converting this to binary gives
OB16 = 000010112.
Placing this in the CCR as discussed gives:
00001011
SXHINZVC.
From this you can see that the execution of the program results in
the N, V, and C flags being set. This is interpreted to mean that the
program executed contained instructions causing these conditions.
At this point, although the basics of what the CCR does may be
fairly clear, you may be wondering how the CCR applies to MPU
programming. The answer to this involves programs which monitor or test certain specific conditions and act accordingly. The
instructions used in this type of program are referred to as branches,
or conditional branches. These instructions are at the foundation
of MPU program "intelligent decision making" and will be discussed in the next experiment.

PROCEDURE
1. Turn the trainer on and press the Reset key.
2. Examine the contents of the CCR by pressing the Exm Reg key.
Record the contents of the CCR below.
CCR =

16

EXPERIMENT FIVE - THE CONDITION CODE REGISTER 1

Notice that the CCR, like all other MPU registers, is cleared by
the trainer Reset function. Also, notice that the contents of all
registers are given in hexadecimal. Because the individual
flag bits of the CCR are set or cleared as a binary value, you
must convert the hex CCR value displayed into its binary
equivalent for analysis.
Convert the following hexadecimal values to their 8-bit binary
equivalents. You can refer to these converted values throughout this experiment.
Hexadecimal

Binary
SXH INZ VC

00
01
02
03
04
05
06
07
08
09
OA
OB
OC
OD
OE
OF
3. Press and release the Reset key.

5-3

5-4 I LABORATORY MANUAL


4.

Enter the following program lines beginning at address 0000.


Do this by keying-in Exm Mem, the start address (Return =
0000), and the three program lines.
Address
0000
0001
0002

Mnemonic

Opcode/Operand

LDA

86
01
CF

STOP

5.

Press and release the Return to Previous Operation (RPO) key


twice, SS, and enter the start address (Return = 0000) of the
program.

6.

Single step through the program by pressing and releasing the


SS key.

7.

Observe and record the value of the registers by pressing the


Exm Reg key and then the + key to advance the display as
needed.
Register

Value Observed

CCR

16

ACCB

16

ACCA

16

PC

16

Were any condition code flags set?

(yes/no)

You should have observed that no CCR flags were set. This is
because the program you executed contains no instructions
that affect the CCR. Note that although there are a total of
eight flags in the CCR, the vast majority of "action" in the CCR
occurs in the lower four bits, N, Z, V, and C.
8. Press Reset.

EXPERIMENT FIVE - THE CONDITION CODE REGISTER

9. Enter the following program lines.


Address
0000
0001
0002
0003
0004

Opcode/Operand
86
01
4A
4A
CF

Mnemonic
LDA
DECA
DECA
STOP

Do this as before by entering Exm Mem, the start address


(Return = 0000), and the program.
Notice that this short program functions to load ACCA with a
positive value (01), and then decrement the accumulator A
twice using the DECA instruction.
What value do you expect in ACCA after the execution of this
program?
ACCA (expected) =

16

10. With the program loaded, single step (SS) through it by pressing RPO (twice), SS, the start address (Return = 0000), and the
SS key (three times).
11. Examine the MPU registers by pressing the Exm Reg key, and
the + key as needed. Record the values of the CCR and ACCA
below.
MPU
Register

Value Observed
(hexadecimal)

Equivalent
(binary)

CCR =

16 =

ACCA =

16

2
SXHINZVC

5 -5

5-6 I LABORATORY MANUAL


Remember that the MPU works with 2's complement binary
numbers to represent negative values. As you should recall,
this system works as follows
2's Complement Equivalents
binary form
100000002,..., 111111112, 000000002, 000000012,...,011111112
hexadecimal equivalent

8016,...,FE16, FF16, 016, 0116, 0216,...,7F16


decimal equivalent
12810,...,-210, 110, 010, +110, +210,...,+127i0.
By loading ACCA with the value 01 and then decrementing the
register twice, the final value of ACCA should be negative.
Subtracting 2 from 1 in 2's complement form gives FF16. Notice
that, because this is a negative value, the N flag of the CCR is
set. That is,
CCR = 0816 = 000010002 = N flag set.
12. Press Reset.
13. Enter the following short program as before by keying-in Exm
Mem, the start address (Reset = 0000), and the program lines.
Address
0000
0001
0002

Opcode/Operand
86
00
CF

Mnemonic
LDA
STOP

14. Prepare to run the program by pressing the RPO key (twice),
SS, and the start address (Return = 0000).

EXPERIMENT FIVE - THE CONDITION CODE REGISTER 1

15. Single step through the program. Do this by pressing the SS


key.
16. Examine the contents of the CCR by pressing the Exm Reg key.
Record the value observed below.
CCR =

16 =

SXHINZVC
(yes/no)

Is any CCR flag bit set?


If yes, which CCR flag bit is set?

The information you recorded above should indicate that the


result of the last arithmetic, logic, or data manipulation is a
zero. When you loaded ACCA with 00, the Z flag was set. This
resulted in the hexadecimal condition code 04 in the CCR.
17. Press the Reset key.
18. Prepare to enter the next program by keying-in Exm Mem, and
the start address (Return = 0000).
19. Enter the following short program.
Address
0000
0001
0002
0003
0004
0005
0006

Opcode/Operand
CC
FF
FF
C3
00
02
CF

Mnemonic
LDD

ADDD

STOP

20. Press and release the RPO key (twice), press the SS key, and
enter the start address (Return = 0000).

5-7

5-8 I

LABORATORY MANUAL

21. Single step (SS) through the program by pressing and releasing the SS key (twice). Examine the CCR and ACCD (ACCA =
Hi byte, ACCB = Lo byte) values. Record these below.
MPU
Register

Equivalent
(binary)

Value Observed
(hexadecimal)

CCR =

16 =

SXHINZVC
ACCA =

16

ACCB =

16

The LDD instruction in the above program loads the double accumulator ACCD with the value FFFF16. Because this is the largest
number that can be held at one time in ACCD, any additions result
in a carry. Adding 2 to ACCD results in a carry of 1 back into the low
8-bits (i.e., ACCB) of the double accumulator. This makes the value
of ACCD equal to 1, or ACCB = 0116, and ACCA = 0016.
22. Reset the trainer.
23. Enter the following program. Do this as before by entering
Exm Mem, the start address (Return = 0000), and the program.
Address
0000
0001
0002
0003
0004
0005
0006
0007

Opcode/Operand
CC
00
02
CE
00
01
03
CF

Mnemonic
LDD

LDX

FDIV
STOP

24. Enter RPO (twice), SS, and the program start address (Return
= 0000).

EXPERIMENT FIVE - THE CONDITION CODE REGISTER

25. Single step through the program by pressing and releasing the
SS key three times. Examine the CCR. Record its value below.
MPU
Register

Value Observed
(hexadecimal)

CCR =

Equivalent
(binary)
2

16 =

SXHINZVC
Is a CCR flag bit set?

(yes/no)

If so, which one(s)?


The short program listed above contains some instructions
which may be unfamiliar to you. Let's take a moment to
analyze the program. The first instruction is the LDD or "load
double accumulator" (immediate). This instruction serves to
load the value of 0002 into the 16-bit double accumulator,
ACCD. Next, the LDX or "load index register X" (immediate)
instruction loads the value of 0001 into the 16-bit X-index
register (Note: Index registers are discussed in detail later).
Finally, the FDIV or "fractional divide" instruction attempts a
fractional divide of ACCD by IX, however, because the value of
ACCD (02) is greater than that of IX (01), the resulting
quotient would not be a fraction. Because the FDIV instruction is designed to be used on fractions only, an overflow
results. This is indicated by the V flag being set in the CCR.
To this point, you have seen how each of the main (lower four)
condition code flags are set. For clarity, examples were given
in which each bit was set exclusively, that is, an operation
occurring in which a negative value result sets only the N flag,
one which resulted in a zero sets only the Z flag, etc. However,
note that, in many cases, more than one CCR flag may be set
simultaneously. This could occur, for example, if a program
resulted in both a zero and a carry. In this case the CCR would
contain the value 0516. An overflow and a carry would result in
the CCR = 0316, etc. Furthermore, other combinations involving the higher four CCR flag bits are also possible. For example, a CCR = 2816 indicates that both the H or half-carry
flag (CCR bit 5) and the N flags are set. Although the upper
four CCR bits are used, we will continue to be mainly concerned with the lower four bits in this experiment.

5 -9

5-10 I LABORATORY MANUAL

The following steps illustrate the setting of multiple CCR


flags.
26. Reset the trainer.
27. Enter the following program lines. Do this as before by keyingin Exm Mem, the start address (Reset = 0000), and the program.
Address

Opcode/Operand

Mnemonic

86
80
48
CF

0000
0001
0002
0003

LDA
ASL
STOP

28. Single step though the program by entering RPO (twice), SS,
the start address (Return = 0000), and SS (twice).
29. Examine and record the values of the CCR, ACCA, and ACCB.
MPU
Register

Value Observed
(hexadecimal)

CCR =

Equivalent
(binary)
16 27-

SXHINZVC
AC CA =

16

ACCB =

16

Are any CCR flags set?

(yes/no)

If so which ones?
The short program executed loaded ACCA with the 2's complement (negative) value of 8016. The next instruction, ASL or
"arithmetic shift left" (ACCA) then shifted all bits (100000002
= 8016) of the ACCA contents one place to the left.
This short sequence resulted first in the CCR = 08 (N flag only
set), and then in the CCR = 07 (N flag cleared) with the three
lowest flag bits (C, V, and Z) being set. The C and V flags were
set as a result of the carry and subsequent overflow from ACCA

EXPERIMENT FIVE - THE CONDITION CODE REGISTER 15-1 1

to the left and out. The Z flag was set because the resulting
value left in ACCA was zero (after the bit shift). Figure 5-2
summarizes this.
ACCA initially
0 0 0 0 0 0 0 0

CCR
0 0 0 0 0 0 0 0
SXHINZVC

ACCA loaded
1 0 0 0 0 0 0 0

CCR
0 0 0 0 1 0 0 0
SXHINZVC

ACCA After ASL


0 0 0 0 0 0 0 0

CCR
0 0 0 0 0 1 1 1
SXHINZVC

Figure 5-2
Multiple CCR flag settings.

Before leaving this experiment on the CCR, it should be


pointed out that the 68HC11 instruction set contains instructions to clear certain previously set flags. These fall into the
category of the "clear" instructions. They include:
CLC CLear Carry flag (C)
CLI CLear Interrupt Mask (I) flag
CLV CLear oVerflow (V) flag.
These will be demonstrated in the next steps of this experiment.
30. Reset the trainer.
31. Enter the following short program.
Address
0000
0001
0002
0003
0004
0005

Opcode/Operand
86
80
48
OC
OA
CF

Mnemonic
LDA
ASL
CLC
CLV
STOP

5-12

I LABORATORY MANUAL

32. Now press the RPO key twice, the SS key, and enter the start
address of the program (Return = 0000).
33. You will now single-step through the program in segments.
Press and release the SS key. The display should read:
0002 48
ASLA
You have executed the first instruction in the program.
34. Press the Exm Reg key and record the values of the registers
indicated.
MPU
Register

Value Observed
(hexadecimal)

Equivalent
(binary)

CCR =

16 =

SXHINZVC
ACCA =

16

ACCB =

16

Notice that the first two lines of the program are identical to
those which resulted in a CCR = 08 as illustrated in Figure 52.
35. Press and release the RPO key.
36. Resume program execution at the ASLA instruction. To execute this instruction press the SS key once.
37. Press the Exm Reg key. Record the value of the following
registers.
MPU
Register
CCR =

Equivalent
(binary)

Value Observed
(hexadecimal)
16 =

SXHINZVC
ACCA =

16

ACCB =

16

EXPERIMENT FIVE - THE CONDITION CODE REGISTER 15-1 3

Notice that the CCR value has changed from 08 to 07. As


discussed, this reflects the bit shift to the left out of ACCA.
After the ASLA instruction is executed, the N Flag is cleared
because there is no longer a negative value in ACCA. However,
ACCA now contains a zero, therefore the Z flag is set. Because
execution of the ASLA instruction also caused an overflow and
carry, the V and Z flags are also set. The value of the CCR
should now be
CCR = 0716 = 0 0 0 0 0 1 1 12
SXHINZVC.
38. Resume Program execution at the next instruction by pressing
the RPO key one time.
39. Execute the CLC instruction by pressing and releasing the SS
key once.
40. Examine the registers indicated using the Exm Reg key. Record
the following values.
MPU
Register
CCR =

Value Observed
(hexadecimal)

Equivalent
(binary)
16 =

SXHINZVC
ACCA =

16

ACCB =

16

Notice that the CCR now contains 0616 instead of 0716 (observed earlier). The execution of the CLC or clear carry flag
has resulted in the C flag (previously set) being cleared to zero.
Before execution of CLC
CCR = 0716 = 0 0 0 0 0 1 1 12
SXHINZVC
After execution of CLC
CCR = 0616 = 0 0 0 0 0 1 1 02
SXHINZVC

5-14

1 LABORATORY MANUAL

41. Resume program execution at the next instruction by pressing


the RPO key.
42. Execute the CLV instruction by pressing and releasing the SS
key one time.
43. Press and release the Exm Reg key and record the following
values.
MPU
Register
CCR =

Value Observed
(hexadecimal)

Equivalent
(binary)
16=

S XHINZVC
ACCA =

16

ACCB =

16

Notice the CCR now contains 0416. Execution of the CLV or


clear over flow (V) flag has cleared this (previously set) bit.
Before execution of CLV
CCR = 0616 = 0 0 0 0 0 1 1 02
SXHINZ VC.
After execution of CLV
CCR = 0416 = 0 0 0 0 0 1 0 02
SXHINZ VC.
Note that the only bit remaining set is the Z flag.
Explain why the Z flag remains set.

What program line(s) could be added to the program shown in


step #31 to clear all CCR flag bits in the course of the program's
execution?

EXPERIMENT FIVE - THE CONDITION CODE REGISTER

Use the following blanks to rewrite the program shown in step


#31 with the lines you suggested.
Address

Opcode/Operand

Mnemonic

DISCUSSION

In this experiment you have gained experience about the condition


code register in the microprocessor. The basic operation of this
important MPU register was demonstrated using a series of short
programs. First, you saw how to interpret the hexadecimal CCR
value displayed by the MPU trainer as an 8-bit binary byte representing the state of the 8 flag bits composing the register. Next, the
setting of individual flags was demonstrated. This led into a
demonstration and discussion of multiple flag bit settings. Finally,
the 68HC11 instructions to clear certain CCR flags were demonstrated.

i 5-1 5

5-1 6

I LABORATORY MANUAL

At this point you should have a fairly good understanding of the


MPU's condition code register. In the next experiment, you will
investigate program branches. The proper execution of these instructions relies heavily upon the status of the condition code
register.

EXPERIMENT SIX - PROGRAM BRANCHES

EXPERIMENT 6
PROGRAM BRANCHES
Objectives:
1. To verify the operation of a simple "multiply by repeated
addition" program that uses the BEQ conditional branch
instruction and the BRA instruction.
2. To demonstrate the ability to write a program that "divides
by repeated subtraction" and uses a conditional branch
and BRA instruction.
3. To introduce a shorthand method of calculating relative
addresses.
4. To verify the operation of a program that converts BCD
numbers to their binary equivalent.
5. To demonstrate the effect an incorrect relative address can
have on program operation and how the microprocessor
trainer can be used to debug programs.

INTRODUCTION
In the previous experiment you investigated the interpretation of
the condition code register by analyzing how it works. You concentrated specifically on the meaning of the individual and combined
flag bits and studied the effects of various short programs upon the
condition code register.
Now it is time to further extend your knowledge of some of the
programming applications of the condition code register. One very
important programming application of this register is program
branches. As discussed in Unit 4, branching is a technique used
quite extensively to accomplish repetitive (and other) programming tasks. The ability of an MPU program to monitor, process,
and respond intelligently to various types of input data is, to some
degree, related to its ability to execute various kinds of program
branches. This experiment demonstrates how certain "branch"
instructions can be used to accomplish multiplication, division,

6-1

6-2 I

LABORATORY MANUAL

and BCD to hexadecimal conversion. Methods to calculate relative


branch address are also presented along with an example of the
consequences of using an incorrect relative branch address in a
program.
You will notice that the procedure steps used in this experiment
contain much less redundancy than previous experiments. By this
time you should be relatively comfortable with the frequently used
and routine functions of the trainer. For example, step 3 instructs
you to execute a program in the single-step mode and record
various register values after the execution of each opcode. By now
you should realize that this involves:
1. Pressing the RPO (twice)
2. Pressing the SS key (to put you in the single-step mode).
3. Entering the beginning address of the program.
4. Pressing the SS key (to execute each line of opcode).
5. Pressing the Exm Reg key, or the Exm Mem key (to view
either the register or memory contents respectively).
6. Pressing the RPO or "return to previous operation" key to
resume single-stepping through the program (from the
last line displayed).
As mentioned, these and other previously used operations should
be known to you by now, however, it should be noted that, if you
forget how to perform a particular operation, you can always go
back and re-study a previously done experiment for reference. As
always, after mastering the material contained in the experiment,
feel free to try your own ideas by rewriting, or modifying the
programs given to your satisfaction.

PROCEDURE
1. Load the program listed in Figure 6-1 into the trainer (Exm
Mem, address, etc.). This program multiplies 0516 and 0216
and stores the product in address 001316. Recheck the program
to insure that it's entered correctly.

EXPERIMENT SIX PROGRAM BRANCHES

2. This is the same program that you studied in Unit 4. Notice


that the program contains two branch instructions; the BEQ
(Branch if Equal Zero) at address 000516 and the BRA (Branch
Always) at address 000E16.
The branch if equal zero (BEQ) instruction implies by its name
that a conditional branch occurs when the flag is set.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013

4F
97
13
96
12
27
09
4A
97
12
96
13
9B
11
20
Fl
CF
05
02
00

MNEMONICS/
CONTENTS

CLRA
0,- STAA
13
LDAA
12
BEQ
09
DECA
STAA
12
LDAA
13
ADDA
11
BRA
Fl
01- STOP
05
02
00

COMMENTS
Clear the accumulator.
Store the product
in location 1316.
Load the accumulator with the
multiplier from location 1216.
If the multiplier is equal to zero,
branch down to the Stop instruction.
Otherwise, decrement the multiplier.
Store the new value of the
multiplier back in location 121,.
Load the accumulator with the
product from location 13,,.
Add
the multiplicand to the product.
Branch back to instruction
in location 01.
Stop.
Multiplicand.
Multiplier.
Product.

Figure 6-1
Program to multiply by repeated addition (File digit 1).

3. Now, single-step through the program, by entering RPO (twice),


SS, and the start address (Return = 0000). Press the Exm Reg
key to view and record the information in the chart of Figure
6-2. After each step use the RPO key to return to, and execute
the next instruction. Notice that you will be monitoring the Z
flag. A comments column is provided so you can make notes
about each step. Use the program listing as a reference for
each opcode and the corresponding operand.

6-3

6-4 I LABORATORY MANUAL


When the BEQ instruction is executed and the Z flag is set, the
program branches to the
instruction.

4.

When the multiplier was 0216, the program stopped on the


pass through the program.
If the multiplier is changed to 0616, how many passes would
the program make before it stops?
Examine the contents of address 001316 and record below.

5.

0013 =

STEP

PROGRAM
OPCODE
COUNTER

ACCA

Z
FLAG

COMMENTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

...-

17
18
19
20

Figure 6-2
Single-stepping through the Multiply by repeated addition program.

EXPERIMENT SIX PROGRAM BRANCHES 1

DISCUSSION
The chart that you completed should be similar to the one shown in
Figure 6-3. Compare the charts.
STEP

PROGRAM
OPCODE
COUNTER

ACCA

Z
FLAG

0001

97

00

0003

96

00

0005

27

4
5

0007
0008

4A
97

000A

96

02
T
Multiplier
02
01
1'
New Multiplier
01

000C

9B

00

000E

20

0001

97

05
1'
New Product
05

10

0003

96

05

11

0005

27

01

12
13

0007
0008

4A
97

0
1

14

COCA

96

01
00
1'
New Multiplier
00

15

000C

9B

05

16

000E

20

17

0001

97

OA
i
New Product
OA

18

0003

96

OA

19

0005

27

00

20

0010

CF

00

COMMENTS
Store the product (0016 ) in
address 001316Load the accumulator with
the multiplier (0216) from
address 001216.
BEQ. Check the Z flag.
It's not set so continued.

0
0

Decrement the multiplier (0216)Store the new multiplier (0116)


at address 001216.

Load the accumulator with the


product (00) at address 001316.
Add the multiplicand (05)
giving new product.
Branch back to address
000116.

Figure 6-3

Store the product (0516 ) in


address 001316.
Load the accumulator with
the multiplier (0116 ) located
at address 001216 .
BEQ. Check Z flag.
It's not set so continued.
Decrement the multiplier (0116 ).
Store the new multiplier (0016 )
at address 001216.
Load the accumulator with the
product (0516) at address 001316.
Acid the multiplicand (0516 )
giving new product.
Branch back to address
000116.
Store the product (0A16) in
address 001316.
Load the accumulator with the
multiplier (0016 ) from address 001216.
BEQ. Check the Z flag.
Now it's set. Branch to
address 001016.
Stop.

6-5

6-6 I

LABORATORY MANUAL

We don't see the first step, since it's executed before the Trainer
stops at address 0001. Nevertheless, we do see the result of this
clear accumulator instruction because the accumulator contains
00. When step 1 is executed, 0016 is stored in location 001316. Step
2 brings us to address 000316 which loads the accumulator with the
multiplier, in this example, 0216. The BEQ instruction is next, but
the Z flag is cleared so the program continues on the normal route.
Next the multiplier is decremented to 0116 and then stored in
location 001216. Now the product (0016) is loaded and the multiplicand (0516) is added directly. This produces the new product, 0516.
Now the program encounters the BRA, or branch always instruction and it branches back to address 000116.
Here the new product is stored away and the multiplier is loaded
again. It's 0116 this time, so the program continues on through the
BEQ instruction, the multiplier is decremented to 0016, and the
multiplicand 0516 is added to the product. The new product (0A16)
is still in the accumulator. Once again, the BRA instruction loops
flow back to address 000116 and the product is stored in address
001316.
The multiplier is now loaded and, since its been decremented to
0016, it sets the Z flag. The BEQ instruction checks the Z flag, finds
that it is set and branches to the halt instruction at address 001016.
Therefore, the program makes two complete passes, before the
multiplier becomes 0016. On the third pass through, BEQ terminates the program because the Z flag is set.
The multiplier sets the count and determines how many additions
will be performed. If the multiplier is changed to 0616, the progran
will make six complete loops, stopping on the seventh loop. The
BEQ will only be satisfied when the multiplier has been reduced to
00.
All branch instructions use relative addressing. In Unit 4, we
discussed the method used to calculate the destination address for
a branch instruction. However, another shorthand type procedure
that's quite popular with programmers can be used. With this
technique, you simply count in hexadecimal. For a forward branch,
you begin at 0016 and count up to the destination address.
For example, in the program of Figure 6-4, we want to branch from
address 1816 to address 2416. Recall that the relative address is
added to the contents of the program counter. After the BRA
instruction and its operand (the relative address) have been fetched,
the program counter is pointing to address 1A16. Therefore, we

EXPERIMENT SIX PROGRAM BRANCHES

begin our count at address 1A16. Then we count forward in hex as


shown in Figure 6-5. When we reach the destination address, the
hexadecimal count is the relative address. In this case, it's 0A16,
and we insert this operand at address 1916.
HEX
CONTENTS

HEX
ADDRESS

20
18
??
19
1A ,,N
1B
Originating address
1C
1D
lE
1F
20
21
Destination address
\ 22
23

MNEMONICS/
HEX CONTENTS

BRA

24
MIIIIMEM11111

We wish to
Branch to here
Figure 6-4

HEX

HEX

MNEMONICS/

ADDRESS

CONTENTS

HEX CONTENTS

18
20
19
OA
00 ( 1A
Originating Address
01 A1-1B
02 (\;k1C
03 AID
04 (l E
, A1F
05 ?
06 iA20
07 (\lk21
08 A22
09 (*23 / Destination Address
OA \A24
I

Relative
Address
Figure 6-5

Branching forward.

BRA
OA

16-7

6-8 I LABORATORY MANUAL


To branch backward in the program, we simply count down using
negative hex numbers. It may sound more difficult, but once you
are accustomed to it, you will find it easier to use than the previous
method you learned.
For example, in the program shown in Figure 6-6A, we wish to
branch back to address 5816. The BRA instruction, at address 5D16
is fetched and the program count points to address 5F16. Figure 6 6B shows how we calculate the address for this backward branch.
We begin with FF16, and count down. When we reach the destination address (5816), the count at that point is the relative address,
in this case F916.

HEX
ADDRESS
56
57

A
Program
branches
to here

58

59

MNEMONICS/
HEX CONTENTS

20
??

BRA
??

HEX
CONTENTS

MNEMONICS/
HEX CONTENTS

1
Destination
Address

5A
5B
5C
5D
Originating
5E
5F r Address

HEX
ADDRESS

HEX
CONTENTS

56
57
F9 58
Relative FA59
address FR 5A

Destination
Address

FC 5B
FD 5C
I
FE 5D
Originating
II' 5E
Address
5F Ae.

20
F9

BRA
F9

Figure 6-6
Branching back.

Figure 6-7 shows another example of computing the relative address for a larger branch. The branch instruction is at address B016
and therefore, the origination address is B216. We calculate the
relative address as shown in Figure 6-6B. Starting with FF16 at

EXPERIMENT SIX - PROGRAM BRANCHES 6-9

address B116 we count down to the destination address A016. As the


count indicates, the relative address to get to A016 is EE16.
HEX
ADDRESS

HEX
CONTENTS

AO
We wish
Destination
bran
o to/ A 1
-N'Address
A2
here
A3
A4
A5
A6
A7
A8
A9
AA
AR
AC
AD
AE
AF
BO
Originating
13 I
Address
A
rB2

HEX
ADDRESS
Rela tive
Add ress

I.J. AO
I+ AI
FO A 2
Fl A3
F2 A4
F3 A5
F4 A6
F5 A7
F6 A8
F7 A9
F8 AA
1'9 A Fl
FA AC
FB AD
EC AE
FD AF
FE BO
FFBI
B2

MNEMONICS/
HEX CONTENTS

26

RNE

HEX
CONTENTS

MNEMONICS/
HEX CONTENTS

26
EE

Figure 6-7

FINE
EE

6-1 0

I LABORATORY MANUAL

In the next section of this experiment, you will write a program


that divides by repeated subtraction. You will probably have two
branches in this program; a forward branch and a backward
branch. Use this new technique to calculate the relative addresses
for both branches.
PROCEDURE (Continued)

6. In Unit 4, we discussed a program that divides by repeated


subtraction. The flow chart for this program is shown in
Figure 6-8. Use this flow chart as a guide and the instructions
presented in Figure 6-9 to write a program that divides by
repeated subtraction.

( START )

Clear
Accumulator

Store
Quotient

1
Load
Dividend

Subtract
Divisor

Store
Dividend

I
Load
Quotient

I
Increment
Quotient

Figure 6-8

Flow chart for dividing by repeated subtraction.

EXPERIMENT SIX PROGRAM BRANCHES 1

ADDRESSING MODE
INSTRUCTION
Load Accumulator
Clear Accumulator
Decrement Accumulator
Increment Accumulator
Store Accumulator
Add
Subtract
Branch Always
Branch if Carry Set
Branch if
Equal Zero
Branch if Minus
Stop

MNEMONIC IMMEDIATE DIRECT RELATIVE INHERENT


LDA
CLRA
DECA
INCA
STA
ADD
SUB
BRA
BCS
BEQ

86

96
4F
4A
4C

8B
80

97
9B
90
20
25
27

BMI
STOP

2B
CF

Figure 6-9

Instructions to be used.

7. Now load the program into the Trainer. Let the dividend be
OB16 and the divisor be 0516. Enter the starting address of your
program and single-step through the program, recording the
information in the chart of Figure 6-10.
8. Examine the contents of the address that stores the dividend
and the quotient. If you followed the flow chart, the address
where the dividend is stored should now contain the remainder from the division. Record the contents below.
Quotient

Remainder

6-1 1

6-1 2 1LABORATORY MANUAL

STEP

PROGRAM
OPCODE
COUNTER

ACCA

N
FLAG

Figure 6-10

COMMENTS

EXPERIMENT SIX PROGRAM BRANCHES

DISCUSSION (Continued)
Now you've written a program that incorporates an unconditional
branch and a conditional branch. Hopefully, you calculated the
relative addresses using the shorthand technique just discussed.
Our program for the divide by repeated subtraction is listed in
Figure 6-11. If you followed the flow chart your program should be
similar to this.
HEX
HEX
MNEMONIC/HEX
ADDRESS CONTENTS
CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008

4F
97
13
96
11
90
12
2B
07

CLRA
--b-STA
13
LDA
11
SUB
12
BMI
07

0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013

97
11
96
13
4C
20
Fl
CF
OB
05

STA
11
LDA
13
INCA
BRA
F1
-Pp- STOP
OB
05

COMMENTS
Clear the accumulator.
Store in the quotient which
is at address location 1316,
Load the accumulator with the
dividend from location 1116.
Subtract the
divisor from the dividend.
If the difference is negative,
branch down to the Halt
instruction.
Otherwise, store the difference
back in location 1116 .
Load the accumulator with the
quotient.
Increment the quotient by one.
Branch back to instruction
in location 01.
Stop.
Dividend (1116).
Divisor (516).
Quotient.

Figure 6-11
Dividing by repeated subtraction.

I 6-1 3

6-1 4 I LABORATORY MANUAL

STEP

PROGRAM
OPCODE
COUNTER

ACCA

N
FLAG

0001

97

00

0003

96

00

0005

90

OB

T
4

0007

2B

Dividend
06

T
5

0009

97

After subtraction
06

000B

96

06

000D
000E

4C
20

00
01

0
0

T
9

0001

97

Quotient after INC


01

10

0003

96

01

11

0005

90

06

T
12

0007

2B

Dividend Now
01

T
13

0009

97

After Subtraction
01

14

000B

96

01

15
16

000D
000E

4C
20

01
02

0
0

T
17

0001

97

Quotient after INC


02

18

0002

96

02

19

0005

90

01

20

0007

2B

21

0010

CF

FC
I
Negative Number
FC

COMMENTS
Store the quotient (0016 ) at
address 001316.
Load the accumulator with the
dividend from address 001116 .
Subtract the divisor (0516) at
address 001216 from the
accumulator.
BMI. Check the N flag.
It's not set so continue.
Store the difference (0616)
back in address 001116 .
Load the accumulator with the
quotient (0016 ) at address 001316.
Increment the quotient.
Branch back to the instruction
at address 000116 .
Store the quotient (0116 ) at
address 001316 .
Load the accumulator with the
dividend (0616) at address 001116 .
Subtract the divisor (0516) at
address 001216 from the
accumulator.
BMI. Check the N flag.
It's not set so continue.
Store the difference (0116 ) back
in address 001116 .
Load the accumulator with the
quotient (0116 ) at address 001316.
Increment the quotient.
Branch back to the instruction
at address 000116 .
Store the quotient (0216) at
address 001316.
Load the accumulator with the
dividend (0116) at address 001116 .
Subtract the divisor (0516) at address 001216 from the accumulator.
BMI. Check the N flag.
Now its set so branch to the
instruction at address 001016 .
Stop.

Figure 6-12

Notice that we used the BMI (Branch if Minus) conditional branch


instruction. Therefore, the N or negative flag will satisfy the
branch when it's set. Figure 6-12 charts our program as we singlestepped through it. Since the program subtracts the divisor from
the dividend and stores the difference as the new dividend, at the

EXPERIMENT SIX PROGRAM BRANCHES I

conclusion of the program the dividend is actually the remainder


of the division. When OB16 is divided by 0516, the quotient should
be 0216 and the remainder 0116.
So far, we've used the conditional branch instructions only to exit
a loop and then halt program execution. However, these branch
instructions become even more powerful when they are used to
"chain" together different portions of a program. Figure 6-13 shows
an example of this chaining effect. The program starts and runs
through the first loop until the conditional branch BEQ is satisfied. Then it exits this loop and starts another. When the BEQ
condition is satisfied in the second loop, another exit is performed,
and another portion of the program is executed.
( START )

Clear Binary
Result

Load Hundreds
Digit

YES

Load Tens
digit
Decrement
Hundreds
digit

YES
Store
Hundreds
digit
Load Binary
Result
Load Binary
Result

Decrement
tens digit
Add units
digit

Add 100

Store tens
digit
Store Binary
Result

Store Binary
Result

Load Binary
Result

Add 10

Store Binary
Result

Figure 6-13
Conditional branches can chain together portions of a program.

6-1 5

6-1 6 I LABORATORY MANUAL


HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
002B

4F
97
2B
96
28
27
OB
4A
97
28
96
2B
8B
64
97
2B
20
Fl
96
29
27
OB
4A
97
29
96
2B
8B
OA
97
2B
20
Fl
96
2B
9B
2A
97
2B
CF
01
01
07

MNEMONICS/
CONTENTS

COMMENTS

CLRA
STA
2B
LDA
28
BEQ
OB
DECA
STA
28
LDA
2B
ADD
64
STA
2B
BRA
F1
LDA
29
BEQ
OB
DECA
STA
29
LDA
2B
ADD
OA
STA
2B
BRA
Fl
LDA
2B
ADD
2A
STA
2B
STOP
01
01
07

Clear the Accumulator.


Store 00
in location 2B. This clears the binary result.
Load direct into the accumulator
the hundreds BCD digit.
If the hundreds digit is zero, branch
forward to the instruction in location 1216.
Otherwise, decrement the accumulator.
Store the result as the new
hundreds BCD digit.
Load direct into the accumulator
the binary result.
Add immediate
10010 to the binary result.
Store away the new
binary result.
Branch
back to the instruction in location 0316.
Load direct into the accumulator
the tens BCD digit.
If the tens BCD digit is zero, branch
forward to the instruction in location 2116 .
Otherwise, decrement the accumulator.
Store the result as the new
tens BCD digit.
Load direct into the accumulator
the binary result.
Add immediate
1010 to the binary result.
Store away the new
binary result.
Branch
back to the instruction in location 1216.
Load direct into the accumulator
the binary result.
Add direct
the units BCD digit.
Store away the new
binary result.
Stop.
Hundreds BCD digit.
Tens BCD digit.
Units BCD digit.
Reserved for the binary result.

Figure 6-14
Program for converting BCD to binary (File digit 2).

A strategically placed conditional branch at the end of the program


can cause a branch back to the beginning that repeats the program
again and again. In the next portion of this experiment, you will
load the BCD-to-binary conversion program that you studied ear-

EXPERIMENT SIX - PROGRAM BRANCHES 1

Tier. Then you will step through the program and watch as the
Trainer executes each instruction. Keep in mind that, although the
Trainer displays all numbers in hexadecimal, the MPU works with
binary exclusively, hence, we refer to the program as a BCD-tobinary conversion program.

PROCEDURE (Continued)
9. Load the program listed in Figure 6-14 into the Trainer. The
BCD number 11710 will be converted to binary by this program.
The BEQ instruction is used for the conditional branches in
this program. This means that MPU monitors the
flag to determine if the condition is set.
10. Now set the program counter to 0000 and single-step through
the program recording the information in the chart of Figure
6-15. Notice that, at strategic steps, you should stop and
answer questions before you continue.
The
11. What is the hundreds BCD digit at this time?
in the decimal number
result is now 6416, which is
system.
Now return to the Trainer and continue stepping through the
program.
12. What is the tens BCD digit at this time?
The result is now 6E16. This is the equivalent of
the decimal number system.

in

Now return to the Trainer and step through the remainder of


the program.
13. Examine address 002B16 and record the result below.
16

Convert this number to its decimal equivalent.


7516 =

10

6-1 7

6-1 8 I LABORATORY MANUAL

STEP

PROGRAM
OPCODE
COUNTER

ACCA

Z
FLAG

1
2
3
4
5
6
7
Stop! Return to Step 11.
8
9
10
11
12
13
14
15
16
17
18
Stopl Return to Step 12.
19
20
21
22
23
24
25

Figure 6-15

COMMENTS

EXPERIMENT SIX - PROGRAM BRANCHES 1 6 -1 9

DISCUSSION
Now you've verified the operation of the BCD-to-binary conversion
program. The chart that you completed should match the one
shown in Figure 6-16.
Since the BEQ instruction is used for the conditional branches in
the program, we monitored the Z flag. In this example, the BCD
number 11710 was converted to its binary equivalent 7516. This
program converts BCD numbers as high as 25510, to their binary
equivalent (as displayed in hex).*
The program isn't as complicated as it might appear. The hundreds
and tens BCD digits are used to set a count. Each pass through a
loop decrements the BCD digit, or count, and then adds the
equivalent hexadecimal positional value for that BCD digit. For
example, in the hundreds conversion loop, 6416 is added to the
binary result for each hundreds BCD digit. Hence, the BCD digit
sets the count. Then the count is decremented by one and the
program loops back and runs through again. When the count is
zero, that BCD digit has been added the correct number of times
and the program branches off to another loop. This continues until
the program halts.
Stepping through the program, you found that after Step 8, the
Trainer had completed one loop through the hundreds BCD portion
of the program. The count was 0016 and the binary result was 6416,
or the binary equivalent of 10010. On the next pass through, the
program branches to the tens BCD loop.
The first loop through, the tens BCD portion of the program was
completed at step 18. The binary result was 6E16, which is the
equivalent of 11010. The tens BCD digit had been decremented to
0016. Then all that remained was to add the units BCD digit (0710)
and the conversion process was complete.

*NOTE: The value of the BCD number to be converted is changed by running the
program. That is, before the program is run, the BCD number 117 occupies
addresses 0028-002A, after the program is run locations 0028 and 0029 contain 0
(zero). 117, or any BCD number may be loaded, and reloaded into locations 0028002A.

6-20 I LABORATORY MANUAL

STEP

PROGRAM
OPCODE
COUNTER

Z
FLAG

ACCA

COMMENTS

0001

97

00

0003

96

00

0005

27

0007

4A

0008

97

000A

96

Hundreds
BCD)
01
Digit
01
New-3
Hundreds 00
Digit
00

000C

8B

00

000E

97

64

9
10

0010
0003

20
96

64
64

0
0

11

0005

27

00

12

0012

96

00

13

0014

27

01

14

0016

4A

01

BEQ. Check the Z flag.


It's clear so continue.
Decrement the tens BCD digit (0116 ).

00

Store the new tens BCD digit.


Load the accumulator with
the binary result (6416 ).
Add 0A16 to the binary result.

Binary)
Result
Now

Tens
BCD)
Digit
New
Tens)
Digit

Store 00 in address 002B16.


This clears the binary result.
Load the accumulator with
the Hundreds BCD digit (0116 ).

BEQ. Check the Z flag.


It's clear so continue.
Decrement the BCD Hundreds Digit.

Store the new Hundreds Digit (00).

Load the accumulator with the


Binary Result (0016 ).
Add to the binary result
6416.
Store away the new
binary result.
Branch back to address 000316.
Load the accumulator with the
Hundreds BCD digit (00).
BEQ. Check the Z flag.
It's set so branch to address 001216.
Load the accumulator with the
tens BCD digit (0116 ).

15

0017

97

16

0019

96

00

17

001B

8B

18

001D

97

19
20

001F
0012

20
96

64
New
Binary) 6E
Result
6E
6E

21

0014

27

00

22

0021

96

00

23

0023

9B

6E

Store away the new binary


result.
Branch back to address 0012 16.
Load the accumulator with the
tens BCD digit (00).
BEQ. Check the Z flag.
It's set so branch to address 002 116.
Load the accumulator with the
binary result (6E16).
Add the units BCD digit (0716 ).

75

Store the new binary result (7516).

75

Stop

24

0025

97

25

0027

CF

New
Binary)
Result

0
0
0

Figure 6-16
Single-stepping through the BCD-to-binary conversion program.

EXPERIMENT SIX - PROGRAM BRANCHES 16 -21

You verified the final result by checking the binary result at


location 002B16. Here you found the hex number 7516. When you
converted this number to its decimal equivalent, you found that
7516 equals 11710. Also if you converted 7516 to binary, you would
find the number 0111 01012, which is the (binary) equivalent of
11710, so the program works.
The most frequent mistake made by programmers when using the
branch instructions is the improper computation of the relative
address. An improperly coded relative address not only prevents
the program from executing properly, but can even wipe out portions of the program. In the next section of this experiment, you
will witness the result of an incorrect relative address and the
effect it has on the program. In this example, we will use the
binary-to-BCD conversion program you studied earlier.

PROCEDURE (Continued)
14. Load the program listed in Figure 6-17 into the Trainer. This
program should convert the binary number 0111 01012 ( 7516)
into its BCD equivalent. However, one of the relative addresses is incorrect. Part of this exercise is to locate the
incorrect relative address and correct it.

6-22 I

LABORATORY MANUAL

HEX
HEX
MNEMONICS/
ADDRESS CONTENTS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
0008
000C
0000
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
0010
001E
001F
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
002B
002C
002D

4F
97
2B
97
2C
97
2D
96
2A
80
64
25
OA
97
2A
96
2B
4C
97
2B
20
Fl
96
2A

80
OA
25
09
97
2A
96
2C
4C
97
2C
20
Fl
96
2A
97
2D
CF
75

CLRA
STA
2B
STA
2C
STA
2D
LDA
2A
SUB
64
BCS
OA
STA
2A
LDA
2B
INCA
STA
2B
BRA
Fl
LDA
2A
SUB
OA
BCS
09
STA
2A
LDA
2C
INCA
STA
2C
BRA
Fl
LDA
2A
STA
2D
STOP
75

COMMENTS
Clear the accumulator.
Store 00
in location 002B16. This clears the hundreds digit.
Store 00
in location 002C16. This clears the tens digit.
Store 00
in location 002016. This clears the unitrs digit.
Load direct into the accumulator
the binary number to be converted.
Subtract immediate
If a borrow occurred, branch
forward to the instruction in location 001616.
Otherwise, store the result of the subtraction
as the new binary number.
Load direct into the accumulator
the hundreds digit of the BCD result.
Increment the hundreds digit.
Store the hundreds digit
back where it came from.
Branch
back to the instruction at address 000716.
Load direct into the accumulator
the binary number.
Subtract immediate
If a borrow occurred, branch
forward to the instruction in location 002516 .
Otherwise, store the result of the subtraction
as the new binary number.
Load direct into the accumulator
the tens digit.
Increment the tens digit.
Store the tens digit
back where it came from.
Branch
back to the instruction at address 001616.
Load direct into the accumulator
the binary number.
Store it in
the units digit.
Stop.
Place binary number to be converted at this address.
Hundreds digit
Reserved for
Tens digit
BCD result.
Units digit

Figure 6-17
A

program with an incorrect relative address (File digit 3).

EXPERIMENT SIX - PROGRAM BRANCHES 6 -23

STEP

PROGRAM
OPCODE
COUNTER

ACCA

C
FLAG

COMMENTS

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Figure 6-18
Single-Stepping through the binary-to-BCD conversion program.

16. Examine addresses 002B16, 002C16, and 002D16; record the


results below.
002B Hundreds BCD Digit
002C Tens BCD Digit
002D Units BCD Digit
Obviously, there is something wrong with the program. Although the hundreds and tens digits are believable, the units
digit of 11 is impossible. Remember, a decimal number can
only have a units digit of from 0 to 910.

6-24

I LABORATORY MANUAL

17. Use the program listing and the chart that you've compiled
and locate the error in the program. Then record the address
of the instruction below.
HINT: The problem is with the relative address for one of the
branch instructions. When one of these addresses is incorrect,
the program branches to the wrong address, possibly skipping
portions of the program. Therefore, first determine the portions of the program that produced the wrong result and work
back until you find the problem.
Address

Incorrect Relative Address

18. Now calculate the correct relative address (operand) and record
it below.
Correct Relative Address
DISCUSSION
This exercise should have demonstrated the versatility of your
Trainer to assist you in "debugging" programs. When you examined
addresses 002B16, 002C16, and 002D16, you found these results.
002B

0 1 Hundreds BCD Digit

002C

0 0 Tens BCD Digit

002D

1 1 Units BCD Digit

Obviously, the units BCD digit is incorrect. Since the units digit is
wrong, we begin to debug at this portion of the program. This
happens to be the least complex section of the program because the
binary number is simply loaded into the accumulator and stored in
address 002D16. Comparing the chart that you compiled against
the program listing, we find that this portion of the program seems
to be executing correctly.
Therefore, we move back to the tens BCD digit portion of the
program. Checking the program listing, we find that the tens BCD
portion of the program begins at address 001616. But as the chart
in Figure 6-19 shows, when the program is single-stepped the tens
BCD digit loop actually starts at address 001716. This is the wrong
address. We find the problem when we move back to step 14 of the
chart. This is the BCS (Branch if Carry Set) instruction at address
000B16. However, instead of branching to address 001616 as the
comments column suggests, the program goes to address 001716.
Therefore, the relative address at address 000C16 must be incor-

EXPERIMENT SIX PROGRAM BRANCHES

rect. When we check this relative address, we find that it should be


0916, instead of 0A16.*
But, how did this incorrect operand affect the program? Following
the chart in Figure 6-19, we find that the hundreds BCD portion of
the program worked correctly. On the second loop through this
portion of the program, the subtraction resulted in a borrow and
the C flag was set. Hence, the BCS instruction produced the
desired branch.
STEP

PROGRAM
OPCODE
COUNTER

ACCA

C
FLAG

COMMENTS

1
2
3
4

0003
0005
0007

97
97
97
96

00
00
00
00

0
0
0
0

5
6

0009
000B

80
25

75
11

0
0

000D

97

11

000F

96

11

9
10
11
12

0011
0012
0014
0007

4C
97
20
96

00
01
01
01

0
0
0
0

13

0009

80

11

14

000B

25

AD

Store 00 in Hundreds Digit.


Store 00 in tens Di.it.
Store 00 in units Digit.
Load the accumulator with
the Binary number (7516 ).
Subtract 6416 from accumulator
BCS. Check C flag for borrow.
It's clear so continue.
Store away the new binary
number.
Load the accumulator with the
Hundreds Digit (00).
Increment the Hundreds Digit.
Store the Hundreds Digit.
Branch back to address 000716 .
Load the accumulator with the
Binary Number (1116 ).
Subtract 6416 from accumulator.
BCS. Check C Flag for borrow.
It's set so branch to address 001616.

AD

What's this?

OA
25

AD
AD

1
1

15

16
17

0001

Tens BCD 44i Wrong


Address
0017
2A

0019
001A

BCS. Check C Flag.


It's still set so branch to
address 002516.

Units BCD
18

0025

96

AD

19
20

0027
0029

97
CF

11
11

1
1

Load the accumulator with


the Binary number.
Store it in the units Digit.
Stop.

Figure 6-19
Locating the incorrect relative address.

*NOTE: The number to be converted (stored at address 002A) is changed after the
program is run. Address 002A should be loaded, or reloaded before each time the
program is executed.

I 6-25

6-26

I LABORATORY MANUAL

But, instead of branching to address 001616, where we would have


found a load accumulator instruction (9616) with an operand of
2A16, the program branches to address 001716. The Trainer now
interprets the operand (2A16) as an instruction or opcode. The
opcode 2A16, as you may recall, represents a valid instruction
which is "Branch if Plus." The MPU checks the N flag and finds it
set, because at this time, the negative number AD16 is in the
accumulator. Therefore, the condition is not satisfied, and the
Trainer continues on to the next instruction.
Single-stepping again (now we are at step 16) the next opcode
0A16. Actually, this should be the operand for the subtract instruction at address 001816. But since we are off by one, it appears to be
the opcode Trainer checks the opcode 0A16 and finds that it's an
inherent instruction to "clear the overflow flag." It executes this
instruction.
Step 17 finds the program at address 001A16. Here, we encounter
another BCS conditional branch instruction. The C flag is still set
so we branch to address 002516. The program works properly from
this point on.
Therefore, this one incorrect relative address caused the program
to skip the tens BCD portion of the program. The tens unit was
never subtracted, so it carried over into the units BCD digit. This
produced the wrong units digit of 1110.

PROCEDURE (Continued)
19. Now change the operand at address 000C16 from 0A16 to 0916.
20. Also change the number at address 002A16 to 7516. This is the
number that the program will convert to its BCD equivalent.
21. Enter the proper start address and single-step through the
program comparing the program listing with the results that
you obtain.

EXPERIMENT SIX - PROGRAM BRANCHES 1

22. Examine the addresses listed below and record the information stored there.
002B _

Hundreds BCD Digit

002C _

Tens BCD Digit

002D _

Units BCD Digit

Is this the correct BCD representation for the number 7516?


When the program is corrected by inserting the relative address
(0916) at address 000C16, we find that it works perfectly. After
single-stepping through the program, we examine the BCD digits
stored at address 002B16, 002C16, and 002D16. The hundreds digit
is 0110, the tens digit is 0110, and the units digit is 0710. Therefore,
the BCD equivalent of the binary number 0111 01012 ( 7516) is
11710.

DISCUSSION
This experiment has demonstrated several programming applications involving the branch instructions of the 68HC11 MPU. The
multiply by repeated addition, divide by repeated subtraction, and
BCD to binary conversion programs all contained branch instructions. As you saw, the execution of these instructions is dependent
upon the status of the condition code register flags.
You also were introduced to a convenient shorthand method of
calculating relative addresses in programs using branch instructions. In this type of program you saw how critical it is to avoid a
common programming error using the wrong relative address.
The effects of this error, along with a strategy to correct or debug
a program containing it, were also demonstrated.
Finally, the successful completion of this experiment depended
upon your accrued skill and knowledge of the trainer's operation
and functioning. At this point you should have a good understanding of typical trainer operations and a growing knowledge of
68HC11 MPU programming.

6-2 7

EXPERIMENT SEVEN - DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS I

EXPERIMENT 7
DOUBLE ACCUMULATOR AND
SUBROUTINE INSTRUCTIONS
Objectives:
1. To demonstrate the use and operation of the double accumulator instructions as discussed in Unit 7: ADDD, ASLD,
CPD, FDIV, IDIV, LDD, LSRD, MUL, STD, SUBD, XGDX,
XGDY.
2. To demonstrate the execution of subroutine calls in a program.
3. To reveal the presence of the subroutine "jump table" and
trainer operating system subroutines stored in EPROM.

INTRODUCTION
This experiment is divided into two parts. The first deals with the
use and instructions of the double accumulator of the 68HC11
MPU. You will learn some of the capabilities possible with the
double accumulator (ACCD). The second half of the experiment is
concerned with the demonstration of certain subroutine uses and
instructions. Both of these topics were discussed in Unit 7.
As you should recall from your study of Unit 7, the double accumulator, or ACCD is actually composed of a concatenation or stringing-together of the single accumulators A and B. The MSB of the
16-bit ACCD becomes the same as the MSB of ACCA; and, the LSB
of ACCD becomes the same as the LSB of ACCB. That is, ACCA
represents the upper-byte of ACCD, and ACCB represents the
lower byte. This is illustrated below.
Double Accumulator D (ACCD)
MSB (15)

LSB (0)

accumulator B
accumulator A
upper-byte ACCD lower-byte ACCD

7-1

7-2 I LABORATORY MANUAL


In the following experiment on ACCD you will execute a program
using all of the double accumulator instructions discussed in Unit
7. You will then analyze the program to study the operation of each
instruction.

Part 1 Double Accumulator Instructions


PROCEDURE
1. Turn the trainer on and press the Reset key.
2.

Load the Double Accumulator Test (DAT) program shown in


Figure 7-1.
HEX
HEX
MNEMONICS/
ADDRESS CONTENTS
CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020

C3
01
00
05
1A
83
02
00
CE
00
02
02
CC
00
80
03
04
C3
00
FF
83
00
7F
8F
18
CE
00
FO
18
8F
DD
21
CF

ADDD

ASLD
CP D

LDX

IDIV
LDD

FDIV
LSRD
ADDD

SUBD

XGDX
LDY

XGDY
STD
STOP

COMMENTS
Add to ACCD
High byte
Low byte
Arithmetic shift left
Prebyte for,
Compare ACCD to
High byte
Low byte
Load X-index register,
High byte
Low byte
Integer divide ACCD/IX
Load ACCD
High byte
Low byte
Fractional divide ACCD/IX
Logical shift right ACCD
Add to ACCD
High byte
Low byte
Subtract from ACCD
High byte
Low byte
Exchange ACCD & IX
Prebyte for,
Load Y-index register
High byte
Low byte
Prebyte for,
Exchange ACCD & IV
Store ACCD at,
Memory location 0021
Stop.

Figure 7-1

Double Accumulator Test (DAT) program (File digit A).

EXPERIMENT SEVEN - DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS I

3.

Press the Reset key.

4.

Single-step through the program by entering SS, and the start


address (Return = 000016).

5.

Execute the instructions as indicated below. Record the values


requested using the Exm Reg and RPO keys to alternately
examine these and return to the SS program execution mode.

(registers before execution of instruction at program counter)


PC

CCR

0000

00

0003
0004
0008
000B
000C
000F
0010
0011
0014
0017
0018
001C
001E
0020

ACCA ACCB
00

00

IX

IY

0000

0000

7-3

7-4

I LABORATORY MANUAL

6. After executing the STD instruction at the end of the program


(just before STOP), press the Exm Mem key and examine the
contents of memory locations 0021 and 0022. Record these
below.
Contents
Location
0021
0022
Study the DAT program. Where did the values in these memory
locations (0021,0022) come from?

DISCUSSION
A close examination of the DAT program shown in Figure 7-1
reveals that all of the double accumulator instructions discussed in
Unit 7 have been included (remember ASLD is the same as LSLD).
Consider for a moment the "mechanics" of the program.
Initially, all registers are "zeroed" by a reset. The ADDD (add
double accumulator) instruction adds (immediate) the value 010016
to ACCD. The ASLD (arithmetic shift left double accumulator)
instruction then does a bit by bit binary shift of all positions in
ACCD. This changes the previous hex value in ACCD (0100) to
020016. The CPD (compare ACCD to memory) instruction next
compares the value in ACCD with the next two memory locations.
This is done as a subtract of memory from ACCD. Because the
memory value stored, and the value of ACCD are the same, execution of the CPD (subtract) instruction sets the Z flag (CCR = 04).
Next, the LDX (load X-index register) instruction loads the value
000216 into IX. The IDIV (integer divide) instruction then divides
ACCD by IX. The quotient is placed in IX and the remainder (zero
in this case) is placed into ACCD. The LDD (load double accumulator) instruction then loads the value 008016 into ACCD. Next, the
FDIV (fractional divide) instruction carrys out a fractional division of ACCD by IX (i.e., 008016/010016). This results in a quotient
of "0.800016" (one-half in hex) which is placed in IX as the value
800016 (notice that the hexadecimal point is assumed immediately
to the left of the 8). The remainder, 0 is placed in ACCD. The LSRD
(logical shift right double accumulator) instruction then shifts all
bits in ACCD one place to the right. Because the value of ACCD
(before the shift) was zero, a shift results in the Z flag being set.
00FF16 is then added to ACCD. The SUBD (subtract memory from

EXPERIMENT SEVEN - DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS

double accumulator) instruction then subtracts 7F from the value


FF in ACCD. This results in the difference, 8016 in ACCD. The
XGDX (exchange double accumulator with X-index register) instruction then swaps the ACCDIX contents. Next, the LDY (load
Y-index register) instruction (note prebyte) loads 00F016 into IY.
Then, the XGDY (prebyte) instruction swaps the contents of ACCD
with that of IY. Finally, the STD (store double accumulator) instruction stores the final contents of ACCD in memory locations
0021 and 0022 (high and low byte respectively). These events are
summarized in Figure 7-2. Compare this to the results you obtained in step #5. Are they the same?
(yes/no)

(registers before execution of instruction at program counter)


PC

CCR

ACCA

ACCB

IX

IY

0000

00

00

00

0000

0000

0003

00

ol

00

0000

0000

0004

00

02

00

0000

0000

0008

04

02

00

0000

0000

000B

oo

02

00

0002

0000

000C

00

00

00

0100

0000

000F

00

00

80

0100

0000

0010

00

00

00

8000

0000

0011

04

00

00

8000

0000

0014

00

00

FF

8000

0000

0017

00

00

80

8000

0000

0018

00

80

00

0080

0000

001C

00

80

00

0080

00F0

001E

00

00

FO

0080

8000

0020

00

00

FO

0080

8000

Figure 7-2
Registers after single-step execution of DAT program.

17-5

7-6 I LABORATORY MANUAL


Part 2 Subroutine Instructions
In this part of the experiment you will apply what you have studied
about subroutine instructions in Unit 7. As you should recall, a
subroutine is a group of instructions that performs some limited,
but frequently required, task. There are two basic kinds: conditional or unconditional. While unconditional subroutines are commonly used to break longer programs into smaller segments, we
will concentrate here on the conditional subroutine for our discussion. These are used to handle some special condition when it is
present. For example, a subroutine could be used in a common
checkbook-balancing type program to alert you to insufficient
funds. This may take the form of a segment in the main program
that checks to see if your balance is negative and calls a special
subroutine to display a "warning" message if the balance is negative. Another possible use of a subroutine is in an MPU control
system. For example, a low-fuel warning subroutine could be part
of an automobile system control program. The main program would
run continuously, and jump to the low fuel subroutine only if the
specific condition low fuel) was present. At this point a warning
message could be displayed.
Notice in both of the examples above, the subroutine is used to
respond to some condition which does not always exist, but can
arise from time to time. If the condition does not exist, the main
program runs-on ignoring the subroutine. However, if the condition does arise, the subroutine is called.
In the program used in this experiment, you will see how the JMP
and JSR (RTS) instructions can be used repeatedly to call operating system subroutines in the MPU trainer. After learning the
necessary details about this you will write you own program using
subroutine calls.

PROCEDURE
1. Reset the trainer.
2. Load the ASCII Subroutine Can program (ASC) program shown
in Figure 7-3.

EXPERIMENT SEVEN DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS I 7-7

3. Execute the program in the GO mode by entering NMI, GO,


and the start address (Return = 000016). Watch the display.
What does the program do?

HEX
ADDRESS

HEX
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C

C6
OD
BD
CO
06
C6
OD
BD
CO
06
C6
41

LDAB

BD

JSR

CO
06
5C
Cl
5A
22
08
37
BD
CO
27
33
7E
00
OC
CF

MNEMONICS/
CONTENTS

JSR

LDAB
JSR

LDAB

INCB
CMPB
BHI
PHSB
JSR

PULB
JMP

STOP

COMMENTS

Load ACCB immediate,


ASCII carriage return
Jump to subroutine,
High byte address,
Low byte address
Load ACCB immediate,
ASCII carriage return
Jump to subroutine,
High byte address,
High byte address,
Load ACCB immediate,
ASCII character "A"
Jump to subroutine,
High byte address,
Low byte address
Increment ACCB
Compare ACCB to...
Next byte
Branch if ACCB > 5A
+8 from next byte
Push ACCB onto stack
Jump to subroutine
High byte address,
Low byte address
Pull ACCB from stack
Jump back to,
High byte address,
Low byte address
Stop.

Figure 7-3.
ASCII Subroutine Call (ASC) program (File digit B).

7-8 I LABORATORY MANUAL


4. Study the ASC program in Figure 7-3. Can you identify the
subroutine call instructions?
(yes/no)
Not counting the JMP instruction, how many subroutine call
instructions are used in the program?
number of subroutine call instructions =
Which subroutine call instruction or instructions are used?
opcode mnemonic

description

opcode mnemonic

description

Take some time now to analyze the ASC program. It begins


with ACCB being loaded with the value OD16. Consult the
ASCII (American Standard Code for Information Interchange)
chart in the back of the Microprocessor Reference Guide. Find
the ASCII equivalent of OD16. Write it below.
OD16 =
ASCII character
You should have found that the ASCII equivalent for hex OD is
CR, or carriage return. This is used in connection with the JSR
instruction immediately after OD in the ASC program. The
JSR is vectored to address C00616. This address is in the MPU
trainer's ROM (EPROM). This begins at address C00016 and
ranges up to FFFF16. Within this block of memory are all the
instructions to run the trainer. Located at the very beginning
of this block is a subroutine jump table. This table begins at
address C000 and ranges up to CO27. The table contains the
addresses of 14 special subroutines used by the trainer's
monitor program. The subroutine called by jumping to address
C006 (in the ASC program) acts to print the ASCII character
for the hex value contained in the B accumulator. Knowing
this, you can see that the first five program lines act to supply
a carriage return to the trainer display. Because the LCD
display on the trainer can accommodate 2 lines by 20 characters per line, one carriage return would shift the top line off
the display, and move the bottom line to the top. Two consecu-

EXPERIMENT SEVEN - DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS 1

tive carriage returns clear the display. After examining the


next five program lines and seeing that they are identical to
the first five, you can see that these first ten program lines
simply function to clear the trainer display.
After the display has been cleared by the first ten program
lines, a program loop begins with ACCB being re-loaded with
the value 4116. You will find that this is the ASCII value for
"A." Immediately following this, the JSR instruction is again
used to call the ASCII character output (ACO) subroutine.
Because ACCB now contains 4116, the equivalent ASCII character "A" is output to the display. After this, ACCB is
incremented (by 1) using the INCB (increment ACCB) instruction. The CMPB instruction then compares the (incremented)
value in ACCB to the value of the next byte (SA). Notice that
the value of this byte is 5A the hex equivalent for the ASCII
character "Z." If the value in ACCB (42 the first time through
the loop) is less than 5A, the program proceeds (looping) until
all characters, A through Z are displayed. After the last character (Z) has been displayed, the value in ACCB will again be
incremented, however, because this value will exceed that of
the operand (5A) of the CMPB instruction, the BHI (branch if
higher i.e., ACCB > 5A) instruction causes a branch (+8 from
the next instruction) to the STOP at the end of the program.
Notice that in the program loop, the ACCB contents must be
saved on the stack (PSHB) just before the second JSR (CO27)
call. This subroutine is simply a time delay (approximately
one second) between character printings. Calling it corrupts
the register contents, hence the need for the PSHB to save the
value in ACCB. After the time-delay subroutine call the value
of ACCB is restored with the PULB (pull ACCB from stack)
instruction. The JMP instruction completes the loop by vectoring program execution back to the loop beginning.
One last point. Notice that in the ASC program several JSR
instructions are executed to call various subroutines. In Unit
7 you learned that an RTS (return from subroutine) is generally used as the last instruction in the subroutine. Even
though you do not actually see the subroutine code used, you
can safely assume that these RTS instructions have been
included in the trainer's ROM subroutines to return execution
to the main program. Remember to include the RTS instruction when writing your own subroutines.

7 -9

7-1 0 I LABORATORY MANUAL


Now that you have studied and analyzed the ASC program, it
is time to try programming with subroutine calls yourself.
5. Using whatever references necessary, write a program that
will display the lowercase alphabet characters "a" through "z."
Hint you should be able to do this using the instructions in
the ASC program. Test and verify your program and write the
final version of it in the spaces provided.
HEX HEX MNEMONICS/
ADDRESS CONTENTS CONTENTS

COMMENTS

EXPERIMENT SEVEN - DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS

HEX HEX MNEMONICS/


ADDRESS CONTENTS CONTENTS

COMMENTS

If you have gained a good understanding of how the ASC


program works, you should have realized that only a couple of
small modifications were required to produce the desired
result of displaying the lowercase ASCII characters.
In the original ASC program shown in Figure 7-3, notice that
the operand for the third LDAB instruction is the first ASCII
character value to be displayed in the loop. The last value
displayed is established by the operand of the CMP(B) instruction. The lowercase ASCII characters are numbered 6116
through 7A16.

17-1 1

7-121LABORATORY MANUAL
Therefore, by replacing the operand value for the LDAB instruction (mentioned above) with 6116 and by replacing the
operand of the CMP(B) instruction with 7A16, the program
displays the lowercase ASCII characters "a" through "z". This
program is shown in Figure 7-4.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C

C6
OD
BD
CO
06
C6
OD
BD
CO
06
C6
61
BD
CO
06
5C
C1
7A
22
08
37
BD
CO
27
33
7E
00
OC
CF

MNEMONICS/
CONTENTS
LDAB
JSR

LDAB
JSR

LDAB
JSR

INC(B)
CMP(B)
BHI
PHSB
JSR

PULB
JMP

STOP

COMMENTS
Load ACCB immediate,
ASCII carriage return
Jump to subroutine, \
High byte address,
Low byte address
Load ACCB immediate,
ASCII carriage return
Jump to subroutine,
High byte address,
Low byte address
Load ACCB immediate,
ASCII character "a"
Jump to subroutine,
High byte address,
Low byte address
Increment ACCB
Compare ACCB to...
Next byte
Branch if ACCB > 5A
+8 from next byte
Push ACCB onto stack
Jump to subroutine
High byte address,
Low byte address
Pull ACCB from stack
Jump back to,
High byte address,
Low byte address
Stop.

Figure 7-4.
Modified (ASC) program to display lowercase alphabet.

6. Describe how to modify only two program lines (instructions)


in the ASC program so that the decimal characters 0 through
9 would be displayed.
change line

from

to

EXPERIMENT SEVEN DOUBLE ACCUMULATOR AND SUBROUTINE INSTRUCTIONS 17-1 3

7. Rerun the program with these modifications to verify that it


works. The decimal characters 0 through 9 should be displayed. Did you observe this result? If not try modifying the
original ASC program as shown below in Figure 7-5.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
0008
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C

C6
OD
BD
CO
06
C6
OD
BD
CO
06
C6
30
BD
CO
06
5C
C1
39
22
08
37
BD
CO
27
33
7E
00
OC
CF

MNEMONICS/
CONTENTS
LDAB
JSR

LDAB
JSR

LDAB
JSR

INC(B)
CMP(B)
BHI
PHSB
JSR

PULB
JMP

STOP

COMMENTS
Load ACCB immediate,
ASCII carriage return
Jump to subroutine,
High byte address,
Low byte address
Load ACCB immediate,
ASCII carriage return
Jump to subroutine,
High byte address,
Low byte address
Load ACCB immediate,
ASCII character "0"
Jump to subroutine,
High byte address,
Low byte address
Increment ACCB
Compare ACCB to...
Next byte
Branch if ACCB > 5A
+8 from next byte
Push ACCB onto stack
Jump to subroutine
High byte address,
Low byte address
Pull ACCB from stack
Jump back to,
High byte address,
Low byte address
Stop.

Figure 7-5.
Modified (ASC) program to display decimal characters.

DISCUSSION
In this experiment you have seen the workings of two important
aspects of MPU programming and use:
1. Double accumulator (ACCD) operations and instructions.
2. Subroutine programming and instructions.

7-14 I LABORATORY MANUAL


Part 1 of this experiment demonstrated the programming and
operation of the ADDD, ASLD, CPD, FDIV, IDIV, LDD, LSRD,
MUL, STD, SUBD, XGDX, and XGDY instructions as discussed in
Unit 7. All of these instructions were demonstrated in the Double
Accumulator Test (DAT) program.
Part 2 of this experiment featured the topics of subroutine instructions and calls. These were demonstrated in the ASCII Subroutine
Call (ASC) program using subroutine calls to the MPU trainer
monitor program located in high memory (C00016 through FFFF16).
The two subroutine calls were to (1) the ASCII character output
(ACO) subroutine, and (2) the one-second time-delay subroutine.
These were accessed respectively by JSR calls to memory locations
C00616 and CO2716 within the subroutine jump table in the trainer
EPROM.
The ASC program furthermore demonstrated the JMP and BRA
instructions along with the signed relative offsets (jump/branch
forward or backward) associated with them (see experiment #5,
step 11 2's Complement Equivalents).
Finally you were asked to write your own program to output the
lowercase ASCII characters to the display. You found that the
easiest way to do this was to modify the ASC (beginning and
ending) loop operand values to correspond to those of the lower
case ASCII character set (61 through 7A hex). In addition you also
found that the ten decimal characters 0 through 9 could be displayed by making a similar program modification.

EXPERIMENT EIGHT - INPUT/OUTPUT OPERATIONS I

EXPERIMENT 8
INPUT/OUTPUT OPERATIONS
Objectives:
1.

To show how information can be output from the MPU to the


outside-world.

2.

To demonstrate how information can be input to the MPU


system from the outside-world.

3.

To establish the meaning and use of memory-mapped input/


output (I/O).

4.

To demonstrate the use of the sonic logic probe on the ETW3800 MPU trainer.

5.

To use the 8-position (one byte) trainer dip-switch as an outside-world input device.

6.

To use the MPU trainer's 8 LED logic indicators as an outsideworld output device.

7.

To demonstrate the flow of externally generated information


through the MPU by showing how an outside-world byte of
information can be (1) input to the MPU, (2) displayed as an
equivalent ASCII character, and then (3) output from the MPU.

INTRODUCTION
Unit 8 addresses the topics of I/O and Interrupt Operations. While
the most important and frequently encountered forms of interrupts (Reset, Stop, Wait, SWI, etc.) have been demonstrated as a
consequence of previous experiments, the extremely interesting
and crucial topic of MPU input/output operations has yet to be
demonstrated. This experiment deals exclusively with the subject
of I/O operations and provides an introduction to the study of
microprocessor interfacing.
In MPU interfacing, the "outside-world" literally refers to anything external to the microprocessor unit itself. In this sense the
68HC11 MPU unit has already been "interfaced" with the I/O
devices of the ETW-3800 trainer. These include the keypad (for
input), the display (for output), as well as memory (RAM/ROM).

8-1

8-2

I LABORATORY MANUAL

As discussed in Unit 8, the 68HC11 MPU treats I/O operations as


memory transfers of data. This is referred to as memory-mapped I I
0 and is a straightforward and effective means of accomplishing
the exchange of data between the MPU and external devices.
In this experiment you will see how to use the special memory
addresses of the MPU trainer's I/O ports to exchange information
with the outside-world.

PROCEDURE
Refer to Figure 8-1 for the signal locations on the ETW-3800
breadboard. Locate the terminal connector for the logic probe on
the lower-left side of the trainer's terminal block (LPIN). Prepare
a jumper wire (approx. 5") to jump the logic probe to the LSB (bit
0) of the MPU output port (OP 0). Do this by stripping about 1/4
inch of insulation off each end of the wire.
Connector block description:
1 Input Only
(Color A)
2 Output Only
(Color B)
3 Bidirectional (Color C)

3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
I
I
I
4
12
el
16
I
I
I
I

1 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
I
I
I
I
I
I
I
I
44
48
20
24
28
36
40
32
I
I
I
I
I
I
I
I

O DDODOODODDOODOD
O 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7

3 - --ALAAAAAAAAAAAAAAAA
2 RWXR 511111119876543210
R 543210
K ERIE
E AIR 5
WO E
E T
I

CPU Data Bus

II
I
III
S 3 D
I A L
C 2 E N DI
1 0 C
T D R
E 0 E R
WO R E
E R 5
0 U 5
P
R T S
/ 5 T
W
R
0
B
E

CPU Address Bus

III
Timer System

III
CE
0X
PT
E
R
N
A
L

11101111100101001GG
PpppPpPPPPPPPPPpPNN
L 7 6 5 432117654)21000

II

I
Analog Input

I/O
S
E
L
E
C
T

1 1 1 1 1 1 1 1 1 2 2222 2 2 2 2 2
I
1
1
1
I
36
44
32
40
48
I
I
I
I
I

LLG++GA + A A 4 A A A A A 1 6 0 OP 1 1 1 M 8 5
PPN 5 5 NC 1 1 1 1 1 1 1 1 1 1 HOCCAcCCOIC 5
1 A 0 ( 0 1 6 2 2 7 6 5 4 3 2 1 0 2 11 4 5 1 1 2 3 LI 11 LS
NU
DVV
Z
T
K
D
C
I

CPU
C
O
N
T
R
O
L

Top
Connector

M
E
M

1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 2 2
I
I
I
e
I
210
12
16
24
28
I
I
I
I
I
I
I

Logic Power A P
Probe
5 0
NW
D E
R

ERIIIICE
I
// // /OM
R
WODOOP 5
0 1 2 3
0

SPI

M
0
D
E

Input Port

Output Port

Figure 8-1
Signal locations on ETW-3800 trainer breadboard.

Bottom
Connector

I
Power

EXPERIMENT EIGHT - INPUT/OUTPUT OPERATIONS

2.

With the trainer off, insert one end of the jumper prepared
(step 1) into the logic probe connector terminal (LPIN). Leave
the other end of the jumper wire unconnected.

3.

Turn the trainer on.

4.

Locate a ground terminal connector (GND).

5.

Momentarily insert the unconnected end of the logic probe


jumper wire into the GND terminal. Observe the LED indicators for the logic probe. Record your observations below.
Which logic probe indicator LED lit?
red/green

Did you hear an audible tone?


yes/no

6.

Disconnect the grounded end only of the jumper wire.

7.

Momentarily insert the unconnected end of the logic probe


jumper wire into the +5 volt (+5V) terminal. Observe the LED
indicators for the logic probe. Record your observations below.
Which logic probe indicator LED lit?
red/green

Did you hear an audible tone?


yes/no

8.

Disconnect the +5 volt end only of the jumper wire.

9.

Repeat steps 5 and 7 if necessary to determine which tone was


higher in pitch. Record you determination below.
than low logic

High logic level (+5 volts) tone is


higher/lower

(0 volts or ground) tone.


10. Locate the terminal connector point for the 1 Hz square wave
output signal.

18.3

8-4 I LABORATORY MANUAL


11. Insert the unconnected end of the logic probe jumper into the
1 Hz output terminal. Record your observations below.
logic probe indicators
audible tone(s) heard
You should observe the logic indicators cycled on and off with
the level of the 1 Hz square wave output signal. Also the tones
that you heard earlier alternated between high (for +5 volts)
and low (for 0 volts or ground).
12. Disconnect the 1 Hz signal end only of the jumper wire.
13. Locate the terminal connector point for the 60 Hz square wave
output signal.
14. Insert the unconnected end of the logic probe jumper into the
60 Hz output terminal. Record your observations below.
logic probe indicators
audible tone(s) heard
You should observe that the logic indicators both seem to be on
at the same time and you hear a kind of mixture of the two
discrete tones heard earlier. Actually, the logic indicators
alternated on and off, and the tones changed as before, but
because this occurred at a higher frequency (60 Hz) it was
more difficult to discern than it was before at 1 Hz. Notice that
when the logic probe senses a pulse train (alternating highs
and lows at a higher frequency) both indicators are lit and a
tone mixture is heard. The operation of the trainer logic probe
is summarized in Figure 8-2.
High Logic Level

Low Logic Level

Pulse Train

LED

red

green

red/green

Tone

high

low

high/low

Figure 8-2

Trainer logic probe operation.

EXPERIMENT EIGHT - INPUT/OUTPUT OPERATIONS 18-5

NOTE: The audible tone of the logic probe may be disabled by


connecting a jumper wire between LPAUDC and GND on the
trainer signal breadboard. This mutes the sound of the probe
while leaving high/low LED indicators functioning normally.
Now that you know how the logic probe works, you can use it
to check the level of various trainer signals.
15. Reset the trainer.
16. Locate the Output Port terminals (0P0-0P7) on the connector
block. Note that bit 0 corresponds to the LSB of a byte of output
information located at address B24016.
17. Test the status (high/low) of each output port bit by momentarily inserting the unconnected end of the logic probe jumper
into each bit of the port. Record you observations below.
Output Port Bit Status with No Program Running
(logic levels high/low)
LSBbit 0
bit 1
bit 2
bit 3
bit 4
bit 5
bit 6
MSBbit 7

8-6 I LABORATORY MANUAL


18. Load the Output Port Test (OPT) program shown in Figure 83 into the trainer.
HEX
ADDRESS

HEX
CONTENTS

0000
0001
0002
0003
0004
0005
0006

86
AA
B7
B2
40
20
F9

MNEMONICS/
CONTENTS
LDAA
101010102
STAA
B2
40
BRA

COMMENTS
Load ACCA immediate,
Store ACCA extended
Output port
Address ( B2401 )
Branch -7
To beginning

Figure 8-3
Output Port Test (OPT) program.

19. Press the NMI key.


20. Run the OPT program in the GO mode by entering GO, and the
start address of the program (Return = 000016).
21. With the program running (notice the OPT program runs in an
"endless loop") test each bit of the output port with the logic
probe. Do this by momentarily inserting the unconnected end
of the logic probe jumper into each terminal bit of the output
port connector. Record you observations below.
Output Port Bit Status with OPT Program Running
(logic levels high/low)
LSBbit 0
bit 1
bit 2
bit 3
bit 4
bit 5
bit 6
MSBbit 7 _____

EXPERIMENT EIGHT - INPUT/OUTPUT OPERATIONS

Notice that the value stored (AA16) in memory location B24016


is now being output to the trainer's output port. The binary
(byte) value of AA16 is indicated as 101010102.
The program used to output this value to the port is being run
in an endless loop. If the output port were not latched (see Unit
8) this loop would be necessary to maintain a continuous
display of the value output ( 101010102), however, because the
I/O ports of the ETW-3800 trainer are latched the program
would work just as well if the last instruction, branch always,
is replaced with a stop instruction. Understand that by swapping these instructions, the program outputs the value only
once for a brief period to the port. The output latch then holds
the value there.
22. Press the NMI key.
23. Modify the OPT program by replacing the BRA instruction at
address 000516 with a STOP (CF16). Do this by entering Exm
Mem, the address of the instruction to be modified (000516),
the modified code and NMI.
24. Run the modified OPT program and test each bit of the output
port with the logic probe as before (step #21). Record the
results below.
Output Port Bit Status with OPT Program Running
(logic levels high/low)
LSBbit 0
bit 1
bit 2
bit 3
bit 4
bit 5
bit 6
MSBbit 7
Running the modified OPT program should yield the same
results as the original (endless loop version) because of the
latched status of the output port.

18-/

8-8 I LABORATORY MANUAL


25. Prepare 9 (8 inch) jumper wires as before by striping approximately 1/4 inch of insulation from each end.
26. Now connect each output port bit OPO-OP7 to the 8 logic
indicator LEDs on the trainer. Make these connections by
jumping the LSB of the output port to the LSB of the indicators
(right to left) as shown in Figure 8-4.
Also, connect the logic probe input (LPIN) to OPO (you may
disable the logic probe sound if you wish).
MPU
CARTRIDGE

I I I

DISPLAY

E2PROM
CARTRIDGE

LED
TERMINAL
BLOCK

KEYBOARD

BREADBOARD

SIGNAL
CONNECTOR

Figure 8-4
Output port to logic indicators trainer wiring diagram

27. Reset the trainer.

EXPERIMENT EIGHT INPUT/OUTPUT OPERATIONS

28. Enter the ASCII Binary Code Display (ABCD) program shown
in Figure 8-5.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016

C6
30
F7
B2
40
BD
CO
06
5C
C1
7F
22
08
37
BD
CO
27
33
7E
00
02
20
D9

MNEMONICS/
CONTENTS
LDAB
STA(B)

JSR

INC(B)
CMP(B)
BHI
PSHB
JSR

PULB
JMP

BRA

COMMENTS
Load ACCB immediate,
with 3016
Store ACCB at,
Output port address
8240
Jump to subroutine
Display ASCII character
subroutine call
Increment ACCB
Compare ACCB to
last ASCII code value
Branch if ACCB>7F
to end of program
Save ACCB on stack
Jump to subroutine
to delay processing
about 1 second
Pull ACCB from stack
Jump back to address
00 (high byte)
02 (low byte)
Branch back
23 to beginning

Figure 8-5
ASCII Binary Code Display (ABCD) program (File digit C).

30. Press the NMI key.


31. Run the ABCD program in the GO mode by entering GO, and
the start address of the program (Return = 000016). Refer to
the ASCII Chart in the Handy Reference Guide. Notice that
the ASCII character being displayed on the trainer display is
also being displayed as a binary value on the 8 logic indicators
wired to the output port. That is the binary value of each
ASCII character 3016 through 7F16 is being output to the
output port of the trainer. The program is written to endlessly
loop but could easily be altered to run once and stop. How
would you accomplish this alteration?

18-9

8-1 0 I LABORATORY MANUAL


To this point you have seen how information can be output
from the MPU trainer. You will now examine how outsideworld information can be input.
32. Press Reset.
33. Prepare 8 (7 inch) jumper wires by striping approximately 1/
4 inch of insulation from each end.
34. Connect each input port bit IPO-IP7 to the 8 logic switches on
the trainer. Make these connections by jumping the LSB of the
input port to the LSB of the switches (right to left) as shown in
Figure 8-6.
MPU
CARTRIDGE

E2PROM
CARTRIDGE

DISPLAY

11 11111111111 11111

1111

rial
DIP SWITCH
TERMINAL
BLOCK

'v__
,====..,

[IIELILIOUCI

Erf fitil e
'----"---....,... feweveg
;7::

1
-- -

KEYBOARD

1338REIRE63811143BEBEISMESEIESSEIBE88B888888BPFEESEFEE

............ ,..... ...; .. , . , . ..

gigili':ii:::1:

BREADBOARD

Lil
L_1

iiifil li ';,::i1.1.ili'lil ..11 :

--,
'

IMEINIIMS
mom o

--I

_ .::-....--,-,

P8888W8888:MESERMEEig&i.1.!..,-:=

.,.....-i,--

SIGNAL
CONNECTOR

Figure 8-6
Logic switches to input port trainer wiring diagram.

EXPERIMENT EIGHT INPUT/OUTPUT OPERATIONS 18-1 1

35. Enter the I/O Port Test (IOPT) program shown in Figure 8-7.

HEX
ADDRESS

HEX
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D

F6
B2
80
BD
CO
06
F7
B2
40
BD
CO
27
20
F2

MNEMONICS/
CONTENTS
LDAB

JSR

STAB

JSR

BRA

COMMENTS
Load ACCB extended
with input port
address (B280)
Jump to subroutine
to display ASCII
characters
Store ACCB contents
in the output port
address (B240)
Jump to subroutine
for I second delay
BRA Branch back
-14 to beginning

Figure 8-7
I/O Port Test (IOPT) program.

36. Press NMI.


37. Set the logic switches to the following values.
01000001
MSB
LSB
0 = Low (GND) = Logic 0 (switch down)
1 = High (+5V) = Logic 1 (switch up)
Refer to the Binary/Hex ASCII listing in Figure 8-8. Which
ASCII character is indicated by the seven-bit value (LSB to
MSB) on the logic switch 0100 0001?
ASCII character for 0100 0001 =
NOTE: The MSB (8th bit) of the logic switch is set to zero
leaving the remaining seven bits to input ASCII characters on.

8-1 2 I LABORATORY MANUAL

Character

7-BR ASCII

Hex

A
B
C
D
E
F

100 0001
100 0010
100 0011
100 0100
100 0101
100 0110

41
42
43
44
45
46

G
H
I
J
K
L

100 0111
100 1000
100 1001
100 1010
100 1011
100 1100

47
48
49
4A
4B
4C

M
N
0
P
0
R

100 1101
100 1110
100 1111
101 0000
101 0001
101 0010

4D
4E
4F
50
51
52

S
T
U
V
W
X

101 0011
101 0100
101 0101
101 0110
101 0111
101 1000

53
54
55
56
57
58

Y
Z
0
1
2
3

101 1001
101 1010
011 0000
011 0001
011 0010
011 0011

59
5A
30
31
32
33

4
5
6
7
8
9

011 0100
011 0101
011 0110
011 0111
011 1000
011 1001

34
35
36
37
38
39

blank
.
(
+
$
'

010 0000
010 1110
010 1000
010 1011
010 0100
010 1010

20
2E
28
2B
24
2A

010 1001
010 1101
010 1111
010 1100
011 1101

29
2D
2F
2C
3D

Figure 8-8

Binary/Hex ASCII listing.

EXPERIMENT EIGHT INPUT/OUTPUT OPERATIONS 8 -1 3

37. Run the IOPT program in the Go mode. Observe the display
and the 8 logic indicators.
Notice that the 7-bit (binary) value input with the logic switches
is being displayed as an ASCII character. Furthermore, notice
that this 7-bit binary value is also being output to the 8 LED
logic indicators. This can be represented as shown in Figure 89.
logic switches
outside world
input device

MPU
---110.
input port

MPU

MPU
Output Port

8 logic LEDs
outside world
output device

Figure 8-9
Notice that the flow of information is from left to right in the
diagram above. The trainer is set up to accept a byte of data
from the input port, display this byte as its ASCII character,
and then output this byte to the output port.
38. With the IOPT program running, change the setting on the
logic switches to the binary equivalent of ASCII character B.
Logic Switch Setting for ASCII B = 0100 0010
Notice that when a new switch setting is established, the 8
LED logic indicators do not change until the new ASCII
character is displayed on the trainer display. A careful examination of the IOPT program reveals why. Notice that each new
logic switch setting is not displayed or sent to the output port
until after the 1 second time delay subroutine has run.
39. Take a moment now to try different logic switch settings as
input to the MPU trainer. Refer to Figure 6-8 as a quick
reference for binary to ASCII.
Realize that although you are using devices located on the
ETW-3800 trainer as input (switches) and output (logic LEDs)
devices, you could just as easily use information generated
from anywhere. For example, you could build a circuit for a
simple electronic thermometer, do an 8-bit analog to digital
conversion of the thermometer's output, and input temperature information to the MPU trainer. Moreover you could write
a program to respond to this temperature information and
output a particular value (e.g. 0000 0001) to trigger a relay

8-14 I LABORATORY MANUAL

driver circuit for an electric heater if the temperature drops


below a set value. In this way you could construct a simple
microprocessor-based temperature sensor/thermostat/heater
control system.

DISCUSSION
In this experiment you examined the functioning and use of some
other trainer subsystems. These included the logic probe, logic
switches, and logic indicators. These trainer features offer a convenient means to diagnose the operation of, and monitor, digital
signals.
You have also explored the important preliminary concepts involved in the topic of microprocessor I/O and interfacing. While the
actual latched ports used were incorporated into the ETW-3800
trainer, the programming necessary to perform memory-mapped I/
O was demonstrated and discussed. You saw how the logic switches
can be used as an outside-world input device to send information
to the MPU input port memory-mapped to address B28016. Likewise you used the LED logic indicators as a simple output device to
monitor the value sent to the MPU output port memory-mapped to
address B24016. Finally you saw the flow of data through the MPU.
This was shown as data sent into the MPU through the input port,
and back out through the output port. The importance of these I/O
operations is emphasized as the basis for all MPU control applications no matter how complex. In order to have a microprocessorbased system, outside-world data must be input/output to/from the
MPU.

EXPERIMENT NINE - ADDRESS DECODING 1 9 -1

EXPERIMENT 9
ADDRESS DECODING
Objectives:
1. To demonstrate the difference between full and partial
address decoding.
2. To show how an address decoding chart is assembled.
3. To demonstrate how an address can be decoded using
various types
of logic circuits.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
2
74LS27 integrated circuit (#443-800)
1 74LS30 integrated circuit (#443-732)
1 74LS42 integrated circuit (#443-807)
Hookup wire

INTRODUCTION
Many different combinational logic circuits can be used to decode
binary bit patterns. In this experiment, you will observe both the
use of SSI and MSI logic devices to decode addresses generated by
the MPU.

PROCEDURE
1. Turn the Trainer power off and construct the circuit shown in
Figure 9-1. Notice that the output of one-third of the second
74LS27 (pin 12) is connected to the logic probe input connector
on the Trainer. NOTE: Make sure you hook-up power and
ground to each IC the pin numbers are shown in the
schematic. Future experiments assume that you remember to
do this.

9-2

I LABORATORY MANUAL

TTL POWER:
PIN 14:+5V
PIN 7: GND
N
-J
4

2
0

A14
All
A9

in
NC
C.)

O
A8 9
m A7
cc
A6
0
oC.)
A5
W
z A4
z
A3
O
0
cc
A2
w
Al
z
AO
cc
I-

A15
A13
Al2
A10

74LS3C)
E(CLK)

10

(TRAINER) 11

-=.

Figure 9-1
An address decoder to completely decode address B400.

2.

Turn the Trainer power on and verify that the logic probe is
indicating a logic 1 output from the circuit. This is indicated by
the red light in the lower left-hand corner of the Trainer and
a high pitch tone emitting from the Trainer speaker. If you do
not get a logic 1 indication, turn the Trainer power off and
check your circuit.

3.

Examine memory location B40016. The logic probe should


momentarily indicate a logic 0 via the green light and a lower
pitch sound from the speaker. Do it again if you missed the
action!

4.

Press RESET and examine memory address B3FF16. Was


there any change in the logic output of the circuit?

5.

Press RESET and examine memory address B40116. Was there


any change in the logic output of the circuit this time?

12

LPIN
(TRAINER)
"CE"

EXPERIMENT NINE - ADDRESS DECODING 19-3

DISCUSSION
The circuit in Figure 9-1 completely decodes address B40016. In
other words, this circuit only responds to this address. A decoding
chart for the circuit is provided in Figure 9-2. Comparing this chart
to the schematic diagram in Figure 9-1, you find that the logic 0
address lines are being decoded by the NOR gates. Remember that
the only time a NOR gate generates a logic 1 is when all of its inputs
are 0. Thus, when address B40016 appears on the address bus, each
NOR gate generates a logic 1, since all of the NOR gate inputs are
0.
A15

Al2 All

AS A7

A4 A3

AO

0 0

Figure 9 - 2
An address decoding chart for the circuit in Figure 9-1.

Now, recall that the only time a NAND gate produces a logic 0 is
when all of its inputs are 1. From Figure 9-1, you see that the
NAND gate decodes address lines A15, A13, Al2, and A10 as well
as the outputs from the NOR gates. From the decoding chart you
see that these four address lines are high (logic 1) when address
B40016 appears on the address bus. In addition, each NOR gate
produces a logic 1 for this address. As a result, the output of the
NAND gate goes low (logic 0) for address B40016. Although at this
point (the output of the NAND) the address bus is actually decoded,
the generation of the final chip enable pulse requires the decoded
address signal to be gated together with the ECLK (timer) signal
of the 68HC11. This is done with the remaining two NOR gates.
Notice that the last NOR gate is used simply as an inverter.* While
many decoding circuits are possible, the circuit in Figure 9-1 does
the job of decoding the address B400 and providing a timed "chipenable" or "CE" pulse, in this case to the logic probe, quite well.

* NOTE: While it is possible to construct a NOR-inverter by simply tieing all inputs


together, good design practice is to, instead, tie all but the used input to ground.
This is especially true with timer and clock signals, where race conditions can
cause unstable operation.

9-4

1 LABORATORY MANUAL

In step 3, you examined address B40016 and observed a logic 0


output for this address. The examine operation causes the MPU to
place address B40016 on the address bus. The address decoder
recognizes this address and generates a logic 0 output. In steps 4
and 5 you examined addresses B3FF16 and B40116, respectively.
The decoder did not respond to these addresses, since it fully
decodes address B40016. In other words, the only address the
decoder responds to is address B40016. Try examining any other
address; you will not observe any response from the decoder.

PROCEDURE (continued)
6.

Turn the Trainer power off and remove the wire from pin 6 of
the 74LS27(#2) to pin 12 of the 74LS30. Tie pin 12 of the
74LS30 to +5V. This eliminates the contribution of address
lines A0, Al, and A2 to the decoder.

7.

Turn the Trainer power on and examine memory address


B40016. Again the logic probe will indicate a logic 0 output
from the decoder circuit when address B40016 appears on the
bus.

8.

Examine addresses B40116 through B40716. The logic probe


should indicate that the decoder is responding to any addresses within this range. Why?

9.

Press RESET and examine any address outside of the B40016


B40716 range and the decoder will not respond. Why?

DISCUSSION
By removing address lines A0, Al, and A2, you are only decoding
part of the address bus as can be seen from the address decoding
chart in Figure 9-3. The chart shows that address lines AO, Al, and
A2 are not being decoded, and therefore are indicated as "don't
cares" on the chart. Thus, the lowest address decoded is B40016.

EXPERIMENT NINE - ADDRESS DECODING

when these three address lines are 000. The highest address
decoded is B40716 when these three address lines are 111. Of
course, any address between these two extremes is also decoded.
A15

Al2 All

A8 A7

A4 A3

AO

Figure 9-3

An address decoding chart for the circuit in Figure 9-1 with 74LS27 #2
removed.

PROCEDURE (continued)
10. Turn the Trainer power off and construct the circuit shown in
Figure 9-4. Notice that one of the 3-input NOR gates on the
2nd 74LS27 is eliminated and address lines AO, Al, and A2 are
left unconnected. The input to pin 12 of the 74LS30 is still tied
to +5V.
TTL POWER
74LS30,74LS27
PIN 14: +5V
PIN 7: GND
74LS,42
PIN 16: +5V
PIN 8: GND
TRAINER CONNECTOR BLOCK SIGNALS

A15
A13 Al2 -a
A10
74LS30

A14
All
AS
A8
A3

A7
1
A6 3
14
A5
15
A4

9
10
74LS27
11
#1

+v

5
6
11
12

0\
74LS27
17
(TRAINER *2
E

74LS42 0 2
1
3
2
4
3
5
4
6
5
7
6
9
7
10
8
11

Figure 9-4

An address decoder which employs a 74LS42 1-of-10 decoder IC.

9-5

9-6

1 LABORATORY MANUAL

DEC BCD INPUT


NO. D C B A
0
1

0
0

0
0

0
0

0
1

2
3
4

0
0
0

0
0
1

1
1
0

5
6
7
8
9

0
0
0
1
1

1
1
1
0
0

0
1
1
0
0

>9

OUTPUT LINES
0 1 2 3 4 5 6 7 8 9

0
1
0

0
1
1
1
1

1
0
1
1
1

1 1
1 1
0 1
1 0
1 1

1
0
1
0
1

1
1
1
1
1

1
1
1
1
1

1
1
1
1
1

1 1 0
1 1 1
1 1 1
1 1 1
1 1 1

INVALID CODES

1 1 1
1 1 1
1 1 1
1 1 1
0 1 1

1
1
1
1
1

1
1
1
1
1

1
0
1
1
1

1
1
0
1
1

1 1
1 1
1 1
0 1
1 0

1
1
1
1

Figure 9-5
Logic truth table for the 74LS42 1-of-10 decoder IC.

11. Using the schematic in Figure 9-4 and the truth table for the
74LS42 shown in Figure 9-5, fill in the address decoding chart
in Figure 9-6.
A15

Al2 All

A8 A7

A4 A3

AO

Figure 9 - 6
A blank decoding chart.

12. Is the address bus fully or partially decoded? Why?

13. Now that you have determined the address range being decoded, examine all addresses within this range and verify that
the decoder responds. Also examine addresses outside of the
decoded range and verify that the decoder does not respond.

EXPERIMENT NINE - ADDRESS DECODING I 9-7

DISCUSSION
The decoding chart for this circuit is shown in Figure 9-7. Here, you
see that the range of addresses being decoded is B40016 through
B40716, since the lower three address lines are not being decoded.
A15

Al2 All

A8 A7

A4

A3

AO

Figure 9-7
An address decoding chart for the circuit in Figure 9-4.

The 74LS42 IC decodes address lines A7 through A4. Notice from


the circuit that output line 0 is employed as the 74LS42 output
line. From the truth table in Figure 9-5 you see that this output
line is a logic 0 when the decoder inputs (A7A4) are 0000. This
logic 0 output is inverted by the NOR gate and applied as a logic 1
to one of the input lines of the 75LS30 NAND gate. As a result, the
circuit responds to address B40016 B40716.
Now, suppose you were to reconnect the 74LS42 output from line 0
to line 1. Will this change the address range being decoded? Of
course it will, since output line 1 of the 74LS42 only responds to a
0001 input. When this happens, the decoded address range becomes B41016 through B41716 , right? What range would you get if
you reconnected the 74LS42 output to line 2? You're right if you
thought B42016 through B42716. Get the idea? In other words, the
74LS42 determines the second least significant hex digit within
the decoded address range.

PROCEDURE (continued)
14. Reconnect the 74LS42 output from output line 0 (pin 1) to
output line 1 (pin 2).
15. Verify that the decoded address range is now B41016B41716
and not B40016B40716.
16. Reconnect the 74LS42 output from output line 1 (pin 2) to
output line 2 (pin 3).

9-8

LABORATORY MANUAL

17. Verify that the decoded range is now B42016B42716 and not
any of the previous ranges.
How many different address ranges could be decoded with this
circuit? What are they?

EXPERIMENT TEN - DATA INPUT 1 1 0 - 1

EXPERIMENT 10
DATA INPUT
Objectives:
1. To show how to construct a circuit for writing data to the
microprocessor.
2. To demonstrate various methods for programming the microprocessor to accept externally applied data.
3. To demonstrate a software routine for debouncing a switch,
4. To show how to select a debounce routine to fit a specific
system.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
4 SPST pushbutton switches (#64-910)
1 Black pushbutton switch cover-cap (#462-1144)
1 White pushbutton switch cover-cap (#462-1145)
1 Red pushbutton switch cover-cap (#462-1146)
1 Blue pushbutton switch cover-cap (#462-1147)
1 74LS125 integrated circuit (#443-811)
2 74LS30 integrated circuits (#443-732)
1 74LS27 integrated circuit (#443-800)
Hookup wire

INTRODUCTION
In this experiment, you will learn how to input data. While many
devices can be used to transfer data to a microprocessor (keyboard,
mouse, modem, transducer, etc.), they all accomplish their task in
basically the same manner. You will use the Trainer binary data
switches and four external pushbutton switches for data entry.

10-2 I LABORATORY MANUAL


PROCEDURE
1. In the first part of this experiment, you will interface four
binary data switches to the data bus of the MPU. Make sure
the Trainer power is switched off. Then construct the circuit
shown in Figure 10-1. Locate the three ICs next to each other
at the extreme left-hand side of the connector block.
2. Make sure all of the binary data switches are down (logic 0).
Then position switch 0 up to logic 1.
TTL POWER
7LS125
74LS27
74LS30
PIN 14: +5V
PIN 7: GND

TO MPU DATA LINES DO-D3


(CONNECTOR BLOCK ON TAINER)
TRAINER SIGNALS

A14
All
A9

D2

D1

DO

11

IC
12
74LS125

D3

A15-2
A13-3
Al2-4
A10
5
A8
6

1'
4

10
13

BINARY DATA SWITCHES


(8 POSITION DIP SWITCH
CONNECTOR BLOCK ON TRAINER)

Figure 10-1

Circuit diagram for the first part of the input experiment.

3. Switch Trainer power on and enter the program listed in


Figure 10-2. Then execute the program beginning at address
000016.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006

F6
B5
00
F7
01
00
CF

MNEMONICS/
CONTENTS
LDB$$
B5
00
STB$$
01
00
STOP

COMMENTS
Read binary switch
data at address 850016
Store switch data
to address 010016
_ Stop

Figure 10-2

Program for inputting data from binary data switches.

EXPERIMENT TEN DATA INPUT I

4. Examine address 010016. What is the contents?

16.

5. Position data switch 0 down to logic 0. Then position data


switch 1 up to logic 1.
6. Execute the program. Then examine address 010016 . What is
the contents?
16.
7. Position data switches 0 through 3 up to logic 1.
8. Execute the program. Then examine address 010016. What is
the contents?
16.
9. Enter the program listed in Figure 10-3.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
0008
000C

F6
B5
00
BD
CO
15
C6
OD
BD
CO
06
20
F3

MNEMONICS/
CONTENTS
LDB$$
B5
00
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
BRA
F3

COMMENTS
Read switch data
at address B50018
Store value
to the display

Store a carriage
return to the display

Do it again

Figuie 10-3
Program to read and display binary switch data.

10. Position the data switches to their logic 0 position. Execute the
program beginning at address 000016. You should observe the
hex value FO being displayed in the upper left-hand corner of
the Trainer display.
Now, move data switch 0 from its logic 0 position up to its logic
1 position. The display should now reflect the change by
displaying the hex value Fl.
Change the lower four data switches to any arbitrary logic
pattern and the display should reflect the hex equivalent of
the binary setting. Of course, only the least significant hex
digit is affected since only the lower four MPU data lines are
being employed.

1 0-3

10-4 I LABORATORY MANUAL

DISCUSSION
Refer again to the circuit in Figure 10-1. It operates like read only
memory, with its data being influenced by external sources, (the
"outside world").
The circuit is partially decoded as shown in Figure 10-4. When any
of the specified addresses are selected, the 74LS125 three state
buffer is enabled via the address decoder. This allows the data
switch logic to be coupled to the Trainer data bus.
A15

Al2 All

A8 A7

A4 A3

AO

Figure 10-4
Decoding chart for the first input circuit.

Notice that the RI W and ECLK signals are also used in the
decoding. The R/W is being decoded so that the three state buffers
are only enabled during a read operation. The ECLK is included to
ensure consistent data transfer timing.
Both programs in this experiment have used address B50016 as an
input port. The first retrieves data from B50016 and stores it at
010016.
The second program also retrieves data from B50016. But this time,
it jumps to a display subroutine at address C01516. The display
subroutine displays the hex contents of accumulator B, which
contains the binary switch data. The program continuously branches
back and retrieves switch data immediately after displaying the
previous data. Thus, when you changed the position of data switches,
the display followed the logic value of the changing switch positions.
Next, some additional hardware and software features will be
added to the circuit.

EXPERIMENT TEN - DATA INPUT j

1 0-5

PROCEDURE (Continued)

NOTE: Before performing the next step, locate the four SPST
pushbutton switches (64-910) and the four colored (black, white,
red, blue) cover-caps. Prepare the switches for use by installing the
caps on the switches. Do this by placing each cap on a switch and
pressing it into place.
11. Refer to Figure 10-5 and construct the circuit shown. This
circuit interconnects with the first circuit you constructed.
Remember, the pushbutton pins are fragile. Press straight
down when you install them in the large connector block,
mounted on the Trainer breadboard. Locate the pushbuttons
close together, just to the right of the ICs.

ON ETW-3800 TRAINER
D3

)NE-HALF OF
8 POSITION
DIP SWITCH
)N TRAINER

D2

01

TO DIP SWITCH
CONNECTOR BLOCK ON TRAINER

-1

DO
+5V

TO

TO
PIN 11 PIN 8
IE-HALF OF
IP SWITCH
ONNEC TOR
BLOCK
1 TRAINER __

J_
0
0

TO TO
PIN 6 PIN 3

-I_
0
0

-r-

LL LL .LLLIJ LL LL

WIRED AS BEFORE'.

74LS125

74LS125
(AS BEFORE)

-I-

Wilia=1..11.112111

L)

LL
LL

LL

GND

666

LLL i.L LL

BREADBOARD
BLUE RED

WHITE I BL ACK

103 I1 D2 1101 100

? T T
Figure 10-5

Added circuitry for the data input experiment.

12. Position all of the Trainer binary data switches up to logic 1.


13. Execute the program beginning at address 000016. The display
should display the hex value FF16.
14. Press one of the four pushbuttons and note the displayed
result.

66666

1 0-6 I LABORATORY MANUAL


15. Simultaneously press any two pushbuttons and note the result.
16. Simultaneously press any three pushbuttons and note the
result.
17. Simultaneously press all four pushbuttons and note the result.

DISCUSSION
The four pushbuttons that you added in Figure 10-5 simply provide
a convenient substitute for the four Trainer data switches. You
could obtain the same result by manipulating the data switches.
However, the pushbuttons will be needed in the next portion of the
experiment.
The program simply reads the pushbutton data at address B50016
and repeatedly displays the hex equivalent of the data. The four
pushbutton switches are connected in a pull up configuration.
Thus, when a switch is depressed a ground potential (logic 0) is
placed on the corresponding data bus line. Of course, the upper
four data bus lines are not being affected by the circuit and are seen
as logic l's.
Try depressing any combination of the pushbutton switches while
the program is running and observe the display. Write the binary
equivalent of the hex display value and you should find logic 0's in
the bit positions corresponding to the depressed pushbuttons.

PROCEDURE (Continued)
18. Switch the Trainer power off. Then refer to Figure 10-6 and
add the circuit shown to the circuit already wired to the
Trainer. There should be enough room near the right end of the
large connector block "on board" the Trainer to hold the additional 74LS30. Notice that the inputs to the 74LS30 are
connected in parallel with the data lines leaving the four push
button switches. The NOR gate is obtained from the 74LS27 IC
already in the circuit. Make sure the NOR gate output (pin 12)
is connected to the XIRQ interrupt input on the Trainer.

EXPERIMENT TEN - DATA INPUT

TO PINS
11 8 6 3
ON 74LS125 4
+
Ii
(AS BEFORE)

IiliI

1/2 BINARY DATA


(DIP) SWITCH
BLOCK
ON TRAINER

+5V
12

I I I

i I I
I II L

I -- - - -

I
12 %IRO
(ON TRAINER)

74LS30
74LS27
EXTERNAL
BKI
PUSHBUTTON
SWITCHES

Figure 10-6
Interrupt circuitry for data input experiment circuit.

19. Switch the Trainer power on. Then refer to Figure 10-7 (on the
next page) and enter the program listed beginning at address
000016.
20. Now enter 0016 into address 0100 through 011016. These
addresses are used as data storage registers.
21. Execute the program beginning at address 000016.
22. Strike each pushbutton sequentially in a 4, 3, 2, 1 order. When
you strike each button, use a moderate force, such as you
would use when typing with a mechanical typewriter. The data
you entered is stored in memory and will not be displayed.
23. Examine address 000916. It should contain 0416, which is the
number of pushbutton contact closures made. Change the
contents back to 0016.
24. Examine addresses 0100 through 010316. They should contain
08, 04, 02, and 0116 respectively. Change the data in these four
locations back to 0016. Note (Figure 10-5) that the pushbuttons
are connected to data lines D3, D2, D1, and DO Therefore, the
switches will enter the binary values 8, 4, 2, and 1.

1 0-7

1 0-8 I LABORATORY MANUAL


HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
0000
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
002B
002C
002D
002E
002F
0030
0031

CE
00
OE
FF
69
2E
OE
CE
01
00
01
01
20
F9
B6
135
00
B1
00
32
27
07
87
00
32
7F
00
33
3B
C6
40
Fl
00
33
27
04
7C
00
33
3B
43
A7
00
7F
00
33
08
DF
08
3B

MNEMONICS/
CONTENTS
LDX#
00
OE
STX$$
69
2E
CLI
LDX#
01
00
NOP
NOP
BRA
F9
LDA$$
B5
00
CMPA$$
00
32
BEQ
07
STA$$
00
32
CLR$$
00
33
RTI
LDB#
40
CMPB$$
00
33
BEQ
04
INC$$
00
33
RTI
COMA
STA X
00
CLR$$
00
33
INX
STX$
08
RTI

COMMENTS

Store XIRQ interrupt


vector to address 692E16

Clear I-flag

Point to storage and loop


until interrupt received.

Get data and compare to


previous data.

If different, store in memory


location 003216If not, branch to debounce
routine at address 001D16.
Reset counter and return
from interrupt

Debounce routine causes


switch to be read 64 times
to eliminate contact bounce

Complement switch
logic and store.

Return from interrupt

Figure 10-7

Program to debounce the pushbutton switches.

EXPERIMENT TEN - DATA INPUT I

25. Execute the program. Then press each pushbutton twice in


succession (4, 4, 3, 3, 2, 2, 1, 1). Address 000916 now contains
0816, representing eight pushbutton contact closures. Enter
0016 at address 000916.
26. Examine addresses 0100 through 010716. They show the value
of each pushbutton pressed and the sequence it was pressed.
Change the data in these addresses back to 0016.
27. Examine address 001E16. It should contain data value 4016.
Change the value to 0016.
28. Execute the program. Then press each pushbutton once in
sequence.
29. Examine address 000916 and record the contents.
16.
This number should equal 0416. However, it may be higher.
30. Record the data in the following addresses. You need only
examine the number of addresses that correspond to the value
recorded in step 29.
0100

0109

0101

010A

0102

010B

0103

010C

0104

010D

0105

010E

0106

010F

0107

0110

0108

1 0-9

1 0-1 0 I LABORATORY MANUAL

DISCUSSION
The additional NAND and NOR gates provide an interface between
the four external pushbuttons and the interrupt request line
XIRQ . The remaining circuitry functions as before. Thus, whenever you attempt to enter data with the pushbutton switches, a
request for program interrupt signal is sent to the microprocessor.
The program listed in Figure 10-7 processes the interrupt and
debounces the keys. The program is actually two programs in one.
The first part serves as a "simulated" program that runs in an
endless loop until it is interrupted. The remaining program steps
actually service the input data pushbuttons during the interrupt.
This is the program we will deal with.
Figure 10-8 is a flowchart for the interrupt program.
(NTERRUPT)

GET
INPUT
DATA

NO

STORE
INPUT IN
TEMP

YES

NO INCREMENT
COUNT

CLEAR
INPUT

YES
STORE
INPUT IN
MEMORY

RTI

RTI

CLEAR
COUNT
THEN INX

SAVE INDEX
REGISTER
BEFORE RTI

RTI

Figure 10-8
Flowchart for interrupt routine in the debounce program.

EXPERIMENT TEN - DATA INPUT

When the MPU receives an interrupt request; it completes the


instruction it is presently performing, stores the internal registers
and accumulators into the stack, sets the interrupt mask in the
condition code register, then examines ROM to find out where the
program counter is to be vectored. The vector address instruction
sends the program counter to the beginning address of the interrupt program.
Pushbutton data is loaded and compared to the data in the temporary register (address 003216). Since this is the first time data is
examined, there can be no match. Therefore, the pushbutton data
is stored in the temporary register, the counter register (address
003316) is reset, and the MPU returns to the original program. This
is the first time the MPU looks at the pushbuttons during the
debounce routine. The data in the temporary register serves as the
reference for all future interrupts. If the input data changes, this
new data is entered, and the counter register is reset. The counter
is used later in the interrupt program to monitor the number of
data examinations performed.
Upon return from the interrupt program, the MPU pulls the
accumulator and register data from the stack. This clears the
interrupt mask, and since you still have the pushbutton pressed,
the MPU immediately acknowledges the interrupt request again.
Whereupon, it stores it into the stack, sets the mask, and looks up
the interrupt vector.
Pushbutton data is again compared with the temporary register.
This time, it matches. Thus, allowing a branch to address 001D16.
Data value 4016 is loaded into the B accumulator and then compared with the count register. Since the count is zero, there is no
match. Therefore, the count is incremented and the MPU returns
to the main program.
Assuming you are still holding the pushbutton down, the MPU goes
through the interrupt routine 62 more times (63 total). During the
64th cycle, if the data is still good, the MPU is satisfied that the
data supplied by the pushbutton is true, and the program is
allowed to branch to address 002816.
The contents of accumulator A (pushbutton data) is complemented
and stored at the address pointed to by the index register. This
address was loaded into the index register in the main program. It
is the first of 1710 addresses you reserved for data when you
performed the experiment.

1 0- 1 1

1 0- 1 2 I LABORATORY MANUAL

The counter register is cleared (in case the same pushbutton is


again pressed). The index register is incremented and stored at
address 000816. This points to the next data address, in preparation for the next pushbutton closure. Finally, the MPU returns to
the main program.
You may have wondered why the pushbutton data was complemented before storage (address 002816). This was necessary since
the pushbuttons were wired using inverse logic. That is, when the
#1 pushbutton was pressed, data 1111 11102 was transferred on the
data bus, rather than 0000 00012. Thus, it was necessary to invert
the data for "logical" interpretation.
In the second part of this portion of the experiment, you changed
the number of data examinations from 4016 to 0016 (address 001E16).
Then when you entered four pushbutton closures, you probably
found more than four entries stored at address 000916. This occurred because the contacts of a switch tend to bounce open and
closed a number of times before they stay closed. Since the bounce
period can last many milliseconds, the MPU could treat each
bounce as separate entry, as you probably experienced.
Again look at the data you recorded in step 30. As you know, the
program is designed to store one pushbutton closure in each
address. A series of two or more identical entries indicates bounce.
You may even have one or two zeroes recorded. This occurred
because the contacts opened after an interrupt request, but before
the data could be tested. Thus, a zero is stored.
Contact bounce cannot be tolerated. But, what is a desirable
number of switch samples? This depends upon the type of switch.
If the sample is too low, bounce can occasionally get through. Large
samples waste time and may require long switch hold-down periods. Normally five to eight samples are sufficient for a program of
the type you used in this experiment. However, some switches
produce excessive bounce. As a precaution, 64 samples are used in
the program.
Your Microprocessor Trainer uses a similar software routine for
key debounce. This is stored in its ROM. Another method for
debouncing a switch is to use cross-coupled NAND gates. They
latch on the first closure and any additional bouncing is ignored.
Regardless of the method used, you must debounce any mechanical
switch used for data entry.

EXPERIMENT TEN - DATA INPUT I 1

If you experiment with the sample rates in the program you


entered, always be sure to change the data at addresses 000916 and
010016 through 011016 before you execute the program.

PROCEDURE (Continued)
31. This completes this experiment. Switch the Trainer power off.
Then remove all of the hookup wire and components from the
large connector block.

0-1 3

EXPERIMENT ELEVEN - DATA OUTPUT I 1 1 -1

EXPERIMENT 11
DATA OUTPUT
Objectives:
1. To demonstrate microprocessor interfacing to an external
data display.
2. To show how a 7-segment display is connected.
3. To demonstrate the trade-offs between hardware and software display decoding.
4. To provide an opportunity to write a number of output
programs.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
8 470 C2, 1/4-watt, 5% resistors (#6-471-12)
1 TIL-312 7-segment LED (#411-831) or 5082-7731 7-segment
LED (#411-875)
2
7475 integrated circuits (#443-13)
1 7447 integrated circuit (#443-36)
1 74LS30 integrated circuit (#443-732)
1 74LS27 integrated circuit (#443-800)
Hookup wire

INTRODUCTION
Until now, you have been using programs that moved data within
the Trainer, with any results displayed by the "on-board" display or
binary LEDs. This may be adequate for your purposes, but other
methods are needed if external equipment uses the data. The data
may take the form of a visual display for an operator to read, or a
digital control signal to manipulate an electromechanical device.
This experiment presents a number of interfacing methods and
examines some of the advantages and disadvantages of each method.

11-2 I

LABORATORY MANUAL

PROCEDURE
1. In this part of the experiment, you will examine how the MPU
can be interfaced to LEDs. Make sure the Trainer power is
switched off; then construct the circuit shown in Figure 11-1.
Notice that +5 volts and ground are connected to pins 5 and 12
respectively for the 7475 ICs. The other ICs use pin 14 for +5
volts and pin 7 for ground.
TTL POWER
74LS27,74LS30
PIN 14: +5V
PIN 7: GND
DATA LED CONNECTOR BLOCK

7475
PIN 5: +5V
PIN 12: GND

T
A

E
R

N
A

(ON TRAINER)
3 2 1 0

7 6 5 4
9 10 15 16

Al5 2
Al3 3
A 12
4
A10 5
AB
E
12j
+5
12

04 03 02 01 4

12

9 10 15 16
4 04 03 02 01

7475 #2
7475 #1
13 13
D4 D3 D2 D1
D4 D3 D2 D1
7 6 3 2
2
7 6 3
3 2 1 0
7 6 5 4
D3 D2 D1 DO
D7 D6 D5 D4
TRAINER DATA BUS

A14
All
A9

Figure 11-1

Latching binary data for output.

2.

Recheck your wiring; then switch the Trainer power on. The
data LED's on the Trainer will show a random value.

3.

Figure 11-2 is a decoding chart for the circuit you constructed.


This shows that the circuit is partially decoded. A 2-digit hex
number can be stored at any of these decoded addresses.
Al5

1\
A4-1- A49-

A8 A7

A4 A3

Figure 11-2

Decoding chart for the circuit in Figure 11-1.

AO

EXPERIMENT ELEVEN DATA OUTPUT I 1

4. Enter the program listed in Figure 11-3. Execute the program


beginning at address 000016. The data LEDs indicate
2.
This is the binary equivalent of the data the program stored to
address B50016.
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005

86
55
B7
B5
00
CF

LDA#
55
STA$$
B5
00
STOP

COMMENTS
Load A with the value 5516
Store A to data LEDs
Stop

Figure 11-3
Program to store data to the LEDs.

5. What hex value would be required to turn off all of the data
LEDs?
16. Verify your answer by placing this value in
the program at address 000116 and executing the program.
6. What hex value would be required to turn on all of the data
LEDs
16. Verify your answer by placing this value at
address 000116 and executing the program.
7. Change the data at address 000116 a number of times and
verify its value with the data LEDs. Each time you must reexecute the program.
8. Write and execute a program that alternately turns all of the
data LEDs on and off. Use a delay loop in the program so that
the on and off cycles can be recognized. Remember that an
MPU cycle takes approximately 1 microsecond in the Trainer.
If you have any difficulty, use the Trainer single-step function
to examine the operation of your program.

DISCUSSION
Refer to Figures 11-1 and 11-2. Notice that a partial decoding
scheme is used. A fully decoded circuit could have been used by
adding more combinational logic.

1 -3

11-4 I LABORATORY MANUAL


The circuit you constructed appears as a write-only memory to the
microprocessor. That is, the MPU can write into the selected
address, but it cannot read the data stored. However, since eight
data LEDs monitor the stored information, you can see the data.
Thus, the MPU is interfaced in a way that produces usable data.
Two bistable quad latch ICs are enabled when one of the eight
preselected addresses is accessed. They act as an 8-bit memory
storage device. Thus, any data appearing on the data lines is
latched into the two devices. Since the output of each latch is
active, the data LED connected to each follows the data level.
Storing 0016 turns off all the LEDs, while storing FF16 turns each
LED on.
Right now, the data LEDs should be switching on and off at a
regular interval, because of the program you wrote and executed.
If you had any difficulty with the program, refer to Figure 11-4. It
lists a program to flash the data LEDs. While this program may not
match your program, it is one of many ways to accomplish the same
objective.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C

4F
B7
B5
00
CE
55
00
09
26
FD
43
20
F4

MNEMONICS/
CONTENTS
CLRA
STA$$
B5

COMMENTS
Clear A
Store A to LEDs

00

LDX#
55
00
DEX
BNE
FD
COMA
BRA
F4

Delay

Toggle A
Do it Again

Figure 11-4

Program to flash the data LEDs.

EXPERIMENT ELEVEN - DATA OUTPUT 1 1

Alternatively, you may display a binary upcount on the eight LED


indicators with the following program:

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
0000
000D
000E
000F
0010

4F
B7
B5
00
CE
40
00
09
2E
FD
4C
81
FF
24
F1
20
FO

MNEMONICS/
CONTENTS

COMMENTS

CLRA
STAA
B5
00
LDX
40
00
DEX
BGT
FD
INCA
CMPA
FF
BHS
F1
BRA
FO

Clear ACCA
Store ACCA
to LEDs
Delay

Upcount

Do it again

Figure 11-5
Program to display a binary upcount.

PROCEDURE (Continued)
9. Write a program to alternately store l.'s and 0's to the display
LEDs. But this time, adjust the timing so the LED "on" time is
longer than the "off" time. Then execute the program.

1 -5

11-6 I LABORATORY MANUAL

DISCUSSION
This program required two timing loops to allow for the difference
between on and off time. If your first program contained two timing
loops of equal duration, it is a simple matter to modify the delay
times. Figure 11-6 illustrates a method for accomplishing the task.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016

4F
CE
55
00
B7
B5
00
43
09
26
FD
CE
FF
00
B7
85
00
43
09
26
FD
20
EA

MNEMONICS/
CONTENTS
CLRA
LDX#
55
00
STA$$
B5
00
COMA
DEX
BNE
FD
LDX#
FF
00
STA$$
B5
00
COMA
DEX
BNE
FD
BRA
EA

COMMENTS

Store FF16 to LEDs


and delay

Store 0016 to LEDs


and delay

Do it again

Figure 11-6

Program to flash LEDs at nonregular intervals.

In the next part of the experiment, you will add a decoder-driver


and a common-anode 7-segment display to the circuit.

1 -7

EXPERIMENT ELEVEN - DATA OUTPUT I 1

PROCEDURE (Continued)
10. Switch the Trainer power off. Then, without disturbing the
circuit wired to the Trainer, add the circuit shown in Figure 117.
(WIRED AS BEFORE TO 7475--FIGURE E-16)
7447 POWER
DATA LED
CONNECTOR BLOCK
(ON TRAINER)

PIN 16: +5V


PIN 8: GND

TIL312 LED

Figure 11-7
Additional data display for first output circuit.

11. Recheck your wiring, then switch the Trainer power on and
press RESET.
12. The lower four bits of your data byte will determine the digit
displayed. Enter the program back in Figure 11-3.
13. Execute the program. What is the bit pattern displayed by
lower four display LEDs?
2.
14. What is the hex equivalent?

16

15. What is displayed by the new 7-segment display?

16-

16. Write a program that will cause the 7-segment display to count
from 0 to 9 and then continuously repeat. Include a delay loop
so that each digit remains on long enough to be identified.
Execute the program.

11-8 1 LABORATORY MANUAL

DISCUSSION
The circuit you just constructed contains a 4-line-to-7-segment
decoder driver and a 7-segment, common anode display. The 7447
decoder driver contains a large maze of combinational logic which
allows it to decode four data bits and drive the proper segments in
a 7-segment display to produce the corresponding decimal digit.
The display circuit is a multiple LED array with common anodes.
The anodes are tied to +5V and the decoder driver supplies the
necessary grounds to light the selected LED segments.
If you had any questions concerning the program to increment the
display, refer to Figure 11-8. It contains a simple program to
increment the display from 0 to 9 at a slow rate. Enter the program
in Figure 11-8 and watch the eight data LED's. They show the
actual value stored in accumulator A.

HEX
HEX
ADDRESS CONTENTS

0
:a0 .$. _$.- .. R
gi
,r
. 0
3 0
ge
rgvg
19
00
00
00
-

4F
81
OA
27
FB
B7
B5
00
4C
CE
FF
FF

og
26
FD
20
FO

MNEMONICS/
CONTENTS
CLRA
CMPA#
OA
BEG)
FB
STA$$
B5
00
INCA
LDX#
FF
FF
DEX
BNE
FD
BRA
FO

COMMENTS

Start with 0

Store to display
Add one

Delay

Repeat

Figure 11-8

Program to increment the 7-segment display from 0 to 9.

Next, you will see that a decoder driver is not necessary if you are
willing to let the MPU do the decoding.

EXPERIMENT ELEVEN DATA OUTPUT I 1

PROCEDURE (Continued)
17. Switch Trainer power off and remove the decoder driver, and
display package. Leave the 74LS27, 74LS30, and 7475 ICs
wired to the Trainer per Figure 11-1.
18. Refer to Figure 11-9 and construct the circuit shown. Since the
resistor leads are too short to reach from the connector block
to the data LED connectors, insert the free end of each resistor
into an unused connector socket. Then run hookup wire to the
appropriate LED connector block.

R1R8
47011

TIL312
DATA BIT 7 6 5 4 3 2 1 0
LED SEGMENT a b c d e I g dp

Figure 11-9
Additional data display.

19. Re-examine the circuit to make sure it is properly wired, and


the resistor leads do not touch adjacent resistor leads. Then,
switch Trainer power on and press RESET.
20. This circuit, like the previous circuit, uses the address decoder
and latches initially wired to the Trainer. Data stored at
address B50016 determines which display segment lights.
Enter the program back in Figure 11-3.
21. Change the data at address 000116 to 4. Execute the program.
What does the display indicate?
16.
22. To light a particular segment in the display, the corresponding
data bit must be logic 0. The table below the circuit in Figure
11-9 indicates the segments connected to the data bits. What
bit pattern will produce the number 1 in the display?
2.
23. Convert the bit pattern from step 22 to hex and enter it at
address 000116 . Although it is possible to display two ls, the
correct 1 is produced when segments b and c are lit.

1 -9

1 1 -1 0

LABORATORY MANUAL

24. Load and execute the program listed in Figure 11-10.


HEX
HEX
ADDRESS CONTENTS
iNcovin wt,cooc0 00uiu- R KAR 7,:sto gr,co m
8 688888^ 18<m c"c"-u"
8888888
SVg 88888888 88888 88 888888888g 8gg 8

CE
00
1A
A6
00
B7
B5
00
86
FF
C6
FF
5A
26
FD
4A
26
F8
08
8C
00
2A
27
E8
20
E9
03
9F
25
OD
99
49
41
1F
01
19
11
CO
63
85
61
71

MNEMONICS/
CONTENTS
LDX#
00
1A
LDA X
00
STA$$
B5
00
LDA#
FF
LDB#
FF
DECB
BNE
FD
DECA
BNE
F8
I NX
CPX#
00
2A
BEQ
E8
BRA
E9
03
9F
25
OD
99
49
41
1F
01
19
11
CO
63
85
61
71

COMMENTS
Load beginning table address
Load display code
Store display code to display

Delay

Get next display code

Display codes

Figure 11-10

Program for incrementing 7-segment display from 016 to F16-

EXPERIMENT ELEVEN - DATA OUTPUT I 1 1 -1 1

DISCUSSION
In this experiment, you have successfully eliminated a decoder
driver, but at the expense of increased software. The program
sequentially stores bit patterns to the display to make it appear as
the numbers 0 through F16 are being stored.
Addresses 001A16 through 002916 contain the sixteen display codes
in numerical sequence. This "look-up" table is then accessed by the
index register to obtain the required code.
You may have noticed that the B16 digit had a decimal point lit next
to it. This is sometimes used to indicate it is a B rather than a 6.
If you prefer not to have the decimal point, you can change address
002516 to 0116.

EXPERIMENT TWELVE - INTRODUCTION TO THE PERIPHERAL INTERFACE ADAPTER

EXPERIMENT 12
INTRODUCTION TO THE PERIPHERAL
INTERFACE ADAPTER (PIA)
Objectives:
1. To show how to interface the MPU to the outside world
using a PIA.
2. To demonstrate various ways the PIA can be initialized as
an input I output, or I/O, device.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 6821 PIA integrated circuit (443-1014)
Hookup wire

INTRODUCTION
As you have seen in the previous experiments, the need for latches
and drivers to communicate with the MPU from the outside world
can become quite burdensome. Then, once you have established a
hardware interface circuit, you cannot easily modify its function.
However, the PIA can simplify your interface requirements in such
a way that standardization is possible regardless of the application. Therefore, you can easily develop interface systems compatible with your hardware and software needs. This is possible
because most of the PIA performance characteristics are software
controlled. Thus, performance and design features can be modified
with little difficulty. In this experiment, some of the PTA's characteristics will be examined.
The importance of the principles and techniques described in this
experiment cannot be overemphasized. Beginning with this experiment you will find the PIA chip used in almost all subsequent
experiments as an interface between the MPU circuit of the Trainer,
and a variety of I/O circuits. Take your time and pay close attention
to the workings of the PIA.

1 2-1

I LABORATORY MANUAL

PROCEDURE
1. Make sure the Trainer power is off. Then construct the circuit
shown in Figure 12-1. CAUTION: The PIA is a static sensitive
MOS device; handle it properly as described below.
Keep this device (and all other static sensitive devices) with
all pins plugged into the conductive foam until it is ready for
use. Before you remove a MOS device from its protective foam,
ground both the foam and yourself. Remove the device from
the foam and insert it into the breadboard. Hook up power and
ground immediately at the proper pins.
+5V
120

T
R
A
I
N
E
13
S
I
G
N
A
L
S

DO 33 DOVCC
D132 D1
D231 D2
D3-3-6 D3
D4 29 D4
28
D5 D5
27
D6 D6
PIA
I/O 0 D7T5-, D7
E Ti E
1
3; CS2
+5V AO RS1
24
6 CS1
A1 RSO
22
CSO
T
I L Riw
RESET L4

GND
I1

SS
PAD
PA1
PA2
PA3
PA4
PA5
PA6
PA7

PBO
PB1
PB2
PB3
PB4
PB5
PB6
P87

2
3
4
5
6
7
8

10
11
12
13
14
15
16
17

0
1.
2
3
4
5
6
7

B INA R Y SWIT CHES


( ONTRAINE R)

2-2

2
3
4
5
6
7

Figure 12-1
Circuit diagram for the first PIA experiment.

2. Carefully reexamine the circuit you constructed.

EXPERIMENT TWELVE INTRODUCTION TO THE PERIPHERAL INTERFACE ADAPTER 1

3. Switch the Trainer power on. Then enter the program listed in
Figure 12-2.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
0018
001C

CE
00
00
FF
B3
02
CE
00
FF
FF
B3
00
CE
04

04
FF
B3
02
B6
B3
00
01
01
01
B7
B3
01
20
F5

MNEMONICS/
CONTENTS
LDX#
00
00
STX$$
B3
02
LDX#
00
FF
STX$$
B3
00
LDX#
04
04
STX$$
B3
02
LDA$$
B3
00
NOP
NOP
NOP
STA$$
B3
01
BRA
F5

COMMENTS

Clear bit 2 of both control


registers

Configure port A for input and


port B for output

Set bit 2 of both control


registers

Read switch data from port A

No operation

Write switch data to port B

Do it again

Figure 12-2
Program for data input and output.

4.

Set all of the binary data switches to their down (logic 0)


position. Then execute the program. The display will go blank.

5.

Randomly set the data switches and observe the data LEDs.
Notice that the LED corresponding to each switch follows the
logic level of the switch.

6.

Change the instruction at address 001616 to 4316.

7.

Execute the program and again randomly set the data switches.
Notice that the data LEDs now show the complement logic
level of the switches.

1 2-3

12-4 I LABORATORY MANUAL


8. Refer to Figure 12-2 and briefly describe the PIA initialization
service routine sections of the program.

DISCUSSION
We will begin with a discussion of address decoding for the PIA. As
you are aware, the PIA has three chip select and two register select
lines. The CSO and CS/ chip select lines are active high, while the
CS2 line is active low. From Figure 12-1, you find that CSO and CS1
are connected together and hard-wired to the -F5V supply. As a
result, these two lines are always activated. The CS2 line is
connected to the I/O 0 output line on the Trainer. This Trainer
output line is internally decoded so that it generates a logic 0 for
any address within the range B30016 through B3FF16. Thus, the
PIA is selected via CS2 whenever the MPU generates an address
within this range.
Now, observe from Figure 12-1 that MPU address lines AO and Al
are connected to PIA register select lines RS1 and RSO, respectively. These connections, along with the CS2 connection to the
Trainer I/O 0 output line produce the PIA register address assignments shown in Figure 12-3.

ADDRESS

PIA REGISTER

B300
B301
B302
B303

DRA/DDRA
DRB/DDRB
CRA
CRB

Figure 12-3
PIA register selection.

EXPERIMENT TWELVE - INTRODUCTION TO THE PERIPHERAL INTERFACE ADAPTER

Recall that the PIA RESET pin clears all the PIA registers and is
normally used at system turn-on. Therefore, it is connected to the
MPU RESET line.
The R / W pin on the PIA controls the direction of data flow in the
PIA. Thus, it is connected to MPU R I W line.
The PIA Enable (E) pin synchronizes data transfer between the
PIA and MPU. As a result, it is connected to the E clock line of the
MPU.
Data pins 0 through 7 are connected to the MPU data bus for device
communication.
PIA port lines PAO through PA7 can be programmed as inputs or
outputs. In this experiment, they are programmed as inputs and
are connected to the binary data switches.
PIA port lines PBO through PB7 can also be programmed as inputs
or outputs. In this experiment, they are programmed as outputs
and are connected to the data LEDs. Normally, port B is used as- an
output because of its extra drive capabilities.
As you learned in Unit 10, the PIA must be initialized before it can
function properly. This is accomplished through a software routine. Because initialization is accomplished by software, the PTA's
operation can be modified at any time during the program.
When the PIA receives a reset pulse, its six registers are cleared.
Thus, whenever the Trainer RESET key is pressed, the PIA is
reset. For this reason, the PIA must be initialized after each reset.
The program you entered (Figure 12-2) used the instructions in
addresses 0000 through 001316 to initialize the PIA. This programs
port A of the PIA as an input. Then, 0416 was loaded into control
register A. This sets bit 2 of the control register high, which
isolates the data direction register and accesses the data register.
In a like manner, port B of the PIA is set up as an output by loading
FF16 into the data direction register. Then the data direction
register is isolated and the data register accessed by loading 0416
into the control register.
The remaining steps in the program comprise the service routine.
The MPU reads data from port A of the PIA and stores it to port B.
Once the PIA is initialized, it functions as programmed until it is
reset.

1 2-5

1 2-6 I LABORATORY MANUAL


When you changed the instruction at address 001616 to 4316, you
instructed the MPU to complement the data in the A accumulator
before storing the data.

PROCEDURE (Continued)
9.

Reset the Trainer and examine the PIA registers at addresses


'B30016 through B30116. You should find that they are all
cleared to zero as a result of the reset operation. In addition,
observe that all of the binary LEDs have gone blank as a result
of port B being cleared.

10. Enter the subroutine listed in Figure 12-4, beginning at address 003016 as shown.
HEX
HEX
ADDRESS CONTENTS
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
003A
003B

C6
05
CE
FF
FF
09
26
FD
5A
26
F7
39

MNEMONICS/
CONTENTS
LDB#
05
LDX#
FF
FF
DEX
BNE
FD
DECB
BNE
F7
RTS

COMMENTS

INNER
DELAY
LOOP

OUTER
DELAY
LOOP

Figure 12-4
Delay subroutine for the PIA.

11. Change addresses 001516 through 001716 of the main PIA


program as follows:
0015 BD JSR
0016 00
00
0017 30
30
12. Set the binary switches to any random pattern and execute the
main program at address 000016. After about two seconds, the
LEDs should indicate the binary switch setting.

EXPERIMENT TWELVE - INTRODUCTION TO THE PERIPHERAL INTERFACE ADAPTER 1

13. Change the value at address 003116 to any arbitrary value and
execute the main program at address 000016 again. How does
this value affect the amount of time delay before the LEDs
indicate the binary switch setting?

DISCUSSION
In step 11, you inserted an instruction into the main PIA program
that calls the subroutine you entered beginning at address 003016 _
This subroutine (Figure 12-4) is a delay subroutine that employs
both accumulator B and the X index register. The inner loop of the
delay decrements the X register from FFFF16 down to 000016 for
each iteration of the outer loop of the delay. Thus, the number of
times the inner loop is executed is controlled by the outer loop.
This, in turn, is controlled by the value loaded into accumulator B
at address 003116. In general, the higher the value the longer the
delay. However, the longest delay is created using a value of 0016.
Why?

Save your PIA circuit for the next experiment, if possible.

1 2-7

EXPERIMENT THIRTEEN - DISPLAY MULTIPLEXING USING THE PIA

EXPERIMENT 13
DISPLAY MULTIPLEXING
USING THE PIA
Objectives:
1. To review PIA interfacing, addressing, and initialization.
Show how to multiplex two 7-segment LED's using ports A
and B of the PIA.
2. To show how different refresh rates effect the display:
Demonstrate the effect of using different display on times.
3. To show how the MPU interrupt request ( IRQ ) line can be
used for display refreshing.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 6821 PIA integrated circuit (#443-1014)
2 TIL312 7-segment LED (#411-831) or 5082-7731 7-segment
LED (#411-875)
2 2N3904 NPN transistors (#417-875)
8 47 Q, 1/4-watt, 5% resistors (#6-470-12)
1 3300 CI, 1/4-watt, 5% resistor (#6-332-12)
1 .01 0' capacitor (#21-185)
Hook-up wire

INTRODUCTION
In order to display words and messages using a 7-segment LED
display, several displays must be multiplexed together from a
common display bus. Display multiplexing (sequentially turning
on one display at a time) must be used for multiple character
displays to conserve on hardware, software, and MPU time.
In this experiment you will multiplex two 7-segment LEDs using
the PIA. The common character code display bus is provided by
port A, with port B used to perform the multiplexing operation. The
displayed message is periodically refreshed under interrupt control by using the interrupt request (IRQ ) input line.

1 3-1

1 3-2 I LABORATORY MANUAL

PROCEDURE
1. Switch the Trainer power off and construct the circuit shown
in Figure 13-1. Install the 6821 PIA, and the transistors and
7-segment LEDs on the Trainer connector block. Use caution
when you handle the PIA, since it is a MOS device and
sensitive to static electricity. Make sure you are grounded, and
avoid touching the pins.
+5V
2N3904
EBC
01
+5V GND
20
D0 33 DO
32
D1

1
PAO
PA 1

D1

D2 31 D2
30
D3 D3
29
D4 D4

PA2
PA3
PA4

R1-R8
47Q

2N3904
(BOTTOM)
a

4
5

7
D528 D5
PA5
8
2
D6
7 D6
PA6
9
2
D7
6 D7 6821 PA7
PIA
I/O0 E 25 E
10
PBO
I
23 ET2
35
RS1
+5V A 0

"s/sA.--

24
CS1
36
Al RSO

14

d
e

2
11

0
LI

DP

+5V

2N3904

02

22

P81

CSO
Rivi 21 Rriv-

11
14

RESET 34 RESET
Um.

13

a 1

10

f 2

BINARY SWITCH

ANODE 3

1
.01 NF

Inset

33000

+5V

b
C
d
1

11
9
IRO

9
DP

14 ANODE
13 b
a

11 g lb
11 9
el lc
10 c
DECIMAL
DECIMAL
9
POINT 6
POINT
e 7
8 d

Figure 13-1

Circuit diagram for LED multiplexing experiment.

2. Connect a wire from the IRQ terminal provided on the Trainer


through an RC network to one of the binary data switches as
shown in the inset. Set the data switch to its logic 1 position.

EXPERIMENT THIRTEEN DISPLAY MULTIPLEXING USING THE

HEX
HEX
MNEMONICS/
ADDRESS CONTENTS CONTENTS
0000
0001
.0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119

CE
FF
FF
FF
B3
00
CE
04
04
FF
B3
02
CE
01
CO
FF
69
2B
3E
20
FD

CE
89
01
FF
B3
00
86
FF
4A
26
FD
CE
F9
02
FF
B3

LDX#
FF
FF
STX$$
B3
00
LDX#
04
04
STX$$
B3
02
LDX#
01
00
STX$$
69
2B
WAI
BRA
FD

LDX#
89
01
STX$$
B3
00
LDA#
FF
DECA
BNE
FD
LDX#
F9
02
STX$$
B3

00

00

86
FF
4A
26
FD
7F
B3
01
3B

LDA#
FF
DECA
BNE
FD
CLR
B3
01
RTI

COMMENTS

Configure ports A and B for


output

Store Tri0 interrupt vector

Wait for interrupt


Branch back to WAI
Enter NMI, Exm Mem and
0100 to continue programming
at address 0100

Store character code to port A


and turn on first LED.

Delay

Store character code to port A,


turn on second LED, and turn off
first LED.

Delay

Turn off second LED


Return from interrupt

Figure 13-2
7-segment LED multiplexing program.

PIA 11 3-3

13-4 I LABORATORY MANUAL

3. Switch the Trainer on and enter the program listed in Figure


13-2. Press RESET after the program has been entered.
4. Execute the program by pressing GO and entering the beginning program address (0000).
5. Actuate the binary data switch that was connected to the MPU
IRQ interrupt input line. Each time you provide a high-to-low
transition with the switch, the message "H I" should flash on
the LED displays. This happens very quickly, so try it several
times paying careful attention to the displays on the breadboard as you switch from high to low on the data switch.

DISCUSSION
The PIA decoding circuit assigns the PIA registers to addresses
B300 through B303 as shown in Figure 13-3. The program in
Figure 13-2 first initializes the PIA by configuring both ports (A
and B) for output. The RESET operation clears all the PIA registers. Therefore, you can access the PIA data direction registers
immediately. The program stores all 1s (FF) in both data direction
registers from the MPU index register. This can be done since the
data direction registers are located in consecutive memory locations (B300, B301). After configuring the data direction registers,
the program sets bit 2 of each control register for subsequent data
transfer operations via the port data registers. The program then
waits for an interrupt to occur.

Address

PIA Register
Assignment

B300

Port A data reg. or data direction reg.

B301

Port B data reg. or data direction reg.

B302

Port A control register

B303

Port B control register

Figure 13-3

PLA register assignments for the circuit in Figure 13-3.

EXPERIMENT THIRTEEN - DISPLAY MULTIPLEXING USING THE PIA

When the binary data switch makes a high-to-low transition, an


Q is generated to the MPU. The Trainer IRQ interinterrupt (Ti)
rupt vector is 0100. Therefore, when an IRQ interrupt occurs, the
MPU vectors to address 0100 to execute the interrupt service
routine. The interrupt service routine multiplexes the displays.
The display multiplex routine uses the MPU index register to write
information simultaneously to both ports A and B of the PIA. Port
A provides the display character code and port B multiplexes the
two displays via the two control transistors (Q1 and Q2).
The first character code (89) is loaded into the high byte of the
index register and the multiplex code (01) is loaded into the low
index register byte. When the
STX $$
B3
00
instruction is executed, the character code is transferred to port A
at address B300 and the multiplex code is transferred to port B at
address B301.
The multiplex code (01) sets PBO which turns on transistor Ql. The
transistor then enables the first display.
A delay of approximately 1.0 millisecond is provided before the
next display is enabled. This delay is required to give the LED
sufficient time to illuminate properly.
After the delay, the second character code (F9) is loaded into the
high index register byte and the multiplex code (02) is loaded into
the low index register byte. The store instruction then provides the
second character code to port A and the associated multiplex code
to port B. This multiplex code sets PB1 to enable the second display
via transistor Q2. Note that the first display is turned off since PBO
is cleared.
After another 1.0 millisecond delay, the second display is turned off
with the clear-port B operation. The program then returns to the
main program and wait for another interrupt to occur.

1 3-5

13-6 I LABORATORY MANUAL

PROCEDURE (Continued)
6.

Reconnect the IRQ interrupt line to the 1 Hz connection


provided on the Trainer. The message should now flash on and
off very quickly once every second. Since you are now providing a display interrupt at a 1 Hz rate. Of course this is not
acceptable since you must refresh the displays at a higher rate
to prevent flickering and create the illusion of a constant
display.

7.

Reconnect the IRQ interrupt line to the 60 Hz connection


provided on the Trainer. The message should now appear
constant, since you are refreshing the display at a 60 Hz rate.
Actually, the display is turning on and off sixty times per
second, but your eye retains the image between refresh cycles
such that the display appears constant and doesn't flicker. For
this reason, refresh rates above 30 Hz must be provided. Even
at the 60 Hz rate, the MPU has plenty of time between refresh
cycles to perform other tasks.

8.

Remove the refresh interrupt line from the 60 Hz connector.


Reconnect the IRQ interrupt line to the E-clock (E) signal on
the trainer connector block. You should now see a brighter
display of the message "H I" on the 7-segment displays. This is
because the information is being refreshed at the frequency of
the E-clock, approximately 921 kHz.
Remove the IRQ jumper from the E-clock (E). Leave the IRQ
jumper unconnected for the moment.

9.

RESET the system and change the value located at program


addresses 0107 and 0112 to 10. Execute the revised program.

10. Re-insert the refresh interrupt line in the 60 Hz LINE connector.

EXPERIMENT THIRTEEN - DISPLAY MULTIPLEXING USING THE PIA

DISCUSSION
In step 10, you should observe that the displays are much dimmer.
This is because the revised program shortens the time delay loops
which control the length of time that each display is on during each
refresh cycle. By changing the software delay time, you are changing the average amount of current to the display, and therefore
directly controlling its brightness level.
A word of caution: Since we are not using current limiting resistors, too long of a delay loop creates an excessive average current
and might result in damage to the LED display and/or the PIA.
Therefore, none of the displays should be on for more than 1.0-2.0
milliseconds with this circuit arrangement.
You might want to get various brightness levels by storing different values in program addresses 0107 and 0112. Remember to
change the program and rerun it, you must disconnect the clock
(refresh) end of the IRQ to clock jumper; and reset the trainer. After
the program change is made, you should rerun the program and
then reinsert the open end of the IRQ jumper into one of the clock
signals 1 Hz, 60 Hz, or E. Try different combinations of "ontimes" and "refresh-rates" by changing the values at addresses
0107 and 0112 along with different refresh rate signals. Notice
that even with a shorter on-time the refresh rate greatly effects the
brightness of the display. For example, with the value 01 placed at
addresses 0107 and 0112 and the program running, using a 1 Hz
refresh rate does not even cause the displays to be visibly lit. A 60
Hz rate just make the displays barely visible. However, the nearly
1 MHz rate of the E-clock makes the displays quite visible.
In addition, you can change the display characters by changing the
character codes located at addresses 0101 and 010C. A table of 7segment LED character codes is provided in Figure 13-4. The 7segment LEDs are common anode type LEDs.
Save the PIA circuitry. This same circuit will be used for the next
experiment.

1 3-7

13-8 I LABORATORY MANUAL

n m m a. nIT31_OM _I rri1 il C will-0

IT I 1 I IO m 0 D DI -/-LrCC
c
ritri% 7

N .0 X * < C "*" (/)

" 0 -ri

0 mK 1

X r M G)mma 0

C C
CaK)
0- >ODCO--NIb n41'
--

Display

Common Cathode

Common Anode

3F
06
5B
4F
66
6D
7D
07
7F
67
77
7C
39
5E
79
71
BD
76
19
1E
70
38
37
54
65
73
6B
50
2D
78
1C
72
3E
64
6E
1B

CO
F9
A4
BO
99
92
82
F8
80
98
88
83
C6
Al
86
8E
42
89
E6
El
8F
C7
C8
AB
9A
SC
94
AF
D2
87
E3
8D
Cl
9B
91
E4

Figure 13-4
Hexadecimal character codes for common-cathode and
common-anode 7-segment LEDs.

EXPERIMENT FOURTEEN - I/O CONTROL AND HANDSHAKING USING THE

EXPERIMENT 14
110 CONTROL AND HANDSHAKING
USING THE PIA
Objectives:
1. To show how the PIA control registers are configured for
various I/O control operations.
2. To demonstrate the use of the PIA input control lines to
control input operations.
3. To demonstrate the use of the PIA output control lines to
control output operations.
4. To demonstrate a complete output handshake operation via
the PIA using a polling routine.
5. To demonstrate a complete output handshake operation via
the PIA
using interrupt control.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 6821 PIA integrated circuit (#443-1014)
1 Pushbutton switch (#64-910) with cover-cap installed
1 1000 Q, 1/4-watt, 5% resistor (#6-102-12)
Hookup wire

INTRODUCTION
In this experiment you will see how the PIA can be used to control
input and output operations between the MPU and an external
device. The initial sections of the experiment familiarize you with
how to configure the PIA control registers for input and output
control operations using the PIA control lines. The remaining
experiment sections show you how to perform handshaking operations using both programmed control and interrupt control techniques.

PIA

1 4-1

1 4-2

1 LABORATORY MANUAL

PROCEDURE
1. Switch the Trainer power off and construct the circuit shown
in Figure 14-1A. If you saved the circuit from Experiment 13,
simply disconnect the 7-segment LEDs and transistors from
ports A and B of the PIA and connect the pushbutton and pullup resistor as shown in Figure 14-1A. Disconnect the MPU
interrupt request (IRQ ) connection that you made in the
previous experiment. All of the other PIA interface connections on the Trainer connector block are the same as those used
in Experiment 13.
+5V

GND
120
T
R
A
N
E
R
S

G
N
A
L
S

I/O 0

33
DO -.
32
D1 31
D2 30
D3 29
D4
28
05 -
27
D6 26
D7-25
E -.g
23

I1

DO

1000 OHM

Di
D2
D3

CA1

S1

40
0

0-1

D4
05
D6

TO ANY DATA

D7
E

CA2

____Iii. LED (CONNECTOR


39
TERMINAL) ON
TRAINER

6821
PIA

CS2
35
AO
+5V
RS1
24
CS1
36
Al -, RSO
22
CSO
21
R/171
R/W
34
RESET-- RESET

+5V

1000 OHM

Si

CB2

TO ANY (UNUSED)
DATA LED
(CONNECTOR TERMINAL)
ON TRAINER

Figure 14-1

Circuit diagram for first part of I/O control experiment.

EXPERIMENT FOURTEEN

I/O

CONTROL AND HANDSHAKING USING THE

2. Switch the trainer on and enter the program listed in Figure


14-2. Press RESET after the program has been entered.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008

86
24
B7
B3
02
B6
B3
00
CF

MNEMONICS/
CONTENTS
LDA#
24
STA$$
B3
02
LDA$$
B3
00
STOP

COMMENTS

Configure port A control register


as shown in Figure 14-3

Figure 14-2

Program to configure port A control register.

3.

Execute the program by pressing GO and entering the beginning program address (0000).

4.

Press NMI and examine the port A control register at address


B302. You should find the hex value 24 (0010 0100) stored
there by the program.

5.

Press the pushbutton. You have just activated the CAI input
control line. The data LED should go on, indicating that the
CA2 output control line has gone from a low-to-high state,
acknowledging the active CA1 input line.

6.

Press NMI and examine the port A control register again at


address B302. You should observe its contents to be A4 (1010
0100). Note that by activating the CAI control line, the CA1
status flag (bit 7) in the control register has set.

7.

Now, press NMI and examine the port A output register at


address B300. You should observe that the data LED has gone
off. Why? Because when you examined address B300, you
performed a "read port A" operation which clears the CAI
status flag and causes the CA2 output control line to return to
its normal low state.

8.

Verify that the CAI status flag has cleared by examining the
port A control register contents at address B302. You should
find the value 24 (0010 0100), indicating that the CAI status
flag is cleared and ready for another active CAI input.

PIA 1

4-3

14-4 1 LABORATORY MANUAL


DISCUSSION
The PIA decoding circuit assigns the PIA to addresses B300 through
B303, as in the previous experiment. The program stores the hex
value 24 at address B302 and thus configures the port A control
register as shown in Figure 14-3. This configuration defines an
active CAI to be a high-to-low transition and designates CA2 as an
output line.
ADDRESS
B302
(B303)

7 6 5 4 3 2 1

CA1 STATUS
(CBI)
CA2 STATUS
(CB2)

M----CA 1 CONTROL
(CI31)
DR/DDR ACCESS
CA2 CONTROL
(CB2)

Figure 14-3
Port A (B) control register configuration per the program in Figure 14-2.

By pressing the pushbutton, you activate CA1. This causes the CA1
status flag (bit 7) in the port A control register to set. In addition,
the CA2 output line goes from a low-to-high state, indicating an
active input. The CAI status flag and CA2 output line then remain
high until a "read port A" operation is performed. This is done when
you examine address B300. The CA1 and CA2 control line activity
is summarized in Figure 14-4.
NORMALLY HIGH DUE TO
PULL-UP RESISTOR

CA1

PUSHBUTTON PRESSED-4-L-f-j"-PUSHBUTTON RELEASED


(ACTIVATE))
1
I
I
ACTIVE CA1 -1
CA2

i-READ PORT A

Figure 14-4
Summary of CA1 and CA2 control line activity for first part of experiment.

EXPERIMENT FOURTEEN - I/O CONTROL AND HANDSHAKING USING THE

PROCEDURE (Continued)

9. Switch off the Trainer and reconnect the circuit as follows:


Remove the pushbutton wire and 1 KSZ pull-up resistor from
pin 40 (CA1) and connect them to pin 18 (CB1), as shown in
Figure 14-1B.
Remove the data LED wire from pin 39 (CA2) and connect
it to pin 19 (CB2).
Switch the Trainer on and, if necessary, re-enter the program listed in Figure 14-2.
10. Change the value at program address 0004 to 03, 0005 to B7,
and 0007 to 01.
11. You will now verify the activity of CB1 and CB2 for an output
operation. Press RESET and execute the program.
12. Press NMI and examine the port B control register at address
B303. You should find the value 24 (0010 0100), which was
stored there by the program.
13. Press the pushbutton. You have just activated the CB1 input
control line. The data LED should go on, indicating that the
CB2 output control line has gone from a low to high state,
acknowledging the active CB1 input line.
14. Press NMI and examine the port B control register again at
address B303. You should observe its contents to be A4 (1010
0100). By activating the CB1 control line, the CB1 status flag
(bit 7) in the control register has set.
15. Press NMI and examine the port B output register at address
B301. Note that the data LED does not go out. Why? The
examine operation performs read port B operation. To deactivate the CB2 output line, a write port B operation must be
performed.
16. Now change the contents of address B301 to any value. The
data LED should go off, indicating that the CB2 has gone low
as a result of the write port B operation.
17. Press NMI and verify that the CB1 status flag (bit 7) has
cleared by examining the port B control register contents at
address B303.

PIA 1

1 4-5

1 4-6 I

LABORATORY MANUAL

DISCUSSION
The revised program configures the port B control register as
shown in Figure 14-3. This configuration defines an active CB1 to
be a high-to-low transition and designates CB2 as an output line.
By pressing the pushbutton, you activate CB1. This causes the CB1
status flag (bit 7) in the port B control register to set. In addition,
the CB2 output line goes from a low-to-high state, indicating an
active input. The CB1 status flag and CB2 output line then remain
high until a "write port B" operation is performed. This is done
when you change the contents of address B301. The CB1 and CB2
control line activity is summarized in Figure 14-5.
In the next part of this experiment, you will see how a polling
routine is used to control a complete output handshake operation
via CB1 and CB2.
CB1
PUSHBUTTON PRESSED-4_ J.-PUSHBUTTON F RELEASE

ACTIVE CBI-.

WRITE
PORT B

CB2

Figure 14-5

Summary of CB1 and CB2 control line activity for second part of experiment.

EXPERIMENT FOURTEEN

I/O

CONTROL AND HANDSHAKING USING THE

PROCEDURE (Continued)
18. Enter the program listed in Figure 14-6.
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
0018
001C
0010
001E
001F

86
24
B7
B3
03
B7
B3
01
B6
B3
03
2A
FB
C6
OC
CE
FF
FF
09
26
FD
5A
26
F7
B6
B3
01
B7
B3
01
20
E8

LDA#
24
STA$$
B3
03
STA$$
B3
01
LDA$$
B3
03
BPL
FB
LDB#
OC
LDX#
FF
FF
DEX
BNE
FD
DECB
BNE
F7
LDA$$
B3
01
STA$$
B3
01
BRA
E8

COMMENTS

Configure port B control register


for a complete output handshake

Poll the CB1 status flag.

Delay approximately 5 seconds.

Write to port B to complete the


handshake

Do it again

Figure 14-6
Port B handshake control program.

19. Press RESET and execute the given program.


20. Press the pushbutton. The CB2 data LED should come on,
indicating that an active CB1 has been detected. After approximately five seconds, the CB2 data LED should go off,
indicating that a "write port B" operation has taken place and
the handshake is complete. Push the button again, just in case
you missed the action.

PIA

1 4-7

14-8 1LABORATORY MANUAL

DISCUSSION
The program in Figure 14-6 first configures the port B control
register for a complete output handshake using CB1 as an input
control line and CB2 as an output control line. The program then
repeatedly polls the status of the CB1 flag (bit 7) in the port B
control register. As long as the CB1 line is inactive, the bit 7 status
flag is cleared. This indicates a positive quantity in the control
register and the program loops as a result of the BPL (branch if
plus) instruction. Recall that the most significant data bit (bit 7)
determines the sign of the data. Now, when you activate the CB1
line by pressing the pushbutton, the bit 7 flag sets and the program
breaks out of the polling loop. A short delay of approximately five
seconds is then provided before the MPU writes to port B. Once the
"write port B" operation takes place, the CB2 line goes back low
and the handshake is complete. The program then branches back
to the polling loop, ready to detect another active CB1 input line.
You might want to take a closer look at the five second delay
routine provided in the program, since it will be used in future
experiments. The delay routine consists of a loop within a loop.
Note that the index register is loaded with the value and then
decremented down to zero. I have found that this takes approximately one-half second. Each time the index register reaches zero,
accumulator B is decremented. Therefore, the value initially loaded
into accumulator B determines the number of times the index
register decrement loop is executed. Note that the value OC is
initially loaded into accumulator B. Thus, a delay of approximately
five to six seconds results. You might want to change the value at
program address 000E and repeat the above steps to achieve
various delay times within the handshake.
Next, you will accomplish the same complete output handshake
using interrupt control.

EXPERIMENT FOURTEEN I/O CONTROL AND HANDSHAKING USING THE PIA 1

PROCEDURE (Continued)
21. Connect a wire from pin 37 ( IRQB ) of the PIA to the IRQ
terminal on the Trainer.
22. Enter the program listed in Figure 14-7.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F
0110
0111

MNEMONICS/
CONTENTS

86
25
67
B3
03
B7
B3
01
CE
01
00
FF
69
2B
3E
20
FD

LDA#
25
STA$$
B3
03
STA$$
B3
01
LDX#
01
00
STX$$
69
2B
WAI
BRA
FD

C6
OC
CE
FF
FF
09
26
FD
5A
26
F7
B6
B3
01
B7
B3
01
3B

LOU
OC
LDX#
FF
FF
DEX
BNE
FD
DECB
BNE
F7
LDA$$
83
01
STA$$
B3
01
RTI

COMMENTS

Configure port B control register


for a complete output handshake.

Store IRO interrupt vector.

Wait for interrupt.


Branch back to WAI.

Delay
Approximately 5 seconds.

Write to port B to complete


handshake

Return from interrupt.

Figure 14-7
Port B handshake routine - interrupt control.

1 4-9

14-101LABORATORY MANUAL

23. Press RESET and execute the program.


24. Press the pushbutton. Again, the CB2 data LED should come
on, indicating that an active CB1 input line has been detected.
After the time delay, the CB2 data LED should go off, completing the handshake.

DISCUSSION
The revised program uses the interrupt request (IRQ) of the MPU
to detect an active CB1 input line, instead of a polling routine. Port
B is first configured for a complete output handshake using CB1 as
an input control line and CB2 as an output control line the same as
before. However, note that the hex value 25 (0010 0101) is stored
in the port B control register. This enables the IRQB interrupt line
(pin 37), which has been connected to the MPU IRQ input line.
Thus, when CB1 is active, an interrupt is generated to the MPU.
Once the control register has been configured the IRQ interrupt
vector (0100) is stored to address 692B and the program waits at
address 000E for the interrupt to occur. The interrupt is generated
when you press the pushbutton and thus activate the CB1 input
line. The IRQ interrupt vector is 0100. Therefore, when an IRQ
interrupt occurs, the MPU vectors to address 0100 to execute the
interrupt service routine. After the delay, the program writes to
port B to complete the handshake.

EXPERIMENT FIFTEEN STATIC

RAM

INTERFACING

EXPERIMENT 15
STATIC RAM INTERFACING
Objectives:
1. To interface static RAM to a microprocessor.
2. To demonstrate timing requirements when using memory
circuits.
3. To show how data is stored and read from memory circuits.
4. To demonstrate an elementary memory test to ensure proper,
reliable operation.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 74LS00 integrated circuit (#443-728)
1 74LS27 integrated circuit (#443-800)
1 TC5565 (#443-1422) 8K x 8 CMOS static RAM. Do not remove from conductive foam pad until you are instructed
to do so.
Hookup wire

INTRODUCTION
In this experiment, you will construct a memory circuit on the
large connector block of the Microprocessor Trainer and interface
the circuit with the Trainer circuits. This provide an additional 8K
bytes of read/write memory (RAM) for the Trainer.

1 5-1

15-2

LABORATORY MANUAL

PROCEDURE
1. Switch the Trainer power off.
2. Remove the 443-1422 RAM IC from its protective foam and
construct the circuit shown in Figure 15-1. Then, connect a
wire between ground and the 32KEN connector in the upper
signal connector block.
TRAINER DATA
BUS LINES D0-D7

TTL POWER:
PIN 14: +5V
PIN 7: GND
27
ADDRESS DECODER CIRCUIT

A15
A14

74LS27

A13
2 74LS00
6

20

281

.....D7D6 D5 Da D3 D2 D1 DO
R/W

22
READ- OE
3
4

+5V

D7 D6 D5 D4 D3 D2 D1 DO
191181 171161 151131 121 111

VDD

GND
141
GND

8K x8
STATIC RAM

CE1

26
CE2 A0 Al A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 Al2

101
51 41 31 251 241 211 231 21
1 81 81
A0 Al A2 A3 A4 A5 A6 A7 A8 A9 A10A11 Al2

71 61

Al5
0

Al2 All
0

A8 A7
X

A4 A3

X ix

0-F

X
0-F

AO
X

TRAINER ADDRESS
BUS LINES A0-Al2

0-F

2000.3FFF
DECODED ADDRESSES

Figure 15-1
An 8K x 8 static RAM interface circuit.

3. The memory circuit you have wired now interfaces with the
microprocessor and allows data transfers from address 200016
through 3FFF16. Use the Trainer Examine function and randomly select an address in this memory block. Change the data
at this location to AA16. Press the FORWARD(+) key, then
press the BACK() key. Does the memory still contain the
value AA16?
4. Examine address 400016. Change its contents to AA16. Press
the FORWARD (+) key, then press the BACK () key. Does the
memory still contain the value AA16?
The data you entered in step 3 was retained because of the
memory circuit you wired into the Trainer. The data you
entered in step 4 at location 400016 was not retained because
no memory exists at that location.

EXPERIMENT FIFTEEN - STATIC RAM INTERFACING 1

5. Examine address 200016 and change its contents to AA16.


6. Press RESET, then without switching the Trainer power off,
interchange the D 6 and D 7 wires at the data bus block.
7. Examine address 200016 and notice that the indicated data is
now 6A16 . By interchanging the sixth and seventh data lines,
1010 10102 became 0110 10102. The memory IC still retains
the original data you programmed. To see this relationship,
press RESET then return the two wires to their original
position. Examine address 200016. The correct memory contents should now be displayed.

DISCUSSION
The 74LS27 and 74LS00 ICs shown in Figure 15-1 form an address
decoder. The inputs of this decoder are connected to address lines
A13 through A15.
To enable the 5565 RAM IC the CE1 pin must be at logic 0. This
occurs when A14 and A15 are logic 0 and A13 is logic 1. Therefore,
only address 001 decodes completely. This is the high order three
bits of a 16-bit address. The two zeros generated by A14 and A15 are
decoded by the 74LS27. When these two address lines go to a logic
0, the 74LS27 generates a logic 1 to the 74LS00. Address line A13
is decoded directly by the 74LS00. When A13 goes to a logic 1, the
output of the 74LS00 goes to a logic 0 and the memory is enabled.
The low order thirteen bits of the 16-bit address determine the
memory location in the RAM where data is stored or retrieved. The
5565 is an 8K x 8 static RAM device. Thus, 819210 8-bit data words
can be stored from address 200016 through 3FFF16. In the circuit
shown in Figure 15-1, address bits Ao through Al2 select the
memory location and address bits A13 through A15 select the IC.
Data flow direction is determined by the R / W line. When this line
is at logic 0, the MPU can write into memory. When this line is at
logic 1, the MPU can read from memory. In addition, the OE line
of the 5565 must be low to perform a read operation. Notice that
this line is connected to the READ output line on the Trainer.
You grounded the 32KEN input to the trainer to disable the first
32K bytes of internal trainer RAM. This removes the conflict of two
blocks of RAM being decoded by the same range of addresses.

1 5-3

15-4 I LABORATORY MANUAL


In small microprocessor systems (less than ten devices), the MPU
and its support ICs can be connected directly together. However,
when more circuits are added to the address and data busses the
MPU can no longer supply the necessary power to drive the ICs.
To solve this problem, bus extenders (buffers) are connected between the MPU and most of the surrounding ICs. These supply the
necessary drive current for supplying logic to the additional ICs.
Figure 15-2 illustrates a typical circuit.
INSET #2
INSET #1

ADORES
BUS

UNIDIRECTION ADDRESS
BUS
BUS
EXTENDER

TO ALL
ADDRESS
DECODING
CIRCUITS

MPU
BIDIRECTION
BUS
EXTENDER

R/W

MEMORY
200016
TO 3FFF16
R/W

MEMORY
000016
TO 100016

Figure 15-2

Block diagram of a typical microprocessor system using bus extenders.

The address bus extender is unidirectional. That is, it passes a


signal in only one direction. It consists of 16 individual buffer
drivers, one for each address line.
Unlike address signals, data signals can originate at the MPU or
in peripheral circuits such as memory. Therefore, bidirectional bus
extenders are required. Each data bus extender consists of two 3state buffer drivers wired back-to-back as shown in Inset 2 of

EXPERIMENT FIFTEEN - STATIC

RAM INTERFACING 1

Figure 15-2. The 3-state feature in this case is complementary.


That is, when the read enable (RE) control line is low, the read
buffer is enabled, and when the RE line is high, the write buffer is
enabled. Remember, the terms read and write are always expressed in relation to the MPU.
You may wonder why an RE line is required in addition to the R /
W line. It wouldn't be if all the memory and any other bus operated
devices were electrically connected outside of the bus extenders.
However, in most systems, there are some circuits connected
directly to the MPU, with additional circuits connected to bus
extenders. Thus, the RE control is necessary for valid logic transfer.
During a read cycle, data is transferred to the MPU from memory
or other support devices. When a memory location "down line" from
the bus extender is addressed, the bus extender receives an RE
logic 0 signal, which enables the buffer in the "read" direction. All
devices not addressed, before or after the bus extender, are 3stated into their open circuit configuration. In this case, the R / W
control could have been inverted and connected to the bus extender
RE input. However, if memory "up line" from the bus extender
(MPU side) is addressed, the bus extender must remain in its
"write" configuration. It could not do this if the inverted RI W
control line was used.
Since all of the devices "down line" are 3-stated to their opencircuit condition, the input to the "read" buffer of the bus extender
is undefined and its output assumes a logic level (usually logic 1 for
TTL gates) that could interfere with data transfer. By using an RE
control signal not totally defined by the RI W control, the bus
extender can be forced into its "write" state and prevent any "down
line" interference.

1 5-5

1 5-6 I LABORATORY MANUAL


PROCEDURE (Continued)
8. Refer to Figure 15-3 and enter the program beginning at
address 200016.
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
200A
200B
200C
200D

CE
20
10
86
A5
A7
00
08
8C
40
00
26
F8
CF

LDX#
20
10
LDA
A5
STAA
00
INX
CPX#
40
00
BNE
F8
STOP

COMMENTS
Load X with first address.
Load A with value to store.
Store value to memory.
Next Address.
Last address yet?
If not, do it again.
Job done.

Figure 15-3
A memory block check program.

9.

Press RESET, then press GO and enter address 200016.

10. Press RESET and examine a number of memory locations


between 201016 and 3FFF16. Their contents is A516. You should
be able to single-step through each memory location and verify
that it functions properly by observing that A516 is stored at
each address. By changing the contents at address 200416 to a
different value, say 6A16, and executing the program again,
you can verify the storage of the value. Try it!

DISCUSSION
First, the program in Figure 15-3 writes a constant value to all of
the external (breadboard RAM) memory locations, except for the
area where the program is loaded. Then, you examined those
memory locations to verify that the correct value was in fact stored
there. This is basically the same thing that many microcomputer
systems do during initial power-up to test their own memory

EXPERIMENT FIFTEEN - STATIC

RAM INTERFACING 1

circuits. The system writes a value to all of its memory locations;


then, it reads all of the memory locations and compares the value
obtained to the original stored value. This ensures proper, reliable
memory operation.
Do you know why the program was loaded at address 200016 and
not address 000016? The first 32K bytes of internal trainer memory
is disabled there is no address 000016.

1 5-7

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS

EXPERIMENT 16
MICROPROCESSOR/DAC
INTERFACING AND APPLICATIONS
Objectives:
1. To interface a DAC to a microprocessor.
2.

To demonstrate how to write a program to initialize the PIA


and provide digital-to-analog conversions via the PIA I
DAC interface.

3. To demonstrate how to write programs to generate the


following waveforms from the microprocessor-controlled
DAC circuit:
ramp
triangular waveform
square waveform
4. To show how output waveform frequency and amplitude
are adjusted via hardware/ software techniques.
5. To show how to construct a programmable-gain amplifier
and attenuator using the DAC circuit.
6. To demonstrate how the DAC can be controlled by the
microprocessor to amplify and attenuate analog signals.

MATERIALS REQUIRED
1 1000 CI, 1/4-watt, 5% resistor (#6-102-12)
1 47 SI, 1/4-watt, 5% resistor (#6-470-12)
1 4.7 k5-2, 1/4-watt, 5% resistor (#6-472-12)
1 10 l(S2 potentiometer (#10-1138)
1 .1 F capacitor (#21-192)
1 741C operational amplifier (#442-22)
1 MC1408 DAC (#442-751)
1 6821 PIA (#443-1014)
1 ETW-3800 Microprocessor Trainer
1 VOM or DVM
1 Oscilloscope

1 6-1

1 6-2

I LABORATORY MANUAL

INTRODUCTION
In this experiment, you will see how a Digital-to-Analog (DAC) can
be controlled by a microprocessor to perform programmable control
tasks. We will show you how to program the ETW-3800 to generate
various signals and waveforms via the DAC circuit. Finally, you
will see how the microcomputer controlled DAC circuit developed
in this experiment can be used as a programmable gain amplifier
and attenuator.
For clarity, we have divided this experiment into three major
sections: "The DAC Interface," "Waveform Generation," and "Programmable Gain Amplifier and Attenuator." The latter sections of
this experiment require an oscilloscope so you can observe the
various outputs provided by the DAC circuit. However, if you do not
have an oscilloscope, we suggest you still perform the related
experiment steps, because we have provided pictures of the resulting oscilloscope displays.

The DAC Interface


PROCEDURE
1. Construct the PIA/DAC interface circuit shown in Figure 161.
+5V GND
120
DO 33
32
D1
31
D2
30
D3

11
-12V

DO
+ 5V

D1

D2

D4 29 D4
28
D5- 05
27
D6
D6
1/00
26
D7
25
E
E
23
CS2
35
+5V
RS1
AO
CS 1
Al 3264 RSO
22
CSO
Ro.T., 21
R /W
4
RST 3 RE ET

13

D3

PBO
PB1
PB2
6821
PIA

PB3
PB4
PB5
PB6
PB7

10

12

11

11

12

10

13
14
15
16
17

DO

.1pF

V EE

D1

COMP

D2

V REF(+)

D3

CC

D4
05
D6

DAC CIRCUIT

MC1408
DAC

6T
14 4.71(0 +5V (VREF)

R REF

OUT
v REF(.)

15 470

D7

1k0

Figure 16-1
A microprocessor-controlled DAC circuit.

0-10kt-2
(Rf )
+12V
7

EXPERIMENT SIXTEEN MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

2.

Turn the Trainer power on and enter the program listed in


Figure 14-2.

3.

Connect a voltmeter or oscilloscope to the output of the DAC


circuit at pin 6 of the op amp. Set the voltmeter or oscilloscope
to a range that permits you to measure 0 to 10 VDC. Set your
scope for DC coupling of the input signal.

4.

Execute the program by pressing GO and entering the beginning program address 0000.

5.

Observe the voltmeter or oscilloscope and adjust the op amp


feedback resistor, Rf, such that you obtain an output voltage of
10 volts.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
0000
000E
000F

86
FF
B7
B3
01
86
04
B7
B3
03
86
FF
B7
B3
01
CF

MNEMONICS/
CONTENTS
LDA #
FF
STA $$
B3
01
LDA #
04
STA $$
B3
03
LDA #
FF
STA $$
B3
01
STOP

COMMENTS

Configure port B of the PIA for


output.

Store the hex value FF to the


DAC (port B).

Figure 16-2
PIA initialization program for the DAC interface circuit in Figure 16-1.

6.

Press NMI and examine memory location B301. You should


find the value FF16 stored at this location. Address B301 is the
address of the port B data register. The program in Figure 162 configures port B for output, and then stores the value FF16
to the DAC via the port B data register at address B301.

7.

Change the contents of address B301 to 0016 and observe the


output voltage reading. You should observe an output voltage
of 0 volts.

1 6-3

1 6-4 I LABORATORY MANUAL


8.

Change the contents of address B301 to 8016 and observe the


output voltage reading. You should now observe an output
voltage reading of approximately 5 V.

9.

Change the contents of address B301 to any desired value(s)


and observe the output voltage reading. You should observe a
0 to 10 V unipolar reading that is proportional to the digital
value located at address B301.

DISCUSSION
You have just interfaced a DAC to the ETW-3800 Trainer via a PIA.
Because the DAC circuit is connected to port B of the PIA, the
program in Figure 16-2 first configures port B for output. Then the
value FF is stored to the port B data register located at address
B301. This value should provide the maximum output level from
the DAC circuit, since the DAC circuit is now connected to provide
a unipolar output. You then adjusted the op amp feedback resistor,
Rf, to set the DAC circuit for a 0 to 10 volt output range. By
changing the contents of the port B data register at address B301,
you were changing the digital input value to the DAC. Consequently, the DAC circuit provided a proportional analog voltage
within the 0 to 10 V unipolar output range. Now let's observe some
applications of this microprocessor-controlled DAC circuit.

ADDRESS
8300
B301
B302
B303

PIA REGISTER
ASSIGNMENT
Port A data reg. or data direction reg.
Port B data reg. or data direction reg.
Port A control register
Port B control register

Figure 16-3

The PIA register assignments provided by the circuit in Figure 16-1.

EXPERIMENT SIXTEEN MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

Waveform Generation
PROCEDURE
1. RESET the Trainer and enter the ramp generating program
listed in Figure 16-4.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014

86
FF
B7
B3
01
86
04
B7
B3
03
7C
B3
01
CE
00
00
08
26
FD
20
F5

MNEMONICS/
CONTENTS
LDA #
FF
STA $$
B3
01
LDA *
04
STA $$
B3
03
INC $$
B3
01
LDX *
00
00
INX
BNE
FD
BRA
F5

COMMENTS

Configure port B for output.

Increment port B output register.

Delay.

Repeat

Figure 16-4
A ramp waveform generator program.

2.

Execute the program by pressing GO and entering the beginning program address, 0000. Observe the output voltage indication. You should observe that the output voltage increases
from 0 to 10 volts very slowly. Once the 10-volt level is reached,
the output level drops back to 0 volts and begins slowly
increasing again.

3.

RESET the Trainer and change the contents of memory location 000E to FO.

4.

Execute the program again by pressing GO and entering the


beginning program address, 0000.

1 6-5

1 6-6 I

LABORATORY MANUAL

5. Observe the output voltage indication. This time, the rate of


increase has increased. Why?

6.

RESET the Trainer and change the contents of memory location 000E to FF and memory location 000F to F5.

7.

Execute the program again and observe the output voltage


indication. If you are using a voltmeter, you should observe a
relatively constant 5 V output. However, if you are using an
oscilloscope to measure the output, you should observe the
ramp waveform pictured in Figure 16-5. Notice that the waveform has an amplitude of 10 V and a frequency of approximately 47 Hz.* The voltmeter reading of 5 volts represents the
average level of the output waveform since a voltmeter cannot
"follow" the higher waveform frequencies.

1 I

I A

1 1

I 1

II

_
.
SCOPE SETTING
2 V/CM
5 mS/CM

Figure 16-5
The ramp output generated by the program listed in Figure 16-4.

* Note: Your results might be slightly different due to component tolerances and
variations in measurement instruments.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

Now, if you were to expand the oscilloscope time base and volts/
division setting, you could observe the DAC output steps, or
staircase; as pictured in Figure 16-6. Try it! Notice that the stepsize is approximately 40 millivolts. This value makes sense because the calculated step-size for this DAC circuit is:
Step size = 21, x 10 volts
=

x 10 volts
256
= 39 millivolts

III 1

I1

Figure 16-6
The output steps, or staircase, generated by the MC1408 DAC.

8. RESET the Trainer and change the contents of memory location 000F to FF.

1 6-7

1 6-8 I LABORATORY MANUAL


9. Execute the program again and you should observe the ramp
pictured in Figure 16-7. Notice that its frequency has now
increased to approximately 200 Hz. Why?

SCOPE SETTING
2 V/CM
5 mS/CM

Figure 16-7
An increased ramp frequency obtained by a shorter time delay
in the ramp generating program.

DISCUSSION
The program listed in Figure 16-4 first configures port B of the PIA
for output. The port B data register located at address B301 is then
repeatedly incremented to provide the ramp output. The output
voltage increases to its maximum level (10 volts) when the value in
the port B output register is FF16. The output voltage then falls to
0 volts when the value FF16 is incremented to 0016.
The MPU index register is being used to create a delay within the
increment loop and, thus, control the ramp waveform frequency. At
first, the index register is loaded with the value 000016. Then it is
incremented from 000016 to FFFF16 each time the output value to
port B is incremented. This results in an extremely low output
frequency. In fact, the output frequency is so low that voltmeter
changes can barely be seen.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

The second time the program was executed, the MPU index register was loaded with the value F00016. This resulted in a higher
output frequency because the index register was incremented from
F00016 to FFFF16 each time the output value to port B was
incremented. You observed that the voltmeter movement was more
rapid.
The third time the program was executed, the MPU index register
was loaded with the value FFF516. The index register was then
only incremented between FFF516 and FFFF16 each time port B
was incremented. This relatively short delay created an output
frequency that was too high to be observed with a standard voltmeter. Consequently, an oscilloscope was used to display the output
waveform as pictured in Figure 16-5.
Finally, the last time the program was executed, the MPU index
register was loaded with the value FFFF16. This resulted in the
ramp output waveform pictured in Figure 16-7.
It is important that you understand the software/hardware relationship in this experiment. Even though the DAC circuit, or
hardware, is actually generating the waveform, the shape and
frequency of the waveform are controlled by the microcomputer
program, or software.

1 6-9

1 6-1 0 I LABORATORY MANUAL


PROCEDURE (Continued)
10. Enter the triangular waveform generating program listed in
Figure 16-8 into your Trainer.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
0000
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
0023

86
FF
B7
B3
01
86
04
B7
113
03
7C
B3
01
CE
FO
00
08
26
FD
B6
B3
01
81
FF
26
FO
7A
B3
01
CE
FO

00
08
26
FD
B6
B3
01
81
00
26
FO
20
DE

MNEMONICS/
CONTENTS
LDA #
FF
STA $$
B3
01
LDA #
04
STA $$
B3
03
INC $$
B3
01
LDX #
FO
00
INX
BNE
FD
LDA $$
B3
01
CMPA #
FF
BNE
FO
DEC $$
33
01
LDX #
FO
00
INX
BNE
FD
LDA $$
B3
01
CMPA #
00
BNE
FO
BRA
DE

COMMENTS

Configure PIA port B for output.

Increment port B data register.

Delay.

Maximum count?
If not, increment port B again.

,
Decrement Port B data register.

Delay.

Minimum Count?
If not, decrement port B again.

Repeat

Figure 16-8
A triangular waveform generating program.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS

11. RESET the Trainer and execute the program by pressing GO


and entering the beginning program address, 0000.
12. Observe the voltmeter and/or oscilloscope display. Notice that
the output voltage gradually increases from 0 to 10 volts, and
then gradually decreases from 10 volts back to 0 volts.
13. RESET the Trainer and change the following memory locations as shown below:
000E change to FF
000F change to F5
001E change to FF
001F change to F5
14. Execute the program again and observe the output voltage
indication. A voltmeter indicates a 5 V average output level.
However, an oscilloscope shows you the actual triangular
waveform output pictured in Figure 16-9. Notice that the
waveform amplitude is 10 V and its frequency is approximately 22 Hz.

A
_H_H,,,

, , ,i

H+

44 , i

SCOPE SETTING
2 V/CM
10 mS/CM
1

Figure 16-9
The triangular waveform output generated by
the program listed in Figure 16-8.

1 6-1 1

1 6-1 2 I LABORATORY MANUAL

15. RESET the Trainer and change memory location 000F to FF


and memory location 001F to FF.
16. Execute the program again and you should observe the triangular waveform pictured in Figure 16-10. Notice that its
frequency has been increased to approximately 75 Hz. Why?

SCOPE SETTING
2 V/CM
10 mS/CM

1-

Figure 16 -10
An increased triangular waveform frequency obtained by shorter
time delays in the triangular waveform generating program.

DISCUSSION
The triangular waveform generating program listed in Figure 168 is a combination increment/decrement routine that causes the
DAC output to increase from 0 V to 10 V and then decrease from 10
V back to 0 V. Notice that there are two time delays created within
the program one for the increment routine and one for the
decrement routine. Both delays increment the MPU index register
to create the time delay. The output waveform frequency is controlled by the value initially loaded into the index register. What
would happen if two different values were loaded into the index
register to create two different time delays? Try it!

EXPERIMENT SIXTEEN MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

PROCEDURE
17. If you haven't already done so, connect an oscilloscope to the
output of the DAC circuit at pin 6 of the 741C op amp. Set the
oscilloscope volts/division and time base to measure a 0 10 V
signal with a frequency of approximately 250 Hz.
18. Enter the square waveform generating program listed in Figure 16-11 into your Trainer.
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
0018
001C
001D
001E
001F
0020
0021

86
FF
B7
B3
01
86
04
B7
B3
03
86
FF
B7
B3
01
CE
FE
CC
08
26
FD
86
00
B7
B3
01
CE
FE
CC
08
26
FD
20
E8

LDA #
FF
STA $$
B3
01
LDA #
04
STA $$
B3
03
LDA #
FF
STA $$
B3
01
LDX #
FE
CC
INX
BNE
FD
LDA #
00
STA $$
B3
01
LDX #
FE
CC
INX
BNE
FD
BRA
E8

COMMENTS

Configure port B for output.

Store maximum value to port B


data register.

Delay.

Store minimum value to port B


data register.

Delay.

Repeat.

Figure 16-11
A square waveform generating program.

1 6-1 3

1 6-1 4 I LABORATORY MANUAL


19. Execute the program by pressing GO and entering the beginning program address, 0000.
20. Observe the oscilloscope display. You should observe a unipolar square waveform output as pictured in Figure 16-12.
Notice that we obtained a 0 10 V square waveform with a
frequency of 250 Hz. Your waveform frequency might be different, depending upon your Trainer. In addition, notice that the
waveform has a duty cycle of 50%.
T
.,_

+-L ++

H.---P

I + 1-

SCOPE SETTING
2 V/CM
1 mS/CM

Figure 16-12

The square waveform output generated by the program listed in Figure 16-11.

21. RESET the Trainer and change the contents of memory location 0010 to FD.
22. Execute the program again and observe the oscilloscope display. You should observe the square waveform pictured in
Figure 16-13. Notice that the waveform amplitude is the same
as before. However, the frequency and duty cycle have changed.
Why? We measured an output frequency of approximately 178
Hz and a duty cycle of 65%. (Refer to Figure 16-13).

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

1111

11

11111

IIII

11

II

1+

_
SCOPE SETTING
2 V/CM
1 mS/CM
F--

Figure 16-13
A square waveform output with a 65% duty cycle obtained by unequal
time delays in the square waveform generating program.

23. How would you maintain the same frequency and change the
duty cycle to 35%? Try this:
Change memory location 0010 back to FE.
Change memory location 001B to FD.
24. Observe the oscilloscope display and you should find the
waveform pictured in Figure 16-14. Notice that the waveform
frequency is 178 Hz as before; however, the duty cycle is now
about 35%.

SCOPE SETTING
2 V/CM
1 mS/CM

Figure 16-14
A square waveform output with a 35% duty cycle obtained by
unequal time delay sin the square waveform generating program.

1 6-1 5

1 6-1 6 I LABORATORY MANUAL


25. RESET the Trainer and change the following memory locations:
0010FF
0011F2
001BFF
001CF2
26. Execute the program and you should observe the waveform
pictured in Figure 16-15. Notice that the output frequency has
been increased to approximately 5 kHz with a 50% duty cycle.
Why? In addition, notice that the "sides" of the waveform are
beginning to slope. You are beginning to observe the higher
frequency limitations of the DAC circuit.

If1 1-- I

HH

-H- 1+1

SCOPE SETTING
2 V/CM
50 pS/CM

Figure 16-15
Distortion begins appearing above 5 kHz due to the
DAC settling time and op amp slew rate.

27. Now, RESET the Trainer and change memory locations 0011
and 001C to FF.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS

28. Execute the program again and observe the oscilloscope display. You should now observe something that resembles the
waveform pictured in Figure 16-16. How can this be? The
waveform pictured in Figure 16-16 is not a square waveform.
Why?

SCOPE SETTING
2 V/CM
50 'S/CM

Figure 16-16
Distortion is extreme at 25 kHz.

DISCUSSION
The program in Figure 16-11 allows you to generate a square
waveform with a variable amplitude, frequency, and duty cycle.
You can control the amplitude by adjusting RREF, Rf, or the value
stored to the port B data register. This value is located at address
000B in the program listed in Figure 16-11.
You must control the waveform frequency and duty cycle by the two
time delay loops within the program. Each delay loop uses an
incrementing routine on the MPU index register to create the time
delay. The value initially loaded into the index registers controls
the amount of time delay.
Finally, the DAC circuit in Figure 16-1 does have limits on the
maximum frequency that can be generated. You observed that the
square waveform became distorted above 5 kHz. This distortion is
due to the settling time of the DAC and the slew rate of the op amp.

1 6-1 7

1 6-1 8 I LABORATORY MANUAL


Programmable Gain Amplifier
and Attenuator
PROCEDURE
1.

Turn the Trainer power off. Remove the VREF input to the DAC
from the +5 V supply and reconnect it to the 60 Hz output
available on the Trainer.

2.

Turn the Trainer power on and change memory location 000F


to 3E as shown in Figure 16-17.
HEX
HEX
ADDRESS CONTENTS

0000
.
.
.
.

000F

.
.
.

0021

86

.
.

3E

.
.
.
E8

MNEMONICS/
CONTENTS

COMMENTS

LDA #

.
.
.

WAI

Wait.

'
.
.
.

E8

Repeat.

Figure 16-17
Modification to square-wave program.

3.

Execute the program by pressing GO and entering the beginning program address, 0000.

4.

Using an oscilloscope, measure the VREF input to the DAC.


Remember, the VREF to the DAC is now the 60 Hz output
available on the Trainer. You should observe a 60 Hz square
waveform with an amplitude of approximately 5.0 V. Record
this value in Table 16-1 in the entire VREF input column.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS

Table 16-1
Output versus input signal amplitude levels for
the programmable gain amplifier and attenuator.

Digital
Control Value
(port B)

VREF Input

VOUT

VOUT

(LINE)
Amplitude

(measured)
Amplitude

(calculated)
Amplitude

FF
80
10
00

5. Now, use your oscilloscope to measure the output of the DAC


circuit at pin 6 of the op amp. You should observe a 60 Hz
squarewave output signal. Adjust the 10 K potentiometer to
obtain an output of approximately 4.9 V. Record this \Tour
value in Table 16-1 across from the digital control input value
of FF. The output versus input signals for the digital control
value of FF16 are pictured in Figure 16-18. The input signal to
the DAC (VREF) is pictured at the top, and the output from the
DAC circuit is pictured at the bottom of Figure 16-18.

CHANNEL B
5 V/CM
2 mS/CM

Figure 16-18
Output (bottom) versus input (top) for a control value of FFls

16-1 9

1 6-20 I

LABORATORY MANUAL

6.

Recall that you can calculate the output voltage level of a


programmable gain amplifier and attenuator using the following equation:
vOUT

- NiN

I D7 + D6 + D5 + D4 + D3 + D2 + D1 + DO
2 4 8 16 32 64 128 256
RREF
Rf

You have fixed RREF at 4.7 IcS1 and adjusted Rf to about 7.8 Ica
Furthermore, you have measured the VIN level to the DAC
circuit. The program in Figure 16-17 stores the digital value
FF16 to the DAC. Using this information and the above equation, calculate the expected output level, Vour, and enter this
value in Table 16-1 in the \Tour (calculated) column. Is the
calculated value close to the measured value?
7.

Press NMI and examine the port B data register at address


B301. You should find the value FF16 which was stored there
by the program.

8.

Change the contents of memory location B301 to 8016 and


rerun the program.

9.

Observe the output of the DAC circuit with your oscilloscope.


Record this value in the VOUT (meal) column across from the
digital control value of 8016 in Table 16-1. You should have
measured an output amplitude of approximately 2.5 V. The
output versus input signals are pictured in Figure 16-19. Has
the input signal been amplified or attenuated?

CHANNEL A
5 VICM
2 mS/CM

CHANNEL B
5 V/CM
2 mS/CM

Figure 16 - 19

Output (bottom) versus input (top) for a control value of 801s.

EXPERIMENT SIXTEEN - MICROPROCESSOR/DAC INTERFACING AND APPLICATIONS 1

10. Calculate the expected output amplitude for a digital control


value of 8016. Record your calculated value next to the measured value in Table 16-1.
11. Press NMI and change the digital control value at address
B301 to 1016. Do not press RESET when performing this
operation.
12. Repeat the above measuring and calculating procedure for
this digital control value. Record your results in Table 16-1.
The output versus input signals for the digital control value of
1016 are pictured in Figure 16-20. Has the input signal been
amplified or attenuated?

CHANNEL A
5 V/CM
2 mS/CM

CHANNEL B
5 V/CM
2 mS/CM

Figure 16-20
Output (bottom) versus input (top) for a control value of 1016.

13. Change the digital control value at address B301 to 0016 and
repeat the above measuring and calculating procedure. Record
your results in Table 16-1. The output versus input signals for
this digital control value are pictured in Figure 16-21. Notice
that the DAC circuit has now completely attenuated the input
signal.

1 6-2 1

16-221 LABORATORY MANUAL

CHANNEL A
5 V/CM
2 mS/CM

11

1111

1+1-1111

1117+4

1111

III

1111

1111

-CHANNEL B
5 V/CM
2 mS/CM

Figure 16-21
Output (bottom) versus input (top) for a control value of 0016.

DISCUSSION
A programmable gain amplifier and attenuator uses a multiplying
DAC circuit. The signal to be amplified or attenuated is applied to
the VREF input of the DAC via a reference resistor, RREF The DAC
circuit then amplifies or attenuates the input signal according to
the digital control value that is present at the digital input lines of
the DAC. The above data shows that, with our DAC circuit, the
input signal was amplified by a gain factor of approximately 2.5
when a digital control value of FF16 was stored to the DAC. The
DAC circuit completely attenuates the input signal with a digital
control value of 0016.
You can achieve various gain and attenuation factors by storing
values between 0016 and FF16 to the DAC. You might want to try
using some digital control values other than the ones we have used.
To do this, simply change the contents of the port B data register
at address B301 to the desired value. Remember not to press
RESET, since this clears all the PIA registers and you will have to
reconfigure the PIA. Use the NMI key.
One other comment, when a multiplying DAC is being used as a
programmable attenuator, it is sometimes called a programmable
potentiometer, for obvious reasons.

EXPERIMENT SEVENTEEN - ND CONVERTER INTERFACING AND APPLICATIONS I

EXPERIMENT 17
A/D CONVERTER INTERFACING
AND APPLICATIONS
Objectives:
1. To interface an ADC to a microprocessor.
2.

To demonstrate the software requirements of interfacing an


ADC to a microprocessor system.

3. To show how the PIA control lines are used to provide


handshake control of the ADC conversion process.
4.

To demonstrate the construction of a microprocessor-controlled digital voltmeter.

5. To demonstrate the construction of a microprocessor-controlled digital ammeter.


6. To demonstrate the use of a memory lookup table to interpret and display voltage and current values.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 6821 PIA integrated circuit (#443-1014)
1 ADC0809 integrated circuit (#443-1122)
1 5 1(11 potentiometer (#10-1216)
1
10 ktl potentiometer (#10-1138)
1 1 ki2, 1/4-watt, 5% resistor (#6-102-12)
1 VOM, DVM, or Oscilloscope
Hook-up wire

1 7-1

17-2

LABORATORY MANUAL

INTRODUCTION
In Unit 12 you learned how to interlace an ADC to a microprocessor.
via PIA interface. You found that the microprocessor must control
the conversion process by activating the ADC START line. The
ADC then activates its EOC line to notify the microprocessor when
the conversion is complete. In this experiment, you will interface
the A.DC0809 to the ITITVV-3800 Microprocessor Trainer via the PIA
interface developed earlier. The PIA control lines will be used to
control the conversion process using a handshaking technique as
described in Unit 12.
Once you become familiar with the microprocessor/ADC interface,
you will apply the circuit to voltage and current measurement. An
ADC is at the heart of a digital multimeter, or DMM. The ADC, is
used directly to measure voltage values, and precision resistors
are used on the ADC input to measure current. In this experiment,
you will construct the circuits and write the software required to
convert your Microprocessor Trainer into a DMM, capable of measuring and displaying- DC voltage and current levels.

PROCEDURE
I. With the Trainer power off, construct, the circuit shown in
Figure 17-1. Locate the two [Cs next to each other, at the
extreme left-hand end of the breadboard.
2.

Place all of the channel-select logic switches in their logic 0, or


down, position.

3.

Connect your voltmeter or oscilloscope from pin 26 of the ADC


to ground. Set the voltmeter on a range that will permit you to
measure +5 VDC.

4.

Temporarily disconnect the wire from the IRQ input on the


Trainer. Do not reconnect this wire until a step directs you to
do so.

EXPERIMENT SEVENTEEN -

AID

CONVERTER INTERFACING AND APPLICATIONS 1

+5V GND
201
DO 33 130 CC VSS
D1 32 D1
02 31 D2
30
I33
D3
D4 29 D4
28 05
05

I/O

PIA

D6 27 06
26
D7
07
0
25

TO/FROM
TRAINER LED
CONNECTOR
BLOCK

+5V

11

12
2
INO
IN1 27
28
1N2

23 C 3
+5V

A0-2-1
'RSI

P80

CS1
6
A1 34
2
RSO
22
CSO
- 21
R/W R/W

P131

WC8TIAL1

RESET

PB2
PB3

LED 0
11
12
13

P84 14
15
PB5
16
PI36
17
PB7
18
CI31
19
CO2

LED 1
LED 2
LED 3
LED 4
LED 5
LED 6
LED 7

01

15

18

D2

IN3

D3

IN4

O4

19

10K
POT.

3
INS
4
IN6

ADC

O5

20

D6
3'. D7

5K
POT,

IN7

START
2
9

5\1 0

10

EO
TO FRIT)
INPUT ON.,
TRAINER

DO

EOC

IROB
37

17
14

FROM
TRAINER

ALE
OE

CHANNEL 25

SWITCH 0

SELECT 24

SWITCH 1

23

SWITCH 2

CLOCK
GND REF (-)
13 16

BINARY LOGIC SWITCHES


ON TRAINER

Figure 17-1

ADC interface circuit.

5.

Switch the Trainer power on and enter the program listed in


Figure 17-2.

6.

Set the 10 liC2 potentiometer to provide 0 V to the ADC.

7.

Reset the Trainer and enter a breakpoint at address 0021. To


do this, press the Brk key and enter the breakpoint address,
0021. Do not press RESET again until we tell you to do so,
because this would erase the breakpoint.

8.

Execute the program by pressing GO and entering the beginning program address, 0000. Do not press RESET. The display
will go blank and then display 0021 WAI 3E after approximately one second.

9.

Without pressing RESET, examine memory location B301. At


this location, you should find the hexadecimal equivalent of
the input voltage value indicated by the voltmeter. Since, in
step 5, you set the ADC input voltage to 0 volts, you should find
the value 00 in memory location B301. Notice, also, a binary
LED indication of 0000 0000.

10. Set the 10 kS2 potentiometer to provide +5 V to the ADC.

1 7-3

1 7-4

1 LABORATORY MANUAL

HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023

.
0050

CE
00
50
FF
69
2B
C6
37
F7
B3
03
OE
C6
01
CE
D7
00
09
26
FD
5A
26
F7
C6
3F
F7
B3
03
C6
37
F7
B3
03
3E
20
E2

.
3B

LDX #
00
50
STX $$
69
2B
LDB #
37
STB $$
B3
03
CLI
LDB #
01
LDX #
D7
00
DEX
BNE
FD
DECB
BNE
F7
LDB #
3F
STB $$
B3
03
LDB #
37
STB $$
B3
03
WAI
BRA
E2

RTI

COMMENTS

Store IRO
interrupt vector.

Configure port B
with an initial
control value
of 3716.
Clear I-flag.

Delay approximately
one second.

Start a conversion
by toggling
CB2 output line.

Wait for interrupt.


Do it again.

Return from interrupt.

Figure 17-2

ADC control program.

EXPERIMEN I SEVE N I LEN - A/D CONVERTFR INTERFACING AND APPLICATIONS 11

11. Press NMI and execute the program again by pressing GO and
entering the beginning program address, 0000. Again, the
display should go blank then display the breakpoint address,
0021, and its contents, 3E.
12. Without pressing RESET, examine memory location B301. You
should now find the value FF at this address since you set the
ADC input voltage to its maximum level +5 V. Observe a
binary LED display of 111.1 1111.
13. Set the 10 ki2 potentiometer to any arbitrary input level
between 0 V and +5 V.
14. Repeat steps 11 and 12. You should now find that memory
location B301 contains a value corresponding to the input
voltage value indicated by the voltmeter. The binary LEDs will
indicate the binary equivalent of the hex value.
15. Set all the channel-select logic switches to their logic 1, or up,
position.
16. Connect your voltmeter between pin 5 of the ADC and ground.
17. Repeat steps 6 through 14 using the 5 kit potentiometer which
is connected to channel 7 of the ADC. Remember not to press
RESET, since this removes the breakpoint in your program.
Use NMI. instead of RESET.
18. Reconnect the free end of the wire coming from the PIA to the
IRQ input on the Trainer.

DISCUSSION
You have now interfaced the ADC0809 to the Microprocessor Trainer
via the PIA interface developed in Unit 12. The eight digital output
lines of the ADC are connected to port B of the PIA, and the
conversion process is controlled using the port B control lines.
Notice from Figure 17-1 that the CB2 output line of the PIA is
connected to the ADC START line, and the CB1 input line of the
PIA is connected to the ADC EOC, line.

7-5

1 7-6 I LABORATORY MANUAL

To start a conversion, the microprocessor toggles the CB2 output


line of the PIA. The ADC requires an active high START pulse.
Consequently, the CB2 line is toggled from low-to-high-to-low to
start a conversion. When the conversion is complete, the ADC
generates a logic 1 on its EOC line. Recall from Unit 12 that, with
these ADC control signal requirements, the microprocessor must
initialize the port B control register at address B303 with the value
3716 . Then, to start a conversion, the microprocessor must write
the value 3F 16 to the port B control register, and then rewrite the
value 37 16 to the control register. These two consecutive write
operations cause the CB2 output line to generate the active high
pulse required by the ADC to start a conversion.
Once a conversion is complete, the ADC
Al)(generates a logic 1 on the
CB1 input line of the PIA. ThelliQB output line ofthe HA has been
connected to the interrupt request, or /HQ, input line of the MPU
to generate an interrupt when a conversion is completed. For now,
the interrupt simply causes the MPU to vector back to the conversion program. In the next part of the experiment, you will add an
interrupt service routine to display the converted voltage val
A flowchart of the program is provided in Figure 17-3. The port B
control register at address B303 is first initialized with the value
3716. After a short delay, the C132 output line is toggled to start a
conversion. You inserted a breakpoint at address 0021 to allow you
to examine a converted value. You found this value at address
B301. Why? because the ADC is connected to port B of the PIA,
a converted value is input to the port B output register which has
been assigned to address B301. Thus, by examining address B301,
you were actually examining the digital output of the ADC present
on the port H input lines of the PIA.

EXPERIMENT SEVENTEEN - AID CONVERTER INTERFACING AND APPLICATIONS 1

INITIALIZE PORT B
CONTROL REGISTER
WITH THE VALUE 3716.

i
DELAY APPROXIMATELY
ONE SECOND.

v
WRITE THE VALUE
3F
16 TO PORT B
CONTROL REGISTER.
START CONVERSION
BY TOGGLING THE CB2
OUTPUT CONTROL LINE.
WRITE THE VALUE
37 16 TO PORT B
CONTROL REGISTER.

WAIT FOR EOC


INTERRUPT.

Figure 17-3
ADC control program for the first part of the experiment.

1 7-7

1 7-8 I LABORATORY MANUAL


The ADC0809 has an internal 8:1 analog multiplexer. The logic
present on its three channel-select input lines determines which
one of eight analog input channels are selected for a conversion.
The required channel selection logic is summarized in Table 17-1.

Table 17-1
The required channel select logic for the ADC0809.

Channel Select Line


C
B
A
(pin 23) (pin 24) (pin 25)

o
0
0

o
1
1
1
1

0
0
1
1
0
0
1
1

0
1
0
1
0
1
0
1

Analog Input
Channel Selected
INO
IN1
IN2
IN3
IN4
LN5
1N6
IN7

In step 15, you placed all the channel-select logic switches in their
logic 1 position. This setting selected input channel #7 (See Figure
17-1). The ADC then converted the output of the 5 Icf2 potentiometer connected to channel #7, rather than the 101c12 potentiometer
which is connected to channel #0 (INO).
Using this ADC, you could have converted any one of eight analog
input signals by applying the appropriate channel-select logic. Of
course, we have only used two of the input channels in this
experiment. You might want to verify that the other channels
operate properly by connecting the wiper of one of the potentiometers to each of the remaining input channels and selecting the
given channel using the channel-select logic switches and Table
17-1. The pin numbers of the remaining input channels are provided in Figure 17-1.

EXPERIMENT SEVENTEEN

AID CONVERTER INTERFACING AND APPLICATIONS

PROCEDURE (Continued)
19. RESET the Trainer and enter the interrupt service routine
listed in Figure 17-2. Notice that this routine begins at address 0050. In addition, enter the memory lookup table which
begins at address 0100.
HEX
HEX
ADDRESS CONTENTS
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
005A
005B
005C
005D
005E
005F
0060
0061
0062
0063
0064
0065
0066

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F

F6
B3
01
54
54
54
54
D7
5D
CE
01
00
E6
00
BD
CO
15
C6
OD
BD
CO
06
3B

00
03
06
10
13
16
19
22
26
29
32
35
38
42
45
48

MNEMONICS/
CONTENTS
LDB $$
B3
01
LSRB
LSRB
LSRB
LSRB
STB $
5D
LDX #
01
00
LDB, X
00
JSR $$
CO
15
LDB #
OD
JSR $$
CO
06
RTI

00
03
06
10
13
16
19
22
26
29
32
35
38
42
45
48

COMMENTS
Read digital value form port B.

Convert to a voltage value via


memory look-up table.

Display voltage value.

Return from interrupt.

Voltage look-up table.

Figure 17-4
ADC interrupt service routine.

1 7-9

17-101 LABORATORY MANUAL


20. Execute the program by pressing GO and entering the beginning main program address, 0000. The display should go
blank, then display a digital value (no decimal point) that
should be within about 10% of the voltage value indicated by
your voltmeter. You have just constructed a microprocessorcontrolled digital voltmeter!
21. After reconfiguring the binary data switches to select IN7
(111), change the setting of the 5 ki2 potentiometer and observe the display while you observe your voltmeter. Compare
the digital display value to your voltmeter reading. The two
readings should be relatively close. Note that although there
is no decimal point, and the voltage displayed is only a rough
approximation, the software could be modified to provide a
more precise display complete with decimal point and other
information.

DISCUSSION
The MPU starts the conversion process by toggling the CB2 output
line as before. However, now each time a conversion is completed,
an interrupt is generated via the CB1 input line and the MPU
vectors to an interrupt service routine which reads port B and
displays the converted value. Flow charts of the conversion control
and display programs are provided in Figure 17-5. Let's take a
closer look at the interrupt service routine.
The interrupt service routine, which begins at address 0050, first
reads the converted digital value from port B. Next, the digital
value must be converted to a decimal value which is equivalent to
the input voltage level. This requires a lookup table. The required
lookup table is in memory, beginning at address 0100.
Now there are 256 (28) different possible digital representations of
the input voltage range, since the ADC0809 is an 8-bit ADC. To
display all of these possible values requires a memory lookup table
256 bytes long. This is normally no problem, especially in ROM or
EPROM. However, for experiment purposes, we are only going to
use the four most significant digital output bits of the ADC to
measure the unknown input voltage and thus limit our lookup
table to 16 (24) bytes. Notice from the interrupt service routine
program that four LSRB instructions are used to drop the four
least significant digital input bits and move the four most significant bits to the least significant bit positions.

EXPERIMENT SEVENTEEN - AID CONVERTER INTERFACING AND APPLICATIONS

ADC CONTROL PROGRAM

INTERRUPT SERVICE ROUTINE

READ DIGITAL VALUE


INITIALIZE PORT B

FROM PORT B.

CONTROL REGISTER
WITH THE VALUE 3716

CONVERT TO
DELAY
APPROXIMATELY
ONE SECOND.

VOLTAGE VALUE
VIA MEMORY
LOOK-UP TABLE.

V
WRITE THE VALUE

DISPLAY VOLTAGE

3F16 TO PORT B

VALUE.

CONTROL REGISTER.
START CONVERSION
BY TOGGLING THE CB2
OUTPUT CONTROL LINE.

RETURN FROM
WRITE THE VALUE

INTERRUPT.

3716 TO PORT B
CONTROL REGISTER.

WAIT FOR EOC


INTERRUPT.

Figure 17-5
A flowchart summary of the software required for
the microprocessor-controlled DVM.

After the shifting process, the digital value is stored at address


005D. This is done because the unknown digital value is used as
the indexed addressing offset to access the memory lookup table.
Our voltage lookup table is located at address 0100 through 001F
and contains the most significant values for the respective voltages.
After the digital value offset is stored in address 005D, the index
register is loaded with the beginning lookup table address (0100).
The LDB,X instruction then accesses the lookup table and loads
the proper voltage value into accumulator B.

1 7-1 1

1 7-1 2 I LABORATORY MANUAL


The remaining portion of the display routine stores the voltage
value to the Trainer display using an ETW-3800 ROM monitor
routine. Consult the ETW-3800 Manual for an explanation of this
routine.
After a value is displayed, the MPU returns from the interrupt
service routine and another conversion is made. The process is
repeated about once every second.

PROCEDURE (Continued)
22. Turn the Trainer power off and remove the two potentiometers
from the ADC circuit.
23. Using the 10 kit potentiometer and a 1 kS2 resistor, construct
the circuit shown in Figure 17-6. Make sure to connect your
VOM in series with the +5 V supply with the polarity shown.
Set the VOM to a current scale that permits you to measure
from 0 mA to 5 mA DC.

IMO 2

5V
10Kfl

ADC
'UNKNOWN

Figure 17-6
Circuit required to measure an unknown current level from 0-5 mA.

24. Place all of the channel-select logic switches in their logic 0, or


down, position.
25. Execute the ADC control program by pressing GO and entering the beginning program address, 0000. The display should
go blank and then display a digital value that should be close
to the current value (in milliamperes) indicated by your VOM.
You have just constructed a microprocessor controlled milliammeter.
26. Change the setting of the 10 kg2 potentiometer and observe the
display while you observe your milliammeter reading. The two
readings should be relatively close.

EXPERIMENT SEVENTEEN - AID CONVERTER INTERFACING AND APPLICATIONS 1

DISCUSSION
The circuit that you constructed in step 23 demonstrates how an
ADC can be used to measure current. We have simulated a precision resistor using a standard 1 Id/ 5% resistor. The resistor was
placed in parallel with the ADC input. Any current through the
resistor produces a proportional voltage drop across the resistor by
Ohm's law. The voltage developed across the resistor is applied to
the ADC for measurement and display. Consequently, changing the
10 kit potentiometer setting changes the current into the 1 161
resistor which, in turn, produces a voltage that is proportional to
the changing current. This is the technique used by a DMM to
measure current. Of course, a DMM uses several precision resistors to produce more accurate readings and several different
current scale ranges.
We picked a 1 ki-I precision resistor value so that input current
levels from 0 to 5 mA produce a corresponding 0 to 5 V voltage drop
across the resistor. This input range is compatible with the ADC
and eliminates the need for scaling circuits. Furthermore, the
same memory lookup table that was used for the digital voltmeter
experiment can also be used for this experiment.
Remove the potentiometers connected to pins 25 and 26 of the ADC
(refer to Figure 17-6). Save the remaining PIA/ADC interface
circuit, and the program for the next experiment, if possible.

1 7-1 3

EXPERIMENT EIGHTEEN - A MICROPROCESSOR-CONTROLLED THERMOMETER

EXPERIMENT 18
A MICROPROCESSOR-CONTROLLED
THERMOMETER
Objectives:
I. To demonstrate the operation of a semiconductor temperature-sensing IC.
2. To show how to condition the output of a temperaturesensing IC to be compatible with the input of an analog-todigital converter.
3. To show how to interface a temperature-sensing circuit to
the Microprocessor Trainer to produce a microprocessorcontrolled thermometer.
4. To show how to write the software required to control the
analog conversion process and display temperature in F.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 LM35 temperature-sensing integrated circuit (#442-783)
1 ADC0809 analog-to-digital converter (#443-1122)
1 6821 PIA integrated circuit (#443-1014)
1 741C op amp integrated circuit (#442-22)
1 1000 S2, 1/4-watt, 5% resistor
1 10 k52, 1/4 watt, 5% resistor
1 Ice cube. (User supplied.)
1 Household thermometer. (User supplied.)
1 VOM, DVM, or Oscilloscope
1 1" length of 1/8" heat-shrink tubing
Solder (#331-17)
25-watt pencil type soldering iron (User supplied)
1 Pair of needle-nose pliers (User supplied)
Hook-up wire
Electrical Tape (#74-4)
1 12" length of yellow hook-up wire
1 12" length of green hook-up wire
1 12" length of blue hook-up wire
1 Alligator clip (User supplied)

1 8-1

1 8-2

I LABORATORY MANUAL

INTRODUCTION
You were acquainted with semiconductor temperature sensing
devices in Unit 13. You found that integrated temperature sensing
devices were very accurate, low cost, and readily available. Such
devices are especially attractive since, unlike other temperaturesensing devices, they provide a very linear output with changes in
temperature.
In this experiment, you will investigate the operation of the LM35
temperature-sensing IC. You will construct a temperature-sensing
probe using this device, and build an op amp circuit to condition its
output to be compatible with an ADC. You will then interface the
temperature sensing circuit to your Microprocessor Trainer to
produce a microprocessor-controlled thermometer. Software will
be written to control the analog conversion process and display
temperature in degrees F.

PROCEDURE
1. Construct a temperature probe as follows:
Cut 12" sections of yellow, green, and blue hook-up wire.
Remove 1/4" of insulation from each end of each wire.
Slip a 1" piece of 1/8" diameter sleeving over one end of the
yellow wire. Form a small hook at this end of the wire.
Form a small hook at one end of each of the remaining
wires.
Form small hooks at the ends of the leads of the temperature sensor and connect (Do not solder at this point!) the
yellow, green, and blue wires as shown in Figure 18-1.
Crimp each wire fitting with your pliers to assure a good
mechanical connection.

EXPERIMENT EIGHTEEN - A MICROPROCESSOR-CONTROLLED THERMOMETER

LM35
TEMPERATURE
SENSOR
USE AN ALLIGATOR
CLIP AS A HEAT SINK
WHEN SOLDERING
THE CONNECTIONS.

GREEN
WIRE

BLUE
WIRE
YELLOW
WIRE

1.
SLEEVING

Figure 18-1
Temperature probe wire connections.

Solder the wires to the leads. Use an alligator clip as a


heat sink to prevent damage to the sensor.
Slide the 1" piece of sleeving up to the bottom of the body
of the sensor.
Cut a 1" piece of electrical tape and wrap it around the
three wires and the sleeving 1/2" from the bottom of the
sensor as shown in Figure 18-2. Be careful not to let the
two exposed leads contact each other.
SLEEVING FLUSH
WITH SENSOR
BODY

TO-92
PLASTIC PACKAGE

1 / 2'

ELECTRICAL
TAPE

Figure 18-2

Electrical tape placement.

BOTTOM VIEW

1 8-3

1 8-4

1 LABORATORY MANUAL

2. Construct the circuit in Figure 18-3.


+5V

VOUT

Figure 18-3

Temperature sensor circuit.

3.

Connect your voltmeter or oscilloscope to pin 3 of the op amp.


Set the instrument to a DC voltage range which permits you to
measure 200 mV. Turn the Trainer power on.

4.

Place the sensor next to your thermometer.

5.

Allow about three minutes to let the sensor and thermometer


stabilize. Then read the room temperature and record it below.
Tambient =

6.

Read the output voltage of the sensor and record it below.


Vsensor =

VDC.

7.

Move your voltmeter or oscilloscope test lead from pin 3 to pin


6 of the op amp. Set the instrument to a range that allows you
to measure +5.0 VDC.

8.

Read the output voltage of the op-amp and record it below.


Vambient =

VDC

EXPERIMENT EIGHTEEN - A MICROPROCESSOR-CONTROLLED THERMOMETER

DISCUSSION
The LM35 temperature sensor produces a small output voltage
proportional to its temperature. This voltage is scaled at about 10
mV per 1C above 0C. At room temperature, about 68F or 20C,
the output voltage is 200 mV. Is this the reading that you obtained
at pin 3 of the op-amp in step 6?
When you measured the output of the op-amp in step 8, you
obtained a reading that was 11 times that of the sensor's output.
This is because the op-amp amplifies the sensor output voltage by
a factor of 11. So, at a temperature of 68F or 20C, the output of
the op-amp should be 2.20V. The amplification is needed to make
the expected output voltage range of the sensor match the input
voltage range of an A/D converter.

PROCEDURE (Continued)
9. Hold the sensor firmly against your neck as shown in Figure
18-4. Do not expose any part of the sensor body to the air.

TO TRAINER

Figure 18-4
Holding the sensor against your neck.

18-5

1 8-6 I LABORATORY MANUAL


10. After about three minutes, read the output voltage at pin 6 of
the op-amp and record it below.
VDC.

Vneck =

Hold the sensor against an ice cube as shown in Figure 18-5.


Grasp the wires about 6" or so from the sensor body to reduce
the effect of heat generated by your hand. Also, do not breath
in the direction of the sensor. DO NOT allow any water to
reach the leads. If it does, dry the leads by blowing on them
and repeat the step.

HOLD LEADS
6' FROM
SENSOR BODY

DO NOT ALLOW WATER


TO REACH THE LEADS
SENSOR
BODY
ICE CUBE

HOLD THIS SURFACE


AGAINST THE ICE CUBE

I I

Figure 18-5

Holding the sensor against an ice cube.

EXPERIMENT EIGHTEEN A MICROPROCESSOR-CONTROLLED THERMOMETER I

12. After about three minutes, read the output voltage and record
it below.
VDC.

Vice =

13. Assume that the temperature of your neck was 98F or 37C
and that the temperature of the ice cube was 32F or 0C.
Using these assumptions, the ambient temperature you recorded earlier, and the output voltages you measured, plot
points on the graph provided in Figure 18-6 representing the
three measurements.
5V

OPAMPOUTPUT V OLTA GE

MENIMISIIIIIMINNEMIIIIIIIMEN1111111111111111111110011111111111111
111111111111111111111111111111111111111111111111111111M1111111MOMII
MMIMMINEMOIMMIIIIIIIMMOMMOMMI
4V

11111111111111111111111111111111111111011111111111111111111111111MMIIIIIIIIIM
IIIIIMIONINE1111111111111111111111111111111MMOIMIIIIIIIII
111111M11111111111111111.1111MIMMIIIIIMOINIM
1111111111111111111111111111111111111111111111111111MMIMIMM
MII111111111111111111111111111111111M0111111111111MMIIIIIII
1111111111111111111MUM111111111111111111111111111111MONIIIIM
summumamommomommmemems
2V
IMONOONOISMINOMMOMMOMMIIIMEN
munimminnumimmiummummm
3V

IV

111111.1111111111MMIMMOMMUINIUMMEMMIN
sommommusmuimmimmummumms
1111MONNIMIIMIMIIIIIMEM111111111111111111111111111111111M11
Mill111111111111111111111111111111111111111111111111111M11111111M1111111111

OV
300 32,,

40

50

80

To.

80

90

950 100

TEMPERATURE

Figure 18-6
Temperature sensor circuit operating curve.

14. Use a straightedge to draw a straight line through all three


points. If you don't quite line up, make the line as close as
possible to all three points.

DISCUSSION
The graph you made in Figure 18-6 allows you to do two things:
predict the output voltage of the circuit for a given temperature,
and determine the actual temperature from a reading of the output
voltage. You were probably not able to run the line through all
three points at the same time, but it should have been close.

1 8-7

1 8-8 I LABORATORY MANUAL


This indicates that the output of the sensor is linear. In fact,
because the slope of the line is essentially constant for each LM35
sensor, an output graph could be constructed with only one point of
reference (with respect to the graph origin).
Thus, using the graph in Figure 18-6, you can determine the
temperature for a given voltage output from the temperaturesensing circuit. However, this isn't practical, especially in the age
of microprocessors. Why not convert the analog output of the
temperature-sensing circuit to a digital output, with an ADC, and
use a microprocessor and a memory lookup table to display the
temperature reading?

PROCEDURE (Continued)
15.

Turn the Trainer power off and construct the microprocessorcontrolled thermometer circuit shown in Figure 18-7. The PIA/
ADC interface circuit should already be constructed on the
Trainer breadboard from the previous experiment.

r+5V GND
20 11
33
DO DO VCC VSS
32
D I 01
31
02
02
0322 D3
29
D4-- 04
05211
05
27 06 PIA
06 T607
79
I00
PBO
E
E
CS2
PHI
35
4-5V Ao_
RS1
PB2
24
CS1
PB3
36
RSO
Al
22
fi
CSO P84
Row 21
R/W PBS
RESET 34 RESET PB6

PIA/ADC INTERFACE CIRCUIT


FROM PREVIOUS EXPERIMENT
TO/FROM
TRAINER LED

FROM
11

12

37

26

PIN 6 OF
74IC OP-AMP

INO
27
IN1
IN? 28
IN3 1

5V0
E 0
FROM
TRAINER

1N4 2
INS 3
IN6 4
IN 7 5

CHANNEL

OE

0 CLOCK SELECT

GND REF(-)
13

2
24
23

TEMPERATURE
PROBE CIRCUIT
(FIGURE

2; ALE

IROB

TRAINER

17
10 ;
LED 0
-p DO
11
14
LED 1 ----wit/ 1
12
15
132
LED 2
13
LED 3
D3
14
18
D4
LED 4
15
ADC
19
05
LED 5
16
20
D6
LED 6
17
21
P87 00 LED 7
07
18
7
CBI
EOC
19
6
START
CB 2

2.3

TO 180
INPUT ON

45V

CONNECTOR
BLOCK

SWITCH 0
SWITCH 1
SWITCH 2

16
BINARY
LOGIC SWITCHES
ON TRAINER

Figure 18-7
An MPU-controlled thermometer circuit.

18 - 3 )

EXPERIMENT EIGHTEEN

MICROPROCESSOR-CONTROLLED THERMOMETER 1

16. Once the circuit has been constructed, turn the Trainer power
on and enter the program listed in Figure 18-8. Set all logic
switches to zero (down).
NOTE: If you saved the program from the previous experiment, simply make the following changes. Change address
001F16 to B3. Change address 005616 to 01. To do this use the
Exm Mem key to make these changes. Change address locations 010016 through 011F16 (i.e., the temperature lookup
table) as indicated.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023

MNEMONICS/
CONTENTS

CE
00
50
FF
69
28
C6
37
F7
B3
03
OE
C6
01
CE
D7
00
09
26
FD
5A
26
F7
C6
3F
F7
B3
03
C6
37
F7
B3
03
3E
20
E2

LDX#
00
50
STX$$
69
2B
LDB#
37
STB$$
B3
03
CLI
LDB#
01
LDX#
D7
00
DEX
BNE
FD
DEC B
BNE
F7
LDB#
3F
STB$$
B3
03
LDB#
37
STB$$
B3
03
WAI
BRA
E2

COMMENTS

Store IRO interrupt vector

Configure port B with an initial


control value of 3716.
Clear I-flag.

Delay approximately one


second.

Start a conversion by toggling


CB2 output line.

,
Wait for interrupt.
Do it again.

ont' .

Figure 18-8
Program for the microprocessor-controlled thermometer.

1 8-9

1 8-1 0 I LABORATORY MANUAL


HEX
HEX
ADDRESS CONTENTS

MNEMONICS/
CONTENTS

0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
005A
005B
005C
005D
005E
005F
0060
0061
0062
0063
0064
0065
0066

F6
B3
01
54
54
54
01
D7
5D
CE
01
00
E6
00
BD
CO
15
C6
OD
BD
CO
06
3B

LDB$$
B3
01
LSRB
LSRB
LSRB
NOP
STB$
5D
LDX#
01
00
LDB,X
00
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
RTI

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
0108
010C
010D
010E
010F
0110
0111
0112
0113
0114
0115
0116
0117
0118

27
30
33
36
39
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99

27
30
33
36
39
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99

COMMENTS

Read digital value from port B.

Convert to a voltage value via


memory look-up table.

Display temperature in F

Return from interrupt

Temperature (F) look-up table.

EXPERIMENT EIGHTEEN A MICROPROCESSOR-CONTROLLED THERMOMETER I

HEX
HEX
ADDRESS CONTENTS
0119
011A
011B
011C
011D
011E
011F

02
05
08
11
14
17
20

MNEMONICS/
CONTENTS
02
05
08
11
14
17
20

COMMENTS

Temperature (F) look-up table.


(Continued)

17. Execute the program by pressing GO and entering the beginning program address, 0000.
18. Observe the Trainer display; you should observe the approximate temperature of your room being displayed in degrees F.
You might also note the digital output value of the ADC, which
is indicated by the eight binary LEDs on the Trainer.
19. Place the temperature probe on the ice cube and observe both
the temperature display and the binary LED display. The
temperature display should decrease to about 33F and the
binary LED display should decrease to 0001 0000 after the
LM35 has stabilized.
20. Place the temperature probe against your neck (Figure 18-9)
and observe the displays. The temperature display should
increase to 99F and the binary LED display should increase
to 1100 0000.
21. Subject the temperature probe to other temperatures with
your hand, cool water, warm water, etc. Use a standard household thermometer to measure the same temperature and compare it to the temperature display on your Trainer. Why
doesn't the thermometer reading and the Trainer display
always compare precisely? How could you make the microprocessor-controlled thermometer more accurate?

DISCUSSION
In this part of the experiment, you constructed a microprocessorcontrolled thermometer by interfacing the temperature-sensing
circuit to your Microprocessor Trainer. The interface consists of an
ADC and a PIA. As before, the temperature-sensing circuit produces an analog output voltage that is proportional to temperature. Note that the op amp signal-conditioning circuit amplifies
the analog voltage level to be compatible with the input requirements of the ADC. The LM35 output could not be applied to the
ADC directly, since it-s output level is too small (10 mV/C).

1 8-1 1

1 8-1 2 I LABORATORY MANUAL


The microprocessor software controls the ADC conversion process
using a control program. When the ADC completes a conversion,
the microprocessor reads the converted value and interprets that
value via a memory lookup table to display the temperature in F.
The flowchart in Figure 18-9 summarizes the software used in this
experiment. Notice that it is virtually identical to the ADC control
program used in the previous experiment, except for the lookup
table values. Here, the lookup table values are of temperature
values rather than voltage or current values.
INTERRUPT SERVICE
MAIN PROGRAM

ROUTINE

C
INITIALIZE PORT B
CONTROL REGISTER

READ DIGITAL
VALUE FROM PORT B.

WITH THE VALUE 3716,

DELAY
APPROXIMATELY
ONE SECOND.

CONVERT TO TEMP
VALUE VIA MEMORY
LOOK-UP TABLE.

V
WRITE THE VALUE

DISPLAY

3F16 TO PORT B

TEMPERATURE

CONTROL REGISTER.

VALUE.

START CONVERSION
BY TOGGLING
THE CB2
OUTPUT CONTROL LINE.

WRITE THE VALUE


3716 TO PORT B

RETURN FROM

CONTROL REGISTER.

INTERRUPT.

WAIT FOR EOC


INTERRUPT.

Figure 18-9

Flowchart summary of the temperature measurement software.

EXPERIMENT EIGHTEEN - A MICROPROCESSOR-CONTROLLED THERMOMETER

For experimental purposes, the memory lookup table is only 32


bytes long. Hence, the resolution of the system is only 100F/32, or
approximately 3F. This is why the Trainer display might not
compare exactly to another thermometer reading. However, you
could obtain much greater temperature measurement resolution
by using the full 8-bit output of the ADC and constructing a 256byte memory lookup table. A 256-byte lookup table would provide
a resolution of 100F/256, or .36F. This is more than enough
resolution for most industrial applications. In practice, a similar
lookup table is placed in ROM or EPROM, where memory space is
not as restricted as the RAM in your Trainer.
Remove the temperature probe circuit, but save the PIA/ADC
interface circuit for the next experiment. Also, save the program
(000016 through 006616) so you won't have to re-enter it for the next
experiment.

1 8-1 3

EXPERIMENT NINETEEN - A MICROPROCESSOR-CONTROLLED PHOTOMETER 1

EXPERIMENT 19
A MICROPROCESSOR-CONTROLLED
PHOTOMETER
Objectives:
1. To demonstrate the conduction properties of a
phototransistor under different light intensity situations.
2. To show how the conduction of a phototransistor produces
a proportional voltage which can be measured and converted to a digital value by an ADC.
3. To show how to interface a phototransistor and an ADC to
the Microprocessor Trainer to produce a microprocessorcontrolled photometer.
4. To show how to write the software required to control the
analog conversion process and display light intensity in
foot-candles.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 ADC0809 analog-to-digital converter integrated circuit (#4431122)
1 6821 PIA integrated circuit (#443-1014)
1 General purpose phototransistor (#417-851)
1 4700 52, 1/4-watt, 5% resistor (#6-472-12)
2 2" lengths of 1/8" heat-shrink tubing
1 3" length of 1/4" heat-shrink tubing
1 Alligator clip (User supplied)
Solder
25-watt pencil-type soldering iron (User supplied)
1 pair needle-nose pliers (User supplied)
Hook-up wire

1 9-1

1 9-2

1 LABORATORY MANUAL

INTRODUCTION
Recall that a phototransistor is a semiconductor device whose
conduction level can be adjusted, or regulated, by different light
intensities. With the proper biasing network, a phototransistor
can be connected directly to the input of an ADC. The conduction
level of the phototransistor produces a proportional voltage which
can be measured and converted to a digital value by the ADC. This
value can then be interpreted by a microprocessor as light intensity in foot-candle units using a memory lookup table.
In this experiment, you will first construct a light probe using a
phototransistor and connect it to the input of an ADC. You will then
observe the digital output of the ADC as the phototransistor is
exposed to different light intensities. In the second part of the
experiment, you will interface the ADC/phototransistor circuits to
the Microprocessor Trainer to produce a microprocessor-controlled
photometer. You will also write software to control the analog
conversion process and display light intensity in foot-candles.

PROCEDURE
1. You will first construct a light probe similar to the temperature probe that you constructed in the last experiment. Construct your light probe as follows:

Cut two pieces of hook-up wire; one 18" long and the other
20" long.

Strip 1/4" of insulation from each end of each wire.

A lead diagram of the phototransistor is shown in Figure


19-1. Clip off the base lead of the device. The base lead is
not used in this experiment.

Use a pair of needle-nose pliers to make a small hook at the


end of each of the remaining phototransistor leads, and at
one end of each of the hook-up wires.

Fit the 18" hook-up wire to the emitter, or E, lead of the


phototransistor; and fit the 20" hook-up wire to the collector, or C, lead of the phototransistor. Crimp each fitting
with your needle-nose pliers to assure a good mechanical
connection.

EXPERIMENT NINETEEN - A MICROPROCESSOR-CONTROLLED PHOTOMETER 1

PLASTIC

METAL

OR

BOTTOM VIEW

TAB

E=EMITTER
B=BASE
C=COLLECTOR

Figure 19-1

A lead diagram of the phototransistor.

Clip an alligator clip to one of the phototransistor leads to


act as a heat sink. If you don't have an alligator clip, your
needle-nose pliers will do the job.

Solder the connection and give it a "tug" to make sure the


connection is secure.

Heat-sink the other phototransistor lead and solder its


connection.

Cut two 2" lengths of 1/8" diameter heat-shrink tubing.

Slide one length of this heat-shrink tubing over each


solder connection. Make sure that the tubing touches the
bottom of the phototransistor.

Apply enough heat to shrink each length of tubing. You


may be able to use a common household hairdryer for this
purpose. If more heat is required, a match can be used.

Cut a 3" length of 1/4" diameter heat-shrink tubing.

Slide the length of a 1/4" heat-shrink tubing over the twolead assembly and up over the bottom of the phototransistor
so that only the phototransistor window is showing.

Apply enough heat to shrink the entire length of the


tubing.

1 9-3

1 9-4 1 LABORATORY MANUAL


2. Turn the Trainer power off and add the light probe to the ADC
circuit from the previous experiment as shown in Figure 19-2.
Notice that the phototransistor is connected to input channel
#0 of the ADC. Remember, the 18" lead on the light probe is the
emitter lead of the phototransistor and the 20" probe lead is
the collector lead of the phototransistor.
+5V

INO

26

C
r-- ---I
I
I LIGHT
I
I PROBE
I
I
I
I
I
I
L-. _____I
E

ADC/PIA
INTERFACE CIRCUIT
FROM PREVIOUS EXPERIMENT

Figure 19-2

Light intensity measurement circuit.

3.

Connect your voltmeter or oscilloscope from the ADC input,


pin 26, to ground as shown. Set the voltmeter to a range that
permits you to measure +5 VDC.

4.

Connect a jumper wire between pin 6 (START) and pin 7 (EOC)


of the ADC.

5.

Place the three channel-select logic switches in their logic 0, or


down, position to select input channel #0.

6.

Turn the Trainer power on and observe the eight data LEDs.
You should observe a digital pattern that is proportional to the
light intensity in your room. Compare this digital output to
the voltmeter reading.

7.

Place the light probe under a room or table lamp and observe
the eight data LEDs and your voltmeter. You should find that
most of the data LEDs illuminate, indicating a maximum
digital output of 1111 1111 under the high intensity light
condition. Furthermore, your voltmeter should read almost +5
V, since the phototransitor has been almost completely saturated by the high intensity light.

EXPERIMENT NINETEEN -

A MICROPROCESSOR-CONTROLLED PHOTOMETER

8. Slowly move the light probe away from your light source and
notice the LED pattern and your voltmeter reading. The
digital output value and the voltmeter reading should gradually decrease as the light probe is moved farther away from the
light source.
9. Place your hand over the end of the light probe and observe the
LED pattern and your voltmeter reading. Both should be zero,
since the phototransistor has been cut off by placing it in
complete darkness.
DISCUSSION
The light probe that you constructed in step 1 consists of a general
purpose phototransistor. Notice from Figure 19-2 that the collector
of the phototransistor is connected to the +5 V supply and the
emitter is connected to ground via a 4.7 k52, emitter resistor. The
phototransistor begins to conduct when it "sees" light. Any conduction produces a proportional voltage drop across the 4.7161 emitter
resistor. This voltage drop is input to the ADC and converted to a
proportional digital value. As the light intensity increases the
phototransistor conducts more, producing a larger emitter voltage
which, when converted, produces a larger digital output value.
When it is placed in high intensity light, the phototransistor
saturates. When saturated, it acts like a direct short and the
emitter voltage equals the V supply voltage, or +5 V. This produces a maximum digital output value of 1111 1111, since the input
range of the ADC is 0 to 5 V. When it is placed in complete darkness,
the phototransistor is cut off, acts like an open, and the emitter
voltage drops to zero. This produces a minimum digital output
value of 0000 0000.
Your next task is to measure and display the digital output from
the ADC with the Microprocessor Trainer, thereby producing a
microprocessor-controlled light intensity meter, or photometer.
PROCEDURE (Continued)
10. Remove the wire jumper connection between the EOC and
START lines (pins 6 and 7) of the ADC.

1 9-5

1 9-6 I LABORATORY MANUAL


11. Turn the Trainer power on and enter the program listed in
Figure 19-3.
NOTE: If you saved the program from the previous experiment, you need only change address location 005616 to 54.
Also, change locations 010016 through 010F16 to the light
intensity lookup table values, as indicated.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022
0023

0050
0051
0052

CE
00
50
FF
69
2B
C6
37
F7
B3
03
OE
C6
01
CE
D7
00
09
26
FD
5A
26
F7
C6
3F
F7
B3
03
C6
37
F7
En
03
3E
20
E2

F6
B3
01

MNEMONICS/
CONTENTS

COMMENTS

LDX#

00
50
STX$$
69
2B
LDB#
37
STB$$
B3
03
CLI
LDB#
01
LDX#
D7

00
DEX
BNE
FD
DECB
BNE
F7
LDB#
3F
STB$$
B3
03
LDB#
37
STB$$
83
03
WAI
BRA
E2

Store IRQ interrupt vector

Configure port B with an initial


control value of
6.
Clear I-flag.

Delay approximately one second.

Start a conversion by toggling


CB2 output line.

Wait for interrupt.


Do it again.

LDB$$
B3
01
.. ..

Read digital value from port B.

Figure 19-3
Program for the microprocessor-controlled photometer.

EXPERIMENT NINETEEN A MICROPROCESSOR-CONTROLLED PHOTOMETER 1

HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0053
0054
0055
0056
0057
0058
0059
005A
005B
005C
005D
005E
005F
0060
0061
0062
0063
0064
0065
0066

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F

54
54
54
54
D7
5D
CE
01
00
E6
00
BD
CO
15
C6
OD
BD
CO
06
3B

00
10
20
25
25
35
45
55
65
75
75
75
75
75
75
75

LSRB
LSRB
LSRB
LSRB
STB$
5D
LDX#
01
00
LDB,X
00
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
RTI

00
10
20
25
25
35
45
55
65
75
75
75
75
75
75
75

COMMENTS

Convert to a voltage value via


memory look-up table.

Display voltage value.

Return from interrupt.

Light intensity (footcandles)


look-up table.

12. Reset the Trainer and execute the program by pressing GO and
entering the beginning program address, 0000.

1 9-7

1 9-8 1 LABORATORY MANUAL

13. Expose the light probe to different light intensities and observe the corresponding display and binary LEDs. The Trainer
display shows the measured light intensity directly in footcandles, while the binary LEDs show the proportional value
being generated by the ADC. Table 19-1 provides a cross
reference between footcandles and common light level situations.
Table 19-1
A cross reference between footcandles and common light level situations.

Footcandle
level
0-20

Common light level situations


Inadequate light for reading.

25-50

Enough light to read newspapers, fine print, etc.

55-75

Enough light for intense visual work for long periods, i.e.,
drafting, inspection, etc.

DISCUSSION
A photometer is a device used to measure light intensity. Photometers are some times called foot-candle meters when they measure
light intensity in terms of foot-candles.
Afoot-candle, or fc, is a unit of light intensity. Technically, one footcandle is defined as the amount of light at a point one foot from a
lighted candle.
The farther you are from a light source, the lower the light
intensity. Actually, light intensity varies inversely as the square of
the distance from the light source. Consequently, twice the distance from a given light source reduces the light intensity to onefourth. As a result, you should have observed a rapid reduction in
the Trainer display as the light probe was moved away from the
light source.
The ADC/phototransistor circuit from the first part of this experiment has now been interfaced to the Trainer via the PIA interface.
As before, the phototransistor produces an analog output voltage
proportional to light intensity, and the ADC converts the
phototransistor output to a proportional digital value. However,

EXPERIMENT NINETEEN -

MICROPROCESSOR-CONTROLLED PHOTOMETER

the ADC conversion process is now controlled by the microprocessor using a control program. When the ADC has completed a
conversion, the microprocessor reads the converted value and
interprets that value in terms of foot-candles via a memory lookup
table. The microprocessor then displays the corresponding footcandle value.
The flowchart in Figure 19-4 summarizes the software used in this
experiment. Note that it is very similar to all the ADC control and
display software used in past experiments. In fact, the only difference between this and previous ADC control software is the lookup
table values. Once a digital signal is produced that is proportional
to some external quantity, it is the lookup table that interprets the
digital value and gives it meaning.
INTERRUPT SERVICE
MAIN PROGRAM

ROUTINE

C
INITIALIZE PORT B
CONTROL REGISTER
WITH THE VALUE 3716.

DELAY
APPROXIMATELY
ONE SECOND.

READ DIGITAL
VALUE FROM PORT B.

CONVERT TO FTCNDL
VALUE VIA MEMORY
LOOK-UP TABLE.

WRITE THE VALUE

DISPLAY

3F16 TO PORT B

FOOTCANDLE

CONTROL REGISTER.

VALUE.

START CONVERSION
BY TOGGLING
THE CB2
OUTPUT CONTROL LINE.
WRITE THE VALUE
3716 TO PORT B

RETURN FROM

CONTROL REGISTER.

INTERRUPT.

WAIT FOR EOC


INTERRUPT.

Figure 19-4
Flowchart summary of the light intensity measurement software.

1 9-9

1 9-1 0

1 LABORATORY MANUAL

The lookup table for this experiment was derived using a commercial photometer. A photometer reading in foot-candles was compared to the digital output of the ADC at different distances from
a 100-watt incandescent light source. Again, for experimental
purposes, the memory lookup table is only 16 bytes long. However,
you could obtain much greater sensitivity by using the full 8-bit
output of the ADC and constructing a 256 byte lookup table.
You can dismantle the phototransistor and ADC circuits from the
breadboard. However, save the PIA circuit for the next experiment.
The light probe will also be used again in a later experiment.

EXPERIMENT TWENTY - MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT

EXPERIMENT 20
MICROPROCESSOR-CONTROLLED
OPTICAL COUNTING, TIMING, AND
MOTOR SPEED MEASUREMENT
Objectives:
1. To demonstrate the operation of a typical optical interrupter module.
2. To exhibit the construction of a microprocessor-controlled
optical counter and timer.
3. To demonstrate the difference between edge-triggered and
level-triggered interrupts.
4. To exhibit the construction of a DC motor speed control
circuit and measure motor speed using a microprocessorcontrolled optical-interrupter circuit.
5. To show the calculation of motor rpm from motor speed
data provided by the Microprocessor Trainer.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 Opto-interrupter module (#150-74)
1 6821 PIA integrated circuit (#443-1014)
1 741 op amp (#442-22)
1 Small 5-volt DC motor (#420-644)
1 50 S-2, 3/4-watt, trimmer potentiometer (#10-1173)
1 100 Q, 1/4-watt, 5% resistor (#6-101-12)
1 1000 Q, 1/4-watt, 5% resistor (#6-102-12)
2 10 kS2, 1/4-watt, 5% resistor (#6-103-12)
1 47 Q, 1/4-watt, 5% resistor (#6-470-12)
1 4700 Q, 1/4-watt, 5% resistor (#6-472-12)
1 1N5231B 5.1 V zener diode (#56-16)
1 Optical encoder wheel (#454-31)
1 3" length of foam tape
1 25-watt pencil-type soldering iron (User supplied)
Solder
Electrical tape
Hook-up wire
1 Oscilloscope

20-1

20-2 1 LABORATORY MANUAL


INTRODUCTION
In Unit 13, you learned that an opto-interrupter module is a solidstate device that contains an IRED and a phototransistor mounted
in one package. The two internal semiconductor devices are separated by a slot. When the IRED is forward biased, it emits light,
which turns-on the phototransistor. However, if an object is placed
in the slot, the light beam is broken and the phototransistor turns
off. As a result, a signal is generated that can be detected by a
microprocessor control circuit.
In this experiment, you will monitor the operation of an optointerrupter module using interrupts to control your Microprocessor Trainer. You will write a program to count the number of times
an object passes through the opto-interrupter slot. The interrupt
request, or IRQ , input will be used for this purpose. Then, using
the non-maskable interrupt, or XIRQ , input, you will see how the
microprocessor can be programmed to determine how long an
object remains within the opto-interrupter slot. This demonstrates
an important difference between these two interrupts. The difference being that the IRQ interrupt is edge-triggered, while the
XIRQ interrupt is level-triggered. Finally, in the last part of the
experiment, you will construct a microprocessor-controlled tachometer to measure the rotational speed of a small DC motor.

PROCEDURE
Insert the opto-interrupter device and 741C IC next to the PIA
from the previous experiment, as shown in Figure 20-1. Note that
there are two different styles of opto-interrupter. Make sure you
orient yours correctly.

EXPERIMENT TWENTY - MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT

TRAINER BREADBOARD

OPTO-INTERRUPTER
PIN 3\
741

PIA

O
PIN 4

1',

PIN 1

_3

WHITE DOT
ON SIDE

2
3Z I

04
4

ARE 7,PEN

OPTION 1 `

INDENTATION OR
WHITE DOT ON TOP

OR

O S

111

LEAVE -HI',

JPIN 2

"I

OPTION 2

4 1

MAY HAVE
INDENTATION OR
WHITE DOT ON TOP

Figure

20-1

Layout the 741C and opto-interrupter device as shown, next to the


PIA from a previous experiment.

2. Turn the Trainer power off and construct the circuit shown in
Figure 20-2. Refer to Figure 20-1 to determine the optointerrupter pin numbers. The PIA may already be wired to the
Trainer from the previous experiment.
+5V

GND

120
DO
D1
D2
03
D4
D5
D6
D7
E
I/O 0
AO
+5V
Al
RNJ
RESET

33
DO
32
01
31
D2
30
D3
29
D4
28
D5
27
06
26
D7
25
E
23
CS2
35
RS1
24
CS1
36
RSO
22
CSO
21

+5V

10k0
TO ANY
TRA NER
LED

3
+12V

()PTO:1 INTERRUPTER
II
=J
1
1000
1\AA,-- +5V

10k52

PIA
CAI

10000
5.1V
,0` ZENER

741

4
-12V

4.7k

RAW

34
8

IRQ

RST
IRQA

+5V

Figure 20-2

Circuit diagram and pin assignments for the optical interrupter.

20.3

20-4 I LABORATORY MANUAL

3.

Turn the Trainer power on and observe the LED that is


connected to your circuit. It should be on.

4.

Place a small piece of paper within the opto-interrupter slot


while you observe the LED. The LED should turn off when the
paper is placed within the opto-interrupter slot. If it does not,
check your circuit to be sure that it is connected properly (See
Figure 20-2). Also, make sure the paper is blocking all of the
light. If the paper is too thin, some light could pass right
through it.

DISCUSSION
You can see from the opto-interrupter circuit diagram in Figure 202 that the internal IRED is forward biased. As a result, the IRED
emits infrared light onto the base of the internal phototransistor.
This causes the phototransistor to conduct, or saturate, and produce a +5 V potential at the top of the 4700 S2 resistor. This is then
conditioned by the op amp circuit to produce a TTL level signal.
When you broke the infrared light path by placing a piece of paper
within the opto-interrupter slot, the phototransistor stopped conducting (was cut off). As a result, the output voltage dropped to
zero.
You might think of the internal phototransistor as an optical
switch that turns on and off with the presence or absence of light
on its base. Of course, you can control this switch by interrupting
the light path within the optical interrupter slot. Now, suppose the
output of this circuit were connected to an interrupt input line of
a microprocessor system. Then, the opto-interrupter would generate an interrupt to the MPU each time an object passed through the
slot of the device.

PROCEDURE (Continued)
5.

Make sure that a wire has been connected from pin 38 (IRQA )
of the PIA to the IRQ input on the Trainer. Also be sure to
connect this wire to +5V through a 10 kt2 resistor as shown in
Figure 20-2.

EXPERIMENT TWENTY MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT

6. With the Trainer power on, enter the program listed in Figure
20-3.
HEX
HEX
ADDRESS CONTENTS

MNEMONICS/
CONTENTS

0000

CE

0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D

01
00
FF
69
2B
86
05
B7
B3
02
7F
00
50

000E

OE

000F
0010

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
0108
010C
010D
010E
010F
0110
0111
0112
0113

20
FD

LDX#
01
00
STX$$
69
2B
LDA#
05
STA$$
B3
02
CLR$$
00
50
CLI
BRA
FD

96
50
4C
01
01
97
50
16
BD
CO
15
C6
OD
BD
CO
06
F6
B3
00
3B

LDA$
50
INCA
NOP
NOP
STA$
50
TAB
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
LDAB$$
B3
00
RTI

COMMENTS

Store IRQ interrupt vector.

Configure PIA for interrupt


input/output.

Clear memory counter.

Clear interrupt mask and loop.

Interrupt service routine - - increment and display count.

Clear PIA interrupt and return.

Figure 20-3

Program for the opto-interrupter interface circuit.

7. Execute the program by pressing GO and entering the beginning program address, 0000.

20.5

20-6

I LABORATORY MANUAL

8.

Place a small piece of paper within the opto-interrupter slot


and observe the Trainer display. Now remove the paper. The
Trainer should display the value "01 ".

9.

Remove and reinsert the paper several times within the optointerrupter slot while observing the Trainer display. Each
time the paper is reinserted into the slot, the Trainer display
increments by one. Thus, the microprocessor is counting the
number of times that the opto-interrupter light path is broken.

10. Continue to remove and re-insert the paper within the slot
while you observe the count. Notice that the Trainer is counting in hexadecimal. This is not very practical, since most of us
count in decimal.
11. Reset the Trainer and change the program as follows:
Memory Location Object Code Source Code
0102
0103
0104

8B
01
19

ADDA #
01
DAA

12. Execute the program again and repeat the above procedure of
repeatedly breaking the opto-interrupter light path. Notice
that the Trainer again counts the number of times that the
light path is broken; however, the count is now in decimal.
Why?
13. Now turn your Trainer power off and remove the opto-interrupter circuit output line from pin 40 (CAI ) of the PIA and
insert it into the XIRQ interrupt input line on the Trainer.
14. Turn the Trainer power on and change the contents of memory
location 0005 from 2B to 2E. Execute the program again.
15. Insert your paper into the opto-interrupter slot and observe
the Trainer display. Notice that the display continues to count
very rapidly as long as the light path within the opto-interrupter slot is broken. The count stops when the object is
removed from the slot. How can this be, since the only difference is that you are using the XIRQ interrupt input rather
than the IRQ interrupt input? Shouldn't they both operate in
the same way, since they are using the same interrupt service
routine?

EXPERIMENT TWENTY - MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT 1

DISCUSSION
In this part of the experiment, you have connected the output of the
opto interrupter circuit to an MPU interrupt line on the Trainer. A
flowchart of the interrupt software is provided in Figure 20-4.
Notice that the main program stores the interrupt vector, configures the PIA, clears a memory counter and the IRQ interrupt mask
bit, and then loops continuously until an interrupt is received.
When an interrupt is received, the MPU is directed to the interrupt
service routine, beginning at address 0100. The interrupt service
routine simply increments the memory counter. The count is then
displayed using a resident ROM display routine. After the count is
displayed, the MPU returns to the main program.
MAIN PROGRAM

STORE IRO
INTERRUPT
VECTOR

CONFIGURE
PIA FOR
INTERRUPT I/O

INTERRUPT SERVICE ROUTINE

11.

CLEAR
MEMORY
COUNTER.

INCREMENT
MEMORY
COUNTER.

CLEAR IRO
INTERRUPT
MASK BIT.

DISPLAY
COUNT.

V
REPEAT.

RETURN FROM
INTERRUPT.

Figure 20-4
A flowchart of the interrupt software.

20-7

20-8 I

LABORATORY MANUAL

The PIA is used to condition the opto-interrupter output signal for


input to the edge-triggered IRQ interrupt input on the Trainer.
The opto-interrupter signal is input to the PIA via the CAI input
line. When the PIA detects a high-to-low transition on CA1, it
generates an high-to-low edge via its IRQA line to the IRQ interrupt input on the Trainer.
At first, the Trainer software generated a hexadecimal count. This
was done using a simple increment (INCA) instruction to increment the count. Then the INCA instruction was replaced with the
ADDA #01 and DAA instructions. This produced a decimal count.
The ADDA #01 instruction does the same thing as the INCA
instruction. However, when ADDA is followed by the decimal
adjust accumulator, or DAA, instruction, the resulting count is
generated in decimal rather than hexadecimal. The DAA instruction can only be used with an ADD instruction. This is why simply
adding a DAA instruction after the original INCA instruction will
not do the job.
So, why did the experiment operate differently for the XIRQ
interrupt versus the IRQ interrupt? The reason for this demonstrates a very important difference between these two interrupts
the IRQ interrupt is an edge-triggered interrupt and the XIRQ
interrupt is a level-triggered interrupt. Since the IRQ interrupt is
edge-triggered, the MPU was interrupted only once each time the
light path was broken. Recall that when the light path is broken,
the opto-interrupter generates a high-to-low transition, or edge.
Thus, the count incremented by one with each high-to-low output
edge generated by the opto-interrupter. The XIRQ interrupt, on the
other hand, is level triggered. As a result, an XIRQ interrupt is
generated when the output of the opto-interrupter goes low. If the
output of the opto-interrupter is still low after the interrupt
service routine is completed, another interrupt is generated, and
so on, as long as the XIRQ interrupt input line is held low. Breaking
the opto-interrupter light path causes its output to go low and
remain low as long as the light path is broken. Consequently,
successive interrupts are generated to the MPU and the count
increments continuously as long as the XIRQ interrupt input line
is held low by the opto-interrupter.
By using the IRQ interrupt input line, you have constructed a
microprocessor-controlled optical counter. By using the XIRQ interrupt input line, you can construct a microprocessor-controlled
optical timer, since the count increments as long as an object
breaks the opto-interrupter light path. The only alteration that

EXPERIMENT TWENTY - MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT 1

you must make is to add a memory lookup table that converts the
count to seconds, thereby generating a display in units of time.
PROCEDURE (Continued)
16. Turn the Trainer power off and remove the opto-interrupter
circuit output line from the XIRQ interrupt input and insert it
back into pin 40 (CA1) of the PIA. Make sure that the optointerrupter circuit output is still connected to one of the
Trainer LEDs.
17. Locate the 5-volt DC motor. Solder a 3" piece of hook-up wire
(1/2" stripped at both ends) to either terminal of the DC motor.
18. Cut another a 3" length of hook-up wire. Strip both ends of the
wire and solder it to the remaining motor terminal.
19. Cut two 1-1/4" lengths of foam tape.
20. Peel the backing off of one side of each piece of tape and stick
the two pieces of tape together.
21. Peel the backing off of one side of the tape assembly and attach
the tape assembly to the circumference of the motor as shown
in Figure 20-5.
END VIEW
OF MOTOR

TWO-PIECE TAPE
ASSEMBLY ATTACHED TO
MOTOR CIRCUMFERENCE

Figure 20-5
A two-piece foam tape assembly must be attached to
the circumference of the DC motor as shown.

22. Take the small optical encoder wheel supplied with this course
and press fit it onto the shaft of the DC motor. The encoder
wheel should fit snugly onto the motor shaft. If it does not, you
might have to add a small amount of model glue to assure a
secure fit.

20-9

20-10 I LABORATORY MANUAL


23. Peel the remaining backing off of the bottom of the foam tape
attached to the motor.
24. Place the DC motor assembly onto the breadboard block as
shown in Figure 20-6. Notice that the optical wheel must be
placed within the opto-interrupter slot. Adjust the motor and/
or opto-interrupter position so that the optical encoder wheel
is free to turn within the opto-interrupter slot.
OPTICAL
INTERRUPTER

OPTICAL ENCODER
WHEEL

DC MOTOR

PIA

POTENTIOMETERRESISTOR
(SPEED CONTROL)

741C
BREADBOARD BLOCK
(SIDE VIEW)
FOAM TAPE

Figure 20-6

The DC motor and opto-interrupter assembly.

25. Turn on the Trainer power. Turn the motor shaft with your
hand and observe the output LED of the opto-interrupter. If
the optical encoder wheel is aligned properly, the LED should
blink on and off as the holes in the wheel are rotated through
the opto-interrupter. Readjust the motor and/or opto-interrupter position until this can be accomplished. Also make sure
that there is no interference between the encoder wheel and
the opto-interrupter.
26. Once the assembly is properly aligned, use electrical tape to
secure the assembly to the breadboard.

EXPERIMENT TWENTY MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT

27. Wire one end of the DC motor to a 50 Q trimmer potentiometer


in series with a 47 Q resistor, as shown in Figure 20-7. Prepare
and connect a 3" length of hook-up wire (to be connected later)
to the other end of the 50 Q potentiometer. Ground the other
motor wire.

5 011
TRIMMER POT

DC
MOTOR

Figure 20-7

The DC motor must be connected on the breadboard as shown.

28. Enter the program listed in Figure 20-8. After it is entered,


press NMI.

HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
0000
000E
000F
0010

CE
01
00
FF
69
2B
86
05
B7
B3
02
7F
00
50
7F

00
60

MNEMONICS/
CONTENTS
LDX#
01
00
STX$$
69
2B
LDA#
05
STA$$
83
02
CLR$$
00
50
CLR$$
00
60

COMMENTS

Store TA-d interrupt vector.

Configure PIA for interrupt I/O.

Clear memory counters.

Figure 20-8

Program to count and display motor speed.

20-11

20-1 2 I LABORATORY MANUAL


HEX
HEX
ADDRESS CONTENTS

MNEMONICS/
CONTENTS

0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B

CE
FF
FF
09
26
FD
BD
01
50
20
EF

LDX#
FF
FF
DEX
BNE
FD
JSR$$
01
50
BRA
EF

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119

96
50
8B
01
19
97
50
81
00
27
04
F6
B3
00
3B
96
60
8B
01
19
97
60
F6
B3
00
3B

D6
60
BD
CO
15
D6
50
BD
CO
15

LDA$
50
ADDA#
01
DAA
STA$
50
CMPA#
00
BEQ
04
LDA$$
BE
00
RTI
LDA$
60
ADDA#
01
DAA
STA$
60
LDA$$
B3
00
RTI

0150
0151
0152
0153
0154
0155
0156
0157
0158
0159

LDB$
60
JSR$$
C4
15
LOBS
50
JSR$$
CO
15

COMMENTS

Accumulate count.

Jump to display subroutine


.
Do it again

Interrupt service routine to


increment count

Return from interrupt

Subroutine to display RPM count.

EXPERIMENT TWENTY MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT

HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

015A
015B
015C
015D
015E
015F

C6
OD
BD
CO
06
39

LDB#
OD
JSR$$
CO
06
RTS

COMMENTS

Subroutine to display RPM count.


(Continued)

Return from subroutine

29. Execute the program by pressing GO and entering the beginning program address, 0000. The Trainer should display 0000.
30. Connect the open end of the potentiometer (step 27) to the +5
VDC supply. The motor shaft should begin rotating and the
Trainer should display a four digit value that is proportional
to the motor speed, or rpm. NOTE: If the 50 Q potentiometer
connected to the motor is adjusted to a minimum, you may
need to turn the pot to get the motor shaft turning.
31. After the motor begins turning, adjust the 50 Q trimmer
potentiometer for a minimum motor speed (without stopping
it)
32. Connect an oscilloscope between the opto-interrupter circuit
output and ground. Adjust the oscilloscope voltage scale to 2
volts per division and the time base to a range that displays
several cycles of the opto-interrupter output signal. You should
observe a square wave signal when the oscilloscope is adjusted
properly.

20-1 3

20-141LABORATORY MANUAL
33. Measure the period (duration of one cycle) of the opto-interrupter output signal and record it in Table 20-1.

Table 20-1
Motor speed data and rpm calculations.

Motor Speed Count


Period
from
Reading from Scope Trainer Display

7.5
Period

(16.5) x Count

#1
#2
#3
#4
#5

34. Observe the four-digit motor speed count on the Trainer display. Record this value next to the period value in Table 20-1.
NOTE: If at any time the count on the trainer decreases from
its constant value to 0000, you may restart the program by
entering NMI, GO, Return. This restarts the count/display.
35. Increase the motor speed slightly by turning the 50 S2 trimmer
potentiometer and repeat steps 33 and 34.
36. Repeat the above procedure to obtain five different motorspeed readings.
37. Calculate the motor rpm for each set of motor speed readings.
Use two different methods, as follows:
1. For a given motor speed reading, calculate the rpm using
the oscilloscope period measurement as follows:
rpm = 7.5
period
Enter this calculated value in Table 20-1.

EXPERIMENT TWENTY - MICROPROCESSOR-CONTROLLED OPTICAL COUNTING, TIMING, AND MOTOR SPEED MEASUREMENT 1

2. For a given motor speed reading, calculate the rpm using


the motor speed count displayed by the Trainer as follows:
rpm = 16.5 x count
Enter this value in Table 20-1.
38. Compare the two calculated rpm values for each motor speed
setting.

DISCUSSION
This experiment demonstrates how a microprocessor can be used to
determine angular velocity using optical sensing techniques. An
optical encoder wheel was attached to the shaft of a DC motor. The
encoder wheel was placed into the slot of an optical interrupter.
Since the encoder wheel has eight holes, eight pulses are generated
by the opto-interrupter for each revolution of the motor shaft. The
microprocessor has been programmed to simply count the number
of pulses that occur in a given period of time. The accumulated
count is directly proportional to the speed of rotation, or angular
velocity, of the motor shaft.
The program in Figure 20-8 uses a software time delay to establish
the pulse count period. The pulse-count is accumulated during the
time delay using the interrupt request, or IRQ , input. At the end
of the time delay, a subroutine is called to display the accumulated
count. The process then repeats.
The precise length of the software time delay and any time associated with the interrupt service routine must be known since these
factors determine the time base that is to be used for the rpm
calculation. Therefore, to determine the time base, you must count
the number of MPU cycles required to execute these routines and
multiply by the clock period of your Trainer. The ETW-3800 Trainer
has a clock period of 1.0851 microseconds. Using this clock period
and the given program, we have determined that the time base in
seconds is:
.42666 + (.000053 x COUNT)

20-1 5

2 0-16 I

LABORATORY MANUAL

The software time delay takes .42666 seconds to execute, and the
interrupt service routine requires (.000053 x COUNT) seconds to
execute. Using this time base, it can be shown that the speed of
rotation in rpm is:
7.5 x COUNT
rpm .42666 + (.000053 x COUNT)
= 16.5 x COUNT
Notice that we have approximated the above equation to simplify
the rpm calculation.
You might want to recalculate the motor rpm using the exact
equations given above. Your data should then compare a bit more
favorably.
At this time, you can dismantle the DC motor assembly. However,
save the PIA and opto-interrupter circuit for the next experiment.

EXPERIMENT TWENTY-ONE - LINEAR POSITION SENSING USING OPTICAL TECHNIQUES

EXPERIMENT 21
LINEAR POSITION SENSING USING
OPTICAL TECHNIQUES
Objectives:
1. To demonstrate linear position sensing using an optointerrupter.
2. To show the difference between absolute and incremental
position sensing.
3. To demonstrate how to write the microprocessor software
required to interpret linear position data.
4. To show how a memory lookup table can be used to perform
conversions between inches and centimeters.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 Opto-interrupter module (#150-74)
1 6821 PIA integrated circuit (#443-1014)
1 741 op amp (#442-22)
1 100 Q, 1/4-watt, 5% resistor (#6-101-12)
2 1000 Q, 1/4-watt, 5% resistor (#6-102-12)
2 10 kQ, 1/4-watt, 5% resistor (#6-103-12)
1 1N5231B 5.1 V zener diode (#56-16)
1 11" x 1-1/4" piece of cardboard (User supplied)
1 Pair of household scissors (User supplied)
1 Paper punch (User supplied)
2 1" x 2" pieces of conductive foam
Hook-up wire

121 -1

21 -2 I LABORATORY MANUAL
INTRODUCTION
Opto-electronics are frequently used by digital systems to sense
external conditions. As you are aware, a microprocessor can count
the number of times that an optical path is broken to determine
how many objects have passed a given point. In addition, a microprocessor can be programmed to determine how long an optical
path is broken, thereby determining how long an object is in a
given position. Finally, opto-electronics can be used to determine
position and velocity.
In the previous experiment, you observed how to use an optical
interrupter module to measure angular velocity and position. In
this experiment, you will use the same versatile interrupter module to demonstrate linear position sensing.

PROCEDURE
1. Before you begin the experiment, you must construct a linear
optical encoder. Assemble the encoder as follows:

Cut out the encoder template in Figure 21-1.

Obtain a piece of cardboard at least the size of the template. The cardboard must be thin enough to fit within the
opto-interrupter slot without interference. Any thin cardboard, such as paper-tablet backing, will do the job.

Tape or paste the template outline onto the cardboard.

Cut out the encoder, following the template outline.

Punch-out the circles in the encoder using a standard 1/4"


paper punch.

Cut two pieces of conductive foam, approximately 1" x 2"


each.

Use a sharp knife or razor blade to cut a 3/4" slit lengthwise in the middle of each piece of conductive foam.

Push each leg of your encoder into the slit in the conductive foam pieces. This provides support for your encoder
and allows it to "stand" on its own.

Your completed linear optical encoder should look like the


one pictured in Figure 21-2.

EXPERIMENT TWENTY-ONE LINEAR POSITION SENSING USING OPTICAL TECHNIQUES

0
0

0
0

0
0
0
0
0
0
0
0

(Page 21-4 Blank)

21 -3

EXPERIMENT TWENTY-ONE LINEAR POSITION SENSING USING OPTICAL TECHNIQUES 1

CARDBOARD

0 0

0 0
PUNCHED HOLES

CONDUCTIVE
FOAM PADS

Figure 21-2
A completed linear optical encoder.

2. Turn the Trainer power off and construct the opto-interrupter


circuit shown in Figure 21-3. NOTE: This is not necessary if
you saved the circuit from the previous experiment. However,
make sure that you removed the DC motor assembly from the
breadboard.
+5V GND
I20
DO
DI
D2
D3
D5
D6
D7
I/O 0
AO
+5V
Al

am
RESET
IRO

33
DO
32
DI
31
02
30
29
28
05
27
D6
PIA
26
D7
25
E
23
CS2
35
RS1
24
CSI
36
RSO
22
CSO
21
RATV
34
RST
38
IROA

I 1
+5V

10k 0

03
04

10k0

TO ANY
TRA NER
LED

CAI

+12V

l000n

741
15.1V
,m ZENER

4
4.7k0

12V

0 04 7c),

OPTION 1 s

4
I WHITE DOT
ON SIDE \

OR

'INDENTATION OR
WHITE DOT ON TOP I

+5V

OPTION 2

I
1
II PTOINTERRUPTER
I
\z-J
1
100 0
+5V

10Ic0

11
11 (3

MAY HAVE
INDENTATION OR
WHITE DOT ON TOP

Figure 21-3
Optical interrupter circuit and pin diagram.

21 -5

21 -6 1 LABORATORY MANUAL
3.

Place your optical encoder within the opto-interrupter slot


and make sure there is no interference with any of the wire
connections. Slide the encoder to the right or left until one of
the holes is centered within the slot. You should position the
opto-interrupter/encoder in such a way so that the encoder is
free to travel its length through the interrupter module.

4.

Turn the Trainer power on and observe the LED connected to


the opto-interrupter output. It should be on. If it is not on,
position the encoder and/or opto-interrupter until the LED
illuminates. You might have to adjust the height of the encoder
and/or opto-interrupter.

5.

Slide the encoder in either direction. The LED should go out as


a hole moves out of the slot and illuminate when a hole is
within the slot.

6.

Position the encoder so that the space between the first and
second holes on the right side of the encoder is within the slot
as shown in Figure 21-4. The LED should be off.
OPTO-INTERRUPTER
(POSITION AS NEEDED)

SOLDERLESS
CONNECTOR BLOCK

Figure 21-4
Initial optical encoder positioning.

7.

Enter the program listed in Figure 21-5.

EXPERIMENT TWENTY-ONE LINEAR POSITION SENSING USING OPTICAL TECHNIQUES

HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
0008
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016

CE
01
50
FF
69
2E
CE
01

LDX#
01
50
STX$$
69
2E
LDX#
01
00
STX$$
69
2B
LDA#
05
STA$$

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F
0110
0111
0112
0113

00
FF
69
2B
86
05
B7
B3
02
7F
00
50
OE
20
FD

96
50
8B
05
19
97
50
16
BD
CO
15
C6
OD
BD
CO
06
F6
B3
00
3B

B3
02
CLR$$
00
50
CLI
BRA
FD

LDA$
50
ADDA#
05
DAA
STA$
50
TAB
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
LDAB$$
B3
00
RTI

COMMENTS

Store XIRQ interrupt vector.

Store IRQ interrupt vector.

Configure PIA for interrupt


input/output.

Clear memory counter

Clear interrupt mask and loop.

IRQ interrupt service routine - - - increment and display memory


count.

Clear PIA interrupt and return.

Figure 21-5
Linear position sensing program.

21 -7

21 -8

LABORATORY MANUAL

HEX
HEX
ADDRESS CONTENTS
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
015A
0158
015C

7F
00
50
5F
BD
CO
15
C6
OD
BD
CO
06
3B

MNEMONICS/
CONTENTS
CLR$$
00
50
CLRB
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
RTI

COMMENTS

XIRC) interrupt service routine - - clear display to 00 and return.

8.

Execute the program by pressing GO and entering the beginning program address, 0000.

9.

Slowly slide the encoder to the right while you observe the
Trainer display. You should observe that the Trainer increments by five each time a hole passes through the optointerrupter. The holes are spaced exactly .5" from each other.
Thus, the Trainer is displaying the absolute linear position of
the encoder in .5" increments.

10. Continue to move the encoder slowly, all the way to the right.
The Trainer display shows the linear position of the encoder in
inches, to the nearest .5".
11. Move the encoder slowly back in the opposite direction, or left.
Notice that the Trainer output continues to increase. Thus,
you might conclude that this system is not capable of determining direction of linear travel. How could this be accomplished?

DISCUSSION
The optical linear position encoder that you constructed in step 1
is rather crude; nevertheless, it gets the idea across. When an
encoder hole is within the opto-interrupter slot, the light path is
not broken and no interrupt is generated to the MPU. However,
when a hole moves out of the slot, the light path is broken and a
IIZQ interrupt is generated to the MPU. Since the holes are spaced
approximately .5" apart, the interrupt service routine increments
the memory counter by five each time a hole moves out of the slot.
The count is accumulated and displayed to provide the absolute
position of the encoder in inches, to the nearest .5".

EXPERIMENT TWENTY-ONE - LINEAR POSITION SENSING USING OPTICAL TECHNIQUES 1

You might have noticed that we used the term absolute position in
the above discussion. Absolute linear position is always measured
relative to a single reference, or zero, point. A major application of
absolute positioning is for machine tool control along two axes. A
reference, or zero, point is established; then all movements are
made with reference to that point. Many times, optical linear
encoders are used to sense the absolute position of the machine tool
at any point within the two axes coordinate system. This provides
position feedback data to the microprocessor controller.
The degree, or resolution, of position sensing is determined by the
encoder increments. In our case, the spacing of the holes determined the position-sensing resolution. Of course, two optical sensing devices would be required to determine direction of movement.

PROCEDURE (Continued)
12. Select any one of the binary data logic switches on the Trainer
and place it in its logic 1, or up, position.
13. Connect a wire between the selected logic switch and the XIRQ
interrupt input of the Trainer.
14. Execute the program by pressing GO and entering the beginning program address, 0000.
15. Slide the encoder as before and note that the Trainer displays
absolute position.
16. When the LED is on, toggle the binary logic switch from 1-to0-to-1 by placing it in its down, then up position. Notice that
the display is now "00".
17. Slide the encoder as before and note that the Trainer now
displays the encoder position with reference to this new zero
position. This is referred to as incremental position.
18. Toggle the binary logic switch at any place within the travel of
the encoder to establish a new zero point. Once this zero is
established, the Trainer will display the incremental position
from the newly established zero reference point.

21 -9

2 1 -1 0 1LABORATORY MANUAL
DISCUSSION
Incremental positioning is useful when an object, such as a machine tool table, must be moved a distance relative to its current,
or present, position. This type of positioning is important since a
workpiece can be placed anywhere within the work area of a
machine tool without precise positioning. The starting, or zero,
position is then determined relative to the position of the workpiece,
rather than a fixed point. In effect, incremental positioning allows
you to move the coordinate axis to the workpiece, rather than
positioning the workpiece precisely at the zero point of a fixed
coordinate axis as is required for absolute positioning.
In our simple system, toggling the binary logic switch generates an
XIRQ interrupt to the MPU. The XIRQ service routine that you
added simply "zeros-out" the display. The IRQ interrupt input
from the opto-interrupter is then used to determine position from
the new zero point.
Up to this point, the display has been in inches. Suppose you want
the position display to be in centimeters. How can this be accomplished, since your optical encoder holes are spaced in .5" units?
You might think that a new position encoder needs to be made, but
with a microprocessor, a memory lookup table can be used to
convert from inch increments to centimeter increments.

PROCEDURE (Continued)
19. Reset the Trainer and change the IRQ interrupt service routine beginning at address 0100 as follows:
Memory Address Hex Contents Mnemonics/Contents
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A

96
50
4C
97
50
B7
01
OC
CE
01
80

LDA$
50
INCA
STA$
50
STA$$
01
OC
LDX#
01
80

EXPERIMENT TWENTY-ONE - LINEAR POSITION SENSING USING OPTICAL TECHNIQUES 121-1 1

010B
010C
010D
010E
010F
0110
0111
0112
0113
0114
0115
0116
0117
0118

E6
00
BD
CO
15
C6
OD
BD
CO
06
F6
B3
00
3B

LDB,X
00
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
LDA$$
B3
00
RTI

20. Enter the following centimeter lookup table beginning at


address 0180:
Memory Address

Hex Contents

0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
018A
018B
018C
018D
018E
018F
0190
0191

00
01
03
04
05
06
08
09
10
11
13
14
15
17
18
19
20
FF

21. Reset the Trainer and execute the program by pressing GO and
entering the beginning program address, 0000.

21 -1 2 1LABORATORY MANUAL
22. Toggle the binary logic switch to zero the display.
23. Slide the position encoder while you observe the display. The
Trainer should now display the incremental position in centimeters. NOTE: If the Trainer displays the value "FF", the
MPU is at the end of the lookup table. This is called a program
sentinel, which marks the end of the memory lookup table.
When the sentinel appears, you must zero the system by
toggling the binary logic switch.

DISCUSSION
The IRQ interrupt service routine beginning at address 0100 has
been altered to access a centimeter memory lookup table. The
service routine uses an incrementing operation along with indexed
addressing to access and display the appropriate centimeter value
from the lookup table. The memory lookup table begins at address
0180 and contains centimeter values which have been rounded-off
to the nearest whole centimeter.
You may now remove all components and wires from the Trainer
breadboard.

EXPERIMENT TWENTY-TWO - LINEAR POSITION AND VELOCITY SENSING USING MAGNETIC HALL-EFFECT DEVICES

EXPERIMENT 22
LINEAR POSITION AND VELOCITY
SENSING USING MAGNETIC
HALL-EFFECT DEVICES
Objectives:
1. To demonstrate the operation of a Hall-effect device.
2.

To show how to interface a Hall-effect device to the ETW3800 Trainer.

3. To show how a Hall-effect device can be used to count


passing objects.
4.

To discuss how Hall-effect devices are used to measure


linear position.

5. To exhibit the programming of the Trainer to measure the


amount of time it takes an object to pass the Hall-effect
device.
6. To show the calculation of the linear velocity of an object
based upon data provided by a microprocessor-controlled
Hall-effect sensing circuit.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
2 UGN3020T Hall-effect device (#442-752)
1 Magnet (#474-1)
2
1000 12, 1/4-watt, 5% resistor (#6-102-12)
1 3300 SI, 1/4-watt, 5% resistor (#6-332-12)
1 .01 !IF capacitor (#21-185)
Hook-up wire

122-1

22-2

I LABORATORY MANUAL

INTRODUCTION
As you are now aware, solid-state Hall-effect devices can be used
in a variety of ways to sense angular and linear motion. These
devices have become very popular in many microprocessor-controlled applications because they are reliable, rugged, and can
produce a signal that is directly compatible with the microprocessor input logic.
In this experiment, you will become acquainted with the operating
characteristics of a typical Hall-effect device. You will then interface the Hall-effect device to the Microprocessor Trainer. You will
program the microprocessor to detect linear motion and determine
linear velocity.

PROCEDURE
1.

Make sure that all components and wires have been removed
from the Trainer breadboard.

2.

Check to see that the Trainer power switch is in the off


position.

3.

Insert one of the UGN3020T Hall-effect devices into the breadboard block as shown in Figure 22-1. Notice that the Halleffect device must be located at the extreme left-hand end of
the breadboard block, and inserted into the row of holes just
behind the breadboard slot. Furthermore, the small circle on
one side of the Hall-effect device must face the front of the
breadboard block as shown.
HALL-EFFECT
DEVICE
SMALL CIRCLE
MUST FACE
FORWARD

FRONT

TRAINER BREADBOARD BLOCK

Figure 22-1
Locate the first Hall-effect device to the extreme left on the breadboard block,
just behind the IC slot. Make sure the small circle on the sensor is facing
forward.

EXPERIMENT TWENTY-TWO - LINEAR POSITION AND VELOCITY SENSING USING MAGNETIC HALL-EFFECT DEVICES 1

4. With the Trainer power off, construct the circuit shown in


Figure 22-2. Notice the position of the pins with respect to the
circle on the front of the Hall-effect device. Locate the components and hook-up wires behind the Hall effect device.
+5V
TO LED #7
ON TRAINER

+5V
3300 11
IRO
SMALL CIRCLE
ON FRONT OF
HALL-EFFECT DEVICE

Figure 22-2

Experimental circuit for the Hall-effect device.

5. Turn the Trainer power on and verify that LED 7 is on. If it is


not, check your circuit and make sure the Hall-effect device's
small circle is towards the front as shown in Figure 22-1.
6. Hold the permanent magnet supplied with this course against
the front of the Hall-effect sensor, while you watch LED 7 on
the Trainer. The LED should go out, indicating the presence of
the magnetic field. If it does not, turn the magnet over and
hold the other side in front of the Hall effect device. One side
should cause the LED to go out. Mark this side of the magnet
by scratching it slightly.
7. Move the magnet back and forth in front of the sensor and you
should observe that the LED goes on and off as the magnet
passes through the sensing region of the device.
8. Hold the magnet against the sensor so the LED is off. Then,
slowly move the magnet away from the sensor while you
observe the LED. How far away is the magnet from the sensor
when the LED turns on? This is the sensing distance for the
magnet/sensor combination. It should be about 1/4 inch.

22-3

22-4 I LABORATORY MANUAL


9.

Connect a wire from the Hall-effect sensor output LED (LED


7) through an RC network to the IRQ interrupt input on the
Trainer as shown in Figure 22-2.

10. Enter the program listed in Figure 22-3.


HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
0100
010E
010F
0110

CE
01
00
FF
69
2B
7F
00
50
OE
20
FD

LDX#
01
00
STX$$
69
2B
CLR$$
00
50
CLI
BRA
FD

96
50
8B
01
19
97
50
16
BD
CO
15
C6
OD
BD
CO
06
3B

LDA$
50
ADDA#
01
DAA
STA$$
50
TAB
JSR$$
CO
15
LDB#
OD
JSR$$
CO
06
RTI

COMMENTS

Store IRQ interrupt vector.

Clear memory counter and


interrupt mask.
Repeat and wait for interrupt

Increment memory counter and


display count value.

Figure 22-3

Magnet counting program.

11. Execute the program by pressing GO and entering the beginning program address, 0000.
12. Move the magnet back and forth in front of the sensor and
observe the Trainer display. You should see that the Trainer is
counting the number of times that the magnet passes through
the sensing region of the Hall-effect device.

EXPERIMENT TWENTY-TWO - LINEAR POSITION AND VELOCITY SENSING USING MAGNETIC HALL-EFFECT DEVICES 1

DISCUSSION
The circuit you just constructed demonstrates how Hall-effect
devices are used to sense the presence, or position, of an object. In
practice, the magnet is attached or embedded into an object such as
a rotating drum or machining table. If the object is a rotating
drum, the Hall-effect device provides a series of output pulses
whose frequency is proportional to the angular velocity, or rpm, of
the drum. Of course, multiple Hall-effect devices must be used to
detect angular position and direction of rotation.
Hall-effect devices are also used to detect and count moving objects. Again, small magnets must be attached to the objects. Then,
a microprocessor can be programmed, as you did, to count either
the number of times a given object passes a point, or how many
separate objects pass the point. The program in Figure 22-3 increments and displays a memory counter each time an IRQ interrupt
is generated by the magnet passing in front of the sensor.
Linear position sensing and determining direction of movement
requires multiple Hall-effect devices spaced at precise intervals.
The position of an object is then determined by sensing which Halleffect device is active at any given time. Direction of movement of
the object is determined by the order in which the Hall-effect
devices are activated. A microprocessor program could easily be
written to accomplish this task.
Linear position sensing could also be accomplished using one Halleffect device. However, multiple magnets must be attached to the
moveable object and spaced at precise intervals. The idea here is
the same as that used for the optical position encoder in the
previous experiment. However, magnets must take the place of the
optical encoder holes. The microprocessor software required to
sense and display both absolute and incremental position is identical to that used in the previous experiment.
Now, let's see how two Hall-effect sensors are used to measure
linear velocity.

22-5

22-6 I LABORATORY MANUAL


PROCEDURE (Continued)
13. Turn the Trainer power off and remove the connection between
LED 7 and the IRQ interrupt on the Trainer.
14. Insert the other Hall-effect device into the breadboard precisely 6 inches to the right of the first Hall-effect device. Wire
this second Hall-effect device per Figure 22-2, except use LED
0 for the output of this sensor.
15. Turn the Trainer power on and test this second device by
placing the marked side of the magnet in front of the sensor.
LED 0 should go out when the magnetic field is detected by the
device. If not, turn the Trainer power off and check your
circuit.
16. Pass the magnet from left to right in front of the two Halleffect devices. Use one continuous straight line motion. LED 7
should blink off followed by LED 0 as the magnet passes by the
left and right sensors, respectively. Repeat this motion several
times at different speeds until you are able to get the two LEDs
to blink consecutively.
17. Turn the Trainer power off and connect a wire from LED 7 to
the IP7 input on the Trainer. Connect another wire from LED
0 to IPO on the Trainer.
18. Turn the Trainer power on and enter the program listed in
Figure 22-4.
19. Execute the program by pressing GO and entering the beginning program address, 0000.
20. Connect a wire from the 1 Hz output on the Trainer through
the RC network to the IRQ interrupt input on the Trainer.
21. Pass the magnet from left to right in front of the two sensors
as before. Make sure that both LEDs blink as the magnet
passes in front of their respective sensors.

EXPERIMENT TWENTY-TWO LINEAR POSITION AND VELOCITY SENSING USING MAGNETIC HALL-EFFECT DEVICES 1

22. After the magnet has passed the right sensor, the Trainer
displays a value. This value is the number of seconds it took to
move the magnet between the two sensors.
Now, since you know that the distance between the two sensors is 6 inches, you can calculate the linear velocity of the
magnet as follows:
Linear Velocity =

Display Value

inches/second.

Using this equation, record the linear velocity below:


inches/second.

Linear Velocity =
HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A

CE
01
00
FF
69
28
7F
00
50
OF
B6
B2

LDX#
01
00
STX$$
69
2B
CLR$$
00
50
SEI
LDA$$
B2
80
BM!
FB
CLI
LDA$$
B2
80
ASRA
BCS
FA
SEI
JSR$$
01
50
STOP

80
28
FB
OE
B6
B2
80
47
25
FA
OF
BD
01
50
CF

COMMENTS

Store IRO interrupt vector

Clear memory counter.


Set interrupt mask
Read input port and repeat until
IN7 clear.
Clear interrupt mask.

Read input port and repeat until


INO clear.

Set interrupt mask.


Jump to display routine.
Stop

onto.

Figure 22-4

Linear velocity measurement program.

22-/

22-8 1 LABORATORY MANUAL


HEX
HEX
ADDRESS CONTENTS
0100
0101
0102
0103
0104
0105
0106
0107

0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
015A
015B
015C
015D
015E
015F
0160
0161
0162
0163
0164
0165

MNEMONICS/
CONTENTS

96
50
8B
01
19
97
50
3B

D6
50
BD
CO
15
CC
01
5C
BD
CO
1B
39
10
53
45
43
4F
4E
44
53
OD
00

LDA$
50
ADDA#
01
DAA
STA$
50
RTI

LDB$
50
JSR$$
CO
15
LDD#
01
5C
JSR$$
CO
1B
RTS
LF
S
E
C
0
N
D
S
CR
NULL

COMMENTS

Increment seconds counter and


return.

.
.

Display seconds count.

23. Temporarily disconnect the 1 Hz output from the IRQ interrupt input on the Trainer.
24. Reset the Trainer and execute the program again.
25. Reconnect the 1 Hz output to the IRQ interrupt input on the
Trainer.
26. This time, move the magnet past the two sensors very slowly.
27. When the seconds value is displayed, calculate the linear
velocity again using the above equation.
Linear Velocity =

inches/second.

28. Repeat the above procedure for several different velocities.

EXPERIMENT TWENTY-TWO - LINEAR POSITION AND VELOCITY SENSING USING MAGNETIC HALL-EFFECT DEVICES 1

DISCUSSION
A flowchart of the linear velocity program is shown in Figure 22-5.
The two Hall-effect sensor outputs are applied to two separate
input port lines on the Trainer (IN7 and INO). When the magnet
passes in front of the left sensor, the sensor generates a logic 0
output which is read by the program at the IN7 input port line.
When this logic 0 is detected, the IRQ interrupt mask bit is cleared
and the interrupt service routine increments a memory counter
each second, as a result of the 1 Hz signal applied to the IRQ
interrupt input of the Trainer.
The program then monitors the INO port line of the Trainer. When
the magnet passes in front of the right sensor, the sensor generates
a logic 0 on this port line. When this logic 0 is detected, the program
sets the IRQ interrupt mask stopping the count accumulation and
displays the count value. Thus, the count value represents the
elapsed time, in seconds, that the magnet has moved from the left
sensor to the right sensor. Now, since the sensors have been placed
precisely 6 inches apart, the linear velocity in inches per second is
the distance (6") divided by the elapsed time (display value), or:
Linear Velocity =

6
inches/second.
Display Value

22-`J

22-1 0 I LABORATORY MANUAL

MAIN PROGRAM

IRO INTERRUPT
SERVICE ROUTINE

INCREMENT
MEMORY
COUNTER

4
C LEAR MEMORY
COUNTER AND
SET INTERRUPT
MASK

_d

RETURN

READ TRAINER
INPUT PORT

CLEAR
INTERRUPT
MASK

READ TRAINER
INPUT PORT

wi
NO

SET
INTERRUPT
MASK

DISPLAY
SECONDS
COUNT

Figure 22-5
A flowchart for the linear velocity sensing program.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS 1

EXPERIMENT 23
MICROPROCESSOR INTERFACING
AND CONTROL OF STEPPER
MOTORS
Objectives:
1. To demonstrate how to interface a stepper motor to the
ETW-3800 Microprocessor Trainer via a PIA interface.
2. To show how to write a stepper motor control program.
3. To experiment with changing the control program to produce different motor speeds and directions of rotation.
4. To demonstrate the maximum operational speed of the
stepper motor.
5. To demonstrate closed loop sensing and control with a light
sensing circuit that allows the stepper motor to be turned
off or on with the presence or absence of light.

MATERIALS REQUIRED
1 ETW-3800 Microprocessor Trainer
1 Stepper motor (#420-626)
1 6821 PIA integrated circuit (#443-1014)
1 741C op amp integrated circuit (#442-22)
4 2N3904 general purpose NPN transistors (#417-875)
1 1N5231B 5.1 volt, 1/4-watt, zener diode (#56-16)
2 10 lifl, 1/4-watt, 5% resistors (#6-103-12)
1 4.7 ktl, 1/4-watt, 5% resistor (#6-472-12)
1 1000 CI, 1/4-watt, 5% resistor (#6-102-12)
4 470 S2, 1/4-watt, 5% resistors (#6-471-12)
1 Light probe from "photometer" experiment (19)
1 Optical encoder wheel (#454-31)
Hook-up wire

23-1

23-2

1 LABORATORY MANUAL

INTRODUCTION
In Unit 15, you became acquainted with the operating and control
principles of stepper motors. You found that a stepper motor is
controlled by writing a digital code sequence to the motor control
transistors. The order of the coded sequence determines the direction of rotation of the motor, and the speed at which the sequence
is generated determines the motor speed.
In this experiment, you will apply these fundamental control
principles to control the speed and direction of rotation of a stepper
motor using the ETW-3800 Microprocessor Trainer. You will then
construct a light-sensing circuit to demonstrate a typical microprocessor sense and control operation. You will program the microprocessor to turn the stepper motor on and off as an object passes
through the light beam.

PROCEDURE
1. Turn the Trainer power off and construct the stepper motor
interface circuit shown in Figure 23-1. Refer back to Figure
16-1 in the "DAC Interfacing" experiment (on Page 16-2) to
interface the PIA chip for port B output. Note that we will use
2N3904 transistors to supply current to the stepper motor
coils. While this will work fine for our purposes here, you
should keep in mind the absolute maximum rating constraints
on the devices you use. For example, the 2N3904 has a Ic( nax)
= 200 mA. While this value may be approached under the "noload" conditions of the experiment, heavier transistors, or
Darlingtons, should be used when loads are applied to the
motor. Make sure to follow the color-coded stepper motor lead
connections shown in Figure 23-1.
2.

Attach the optical encoder wheel from Experiment 20 to the


shaft of the stepper motor. If the wheel does not fit snug on the
motor shaft, use a small amount of glue so that the wheel is
firmly attached. Any common model glue will do. (Alternately,
you can attach a small piece of tape to the motor shaft so it
serves as a "flag.")

3. Lay the stepper motor down on a flat surface so that the shaft
is in a vertical position.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS 1

SEE FIGURE 16-1 FOR


PIA INTERFACE WIRING

.5
3
0

3
>
BROWN

ORANGE
YELLOW

RED

+5V
+5V 0

BLACK-

PIA

01

PBO
PB1
P82

10

47052

11

47052

12

PB3 13

02

03

47052
47052
v"v1/1,0

01,2,3,4=2N3904

Figure 23-1
The stepper motor interface circuit.

4. Turn the Trainer power on and enter the stepper motor control
program listed in Figure 23-2.
HEX
HEX
ADDRESS CONTENTS
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F

CE
00
50
FF
69
2E
86
FF
B7
B3
01
86
04
B7
B3
03

MNEMONICS/
CONTENTS
LDX#
00
50
STX$$
69
2E
LDA#
FF
STA$$
B3
01
LDA#
04
STA$$
B3
03

COMMENTS

Store XIRQ interrupt vector

Configure port B of the PIA for


output.

Figure 23-2
Stepper motor control program.

23-3

23-4 I LABORATORY MANUAL


HEX
ADDRESS

HEX
CONTENTS

MNEMONICS/
CONTENTS

0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
0018
001C
0010
001E
001F
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
002B
002C
0020
002E
002F
0030
0031
0032

0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B

86
OA
67
B3
01
BD
01
00
86
09
B7
B3
01
BD
01
00
86
05
B7
B3
01
BD
01
00
86
06
B7
B3
01
BD
01
00
OE
20
DD

86
01
CE
FF
FF
09
26
FD
4A
26
F7
39

LDA#
OA
STA$$
B3
01
JSR$$
01
00
LDA#
09
STA$$
B3
01
JSR$$
01
00
LDA#
05
STA$$
B3
01
JSR$$
01
00
LDA#
06
STA$$
B3
01
JSR$$
01
00
CLI
BRA
DD

LDA#
01
LDX#
FF
FF
DEX
BNE
FD
DECA
BNE
F7
RTS

COMMENTS

Advance the motor one step.

Jump to delay subroutine.

Advance the motor one step.

Jump to delay subroutine.

Advance the motor one step.

Jump to delay subroutine.

Advance the motor one step.

Jump to delay subroutine.

Do it again.

Delay between steps subroutine.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS 1

5. Execute the program by pressing GO and entering the beginning program address, 0000. Observe that the stepper motor is
stepping relatively slowly in a clockwise direction.
6. Reset the Trainer and examine the contents of memory location 0101. You should observe the value 01. Change this value
to 02.
7. Execute the program again by pressing GO and entering the
beginning program address, 0000. Observe that the stepper
motor speed has been decreased.
8. Reset the Trainer and change the contents of memory location
0101 to the value 03.
9. Execute the program and notice that the stepper motor speed
has been decreased again.
10. Reset the Trainer and change memory location 0101 to any
desired value.
11. Execute the program and observe the action of the stepper
motor. The larger the value located in memory location 0101,
the slower the stepping action of the stepper motor. In fact, if
you entered a relatively large value in memory location 0101,
the stepping action of the motor will be so slow that you have
to wait several minutes between steps.
DISCUSSION
You interfaced the stepper motor to the Microprocessor Trainer via
the PIA as discussed in Unit 15. The four PIA port lines, PBO
through PB3, are configured as outputs and connected to the bases
of the stepper motor drive transistors via current-limiting resistors. The motor is controlled by writing a sequential logic pattern
to the four port B output lines. A logic 1 output on any given port
line will turn on, or saturate, the respective control transistor
which energizes its associated stepper motor coil. As a result, a
sequential logic pattern output from port B sequentially energizes
the control coils and causes the motor shaft to rotate.

23-5

23-6 I LABORATORY MANUAL

DELAY SUBROUTINE

MAIN STEPPING DIAGRAM

CONFIGURE
PBO-PB3
OUTPUT

LOAD A WITH
COUNT VALUE.

V
ADVANCE

LOAD X WITH

ONE STEP.

COUNT VALUE
01

DELAY.
DECREMENT X.

DELAY LOOP DELAY LOOP


#2
#1
ADVANCE
ONE STEP.

DELAY.
DECREMENT A.

ADVANCE
ONE STEP.

NO

V
DELAY.
RETURN.

V
ADVANCE
ONE STEP.

DELAY.

REPEAT.

Figure 23-3
A flowchart for the stepper motor control program.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS 1

The motor speed is determined by how fast the microprocessor


writes the sequential control bit patterns to the PIA. A flowchart of
the stepper motor control program is provided in Figure 23-3.
Notice that there are two sections to the program, the main
program and a delay subroutine. The main program first configures port B of the PIA for output. It then provides the proper logic
sequence to port B to step the motor. The required logic sequence
is shown in Table 23-1. Notice that the direction of motor rotation
depends upon the sequencing order.

Table 23-1

Required stepping motor sequencing logic.

Clockwise
Rotation

PB3 PB2 PB1 PBO

1
1
0
0

0
0
1
1

0
0
1

Counterclockwise
Rotation

0
1
1

From the flowchart in Figure 23-1 you can see that a time delay
subroutine is executed between each motor step. The length of this
time delay determines the rotational speed of the motor. Referring
to the time delay subroutine flowchart, notice that the total amount
of delay is created by two time delay loops. Delay loop #1 loads the
index register with a value, and then decrements down to zero
before coming out of the loop. Once out of loop #1, accumulator A is
decremented in loop #2. If, after decrementing, the accumulator is
not zero, the index register loop (loop #1) repeats again. When the
accumulator is zero, the MPU returns to the main stepping program and advances the stepper motor another step. In summary,
the value stored in accumulator A determines how many times loop
#1 executes. When you changed memory location 0101 in the
experiment, you were changing the value that the time delay
subroutine stores in accumulator A. Consequently, a larger value
caused loop #1 to be executed more times, which created a longer
time delay between motor steps. The end result is that the stepping
motor speed decreased.
Now, how could you increase the speed of the stepper motor? Two
wayS: First, change memory location 0101 back to the value 01 so
that delay loop #1 is only executed once; second, cause the index
register to be loaded with a smaller value so that delay loop #1 is
shorter. You can do this by changing memory locations 0103 and
0104.

23-7

23-8 I LABORATORY MANUAL

PROCEDURE (Continued)
12. Change the contents of memory location 0101 back to the
original value of 01.
13. Change the contents of memory location 0103 to the value 55.
14. Execute the main program at address 0000 and observe the
motor. You should observe an increase in the motor speed since
loop #1 in the time delay subroutine now decrements the index
register from the value 55FF, rather than FFFF.
15. Reset the Trainer and change the contents of memory location
0103 to the value 22.
16. Execute the program again and observe the motor. You should
observe that the motor speed has increased again, why?
17. Reset the Trainer and change the contents of memory location
0103 to the value 01.
18. Execute the program and you should find that the motor speed
has increased still further.
19. Reset the Trainer and change the contents of memory location
0104 to the value 00.
20. Execute the program and observe the motor. What happened?
The motor is not rotating, it is simply vibrating.

DISCUSSION
In steps 12 through 20, you decreased the time delay between
motor steps by decreasing the value the time delay subroutine
loads into the index register. As a result, the motor speed increased. However, in steps 19 and 20, you discovered a physical
limitation of the motor. In these steps, you reduced the time delay
to the point where the microprocessor outputs the stepping se-'
quence too fast for the motor. When this happens, the motor can not
keep up with the logic control sequence and simply vibrates.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS 1

At this point you might want to find the maximum operating speed
of the motor by changing memory location 0104 to the smallest
value that produces motor rotation. This value should be somewhere between the values 00 and FO. You can also measure the
motor rpm with the Trainer using an optical interrupter and the
principles demonstrated in previous experiments using this device.

PROCEDURE (Continued)
21. Reset the Trainer and change memory locations 0103 and 0104
back to the original value of FF.
22. Execute the program and you should observe the original slow
clockwise rotation of the stepper motor.
23. Reset the Trainer and change the main program as follows:
Memory Location Value
0011
0019
0021
0029

06
05
09
OA

24. Execute the program and observe the stepper motor action.
You should observe that the motor rotates at the same speed,
but in a counterclockwise direction.

DISCUSSION
You just reversed the direction of rotation of the motor by reversing
the logic sequence stepping order. The values that determine the
stepping control logic are located in memory locations 0011, 0019,
0021, and 0029. From Table 23-1, you can see that reversing this
control logic sequence produces a counterclockwise motor rotation.
At this point, you might want to change the time delay period as
before to achieve different counterclockwise rotational speeds.

23-9

23-1 0 1 LABORATORY MANUAL


PROCEDURE (Continued)
25. Turn the Trainer power off and construct the circuit shown in
Figure 23-4. Notice that this circuit uses the light probe you
constructed in the "photometer" experiment. The output of the
circuit must be connected to the XIRQ input terminal on the
Trainer.
+5V

+12V

COLLECTOR
(LONG)
LEAD

TO XIRO
INTERRUPT
INPUT ON
TRAINER

EMITTER
(SHORT)
LEAD

Figure 23-4

A light sensing circuit for control of a stepper motor.

26. Turn the Trainer power on and change the program as follows:
Memory Location Value
0050
0101
0103
0104

3B
01
55
FF

27. Point the light probe at a relatively high intensity light source.
A 60-watt bulb or ordinary flashlight will do the job. Make sure
the probe is located close to, and pointed directly at, the light
source.
28. Turn the Trainer power on and execute the program by pressing GO and entering the beginning program address, 0000.

EXPERIMENT TWENTY-THREE - MICROPROCESSOR INTERFACING AND CONTROL OF STEPPER MOTORS

29. Observe the stepper motor. You should observe that it is not
rotating.
30. Break the light path to the probe with your hand and observe
the motor. You should find that the motor begins rotating each
time the light beam is broken.
DISCUSSION
The circuit that you constructed in step 25 is a light probe sensing
circuit. The light probe phototransistor either conducts or does not
conduct with the presence or absence of light.
When the light is present, the phototransistor is saturated and
produces a +5 V level to the inverting input of the op amp comparator. This causes the op amp output to saturate to 12 V. The zener
diode is then forward biased. As a result, the forward voltage drop
across the zener is about .7 V. This potential represents a logic
zero and is applied to the interrupt, or XIRQ , input of the Trainer.
Recall that the XIRQ interrupt is activated with a logic 0 input.
Consequently, the stepper motor control program is interrupted
and the motor does not rotate. The motor will not rotate as long as
the beam is present, since the light sensing circuit is continually
activating the XIRQ interrupt input line, thereby producing an
interrupt to the main motor control program.
When the light is broken, the phototransistor is cut-off and presents a 0 V level to the op amp. This causes the op amp output to
saturate to +12 V. The zener diode is then reversed biased into
breakdown. Since a 5.1 V zener is used, the voltage drop across the
zener is approximately +5 V, which represents a logic 1 to the XIRQ
interrupt input line of the Trainer. Since a logic 1 does not activate
the interrupt request, the motor control program is not interrupted
and the motor is allowed to rotate.
Why was the level sensitive XIRQ interrupt used here, rather than
the edge sensitive IRQ interrupt?

23-11

23-1 2 I LABORATORY MANUAL


PROCEDURE (Continued)
31. Reset the Trainer. Turn the Trainer power off and reverse the
input connections to the op amp; i.e., reverse the connections
of pins 2 and 3 of the op amp. Pull-out the connection to the
XIRQ interrupt input at the Trainer.
32. Turn the Trainer power on and execute the program again. Reinsert the XIRQ interrupt input to the Trainer. You should now
observe that the motor rotates with the presence of light and
stops when an object is in the light path.

DISCUSSION
With its input connections reversed, the op amp circuit generates
an interrupt ( XIRQ ) when the light beam is absent, thereby stopping the motor. At this point, you should be able to explain the
circuit action, since it is just the opposite of what it was before.
This simple, but important, experiment demonstrates a typical
microprocessor sense and control operation. Here, the sensor is a
phototransistor and the final control element is the stepper motor.
The experiment could also be performed using the temperature
sensing principles demonstrated in that experiment. The Trainer
could be programmed to "look" for a given temperature value, then
stop or start the motor when this value is reached. You now have all
the hardware and software knowledge you need. Try it!

APPENDIX A TRAINER TEST PROGRAM 1

APPENDIX A
TRAINER TEST PROGRAM
Before you use the ETW-3800 Microprocessor Trainer to perform the
experiments contained in this course, you should follow the procedure described below to load and run the Trainer Test Program. This
program is provided on Page A-3.

PROCEDURE
1.

Prepare ETW-3800 trainer for operation by properly installing the


MPU cartridge.

2.

Plug the trainer into a standard 120-volt AC outlet.

NOTE: For a quick test proceed directly to step 5 below.


3.

To test the output-port, 8-LED logic indicators, and logic probe,


prepare the following 10 wires:
(8) 8 inch wires with approximately 1/4 inch of insulation
stripped off each end. These will be used to jumper the 8
output-port terminals (labeled OPO through OP7 on the right
side of the lower terminal block) to the 8 terminals for the
LED logic indicators (located just below the 8 LEDs).
(1) 6 inch wire (stripped at both ends as described above).
This will be used to jumper the logic probe input terminal
(labeled LPIN, at the extreme left on the lower terminal
block) to bit 0 of the output-port (OPO).
(1) 2 inch wire (prepared as above). This will be used to
jumper the LPAUDC terminal (located next to LPIN) to the
GND terminal next to it. This connection allows the logic
probe to operate without sound. If you desire sound do not
make this connection.

A-1

A-2 I LABORATORY MANUAL


4. Use the 10 wires prepared in #3 to make the connections diagrammed below:

MPU
CARTRIDGE

DISPLAY

III 1 111111

\N_
KEYBOARD

LED
TERMINAL
BLOCK

BREADBOARD

SIGNAL
CONNECTOR

Figure 1

5.

Switch the trainer ON.

6.

If you are using the EB-6810-30 Program Module, install it in the


trainer. Then load and run the General Trainer Test Program by
pressing the following keys in order: Load, 0 (zero) (wait about 5
seconds), Go, and Return.
If you are not using the Program Module, enter the test program
which begins on Page A-3.
NOTE: If the Trainer Test Program has been correctly loaded and
run, you should observe a brief message displaying the information contained on the title page of this course.

APPENDIX A TRAINER TEST PROGRAM 1 A-3

TRAINER TEST PROGRAM LISTING


Address
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
001A
001B
001C
001D
001E
001F
0020
0021
0022

Contents
CE
00
23
8E
5F
FF
E6
00
9D
OC
20
FA
3C
BD
CO
06
F7
B2
40
18
CE
50
00
18
09
26
FC
38
08
8C
00
DA
24
DE
39

Mnemonic
LDX

LDS

LDAB
JSR
BRA
PSHX
JSR

STAB

LDY

DEY
BNE
PULX
INX
CPX

BHS
RTS

Comments
Load X-index register (immediate)
High byte of ASCII data address
Low byte of ASCII data address
Load stack pointer with address
high byte
low byte
Load ACCB from X-index register
Zero offset
Jump to subroutine (direct)
located at address OC
Branch
back (-6 from next) to 0003
Push X-index register onto stack
Jump to subroutine (extended)
High byte ASCII display subroutine
Low byte ASCII display subroutine
Store ACCB at address of...
output port (high byte)
output port (low byte)
Prebyte for next instruction
Load Y-index register (immediate)
High byte for time delay countdown
Low byte for time delay countdown
Prebyte for next instruction
Decrement Y-index register
Branch if (Y-index reg.) not zero
back-4 (from next inst.) to 0012
Pull X-index register from stack
Increment X-index register
Compare X-index register value to
address of last ASCII (high) byte
address of last ASCII (low) byte
Branch if higher or same
back-34 to 0--begin display again
Return from subroutine to next inst.

A-4 I LABORATORY MANUAL


ASCII CHARACTER CODE DATA (0023 through 00D9)
Address

Contents

Address

Contents

0023
0024
0025
0026
0027
0028
0029
002A
002B
002C
002D
002E
002F
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
003A
003B
003C
003D
003E
003F
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
004A
004B
004C
004D
004E
004F
0050

38
2D
42
49
54
20
4D
49
43
52
4F
50
52
4F
43
45
53
53
4F
52
OD
20
20
20
20
50
52
4F
47
52
41
4D
4D
49
4E
47
20
20
20
20
20
20
20
20
20
48

0051
0052
0053
0054
0055
0056
0057
0058
0059
005A
005B
005C
005D
005E
005F
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
006A
006B
006C
006D
006E
006F
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
007A
007B
007C
007D
007E

45
41
54
48
2F
5A
45
4E
49
54
48
20
20
20
20
45
44
55
43
41
54
49
4F
4E
41
4C
20
53
59
53
54
45
4D
53
20
20
20
20
63
6F
70
79
72
69
67
68

Address
007F
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
008A
008B
008C
008D
008E
008F
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
009A
009B
009C
009D
009E
009F
00A0
00A1
00A2
00A3
00A4
00A5
00A6
00A7
00A8
00A9
00AA
OOAB
00AC

Contents
74
20
31
39
38
38
20
20
20
20
20
20
20
20
72
65
76
69
73
65
64
20
62
79
3A
20
20
20
20
20
47
72
65
67
20
56
2E
20
4D
69
63
68
61
6C
73
6B

APPENDIX

Address

Contents

GOAD
00AE
OOAF
00B0
00B1
00B2
00B3
00B4
00B5
00B6
00B7
00B8
00B9
00BA
OOBB

69
20
20
20
45
64
75
63
61
74
69
6F
6E
61
6C

Address
00BC
OOBD
00BE
00BF
0000
00C1
00C2
00C3
00C4
0005
0006
0007
0008
00C9
OOCA

Contents
20
4D
65
64
69
61
20
OD
20
20
20
20
20
20
44

A TRAINER TEST PROGRAM 1

Address
00CB
00CC
OOCD
00CE
00CF
OODO
00D1
00D2
00D3
00D4
00D5
00D6
00D7
00D8
00D9

Contents
65
73
69
67
6E
65
72
20
20
20
20
20
20
OD
OD

A-5

APPENDIX B PROGRAMMING WORKSHEET

APPENDIX B
PROGRAMMING WORKSHEET
Program Name/Description
ETC-128 Program Cartridge File Digit (0-F)
Address

Contents

Mnemonic

* Note: This sheet may be copied for reuse.

Address

Contents Mnemonic

I B-1

S-ar putea să vă placă și