Ebi 6810 40 PDF
Ebi 6810 40 PDF
Ebi 6810 40 PDF
Industrial Applications
Laboratory Manual
Model EBI-6810-40
HEATHKIT COMPANY, INC.
BENTON HARBOR, MICHIGAN 49022
595-5676-01
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
A-1
B-1
C-1
D-1
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
1
1
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
Qty. Description
INTEGRATED CIRCUITS
Part number.
Type number.
Part number and type number.
Part number with a type number other than the one
listed.
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
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
OR
PLASTIC
METAL
ti
BANDED END (CATHODE)
(;)
EXPERIMENT 1
TRAINER PROGRAMMING
FUNDAMENTALS
Objectives:
1.
2.
3.
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
KEYBOARD
UPPER SIGNAL
CONNECTOR BLOCK
Figure 1-1
1.
2.
1 -3
1 -4 1 LABORATORY MANUAL
9.
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.
Contents Address
00
08
01
09
02
OA
03
OB
04
OC
05
OD
06
OE
07
OF
Contents
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.
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.
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
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.
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
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.
3.
Press and release the Help key. The display should read:
0 Single Step
>_
4.
8
9
A
5.
6.
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
2 -3
EXPERIMENT
Two
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
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
(yes/no)
EXPERIMENT
PROCEDURE
1. With the TFT program still entered from Part 1, Reset the
trainer.
EXPERIMENT
6.
7.
8.
9.
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
PROCEDURE
1. Press and release NMI.
2.
3.
4.
5.
With the TFT program properly entered, press and release the
NMI key.
6.
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.
2 -1 1
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
EXPERIMENT
10
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
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
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 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).
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)
Stop.
Figure 3-1
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.
13-3
3-4
LABORATORY MANUAL
6.
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
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
16
ACCB (actual) =
16
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
16 =
2's complement =
16 =
16 =
16 =
2
2
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.
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.
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.
16
4.
5.
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
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.
PROCEDURE
1. Reset the trainer.
2.
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.
3 -1 1
3-1 2
1 LABORATORY MANUAL
ACCA
ACCB
High Byte (bits 8-15) of ACCD Low Byte (bits 0-7) of ACCD
5.
6.
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?
9.
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 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
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
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
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
6.
7.
16 =
16
16 =
Exclusive OR Operation
l's complement of operand 1 =
Exclusive OR of operands =
16 =
16
Operand 4 =
(address 000F)
16 =
Exclusive OR of operands
ACCD
8.
addressing mode
LDAA
COMA
EORA
LDAB
COMB
E ORB
MUL
STOP
9.
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.
EXPERIMENT 5
THE CONDITION CODE REGISTER
Objectives:
I. To demonstrate the operation, use, and interpretation of
the MPU's Condition Code Register (CCR).
2.
3.
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
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
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
Mnemonic
Opcode/Operand
LDA
86
01
CF
STOP
5.
6.
7.
Value Observed
CCR
16
ACCB
16
ACCA
16
PC
16
(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.
Opcode/Operand
86
01
4A
4A
CF
Mnemonic
LDA
DECA
DECA
STOP
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
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).
16 =
SXHINZVC
(yes/no)
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).
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)
5 -9
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
(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
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
CCR
0 0 0 0 0 1 1 1
SXHINZVC
Figure 5-2
Multiple CCR flag settings.
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
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
Value Observed
(hexadecimal)
Equivalent
(binary)
16=
S XHINZVC
ACCA =
16
ACCB =
16
Opcode/Operand
Mnemonic
DISCUSSION
i 5-1 5
5-1 6
I LABORATORY MANUAL
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
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.
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).
6-3
4.
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.
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
Figure 6-3
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
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
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
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
( START )
Clear
Accumulator
Store
Quotient
1
Load
Dividend
Subtract
Divisor
Store
Dividend
I
Load
Quotient
I
Increment
Quotient
Figure 6-8
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
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
STEP
PROGRAM
OPCODE
COUNTER
ACCA
N
FLAG
Figure 6-10
COMMENTS
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
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
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
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
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
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
Figure 6-14
Program for converting BCD to binary (File digit 2).
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
10
6-1 7
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
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.
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
00
Binary)
Result
Now
Tens
BCD)
Digit
New
Tens)
Digit
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
75
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.
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
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.
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
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
002C
002D
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-
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
AD
What's this?
OA
25
AD
AD
1
1
15
16
17
0001
0019
001A
Units BCD
18
0025
96
AD
19
20
0027
0029
97
CF
11
11
1
1
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
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.
22. Examine the addresses listed below and record the information stored there.
002B _
002C _
002D _
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 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
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
3.
4.
5.
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
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
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
PROCEDURE
1. Reset the trainer.
2. Load the ASCII Subroutine Can program (ASC) program shown
in Figure 7-3.
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
Figure 7-3.
ASCII Subroutine Call (ASC) program (File digit B).
description
opcode mnemonic
description
7 -9
COMMENTS
COMMENTS
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.
from
to
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.
EXPERIMENT 8
INPUT/OUTPUT OPERATIONS
Objectives:
1.
2.
3.
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.
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
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
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
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
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.
4.
5.
6.
7.
8.
9.
18.3
Pulse Train
LED
red
green
red/green
Tone
high
low
high/low
Figure 8-2
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.
18-/
I I I
DISPLAY
E2PROM
CARTRIDGE
LED
TERMINAL
BLOCK
KEYBOARD
BREADBOARD
SIGNAL
CONNECTOR
Figure 8-4
Output port to logic indicators trainer wiring diagram
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).
18-9
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
--,
'
IMEINIIMS
mom o
--I
_ .::-....--,-,
P8888W8888:MESERMEEig&i.1.!..,-:=
.,.....-i,--
SIGNAL
CONNECTOR
Figure 8-6
Logic switches to input port trainer wiring diagram.
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.
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
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
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 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.
4.
5.
12
LPIN
(TRAINER)
"CE"
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.
9-4
1 LABORATORY MANUAL
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.
8.
9.
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.
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
9-5
9-6
1 LABORATORY MANUAL
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.
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.
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.
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 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.
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
Figure 10-1
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
16.
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
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.
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
? T T
Figure 10-5
66666
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.
TO PINS
11 8 6 3
ON 74LS125 4
+
Ii
(AS BEFORE)
IiliI
+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
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
Clear I-flag
Complement switch
logic and store.
Figure 10-7
0109
0101
010A
0102
010B
0103
010C
0104
010D
0105
010E
0106
010F
0107
0110
0108
1 0-9
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.
1 0- 1 1
1 0- 1 2 I LABORATORY MANUAL
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 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
2.
Recheck your wiring; then switch the Trainer power on. The
data LED's on the Trainer will show a random value.
3.
1\
A4-1- A49-
A8 A7
A4 A3
Figure 11-2
AO
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
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
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
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
Do it again
Figure 11-6
1 -7
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)
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
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.
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
Next, you will see that a decoder driver is not necessary if you are
willing to let the MPU do the decoding.
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.
1 -9
1 1 -1 0
LABORATORY MANUAL
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
Display codes
Figure 11-10
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 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
2-2
2
3
4
5
6
7
Figure 12-1
Circuit diagram for the first PIA experiment.
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
No operation
Do it again
Figure 12-2
Program for data input and output.
4.
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.
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
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.
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
PROCEDURE (Continued)
9.
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.
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?
1 2-7
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
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
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
Delay
Delay
Figure 13-2
7-segment LED multiplexing program.
PIA 11 3-3
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
B301
B302
B303
Figure 13-3
1 3-5
PROCEDURE (Continued)
6.
7.
8.
9.
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
IT I 1 I IO m 0 D DI -/-LrCC
c
ritri% 7
" 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 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
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
EXPERIMENT FOURTEEN
I/O
86
24
B7
B3
02
B6
B3
00
CF
MNEMONICS/
CONTENTS
LDA#
24
STA$$
B3
02
LDA$$
B3
00
STOP
COMMENTS
Figure 14-2
3.
Execute the program by pressing GO and entering the beginning program address (0000).
4.
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.
7.
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
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
i-READ PORT A
Figure 14-4
Summary of CA1 and CA2 control line activity for first part of experiment.
PROCEDURE (Continued)
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
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
Do it again
Figure 14-6
Port B handshake control program.
PIA
1 4-7
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.
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
Delay
Approximately 5 seconds.
Figure 14-7
Port B handshake routine - interrupt control.
1 4-9
14-101LABORATORY MANUAL
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.
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.
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
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
RAM INTERFACING 1
1 5-5
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.
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
RAM INTERFACING 1
1 5-7
EXPERIMENT 16
MICROPROCESSOR/DAC
INTERFACING AND APPLICATIONS
Objectives:
1. To interface a DAC to a microprocessor.
2.
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.
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
2.
3.
4.
Execute the program by pressing GO and entering the beginning program address 0000.
5.
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
Figure 16-2
PIA initialization program for the DAC interface circuit in Figure 16-1.
6.
7.
1 6-3
9.
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
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
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.
1 6-5
1 6-6 I
LABORATORY MANUAL
6.
RESET the Trainer and change the contents of memory location 000E to FF and memory location 000F to F5.
7.
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.
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
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.
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
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
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.
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
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!
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
Delay.
Delay.
Repeat.
Figure 16-11
A square waveform generating program.
1 6-1 3
+-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).
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
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.
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
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.
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.
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
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.
- 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.
8.
9.
CHANNEL A
5 VICM
2 mS/CM
CHANNEL B
5 V/CM
2 mS/CM
Figure 16 - 19
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
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 17
A/D CONVERTER INTERFACING
AND APPLICATIONS
Objectives:
1. To interface an ADC to a microprocessor.
2.
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.
3.
4.
EXPERIMENT SEVENTEEN -
AID
+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
Figure 17-1
5.
6.
7.
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.
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.
Figure 17-2
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
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.
Figure 17-3
ADC control program for the first part of the experiment.
1 7-7
Table 17-1
The required channel select logic for the ADC0809.
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
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.
Figure 17-4
ADC interrupt service routine.
1 7-9
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.
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.
Figure 17-5
A flowchart summary of the software required for
the microprocessor-controlled DVM.
1 7-1 1
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.
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 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.
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.
TO-92
PLASTIC PACKAGE
1 / 2'
ELECTRICAL
TAPE
Figure 18-2
BOTTOM VIEW
1 8-3
1 8-4
1 LABORATORY MANUAL
VOUT
Figure 18-3
3.
4.
5.
6.
VDC.
7.
8.
VDC
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
Vneck =
HOLD LEADS
6' FROM
SENSOR BODY
I I
Figure 18-5
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.
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
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
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
,
Wait for interrupt.
Do it again.
ont' .
Figure 18-8
Program for the microprocessor-controlled thermometer.
1 8-9
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
Display temperature in F
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
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
ROUTINE
C
INITIALIZE PORT B
CONTROL REGISTER
READ DIGITAL
VALUE FROM PORT B.
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.
RETURN FROM
CONTROL REGISTER.
INTERRUPT.
Figure 18-9
1 8-1 3
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.
PLASTIC
METAL
OR
BOTTOM VIEW
TAB
E=EMITTER
B=BASE
C=COLLECTOR
Figure 19-1
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.
1 9-3
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
3.
4.
5.
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
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
LDB$$
B3
01
.. ..
Figure 19-3
Program for the microprocessor-controlled photometer.
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
12. Reset the Trainer and execute the program by pressing GO and
entering the beginning program address, 0000.
1 9-7
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
25-50
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.
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.
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
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
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
20.3
3.
4.
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
Figure 20-3
7. Execute the program by pressing GO and entering the beginning program address, 0000.
20.5
20-6
I LABORATORY MANUAL
8.
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
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
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
OPTICAL ENCODER
WHEEL
DC MOTOR
PIA
POTENTIOMETERRESISTOR
(SPEED CONTROL)
741C
BREADBOARD BLOCK
(SIDE VIEW)
FOAM TAPE
Figure 20-6
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
5 011
TRIMMER POT
DC
MOTOR
Figure 20-7
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
Figure 20-8
20-11
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.
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
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.
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
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 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:
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.
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.
0
0
0
0
0
0
0
0
0
0
0
0
21 -3
CARDBOARD
0 0
0 0
PUNCHED HOLES
CONDUCTIVE
FOAM PADS
Figure 21-2
A completed linear optical encoder.
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.
4.
5.
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.
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
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
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".
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
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
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.
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.
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
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
+5V
3300 11
IRO
SMALL CIRCLE
ON FRONT OF
HALL-EFFECT DEVICE
Figure 22-2
22-3
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
Figure 22-3
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
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.
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
onto.
Figure 22-4
22-/
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
.
.
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.
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
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 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.
3. Lay the stepper motor down on a flat surface so that the shaft
is in a vertical position.
.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
Figure 23-2
Stepper motor control program.
23-3
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
Do it again.
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
DELAY SUBROUTINE
CONFIGURE
PBO-PB3
OUTPUT
LOAD A WITH
COUNT VALUE.
V
ADVANCE
LOAD X WITH
ONE STEP.
COUNT VALUE
01
DELAY.
DECREMENT X.
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.
Table 23-1
Clockwise
Rotation
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
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.
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
+12V
COLLECTOR
(LONG)
LEAD
TO XIRO
INTERRUPT
INPUT ON
TRAINER
EMITTER
(SHORT)
LEAD
Figure 23-4
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.
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
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
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.
2.
A-1
MPU
CARTRIDGE
DISPLAY
III 1 111111
\N_
KEYBOARD
LED
TERMINAL
BLOCK
BREADBOARD
SIGNAL
CONNECTOR
Figure 1
5.
6.
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.
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
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
Program Name/Description
ETC-128 Program Cartridge File Digit (0-F)
Address
Contents
Mnemonic
Address
Contents Mnemonic
I B-1