M68 HC 05
M68 HC 05
M68HC05TB/D
Rev. 2.0
HC 5
Freescale Semiconductor, Inc...
M68HC05 Family
Understanding Small Microcontrollers
Acknowledgment
Motorola and the Motorola logo are registered trademarks of Motorola, Inc.
IBM is a registered trademark of IBM Corporation
Macintosh is a trademark of Apple Computer, Inc.
MOTOROLA Acknowledgment 3
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Acknowledgment
Freescale Semiconductor, Inc...
4 Acknowledgment MOTOROLA
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
List of Sections
Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Freescale Semiconductor, Inc...
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
What is a Microcontroller? . . . . . . . . . . . . . . . . . . . . . . . 17
Computer Architecture . . . . . . . . . . . . . . . . . . . . . . . . . 65
Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Table of Contents
What is a Microcontroller?
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Overall View of a Computer System . . . . . . . . . . . . . . . . . . . . . . . . . .18
Freescale Semiconductor, Inc...
Computer Architecture
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
Computer Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
CPU Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
CPU View of a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
CPU Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Detailed Operation of CPU Instructions . . . . . . . . . . . . . . . . . . . . .73
Freescale Semiconductor, Inc...
Programming
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136
Writing a Simple Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136
Flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137
Mnemonic Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139
Software Delay Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
Assembler Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
Object Code File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147
Reference Tables
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287
ASCII to Hexadecimal Conversion . . . . . . . . . . . . . . . . . . . . . . . . . .288
Hexadecimal to Decimal Conversion. . . . . . . . . . . . . . . . . . . . . . . . .290
Decimal to Hexadecimal Conversion. . . . . . . . . . . . . . . . . . . . . . . . .292
Hexadecimal Values vs. M68HC05 Instructions . . . . . . . . . . . . . . . .293
Glossary
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .299
Index
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .317
List of Figures
List of Tables
What is a Microcontroller?
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Freescale Semiconductor, Inc...
Introduction
This chapter sets the groundwork for a detailed exploration of the inner
workings of a small microcontroller. We will see that the microcontroller
is one of the most basic forms of computer system. Although much
smaller than its cousins — personal computers and mainframe
computers — microcontrollers are built from the same basic elements.
In the simplest sense, computers produce a specific pattern of outputs
based on current inputs and the instructions in a computer program.
changing the types of input and output devices, this could be a view of a
personal computer, a room-sized mainframe computer, or a simple
microcontroller (MCU). The input and output (I/O) devices shown in the
figure happen to be typical I/O devices found in a microcontroller
computer system.
PROGRAM
MEMORY
°F CLOCK
TEMPERATURE RELAY
SENSOR
CRYSTAL
Most microcontroller inputs can only process digital input signals at the
same voltage levels as the main logic power source. The 0-volt ground
level is called VSS and the positive power source (VDD) is typically 5 Vdc
(direct current). A level of approximately 0 volts indicates a logic 0signal
and a voltage approximately equal to the positive power source indicates
a logic 1 signal.
Of course, the real world is full of analog signals or signals that are some
other voltage level. Some input devices translate signal voltages from
some other level to the VDD and VSS levels needed for the
microcontroller. Other input devices convert analog signals into digital
signals (binary values made up of 1s and 0s) that the computer can
understand and manipulate. Some microcontrollers even include such
analog-to-digital converter circuits on the same integrated circuit.
If necessary, other circuits can translate VDD and VSS levels that are
native to an MCU into other voltage levels.
The “controller” in microcontroller comes from the fact that these small
computer systems usually control something as compared to a personal
computer that usually processes information. In the case of the personal
computer, most output is information (either displayed on a CRT screen
or printed on paper). In contrast, in a microcontroller system, most
outputs are logic level digital signals that are used to drive display LEDs
(light-emitting diodes) or electrical devices such as relays or motors.
used. This structure is very complex and would not be a good example
for showing a beginner how a computer works.
Clock
With very few exceptions, computers use a small clock oscillator to
trigger the CPU to move from one step in a sequence to the next. In the
chapter on computer architecture, we will see that even the simple
instructions of a microcontroller are broken down into a series of even
more basic steps. Each of these tiny steps in the operation of the
computer takes one cycle of the CPU clock.
Computer Memory
Several kinds of computer memory are used for various purposes in
computer systems. The main kinds of memory found in microcontroller
systems are:
• Read-only memory (ROM)
• Random access read/write memory (RAM)
ROM is used mainly for programs and permanent data that must remain
unchanged even when there is no power applied to the microcontroller.
The smallest unit of computer memory is a single bit that can store one
value of 0 or 1. These bits are grouped into sets of eight bits to make one
byte. Larger computers further group bits into sets of 16 or 32 to make
Freescale Semiconductor, Inc...
a unit called a word. The size of a word can be different for different
computers, but a byte is always eight bits.
Personal computers work with very large programs and large amounts
of data, so they use special forms of memory called mass storage
devices. Floppy disks, hard disks, and compact discs are memory
devices of this type. It is not unusual to find several million bytes of RAM
memory in a personal computer. Even this is not enough to hold the
large programs and data used by personal computers, so most personal
computers also include a hard disk with tens or even hundreds of
millions or even billions of bytes of storage capacity. Compact discs,
very similar to those used for popular music recordings, have a capacity
of about 600 million bytes of read-only memory. In comparison, the small
microcontroller systems we are discussing in this book typically have a
total of 1,000 to 64,000 bytes of memory.
Computer Program
Figure 1 shows the program as a cloud because it originates in the
imagination of a computer programmer or engineer. This is comparable
to an electrical engineer thinking up a new circuit or a mechanical
engineer figuring out a new assembly. The components of a program are
instructions from the instruction set of the CPU. Just as a circuit designer
can build an adder circuit out of simple AND, OR, and NOT elements, a
programmer can write a program to add numbers together out of simple
instructions.
Freescale Semiconductor, Inc...
The Microcontroller
Now that we have discussed the various parts of a computer system, we
are ready to talk about just what a microcontroller is. The top half of
Figure 2 shows a generic computer system with a portion enclosed in a
dashed outline. This outlined portion is a microcontroller and the lower
half of the figure is a block diagram showing its internal structure in
greater detail. The crystal is not contained within the microcontroller, but
it is a required part of the oscillator circuit. In some cases, a less
expensive component such as a ceramic resonator or a
resistor-capacitor (R-C) circuit may be used instead of this crystal.
PROGRAM
MEMORY
INPUTS
OUTPUTS
SWITCH LED LAMP
1 2 3 A CENTRAL
4 5 6 B
7 8 9 C PROCESSOR UNIT
< 0 > ! CPU
Freescale Semiconductor, Inc...
KEYPAD BEEPER
°F CLOCK
TEMPERATURE RELAY
SENSOR
CRYSTAL
POWER PROGRAM
MEMORY
V DD
ADDRESS BUS
DATA BUS
V SS DATA
MEMORY
GROUND
I/O &
PERIPHERALS
DIGITAL DIGITAL
INPUTS OUTPUTS
RESET
CENTRAL PROCESSING UNIT
CPU
OSCILLATOR
&
CLOCKS
CRYSTAL
Review
A microcontroller is a complete computer system, including a CPU,
memory, a clock oscillator, and I/O on a single integrated circuit chip.
Kinds Although all computers share the same basic elements and ideas, there
of Computers are different kinds of computers for different purposes.
The smallest microcontrollers are used for such things as converting the
movements of a computer mouse into serial data for a personal
computer. Very often microcontrollers are embedded into a product and
the user of the product may not even know there is a computer inside.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
Freescale Semiconductor, Inc...
Introduction
This chapter discusses binary, hexadecimal, octal, and binary coded
decimal (BCD) numbers which are commonly used by computers.
Computers work best with information in a different form than people use
to solve problems. Humans typically work in the base 10 (decimal)
numbering system (probably because we have 10 fingers). Digital binary
computers work in the base 2 (binary) numbering system because this
allows all information to be represented by sets of digits, which can only
be 0s or 1s. In turn, a 1 or 0 can be represented by the presence or
absence of a logic voltage on a signal line or the on and off states of a
simple switch.
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
16 0001 0000 10
17 0001 0001 11
100 0110 0100 64
255 1111 1111 FF
1024 0100 0000 0000 400
65,535 1111 1111 1111 1111 FFFF
ASCII Code
Computers must handle many kinds of information other than just
numbers. Text (alphanumeric characters) and instructions must be
encoded in such a way that the computer can understand this
information. The most common code for text information is the American
Standard Code for Information Interchange (or ASCII). The ASCII code
establishes a widely accepted correlation between alphanumeric
characters and specific binary values. Using the ASCII code, $41
corresponds to capital A, $20 corresponds to a space character, etc. The
Freescale Semiconductor, Inc...
beep apost.
BS
$08 $28 ( $48 H $68 h
back sp
HT
$09 $29 ) $49 I $69 i
tab
LF
$0A $2A * $4A J $6A j
linefeed
$0B VT $2B + $4B K $6B k
,
$0C FF $2C $4C L $6C l
comma
CR –
$0D $2D $4D M $6D m
return dash
.
$0E SO $2E $4E N $6E n
period
$0F SI $2F / $4F O $6F o
$10 DLE $30 0 $50 P $70 p
$11 DC1 $31 1 $51 Q $71 q
$12 DC2 $32 2 $52 R $72 r
$13 DC3 $33 3 $53 S $73 s
$14 DC4 $34 4 $54 T $74 t
$15 NAK $35 5 $55 U $75 u
$16 SYN $36 6 $56 V $76 v
$17 ETB $37 7 $57 W $77 w
$18 CAN $38 8 $58 X $78 x
$19 EM $39 9 $59 Y $79 y
$1A SUB $3A : $5A Z $7A z
$1B ESCAPE $3B ; $5B [ $7B {
$1C FS $3C < $5C \ $7C |
$1D GS $3D = $5D ] $7D }
$1E RS $3E > $5E ^ $7E ~
_ DEL
$1F US $3F ? $5F $7F
under delete
Octal
Before leaving this discussion of number systems and codes, we will
look at two additional codes you may have heard about. Octal (base 8)
notation was used for some early computer work but is seldom used
today. Octal notation used the numbers 0 through 7 to represent sets of
three binary digits in the same way hexadecimal is used to represent
sets of four binary digits. The octal system had the advantage of using
customary number symbols, unlike the hexadecimal symbols A through
F discussed earlier.
(Some early computers used 12-bit words that did break down into four
sets of three bits each.) The second problem was that octal is not as
compact as hexadecimal. For example, the ASCII value for capital A is
10000012 in binary, 4116 in hexadecimal, and 1018 in octal. When a
human is talking about the ASCII value for A, it is easier to say “four-one”
than it is to say “one-zero-one.”
typeface. This bold italic 0 is discarded to get the desired 8-bit result. The
“8-bit binary” column has the same binary information as the direct
binary column, except the bits are regrouped into sets of four. Each set
of four bits translates exactly into one hexadecimal digit.
When mentally translating octal values to binary byte values, the octal
value is represented by three octal digits. Each octal digit represents
three binary bits so there is one extra bit (3 digits × 3 bits = 9 bits). Since
Western-speaking people typically work from left to right, it is easy to
forget to throw away the leftmost extra bit from the leftmost octal digit
and end up with an extra (ninth) bit. When translating from hexadecimal
to binary, it is easier because each hexadecimal digit translates into
exactly four binary bits. Two hexadecimal digits exactly match the eight
binary bits in a byte.
Freescale Semiconductor, Inc...
But 10102 is equivalent to A16, which is not a valid BCD value. When the
computer finishes the calculation, a check is performed to see if the
result is still a valid BCD value. If there was any carry from one BCD digit
to another or if there was any invalid code, a sequence of steps would
be performed to correct the result to proper BCD form. The 0000 10102
is corrected to 0001 00002 (BCD 10) in this example.
6 $6 0110 $6
7 $7 0111 $7
8 $8 1000 $8
9 $9 1001 $9
1010 $A
1011 $B
Invalid 1100 $C
BCD 1101 $D
Combinations 1110 $E
1111 $F
10 $10 0001 0000 $10
99 $99 1001 1001 $99
Review
Computers have two logic levels (0 and 1) so they work in the binary
numbering system. Probably because people have 10 fingers, they work
in the base 10 decimal numbering system.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Freescale Semiconductor, Inc...
Introduction
Digital computers are made up of relatively simple logic elements
sometimes called gates, which are small circuits that can be connected
in various ways to manipulate logic-level signal voltages. Although this
textbook is not intended to provide detailed information on logic design,
some knowledge of the most basic logic elements will help you
understand the inner workings of microcontrollers.
This chapter begins with a close look at the requirements for logic-level
voltages. Transistors and interconnections for a typical CMOS
(complementary metal-oxide semiconductor) microcontroller are
discussed. A simple inverter, NAND gate, and NOR gate are explained.
Finally, a transmission gate, a three-state buffer, and a flip-flop circuit
are described. Virtually any part of a microcontroller can be explained in
terms of these few simple logic elements.
Freescale Semiconductor, Inc...
Logic Levels
Earlier, in the discussion of what a microcontroller is, we said a level of
approximately 0 volts indicates a logic 0 and a voltage approximately
equal to the positive power source indicates a logic 1 signal. To be more
precise, there is a voltage level below which the microcontroller
manufacturer guarantees that a signal will be recognized as a valid
logic 0. Similarly, there is a voltage level above which the microcontroller
manufacturer guarantees that a signal will be recognized as a valid
logic 1. When designing a microcontroller system, be sure that all signals
conform to these specified limits, even under worst-case conditions.
CMOS Transistors
Figure 3 shows the symbols for an N-type and a P-type CMOS
transistor. The exact characteristics of these transistors can be
determined by their physical layout, size, and shape. For the purposes
of this textbook, they may be treated as simple switching devices.
VDD
[1]
[2] [4]
[5]
Freescale Semiconductor, Inc...
[3]
[6]
N-TYPE P-TYPE
The N-type transistor in Figure 3 has its source terminal [3] connected
to ground. For an N-type transistor to be on (conducting), its gate voltage
[2] must be higher than its source voltage [3] by an amount known as a
threshold. This N-type transistor is said to be on (conducts between
terminals [1] and [3]) when there is a logic 1 voltage on its gate [2]. When
the gate is at logic 0, this N-type transistor is said to be off and acts as
an open circuit between terminals [1] and [3].
The P-type transistor in Figure 3 has its source terminal [4] connected
to VDD. For a P-type transistor to be on, its gate voltage [5] must be lower
than its source voltage [4] by an amount known as a threshold. A P-type
transistor is indicated by the small opened circle at its gate [5]. When
there is a logic 0 voltage on the gate [5] of this P-type transistor, it is said
to be on and acts like there is a short circuit between terminals [4] and
[6]. When the gate is at logic 1, this P-type transistor is off and acts as
an open circuit between terminals [4] and [6].
Simple Gates
The three most basic types of logic gates found in a microcontroller are
the inverter, the NAND gate, and the NOR gate. A logic designer uses
various combinations of these basic gates to form more-complex logic
circuits, such as those that add two binary numbers together. While this
textbook is not intended to teach logic design techniques, these circuits
are discussed to give you a better understanding of how a
microcontroller operates on digital information.
Freescale Semiconductor, Inc...
Inverter Figure 4 shows the inverter logic symbol, a truth table for an inverter,
and a CMOS equivalent circuit. When a logic-level signal (0 or 1) is
presented to the input [1] of an inverter, the opposite logic level appears
at its output [2].
VDD
NAND Gate Figure 5 shows the NAND gate logic symbol, a truth table for a CMOS
NAND gate, and a CMOS equivalent circuit. When both input [1] and
input [2] of the NAND gate are logic-level 1 signals, the output [3] will be
a logic 0. If any of the inputs to a NAND gate are logic 0s, the output will
be a logic 1.
VDD VDD
Input Output
[6] [4]
[1] [2] [3]
[3]
Freescale Semiconductor, Inc...
[1] 0 0 1
[3] [1]
[2] [5]
0 1 1
[2]
1 0 1 [7]
1 1 0
NOR Gate Figure 6 shows the logic symbol, a truth table for a CMOS NOR gate,
and a CMOS equivalent circuit. When neither input [1] nor input [2] of a
NOR gate is a logic-level 1 signal, the output [3] will be a logic 1. If any
Freescale Semiconductor, Inc...
VDD
1 0 0 [2]
[7] [5]
1 1 0
Transmission Gate Figure 7 shows the logic symbol, a truth table for a CMOS transmission
gate, and a CMOS equivalent circuit. When control input [3] is a logic 1,
the transmission gate is said to be on and whatever logic level is present
on the input [1] is also seen at the output [2]. When the control input [3]
is a logic 0, the transmission gate is said to be off and the output node
[2] appears to be disconnected from everything (high impedance or
Hi-Z).
[4]
Control Input Output
[3] [1] [2]
[1] [2] [5]
0 0 Hi-Z
[1]
0 1 Hi-Z [2]
[3]
1 0 0 [6]
1 1 1
[3]
Refer to the CMOS equivalent circuit at the right of Figure 7 for the
following discussion: When control input [3] is logic 0, the gate of N
transistor [6] will be logic 0 and the gate of P transistor [5] will be logic 1
(VDD). There is no voltage between ground and VDD that would cause P
transistor [5] or N transistor [6] to turn on, so there is no conduction
between the input [1] and the output [2]. Since output node [2] is
effectively isolated from everything, it is said to be high impedance.
[5]
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
1 1 1 On Off 1
Three-State Buffer Figure 9 shows the logic symbol, a CMOS equivalent circuit, and a truth
table for a CMOS three-state buffer. When control input [3] is a logic 0,
the buffer is said to be off and output [2] is an isolated high impedance
node. When control input [3] is a logic 1, the buffer is said to be on and
whatever logic level is present on the input [1] is also seen at the output
[2].
VDD
[1] [2]
[7]
[3]
[9]
[5]
[1] [4]
Control Input Output [2]
[3] [1] [2]
[6]
0 0 Hi-Z
0 1 Hi-Z [8]
1 0 0
[3]
1 1 1
are off. Since output node [2] is effectively isolated from everything, it is
said to be high impedance.
When control input [3] is logic 1, the gate of N transistor [6] will be a logic
1 and the gate of P transistor [5] will be logic 0. If buffer input [1] is logic
0, the output of inverter [4] is logic 1, which turns on N transistor [8] and
turns off P transistor [7]. With control [3] at logic 1 and input [1] at logic
0, buffer output [2] is connected to ground through N transistors [6] and
[8], which are both on.
When control input [3] is logic 1, the gate of N transistor [6] will be a logic
Freescale Semiconductor, Inc...
1 and the gate of P transistor [5] will be logic 0. If buffer input [1] is logic
1, the output of inverter [4] is logic 0, which turns on P transistor [7] and
turns off N transistor [8]. With control [3] and input [1] both at logic 1,
buffer output [2] is connected to VDD through P transistors [7] and [5],
which are both on.
Half Flip Flop Figure 10 shows the logic symbol and a CMOS equivalent circuit for a
(HFF) half flip flop (HFF). When clock input [2] is a logic 1, transmission gate
[9] is on and transmission gate [8] is off. The half flip flop is said to be
transparent because input signal [1] passes directly to the Q [3] and
Q-bar (Q) [4] outputs. When the clock [2] is logic 0, transmission gate [8]
turns on and transmission gate [9] turns off. In this state, the half flip flop
is said to be latched. Transmission gate [8], inverter [6] and inverter [7]
form a stable “ring,” and the Q [3] and Q-bar [4] outputs remain at the
same logic level as when the clock changed from 1 to 0.
Freescale Semiconductor, Inc...
Review
Although we often think about logic levels being 0 volts or 5 volts, they
are actually ranges of voltages that are guaranteed by the MCU
manufacturer. For a specific MCU operating with VDD equal to 5.0 volts,
a logic 0 could be 0.0 to 1.5 volts and a logic 1 might be 3.5 to 5.0 volts.
Always refer to the data sheets for the MCU you are using to obtain the
voltage ranges of logic 0 and logic 1.
Ahalf flip flop (HFF) has a transparent condition and a latched condition.
In the transparent condition (clock input equals logic 1), the Q output is
always equal to the logic level presented at the input. In the latched
condition (clock input equals logic 0), the output maintains the logic level
that was present when the flip flop was last in the transparent condition.
Changes in the input logic level, while the flip flop is latched, do not affect
the output logic level.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Freescale Semiconductor, Inc...
Introduction
Before the operation of a CPU can be discussed in detail, some
conceptual knowledge of computer memory is required. In many
beginning programming classes, memory is presented as being similar
to a matrix of pigeon holes where you can save messages and other
information. The pigeon holes we refer to here are like the mailboxes in
a large apartment building. This is a good analogy, but it needs a little
refinement to explain the inner workings of a CPU.
Next, we will carry this analogy further to explain just how a computer
sees memory. We will confine our discussion to an 8-bit computer so
that we can be very specific.
Kinds of Memory
Computers use several kinds of information that require different kinds
of memory. The instructions that control the operation of a
microcontroller are stored in a non-volatile memory so the system does
not have to be reprogrammed after power has been off. Working
variables and intermediate results need to be stored in a memory that
can be written quickly and easily during system operation. It is not
important to remember this kind of information when there is no power,
so a volatile form of memory can be used. These types of memory are
changed (written) and read only by the CPU in the computer.
Like other memory information, input data is read by the CPU and output
data is written by the CPU. I/O (input/output) and control registers are
also a form of memory to the computer, but they are different than other
kinds of memory because the information can be sensed and/or
changed by something other than the CPU.
Random Access RAM is a volatile form of memory that can be read or written by the CPU.
Memory (RAM) As its name implies, RAM locations may be accessed in any order. This
is the most common type of memory in a personal computer. RAM
requires a relatively large amount of area on an integrated circuit chip.
Because of the relatively large chip area (and thus higher cost), usually
Freescale Semiconductor, Inc...
Read-Only ROM gets its information during the manufacturing process. The
Memory (ROM) information must be provided by the customer before the integrated
circuit, that will contain this information, is made. When the finished
microcontroller is used, this information can be read by the CPU but
cannot be changed. ROM is considered a non-volatile memory because
the information does not change if power is turned off. ROM is the
simplest, smallest, and least expensive type of non-volatile memory.
Programmable PROM is similar to ROM except that it can be programmed after the
ROM (PROM) integrated circuit is made. Some variations of PROM include:
with information. While the mailboxes are away being programmed, the
people at the apartment building cannot access the mailboxes.
I/O as a Memory I/O status and control information is a type of memory location that
Type allows the computer system to get information to or from the outside
world. This type of memory location is unusual because the information
can be sensed and/or changed by something other than the CPU.
The simplest kinds of I/O memory locations are basic input ports and
output ports. In an 8-bit MCU, a simple input port consists of eight pins
that can be read by the CPU. A simple output port consists of eight pins
that the CPU can control (write to). In practice, a simple output port
location is usually implemented with eight latches and feedback paths
Freescale Semiconductor, Inc...
that allow the CPU to read back what was previously written to the
address of the output port.
Figure 11 shows the equivalent circuits for one bit of RAM, one bit of an
input port, and one bit of a typical output port having read-back
capability. In a real MCU, these circuits would be repeated eight times to
make a single 8-bit RAM location, input port, or output port. The half flip
flops (HFF) in Figure 11 are very simple transparent flip flops. When the
clock signal is high, data passes freely from the D input to the Q and
Q-bar outputs. When the clock input is low, data is latched at the Q and
Q-bar outputs.
When the CPU stores a value to the address that corresponds to the
RAM bit in Figure 11 (a), the WRITE signal is activated to latch the data
from the data bus line into the flip flop [1]. This latch is static and
remembers the value written until a new value is written to this location
or power is removed. When the CPU reads the address of this RAM bit,
the READ signal is activated, which enables the multiplexer at [2]. This
multiplexer couples the data from the output of the flip flop onto the data
bus line. In a real MCU, RAM bits are much simpler than shown here,
but they are functionally equivalent to this circuit.
When the CPU reads the address of the input port shown in Figure 11
(b), the READ signal is activated, which enables the multiplexer at [3].
The multiplexer couples the buffered data from the pin onto the data bus
line. A write to this address would have no meaning.
[2]
READ
HFF
DATA BIT n D Q
(n = 0, 1. . .or 7)
WRITE C Q
[1]
READ
Freescale Semiconductor, Inc...
[3]
[6]
READ
HFF [4]
DIGITAL
DATA BIT n D Q PIN
OUTPUT
(n = 0, 1. . .or 7) [5]
WRITE C Q BUFFER – DRIVER
When the CPU stores a value to the address that corresponds to the
output port in Figure 11 (c), the WRITE signal is activated to latch the
data from the data bus line into the half flip flop [4]. The output of this
latch, which is buffered by the buffer driver at [5], appears as a digital
level on the output pin. When the CPU reads the address of this output
port, the READ signal is activated, which enables the multiplexer at [6].
This multiplexer couples the data from the output of the half flip flop onto
the data bus line.
Internal Status and Internal status and control registers are just specialized versions of I/O
Control Registers memory locations. Instead of sensing and controlling external pins,
status and control registers sense and control internal logic level signals.
Look at Figure 11 and compare the RAM bit to the output port. The only
difference is that the output bit has a buffer to connect the state of the
half flip flop to an external pin. In the case of an internal control bit, the
buffer output is connected to some internal control signal rather than an
external pin. An internal status bit is like an input port bit except that the
signal that is sensed during a read is an internal signal rather than an
Freescale Semiconductor, Inc...
external pin.
READ
DDR BIT
HFF
D Q
WRITE C Q
DDR BIT
HFF
DATA BIT n DIGITAL
D Q PIN
(n = 0, 1. . .or 7) I/O
READ BUFFER
PORT
Memory Maps
Since there are a thousand or more memory locations in an MCU
system, it is important to have a convenient way to keep track of where
things are. A memory map is a pictorial representation of the total MCU
memory space. Figure 14 is a typical memory map showing the memory
resources in the MC68HC705J1A.
The 4-digit hexadecimal values along the left edge of Figure 14 are
addresses beginning with $0000 at the top and increasing to $07FF at
Freescale Semiconductor, Inc...
Unused $0D
Unused $0E
Unused $0F
Unused Port A Pulldown Register $10
512 Bytes Port B Pulldown Register $11
Unused $12
Unused $13
Unused $14
$02FF Unused $15
$0300 Unused $16
Unused $17
EPROM Programming Register $18
Unused $19
Unused $1A
Unused $1B
Unused $1C
Unused $1D
User EPROM Unused $1E
1232 Bytes
Reserved $1F
In the memory map (Figure 14), the expansion of the I/O area of
memory identifies each register location with the two low-order digits of
its address rather than the full 4-digit address. For example, the 2-digit
hexadecimal value $00 appears to the right of the port A data register,
which is actually located at address $0000 in the memory map.
Memory Peripherals
Memories can be a form of peripheral. The uses for different types of
Freescale Semiconductor, Inc...
memory were discussed earlier, but the logic required to support these
memories was not considered. ROM and RAM memories are
straightforward and require no support logic — other than address-select
logic — to distinguish one location from another. This select logic is
provided on the same chip as the memory itself.
Review
We can think of computer memory as an array of mailboxes, but a
computer views memory as a series of 8-bit values.
Kinds of Memory
NOTE: Memory Map — A memory map is a pictorial view of all of the memory
locations in a computer system.
have taken and eliminating the clock cycle it would have required to
fetch it).
Computer Architecture
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
Freescale Semiconductor, Inc...
Introduction
This chapter takes us into the very heart of a computer to see what
makes it work. This will be a more detailed look than you normally need
to use an MCU, but it will help you understand why some things are done
in a certain way.
Computer Architecture
Motorola M68HC05 and M68HC11 8-bit MCUs have a specific
organization that is called a Von Neumann architecture after an
American mathematician of the same name. In this architecture, a CPU
and a memory array are interconnected by an address bus and a data
bus. The address bus is used to identify which memory location is being
accessed, and the data bus is used to convey information either from
the CPU to the memory location (pigeon hole) or from the memory
location to the CPU.
All information (other than the CPU registers) accessible to the CPU is
envisioned (by the CPU) to be in a single row of a thousand or more
pigeon holes. This organization is sometimes called a memory-mapped
I/O system because the CPU treats all memory locations alike whether
they contain program instructions, variable data, or input-output (I/O)
controls. There are other computer architectures, but this textbook is not
intended to explore those variations.
The number of wires in the address bus determines the total possible
number of pigeon holes; the number of wires in the data bus determines
the amount of information that can be stored in each pigeon hole.
CPU Registers Different CPUs have different sets of CPU registers. The differences are
primarily the number and size of the registers. Figure 15 shows the CPU
registers found in an M68HC05. While this is a relatively simple set of
CPU registers, it is representative of all types of CPU registers and can
be used to explain all of the fundamental concepts. This chapter
provides a brief description of the M68HC05 registers as an introduction
to CPU architecture in general. M68HC05 Instruction Set addresses
the instruction set of the M68HC05 and includes more detailed
information about M68HC05 registers.
7 ACCUMULATOR 0 A
7 INDEX REGISTER 0 X
9 7 5 0
0 0 1 1 STACK POINTER SP
15 10 0
0 0 0 0 0 PROGRAM COUNTER PC
7 4 3 2 1 0
CONDITION CODE REGISTER 1 1 1 H I N Z C CCR
Freescale Semiconductor, Inc...
CARRY
ZERO
NEGATIVE
I INTERRUPT MASK
HALF-CARRY (FROM BIT 3)
The X register is an 8-bit index register, which can also serve as a simple
scratch pad. The main purpose of an index register is to point at an area
in memory where the CPU will load (read) or store (write) information.
Sometimes an index register is called a pointer register. We will learn
more about index registers when we discuss indexed addressing
modes.
The program counter (PC) register is used by the CPU to keep track of
the address of the next instruction to be executed. When the CPU is
reset (starts up), the PC is loaded from a specific pair of memory
locations called the reset vector. The reset vector locations contain the
address of the first instruction that will be executed by the CPU. As
instructions are executed, logic in the CPU increments the PC such that
it always points to the next piece of information that the CPU will need.
The number of bits in the PC exactly matches the number of wires in the
address bus. This determines the total potentially available memory
space that can be accessed by a CPU. In the case of an
The stack pointer (SP) is used as a pointer to the next available location
in a last-in-first-out (LIFO) stack. The stack can be thought of as a pile
of cards, each holding a single byte of information. At any given time, the
CPU can put a card on top of the stack or take a card off the stack. Cards
within the stack cannot be picked up unless all the cards piled on top are
removed first. The CPU accomplishes this stack effect by way of the SP.
The SP points to a memory location (pigeon hole), which is thought of as
the next available card. When the CPU pushes a piece of data onto the
stack, the data value is written into the pigeon hole pointed to by the SP,
and the SP is then decremented so it points at the next previous memory
location (pigeon hole). When the CPU pulls a piece of data off the stack,
the SP is incremented so it points at the most recently used pigeon hole,
and the data value is read from that pigeon hole. When the CPU is first
started up or after a reset stack pointer (RSP) instruction, the SP points
to a specific memory location in RAM (a certain pigeon hole).
Timing
A high-frequency clock source (typically derived from a crystal
connected to the MCU) is used to control the sequencing of CPU
instructions. Typical MCUs divide the basic crystal frequency by two or
more to arrive at a bus-rate clock. Each memory read or write takes one
bus-rate clock cycle. In the case of the MC68HC705J1A MCU, a 4-MHz
(maximum) crystal oscillator clock is divided by two to arrive at a 2-MHz
(maximum) internal processor clock. Each substep of an instruction
takes one cycle of this internal bus-rate clock (500 ns). Most instructions
take two to five of these substeps; thus, the CPU is capable of executing
more than 500,000 instructions every second.
humans also need to read and understand programs. The first column in
the listing shows four digit hexadecimal addresses. The next few
columns show 8-bit values (the contents of individual memory locations).
The rest of the information in the listing is for the benefit of humans who
need to read the listing. The meaning of all this information will be
discussed in greater detail in the chapter entitled Programming.
Figure 16 shows that the CPU sees the example program as a linear
sequence of binary codes, including instructions and operands in
successive memory locations. An operand is any value other than the
opcode that the CPU needs to complete the instruction. The CPU begins
this program with its program counter (PC) pointing at the first byte in the
program. Each instruction opcode tells the CPU how many (if any) and
what type of operands go with that instruction. In this way, the CPU can
remain aligned to instruction boundaries even though the mixture of
opcodes and operands looks confusing to us.
*******************************************************
* Simple 68HC05 Program Example *
* Read state of switch at port A bit-0; 1=closed *
* When sw. closes, light LED for about 1 sec; LED on *
* when port A bit-7 = 0. Wait for sw release, *
* then repeat. Debounce sw 50mS on & off *
* NOTE: Timing based on instruction execution times *
* If using a simulator or crystal less than 4MHz, *
* this routine will run slower than intended *
*******************************************************
$BASE 10T ;Tell assembler to use decimal
;unless $ or % before value
Freescale Semiconductor, Inc...
***
* DLY50 — Subroutine to delay ~50ms
* Save original accumulator value
* but X will always be zero on return
***
$0000
$A6 $0300
I/O $80 $0301
32 Bytes
$001F $B7 $0302
$0020 $00 $0303
$B7 $0304
Unused
160 Bytes $04 $0305
$B6 $0306
$00BF $00 $0307
$00C0 $A4 $0308
$01 $0309
Stack RAM
64 Bytes $27 $030A
$00FF $FA $030B
$0100 $CD $030C
Freescale Semiconductor, Inc...
$03 $030D
$23 $030E
$1F $030F
Unused $00 $0310
512 Bytes $A6 $0311
$14 $0312
$CD $0313
$03 $0314
$02FF $23 $0315
$0300 $4A $0316
Example $26 $0317
Program $FA $0318
$0330
$1E $0319
$0331
$00 $031A
$00 $031B
$00 $031C
$FD $031D
$CD $031E
User EPROM $03 $031F
1232 Bytes $23 $0320 $B7 $0323
$20 $0321 $C0 $0324
$E3 $0322
$B7 $0323
$C0 $0324
$A6 $0325
$07CF $41 $0326
$07D0 $5F $0327
Unimplemented $5A $0328
30 Bytes $26 $0329
$07ED $FD $032A
$07EE $4A $032B
Test ROM
$07EF $26 $032C
$07F0 User Vectors $F9 $032D
(EPROM) $B6 $032E
$07FF 16 Bytes $C0 $032F
$81 $0330
You should have found this line from near the bottom of
Listing 1. Example Program.
CPU Operation
This section first discusses the detailed operation of CPU instructions
and then explains how the CPU executes an example program. The
detailed descriptions of typical CPU instructions are intended to make
you think like a CPU. We will then go through an example program using
a teaching technique called “playing computer” in which you pretend you
are the CPU interpreting and executing the instructions in a program.
Detailed Before seeing how the CPU executes programs, it would help to know
Operation of CPU (in detail) how the CPU breaks down instructions into fundamental
Instructions operations and performs these tiny steps to accomplish a desired
instruction. As we will see, many small steps execute quickly and
accurately within each instruction, but none of the small steps is too
complicated.
Store Look up the STA instruction in Instruction Set Details. In the table at
Accumulator the bottom of the page, we see that $B7 is the direct (DIR) addressing
Freescale Semiconductor, Inc...
(Direct Addressing mode version of the store accumulator instruction. We also see that the
Mode) instruction requires two bytes, one to specify the opcode ($B7) and the
second to specify the direct address where the accumulator will be
stored. (The two bytes are shown as B7 dd in the machine code column
of the table.)
The table at the bottom of the STA page shows that the direct
addressing version of the STA instruction takes four CPU cycles to
execute. During the first cycle, the CPU puts the value from the program
counter on the internal address bus and reads the opcode $B7, which
identifies the instruction as the direct addressing version of the STA
instruction and advances the PC to the next memory location.
During the second cycle, the CPU places the value from the PC on the
internal address bus and reads the low-order byte of the direct address
($00 for example). The CPU uses the third cycle of this STA instruction
to internally construct the full address where the accumulator is to be
stored and advances the PC so it points to the next address in memory
(the address of the opcode of the next instruction).
In this example, the CPU appends the assumed value $00 (because of
direct addressing mode) to the $00 that was read during the second
cycle of the instruction to arrive at the complete address $0000. During
the fourth cycle of this instruction, the CPU places this constructed
address ($0000) on the internal address bus, places the accumulator
value on the internal data bus, and asserts the write signal. That is, the
CPU writes the contents of the accumulator to $0000 during the fourth
cycle of the STA instruction.
While the accumulator was being stored, the N and Z bits in the condition
code register were set or cleared according to the data that was stored.
The Boolean logic formulae for these bits appear near the middle of the
instruction set page. The Z bit will be set if the value stored was $00;
Freescale Semiconductor, Inc...
otherwise, the Z bit will be cleared. The N bit will be set if the most
significant bit of the value stored was a logic 1; otherwise, N will be
cleared.
Load Next, look up the LDA instruction in the instruction set appendix. The
Accumulator immediate addressing mode (IMM) version of this instruction appears as
(Immediate A6 ii in the machine code column of the table at the bottom of the
Addressing Mode) page. This version of the instruction takes two internal processor clock
cycles to execute.
The $A6 opcode tells the CPU to get the byte of data that immediately
follows the opcode and put this value in the accumulator. During the first
cycle of this instruction, the CPU reads the opcode $A6 and advances
the PC to point to the next location in memory (the address of the
immediate operand ii). During the second cycle of the instruction, the
CPU reads the contents of the byte following the opcode into the
accumulator and advances the PC to point at the next location in
memory (for instance, the opcode byte of the next instruction).
While the accumulator was being loaded, the N and Z bits in the
condition code register were set or cleared according to the data that
was loaded into the accumulator. The Boolean logic formulae for these
bits appear near the middle of the instruction set page. The Z bit will be
set if the value loaded into the accumulator was $00; otherwise, the Z bit
will be cleared. The N bit will be set if the most significant bit of the value
loaded was a logic 1; otherwise, N will be cleared.
The N (negative) condition code bit may be used to detect the sign of a
twos-complement number. In twos-complement numbers, the most
Conditional Branch instructions allow the CPU to select one of two program flow
Branch paths, depending upon the state of a particular bit in memory or various
condition code bits. If the condition checked by the branch instruction is
true, program flow skips to a specified location in memory. If the
condition checked by the branch is not true, the CPU continues to the
instruction following the branch instruction. Decision blocks in a
Freescale Semiconductor, Inc...
Most branch instructions contain two bytes, one for the opcode and one
for a relative offset byte. Branch on bit clear (BRCLR) and branch on bit
set (BRSET) instructions require three bytes: the opcode, a 1-byte direct
address (to specify the memory location to be tested), and the relative
offset byte.
“ “ “ “ “
0300 A6 02 TOP LDA #$02 ;Load an immediate value
0302 CD 04 00 JSR SUBBY ;Go do a subroutine
0305 B7 E0 STA $E0 ;Store accumulator to RAM
0307 “ “ “ “
“ “ “ “ “
“ “ “ “ “
0400 4A SUBBY DECA ;Decrement accumulator
0401 26 FD BNE SUBBY ;Loop till accumulator=0
0403 81 RTS ;Return to main program
Freescale Semiconductor, Inc...
START
The CPU clock cycle numbers (in square brackets) are used as
references in the following explanation of Figure 17.
[2] CPU reads immediate data $02 from location $0301 into the
accumulator.
[9] CPU reads $4A opcode from location $0400. This is the first
instruction of the called subroutine.
[10] The CPU uses its ALU to subtract one from the value in the
accumulator.
[14] During the LDA #$02 instruction at [1], the accumulator was
loaded with the value 2; during the DECA instruction at [9],
the accumulator was decremented to 1 (which is not equal
to 0). Thus, at [14], the branch condition was true, and the
twos-complement offset ($FD or –3) was added to the
internal PC (which was $0403 at the time) to get the value
$0400.
[15] through [19] are a repeat of cycles [9] through [13] except that when
the DECA instruction at [15] was executed this time, the
Freescale Semiconductor, Inc...
[27] CPU reads the STA direct opcode ($B7) from location
$0305.
[28] CPU reads the low-order direct address ($E0) from location
$0306.
[29] [30] The STA direct instruction takes a total of four cycles. During
the last two cycles of the instruction, the CPU constructs the
complete address where the accumulator will be stored by
appending $00 (assumed value for the high-order half of the
address due to direct addressing mode) to the $E0 read
during [28]. The accumulator ($00 at this time) is then stored
to this constructed address ($00E0).
Playing Computer
Playing computer is a learning exercise where you pretend to be a
CPU that is executing a program. Programmers often mentally check
programs by playing computer as they read through a software routine.
While playing computer, it is not necessary to break instructions down to
individual processor cycles. Instead, an instruction is treated as a single
complete operation rather than several detailed steps.
On this worksheet, there is an area for keeping track of the stack. After
you become comfortable with how the stack works, you would probably
leave this section off, but it will be instructive to leave it here for now.
As a value is saved on the stack, you will cross out any prior value and
write the new value to its right in a horizontal row. You must also update
(decrement) the SP value. Cross out any prior value and write the new
value beneath it under the SP heading at the top of the worksheet. As a
value is recovered from the stack, you would update (increment) the
value of SP by crossing out the old value and writing the new value
below it. You would then read the value from the location now pointed to
by the SP and put it wherever it belongs in the CPU (for instance, in the
upper or lower half of the PC).
$00FC
$00FD
$00FE
$00FF
Figure 19 shows how the worksheet will look after working through the
whole JSR sequence. Follow the numbers in square brackets as the
process is explained. During the process, many values were written and
later crossed out; a line has been drawn from the square bracket to
either the value or the crossed-out mark to show which item the
reference number applies to.
Next:
• You cross out the $02 in the accumulator column and write the
new value $01 [11].
• You also change the PC to $0401 [12].
• Because the DECA instruction changed the accumulator from $02
to $01 (which is not zero or negative), the Z bit and N bit remain
clear. Since N and Z were already cleared at [5], you can leave
them alone on the worksheet.
• The CPU now executes the BNE SUBBY instruction. Since the Z
bit is clear, the branch condition is met, and the CPU will take the
Freescale Semiconductor, Inc...
branch. Cross out the $0401 under PC and write $0400 [13].
• The CPU again executes the DECA instruction. The accumulator
is now changed from $01 to $00 [14] (which is 0 and not negative);
thus, the Z bit is set, and the N bit remains clear [15].
• The PC advances to the next instruction [16].
• The CPU now executes the BNE SUBBY instruction, but this time
the branch condition is not true (Z is set now), so the branch will
not be taken. The CPU simply falls to the next instruction (the RTS
at $0403).
• Update the PC to $0403 [17].
• The RTS instruction causes the CPU to recover the previously
stacked PC. Pull the high-order half of the PC from the stack by
incrementing the SP to $00FE [18] and by reading $03 from
location $00FE.
• Next, pull the low-order half of the address from the stack by
incrementing SP to $00FF [19] and by reading $05 from $00FF.
The address recovered from the stack replaces the value in the
PC [20].
• The CPU now reads the STA $E0 instruction from location $0305.
Program flow has returned to the main program sequence where
it left off when the subroutine was called.
• The STA (direct addressing mode) instruction writes the
accumulator value to the direct address $E0 ($00E0), which is in
the RAM of the MC68HC705J1A. We can see from the worksheet
that the current value in the accumulator is $00; therefore, all eight
For a larger program, the worksheet would have many more crossed out
values by the time you are done. Playing computer on a worksheet like
this is a good learning exercise, but, as a programmer gains experience,
the process would be simplified. In the programming chapter, we will see
a development tool called a simulator that automates the playing
computer process. The simulator is a computer program that runs on a
Freescale Semiconductor, Inc...
Resets
Reset is used to force the MCU system to a known starting place
(address). Peripheral systems and many control and status bits are also
forced to a known state as a result of reset.
RESET Pin An external switch or circuit can be connected to this pin to allow a
manual system reset.
Power-On Reset The power-on reset occurs when a positive transition is detected on
VDD. The power-on reset is used strictly for power turn-on conditions
and should not be used to detect any drops in the power supply voltage.
A low-voltage inhibit (LVI) circuit should be used to detect loss of power.
The power-on circuitry provides for a 4064-cycle delay from the time that
the oscillator becomes active. If the external RESET pin is low at the end
of the 4064-cycle delay timeout, the processor remains in the reset
condition until RESET goes high.
Watchdog Timer The computer operating properly (COP) watchdog timer system is
Reset intended to detect software errors. When the COP is being used,
Freescale Semiconductor, Inc...
A control bit in the non-volatile mask option control register can be used
to enable or disable the COP reset. If the COP is enabled, the operating
program must periodically write a 0 to the COPC bit in the COPR control
register. Refer to the MC68HC705J1A Technical Data (Motorola order
number MC68HC705J1A/D) for information about the COP timeout rate.
Some members of the M68HC05 Family have different COP watchdog
timer systems.
Illegal Address If a program is written incorrectly, it is possible that the CPU will attempt
Reset to jump or branch to an address that has no memory. If this happened,
the CPU would continue to read data (though it would be unpredictable
values) and attempt to act on it as if it were a program. These nonsense
instructions could cause the CPU to write unexpected data to
unexpected memory or register addresses. This situation is called
program runaway.
Interrupts
It is sometimes useful to interrupt normal processing to respond to some
unusual event. For instance, the MC68HC705J1A may be interrupted by
any of these sources:
Figure 20 shows how interrupts fit into the normal flow of CPU
instructions. Interrupts cause the processor registers to be saved on the
stack and the interrupt mask (I bit) to be set, to prevent additional
interrupts until the present interrupt is finished. The appropriate interrupt
vector then points to the starting address of the interrupt service routine
(Table 10). Upon completion of the interrupt service routine, an RTI
instruction (which is normally the last instruction of an interrupt service
routine) causes the register contents to be recovered from the stack.
Since the program counter is loaded with the value that was previously
saved on the stack, processing continues from where it left off before the
interrupt. Figure 21 shows that registers are restored from the stack in
the opposite order they were saved.
FROM
RESET
YES
I BIT IN CCR SET ?
NO
NO
Freescale Semiconductor, Inc...
YES
TIMER INTERRUPT ?
NO
STACK
PC, X, A, CCR
SET I BIT
IN CCR
FETCH NEXT
INSTRUCTION
YES
SWI INSTRUCTION ?
NO
EXECUTE
INSTRUCTION
7 0
STACK
1 1 1 CONDITION CODES
ACCUMULATOR
INTERRUPT
RETURN
INDEX REGISTER
0 0 0 0 0 PC HIGH
External Interrupts External interrupts come from the IRQ pin or from bits 3–0 of port A if port
A is configured for port interrupts. In the MC68HC705J1A MCU, the IRQ
pin sensitivity is software programmable.
Software Interrupt The software interrupt is an executable instruction. The action of the SWI
(SWI) instruction is similar to the hardware interrupts. An SWI is executed
regardless of the state of the interrupt mask (I bit) in the condition code
Freescale Semiconductor, Inc...
Interrupt Latency Although we think of interrupts as if they cause the CPU to stop normal
processing immediately in order to respond to the interrupt request, this
is not quite the case. There is a small delay from when an interrupt is
requested until the CPU can actually respond. First, the CPU must finish
any instruction that happens to be in progress at the time the interrupt is
requested. (The CPU would not know how to resume processing after
the interrupt was handled if it had stopped in the middle of an
instruction.) Second, the CPU must make a record of what it was doing
before it responded to the interrupt. The CPU does this by storing a copy
of the contents of all its registers, including the program counter, on the
stack. After the interrupt has been serviced, the CPU recovers this
information in reverse order and normal processing resumes.
Interrupt latency is the total number of CPU cycles (time) from the initial
interrupt request until the CPU starts to execute the first instruction of the
interrupt service routine. This delay depends upon whether or not the I
interrupt mask is set to 1 when the interrupt is requested. If the I bit is
set, the delay could be indefinite and depends upon when an instruction
clears the I bit so the interrupt can be recognized by the CPU. In the
normal case, where the I bit is clear when the interrupt is requested, the
latency will consist of finishing the current instruction, saving the
registers on the stack, and loading the interrupt vector (address of the
interrupt service routine) into the program counter.
handled. In a system that has more than one source of interrupts, the
execution time for the longest interrupt service routine must be
calculated in order to determine the worst-case interrupt latency for the
other interrupt sources.
Nested Interrupts In unusual cases, an interrupt service routine may take so long to
execute that the worst-case latency for other interrupts in the system is
too long. In such a case, instructions in the long interrupt service routine
could clear the I bit to zero, thus allowing a new interrupt to be
recognized before the first interrupt service routine is finished. If a new
interrupt is requested while the CPU is already servicing an interrupt, it
is called nesting. You must use great care if you allow interrupt nesting
because the stack must have enough space to hold more than one copy
of the CPU registers. On small microcontrollers like the MC68HC05K1,
the stack is small and nesting of interrupts is not recommended.
Review
In the M68HC05 architecture, five CPU registers are directly connected
within the CPU and are not part of the memory map. All other information
available to the CPU is located in a series of 8-bit memory locations. A
memory map shows the names and types of memory at all locations
that are accessible to the CPU. The expression memory-mapped I/O
means that the CPU treats I/O and control registers exactly like any
other kind of memory. (Some computer architectures separate the I/O
registers from program memory space and use separate instructions to
Freescale Semiconductor, Inc...
Computers use a high speed clock to step through each small substep
of each operation. Although each instruction takes several cycles of this
clock, it is so fast that operations seem to be instantaneous to a human.
An MC68HC705J1A can execute about 500,000 instructions per
second.
locally by clearing enable control bits for each interrupt source. Requests
can still be registered while interrupts are inhibited so the CPU can
respond as soon as the interrupts are re-enabled. SWI is an instruction
and cannot be inhibited.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Freescale Semiconductor, Inc...
Introduction
A computer’s instruction set is its vocabulary. This chapter describes the
CPU and instruction set of the M68HC05. Instruction Set Details
contains detailed descriptions of each M68HC05 instruction and can be
used as a reference. This chapter discusses the same instructions in
groups of functionally similar operations. The structure and addressing
modes of the M68HC05 are also discussed. Addressing modes refer to
the various ways a CPU can access operands for an instruction.
Freescale Semiconductor, Inc...
ARITHMETIC
CPU
LOGIC UNIT
CONTROL
(ALU)
M68HC05 CPU
CPU REGISTERS ACCUMULATOR
INDEX REGISTER
0 0 0 0 0 1 1 STACK POINTER
0 0 0 PROGRAM COUNTER
CONDITION CODES 1 1 1 H I N Z C
Arithmetic/Logic The arithmetic logic unit (ALU) is used to perform the arithmetic and
Unit (ALU) logical operations defined by the instruction set.
operations within the ALU under control of CPU control logic. The
multiply instruction (MUL) requires 11 internal processor cycles to
complete this chain of operations.
CPU Control The CPU control circuitry sequences the logic elements of the ALU to
carry out the required operations. A central element of the CPU control
section is the instruction decoder. Each opcode is decoded to
determine how many operands are needed and what sequence of steps
will be required to complete the instruction. When one instruction is
Freescale Semiconductor, Inc...
CPU Registers The CPU contains five registers as shown in Figure 23. Registers in the
CPU are memories inside the microprocessor (not part of the memory
map). The set of registers in a CPU is sometimes called a programming
model. An experienced programmer can tell a lot about a computer from
its programming model.
7 0
ACCUMULATOR A
INDEX REGISTER X
12 7 5 0
0 0 0 0 0 1 1 STACK POINTER SP
15 12 0
0 0 0 PROGRAM COUNTER PC
7 4 3 2 1 0
CONDITION CODE REGISTER 1 1 1 H I N Z C CC R
CARRY
ZERO
NEGATIVE
INTERRUPT MASK
HALF-CARRY
(FROM BIT 3)
7 0
ACCUMULATOR A
Freescale Semiconductor, Inc...
Index Register The index register is used for indexed modes of addressing or may be
used as an auxiliary accumulator. This 8-bit register can be loaded either
directly or from memory, its contents can be stored in memory, or its
contents can be compared to memory.
7 0
INDEX REGISTER X
Condition Code The condition code register contains an interrupt mask and four status
Register indicators that reflect the results of arithmetic and other operations of the
CPU. The five flags are:
• Half-carry (H)
• Negative (N)
• Zero (Z)
• Overflow (V)
• Carry borrow (C)
7 4 3 2 1 0
CARRY
ZERO
NEGATIVE
INTERRUPT MASK
HALF-CARRY (FROM BIT 3)
Half-Carry Bit (H) The half-carry flag is used for binary-coded decimal (BCD) arithmetic
operations and is affected by the ADD or ADC addition instructions. The
H bit is set to a 1 when a carry occurs from the low-order hexadecimal
digit in bits 3–0 and the high-order digit in bits 7–4. After the binary
addition of two 2-digit BCD values, this half-carry bit is one piece of
information needed to restore the result to a valid BCD value.
Interrupt Mask The I bit is not a status flag but an interrupt mask bit that disables all
Bit (I) maskable interrupt sources when the I bit is set. Interrupts are enabled
when this bit is a 0. When any interrupt occurs, the I bit is set
automatically after the registers are stacked but before the interrupt
vector is fetched.
If an external interrupt occurs while the I bit is set, the interrupt is latched
and processed after the I bit is cleared; therefore, no interrupts from the
IRQ pin are lost because of the I bit being set.
Negative Bit (N) The N bit is set to 1 when the result of the last arithmetic, logical, or data
manipulation is negative. Twos-complement signed values are
considered negative if the most significant bit is a 1.
The N bit has other uses. By assigning an often-tested flag bit to the
MSB of a register or memory location, you can test this bit simply by
loading the accumulator with the contents of that location.
Zero Bit (Z) The Z bit is set to 1 when the result of the last arithmetic, logical, or data
manipulation is 0. A compare instruction subtracts a value from the
memory location being tested. If the values were equal to each other
before the compare, the Z bit will be set.
Carry/Borrow Bit The C bit is used to indicate if there was a carry from an addition or a
(C) borrow as a result of a subtraction. Shift and rotate instructions operate
with and through the carry bit to facilitate multiple word shift operations.
This bit is also affected during bit test and branch instructions.
Freescale Semiconductor, Inc...
BEFORE 1 1 1 1 1 1 1 1 ($FF) 1 1 1 0 1 1 0 0
CONDITION CODES AND ACCUMULATOR REFLECT THE RESULTS OF THE ADD INSTRUCTION:
AFTER 0 0 0 0 0 0 0 1 ($01) 1 1 1 1 1 0 0 1
H – Set because there was a carry from bit 3 to bit 4 of the accumulator
I – No change
N – Clear because result is not negative (bit 7 of accumulator is 0)
Z – Clear because result is not 0
C – Set because there was a carry out of bit 7 of the accumulator
Program Counter The program counter is a 16-bit register that contains the address of the
next instruction or instruction operand to be fetched by the processor. In
most variations of the M68HC05, some of the upper bits of the program
counter are not used and are always 0. The MC68HC705J1A, for
instance, uses only 11 bits of the program counter so the upper five bits
are always 0. The number of useful bits in the program counter exactly
matches the number of address lines implemented in the computer
system.
15 10 0
0 0 0 0 0 PROGRAM COUNTER PC
Freescale Semiconductor, Inc...
Stack Pointer The stack pointer must have as many bits as there are address lines; in
the MC68HC705J1A this means the SP is an 11-bit register. During an
MCU reset or the reset stack pointer (RSP) instruction, the stack pointer
is set to location $00FF. The stack pointer is then decremented as data
is pushed onto the stack and incremented as data is pulled from the
stack.
10 7 5 0
0 0 0 1 1 STACK POINTER SP
Addressing Modes
The power of any computer lies in its ability to access memory. The
addressing modes of the CPU provide that capability. The addressing
modes define the manner in which an instruction is to obtain the data
required for its execution. Because of different addressing modes, an
instruction may access the operand in one of up to six different ways. In
this manner, the addressing modes expand the basic 62 M68HC05
Family instructions into 210 distinct opcodes.
Freescale Semiconductor, Inc...
• Inherent
• Immediate
• Extended
• Direct
• Indexed,no offset, 8-bit offset, and 16-bit offset,
• Relative
Inherent In inherent addressing mode, all information required for the operation is
Addressing Mode already inherently known to the CPU, and no external operand from
memory or from the program is needed. The operands, if any, are only
the index register and accumulator, and are always 1-byte instructions.
The following is a list of all M68HC05 instructions that can use the
inherent addressing mode.
Instruction Mnemonic
Arithmetic Shift Left ASLA,ASLX
Arithmetic Shift Right ASRA,ASRX
Clear Carry Bit CLC
Clear Interrupt Mask Bit CLI
Clear CLRA,CLRX
Freescale Semiconductor, Inc...
Immediate In the immediate addressing mode, the operand is contained in the byte
Addressing Mode immediately following the opcode. This mode is used to hold a value or
constant which is known at the time the program is written and which is
not changed during program execution. These are 2-byte instructions,
one for the opcode and one for the immediate data byte.
Execution Sequence:
$0300 $A6 [1]
Freescale Semiconductor, Inc...
Explanation:
[1] CPU reads opcode $A6 — load accumulator with the value
immediately following the opcode.
[2] CPU then reads the immediate data $03 from location
$0301 and loads $03 into the accumulator.
The following is a list of all M68HC05 instructions that can use the
immediate addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Bit Test Memory with Accumulator BIT
Compare Accumulator with Memory CMP
Compare Index Register with Memory CPX
Exclusive OR Memory with Accumulator EOR
Load Accumulator from Memory LIDA
Load Index Register from Memory LDX
Inclusive OR ORA
Subtract with Carry SBC
Subtract SUB
Execution Sequence:
$0300 $C6 [1]
Freescale Semiconductor, Inc...
Explanation:
[1] CPU reads opcode $C6 — load accumulator using extended
addressing mode.
[2] CPU then reads $06 from location $0301. This $06 is
interpreted as the high-order half of an address.
[3] CPU then reads $E5 from location $0302. This $E5 is
interpreted as the low-order half of an address.
[4] CPU internally appends $06 to the $E5 read to form the
complete address ($06E5). The CPU then reads whatever
value is contained in the location $06E5 into the
accumulator.
The following is a list of all M68HC05 instructions that can use the
extended addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Bit Test Memory with Accumulator BIT
Compare Accumulator with Memory CMP
Freescale Semiconductor, Inc...
Direct Addressing The direct addressing mode is similar to the extended addressing mode
Mode except the upper byte of the operand address is assumed to be $00.
Thus, only the lower byte of the operand address needs to be included
in the instruction. Direct addressing allows you to efficiently address the
lowest 256 bytes in memory. This area of memory is called the direct
page and includes on-chip RAM and I/O registers. Direct addressing is
efficient in both memory and time. Direct addressing mode instructions
are usually two bytes, one for the opcode and one for the low-order byte
of the operand address.
Freescale Semiconductor, Inc...
Execution Sequence:
$0300 $B6 [1]
$0301 $50 [2] and [3]
Explanation:
[1] CPU reads opcode $B6 — load accumulator using direct
addressing mode.
[2] CPU then reads $50 from location $0301. This $50 is
interpreted as the low-order half of an address. In direct
addressing mode, the high-order half of the address is
assumed to be $00.
[3] CPU internally appends $00 to the $50 read in the second
cycle to form the complete address ($0050). The CPU then
reads whatever value is contained in the location $0050 into
the accumulator.
The following is a list of all M68HC05 instructions that can use the direct
addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Arithmetic Shift Left ASL
Arithmetic Shift Right ASR
Clear Bit in Memory BCLR
Freescale Semiconductor, Inc...
Indexed In the indexed addressing mode, the effective address is variable and
Addressing Modes depends upon two factors:
Indexed, No Offset In the indexed, no-offset addressing mode, the effective address of the
instruction is contained in the 8-bit index register. Thus, this addressing
mode can access the first 256 memory locations. These instructions are
only one byte.
Execution Sequence:
$0300 $F6 [1], [2], [3]
Explanation:
[1] CPU reads opcode $F6 — load accumulator using indexed,
no offset, addressing mode.
[3] CPU then reads the contents of the addressed location into
the accumulator.
The following is a list of all M68HC05 instructions that can use the
indexed, no-offset addressing mode or the indexed, 8-bit offset
addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Arithmetic Shift Left ASL
Freescale Semiconductor, Inc...
Indexed, 8-Bit In the indexed, 8-bit offset addressing mode, the effective address is
Offset obtained by adding the contents of the byte following the opcode to the
contents of the index register. This mode of addressing is useful for
selecting the kth element in an n element table. To use this mode, the
table must begin in the lowest 256 memory locations and may extend
through the first 511 memory locations (IFE is the last location which the
instruction may access). Indexed 8-bit offset addressing can be used for
ROM, RAM, or I/O. This is a 2-byte instruction with the offset contained
in the byte following the opcode. The content of the index register (X) is
not changed. The offset byte supplied in the instruction is an unsigned
Freescale Semiconductor, Inc...
8-bit integer.
Execution Sequence:
$0300 $E6 [1]
$0301 $05 [2], [3], [4]
Explanation:
[2] CPU then reads $05 from location $0301. This $05 is
interpreted as the low-order half of a base address. The
high-order half of the base address is assumed to be $00.
[3] CPU will add the value in the index register to the base
address $0005. The results of this addition is the address
that the CPU will use in the load accumulator operation.
[4] The CPU will then read the value from this address and load
this value into the accumulator.
The list of all M68HC05 instructions that can use the indexed, 8-bit offset
addressing mode is the same as the list of instructions that use indexed,
no-offset addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Arithmetic Shift Left ASL
Arithmetic Shift Right ASR
Freescale Semiconductor, Inc...
Indexed, 16-Bit In the indexed, 16-bit offset addressing mode, the effective address is
Offset the sum of the contents of the 8-bit index register and the two bytes
following the opcode. The content of the index register is not changed.
These instructions are three bytes, one for the opcode and two for a
16-bit offset.
Execution Sequence:
Freescale Semiconductor, Inc...
Explanation:
[1] CPU reads opcode $D6 — load accumulator using indexed,
16-bit offset addressing mode.
[2] CPU then reads $07 from location $0301. This $07 is
interpreted as the high-order half of a base address.
[3] CPU then reads $00 from location $0302. This $00 is
interpreted as the low-order half of a base address.
[4] CPU will add the value in the index register to the base
address $0700. The results of this addition is the address
that the CPU will use in the load accumulator operation.
[5] The CPU will then read the value from this address and load
this value into the accumulator.
The following is a list of all M68HC05 instructions that can use the
indexed, 16-bit offset addressing mode.
Instruction Mnemonic
Add with Carry ADC
Add ADD
Logical AND AND
Bit Test Memory with Accumulator BIT
Compare Accumulator with Memory CMP
Freescale Semiconductor, Inc...
Relative The relative addressing mode is used only for branch instructions.
Addressing Mode Branch instructions, other than the branching versions of
bit-manipulation instructions, generate two machine-code bytes: one for
the opcode and one for the relative offset. Because it is desirable to
branch in either direction, the offset byte is a signed twos-complement
offset with a range of –127 to +128 bytes (with respect to the address
of the instruction immediately following the branch instruction). If the
branch condition is true, the contents of the 8-bit signed byte following
the opcode (offset) are added to the contents of the program counter to
form the effective branch address; otherwise, control proceeds to the
Freescale Semiconductor, Inc...
Execution Sequence:
$0300 $27 [1]
$0301 $rr [2], [3]
Explanation:
[1] CPU reads opcode $27 — branch if Z = 1, (relative
addressing mode).
[3] CPU internally tests the state of the Z bit and causes a
branch if Z is set.
The following is a list of all M68HC05 instructions that can use the
relative addressing mode.
Instruction Mnemonic
Branch if Carry Clear BCC
Branch is Carry Set BCS
Branch if Equal BEQ
Branch if Half-Carry Clear BHCC
Branch if Half-Carry Set BHCS
Freescale Semiconductor, Inc...
Bit Test and Branch These instructions use direct addressing mode to specify the location
Instructions being tested and relative addressing to specify the branch destination.
This text book treats these instructions as direct addressing mode
instructions. Some older Motorola documents call the addressing mode
of these instructions BTB for bit test and branch.
MOTOROLA
Table 11. Register/Memory Instructions
Addressing Modes
Exclusive OR Memory
Arithmetic Compare A
CMP A1 2 2 E11 2 3 C1 3 4 F1 1 3 E1 2 4 D1 3 5
Go to: www.freescale.com
with Memory
Arithmetic Compare X
CPX A3 2 2 B3 2 3 C3 3 4 F3 1 3 E3 2 4 D3 3 5
with Memory
BIT A5 2 2 B5 2 3 C5 3 4 F5 1 3 E 2 4 D5 3 5
A (Logical Compare)
121
Addressing Modes
122
Table 12. Read/Modify-Write Instructions
Addressing Modes
Indexed Indexed
Inherent (A) Inherent (X) Direct
(No Offset) (8-Bit Offset)
code Bytes Cycles code Bytes Cycles code Bytes Cycles code Bytes Cycles code Bytes Cycles
Increment INC 4C 1 3 5C 1 3 3C 2 5 7C 1 5 6C 2 6
Decrement DEC 4A 1 3 5A 1 3 3A 2 5 7A 1 5 6A 2 6
Clear CLR 4F 1 3 5F 1 3 3F 2 5 7F 1 5 6F 2 6
Complement COM 43 1 3 53 1 3 33 2 5 73 1 5 63 2 6
Negate
NEG 40 1 3 50 1 3 30 2 5 70 1 5 60 2 6
Twos Complement
Multiply MUL 42 1 11 — — — — — — — — — — — —
Go to: www.freescale.com
See
Bit Clear BCLR — — — — — — 2 5 — — — — — —
Note
NOTE: Unlike other read-modify-write instructions, BCLR and BSET use only direct addressing.
MOTOROLA
Freescale Semiconductor, Inc.
M68HC05 Instruction Set
Addressing Modes
Branch if Lower
BLO 25 2 3
(Same as BCS)
Transfer A to X TAX 97 1 2
Transfer X to A TXA 9F 1 2
No-Operation NOP 9D 1 2
Stop STOP 8E 1 2
Wait WAIT 8F 1 2
Boolean Operators
( ) — Contents of (For Example, (M) + — Inclusive OR
Means the Contents ⊕ — Exclusive OR
of Memory Location M — — NOT
– — Negation,
← — is loaded with, gets Twos Complement
• — Logical AND x — Multiplication
CPU Registers
A — Accumulator PC — Program Counter
ACCA — Accumulator PCH — PC High Byte
CCR — Condition Code Register PCL — PC Low Byte
X — Index Register SP — Stack Pointer
M — Any memory location REL — Relative Address, One Byte
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
ADC #opr IMM A9 ii 2
ADC opr DIR B9 dd 3
ADC opr EXT C9 hh ll 4
Add with Carry A ← (A) + (M) + (C) ↕ — ↕ ↕ ↕
ADC opr,X IX2 D9 ee ff 5
ADC opr,X IX1 E9 ff 4
ADC ,X IX F9 3
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
BIT #opr IMM A5 ii 2
BIT opr DIR B5 dd 3
BIT opr EXT C5 hh ll 4
Bit Test Accumulator with Memory Byte (A) ∧ (M) — — ↕ ↕ —
BIT opr,X IX2 D5 ee ff 5
BIT opr,X IX1 E5 ff 4
BIT ,X IX F5 3
BLO rel Branch if Lower (Same as BCS) PC ← (PC) + 2 + rel ? C = 1 — — — — — REL 25 rr 3
BLS rel Branch if Lower or Same PC ← (PC) + 2 + rel ? C ∨ Z = 1 — — — — — REL 23 rr 3
Freescale Semiconductor, Inc...
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
CLR opr M ← $00 DIR 3F dd 5
CLRA A ← $00 INH 4F 3
CLRX Clear Byte X ← $00 — — 0 1 — INH 5F 3
CLR opr,X M ← $00 IX1 6F ff 6
CLR ,X M ← $00 IX 7F 5
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
JSR opr DIR BD dd 5
PC ← (PC) + n (n = 1, 2, or 3)
JSR opr EXT CD hh ll 6
Push (PCL); SP ← (SP) – 1
JSR opr,X Jump to Subroutine — — — — — IX2 DD ee ff 7
Push (PCH); SP ← (SP) – 1
JSR opr,X IX1 ED ff 6
PC ← Effective Address
JSR ,X IX FD 5
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
ROR opr DIR 36 dd 5
RORA INH 46 3
RORX Rotate Byte Right through Carry Bit C — — ↕ ↕ ↕ INH 56 3
ROR opr,X b7 b0 IX1 66 ff 6
ROR ,X IX 76 5
Operand
Address
Effect on
Opcode
Cycles
Mode
Source CCR
Operation Description
Form
H I N Z C
TST opr DIR 3D dd 4
TSTA INH 4D 3
TSTX Test Memory Byte for Negative or Zero (M) – $00 — — ↕ ↕ — INH 5D 3
TST opr,X IX1 6D ff 5
TST ,X IX 7D 4
132
Bit Manipulation Branch Read-Modify-Write Control Register/Memory
DIR DIR REL DIR INH INH IX1 IX INH INH IMM DIR EXT IX2 IX1 IX
MSB MSB
0 1 2 3 4 5 6 7 8 9 A B C D E F
LSB LSB
5 5 3 5 3 3 6 5 9 2 3 4 5 4 3
0 BRSET0 BSET0 BRA NEG NEGA NEGX NEG NEG RTI SUB SUB SUB SUB SUB SUB 0
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 6 2 3 4 5 4 3
1 BRCLR0 BCLR0 BRN RTS CMP CMP CMP CMP CMP CMP 1
3 DIR 2 DIR 2 REL 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 11 2 3 4 5 4 3
2 BRSET1 BSET1 BHI MUL SBC SBC SBC SBC SBC SBC 2
3 DIR 2 DIR 2 REL 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
M68HC05 Instruction
5 5 3 5 3 3 6 5 10 2 3 4 5 4 3
3 BRCLR1 BCLR1 BLS COM COMA COMX COM COM SWI CPX CPX CPX CPX CPX CPX 3
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 3 4 5 4 3
4 BRSET2 BSET2 BCC LSR LSRA LSRX LSR LSR AND AND AND AND AND AND 4
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 2 3 4 5 4 3
5 BRCLR2 BCLR2 BCS/BLO BIT BIT BIT BIT BIT BIT 5
3 DIR 2 DIR 2 REL 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 3 4 5 4 3
6 BRSET3 BSET3 BNE ROR RORA RORX ROR ROR LDA LDA LDA LDA LDA LDA 6
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 4 5 6 5 4
7 BRCLR3 BCLR3 BEQ ASR ASRA ASRX ASR ASR TAX STA STA STA STA STA 7
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 2 3 4 5 4 3
8 BRSET4 BSET4 BHCC ASL/LSL ASLA/LSLA ASLX/LSLX ASL/LSL ASL/LSL CLC EOR EOR EOR EOR EOR EOR 8
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 2 3 4 5 4 3
9 BRCLR4 BCLR4 BHCS ROL ROLA ROLX ROL ROL SEC ADC ADC ADC ADC ADC ADC 9
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 2 3 4 5 4 3
A BRSET5 BSET5 BPL DEC DECA DECX DEC DEC CLI ORA ORA ORA ORA ORA ORA A
Go to: www.freescale.com
5 5 3 5 3 3 6 5 2 2 3 4 3 2
C BRSET6 BSET6 BMC INC INCA INCX INC INC RSP JMP JMP JMP JMP JMP C
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
D BRCLR6 BCLR6 BMS TST TSTA TSTX TST TST NOP BSR JSR JSR JSR JSR JSR D
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 2 REL 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 2 2 3 4 5 4 3
E BRSET7 BSET7 BIL STOP LDX LDX LDX LDX LDX LDX E
3 DIR 2 DIR 2 REL 1 INH 2 IMM 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
5 5 3 5 3 3 6 5 2 2 4 5 6 5 4
F BRCLR7 BCLR7 BIH CLR CLRA CLRX CLR CLR WAIT TXA STX STX STX STX STX F
3 DIR 2 DIR 2 REL 2 DIR 1 INH 1 INH 2 IX1 1 IX 1 INH 1 INH 2 DIR 3 EXT 3 IX2 2 IX1 1 IX
MOTOROLA
Freescale Semiconductor, Inc.
M68HC05 Instruction Set
Review
Review
CPU Registers The five CPU registers in the M68HC05 MCUs are not locations in the
memory map. The programming model for the CPU shows the five
CPU registers.
Addressing Modes The M68HC05 CPU has six addressing modes that determine how the
CPU will get the operand(s) needed to complete each instruction. The
M68HC05 CPU has only 62 mnemonic instructions. There are 210
instruction opcodes because each different addressing mode variation
of an instruction must have a unique opcode.
• In direct addressing mode, the low order eight bits of the address
of the operand are located in the next byte of memory after the
opcode and the high order byte of the address is assumed to be
$00. This mode is more efficient than the extended addressing
mode because the high order address byte is not explicitly
included in the program.
• In indexed addressing mode, the current value of the index
register is added to a 0-, 1-, or 2-byte offset in the next 0, 1, or 2
memory locations after the opcode to form a pointer to the address
of the operand in memory.
Freescale Semiconductor, Inc...
Instruction Each opcode tells the CPU the operation to be performed and the
Execution addressing mode to be used to address any operands needed to
complete the instruction. The cycle-by-cycle explanations of example
instructions under each addressing mode provide a view of the tiny
simple steps that make up an instruction.
Programming
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136
Freescale Semiconductor, Inc...
Introduction
This chapter discusses how to plan and write computer programs. We
will learn how to prepare flowcharts, write assembly language programs,
and use a text editor or word processor to write computer programs.
Next, a programming tool called an assembler is used to translate the
program into a form the computer can use. Programming tools are
computer programs for personal computers that help in the development
of microcontroller computer programs. We will discuss assemblers,
simulators, and a few other useful development tools.
Freescale Semiconductor, Inc...
• The first step will be to plan the program and document this plan
with a flowchart.
• Next we will write instruction mnemonics for each block in the
flowchart.
• Finally, we will use an assembler to translate our example
program into the codes the computer needs to execute the
program.
Our program will read the state of a switch connected to an input pin.
When the switch is closed, the program will cause an LED (light-emitting
diode) connected to an output pin to light for about one second and then
go out. The LED will not light again until the switch has been released
and closed again. The length of time the switch is held closed will not
affect the length of time the LED is lighted.
BEGIN
READ SWITCH
Freescale Semiconductor, Inc...
NO
CLOSED ?
YES
DELAY TO DEBOUNCE
TURN ON LED
DELAY 1 SECOND
YES SWITCH
STILL CLOSED ?
NO
DELAY TO DEBOUNCE
block of the flowchart. The meanings of the mnemonics used in the right
side of Figure 31 can be found in Instruction Set Details or in
Instruction Set Summary.
BEGIN
AND #$01
NO
CLOSED ? BEQ TOP
YES
LDA #20
DLYLP JSR DLY50
DELAY 1 SECOND
DECA
BNE DLYLP
NO
BRA TOP
START
6 (JSR)
SUBROUTINE
LOAD VALUE
CORRESPONDING TO 50 ms LDA #65 2
OUTLP CLRX 3
NO COUNT
EXPIRED ? BNE OUTLP 3
YES
RESTORE
LDA TEMP1 3
ACCUMULATOR
RETURN FROM
SUBROUTINE RTS 6
[1] – INNRLP is executed 256 times per pass through outer loop.
[2] – OUTLP is executed 65 times.
Assembler Listing
After a complete program or subprogram is written, it must be converted
from mnemonics into binary machine code that the CPU can later
execute. A separate computer system, such as an IBM PC®, is used to
perform this conversion to machine language. A computer program for
the personal computer, called an assembler, is used. The assembler
reads the mnemonic version of the program (also called the source
version of the program) and produces a machine-code version of the
program in a form that can be programmed into the memory of the MCU.
Freescale Semiconductor, Inc...
*******************************************************
* Simple 68HC05 Program Example *
* Read state of switch at port A bit-0; 1 = closed *
* When sw. closes, light LED for about 1 sec; LED on *
* when port A bit-7 = 0. Wait for sw release, *
* then repeat. Debounce sw 50 ms on & off *
* NOTE: Timing based on instruction execution times *
* If using a simulator or crystal less than 4 MHz, *
* this routine will run slower than intended *
*******************************************************
$BASE 10T ;Tell assembler to use decimal
;unless $ or % before value
Freescale Semiconductor, Inc...
***
* DLY50 - Subroutine to delay ~50mS
* Save original accumulator value
* but X will always be zero on return
***
Refer to Figure 33 for the following discussion. This figure shows some
lines of the listing with reference numbers indicating the various parts of
the line. The first line is an example of an assembler directive line. This
line is not really part of the program; rather, it provides information to the
assembler so that the real program can be converted properly into binary
machine code.
In this assembler listing, the first two fields, [1] and [2], are generated by
the assembler, and the last four fields, [3], [4], [5], and [6], are the original
source program written by the programmer. Field [3] is a label (TOP)
which can be referred to in other instructions. In our example program,
the last instruction was BRA TOP, which simply means the CPU will
continue execution with the instruction that is labeled TOP.
way for the programmer to identify specific points in the program (without
knowing their exact addresses); the assembler can later convert these
mnemonic labels into specific memory addresses and even calculate
offsets for branch instructions so that the CPU can use them.
Field [4] is the instruction field. The LDA mnemonic is short for load
accumulator. Since there are six variations (different opcodes) of the
load accumulator instruction, additional information is required before
the assembler can choose the correct binary opcode for the CPU to use
during execution of the program.
Field [5] is the operand field, providing information about the specific
memory location or value to be operated on by the instruction. The
assembler uses both the instruction mnemonic and the operand
specified in the source program to determine the specific opcode for the
instruction.
Field [6] is called the comment field and is not used by the assembler to
translate the program into machine code. Rather, the comment field is
used by the programmer to document the program. Although the CPU
does not use this information during program execution, a programmer
knows that it is one of the most important parts of a good program. The
comment [6] for this line of the program says ;Read sw at LSB of
port A. This comment tells someone who is reading the listing
something about the instruction or why it is there, which is essential for
understanding how the program works. The semicolon indicates that
the rest of the line should be treated as a comment (not all assemblers
Freescale Semiconductor, Inc...
require this semicolon). An entire line can be made into a comment line
by using an asterisk (*) as the first character in the line. In addition to
good comments in the listing, it is also important to document programs
with a flowchart or other detailed information explaining the overall flow
and operation of the program.
Object Code File We learned in Computer Architecture that the computer expects the
program to be a series of 8-bit values in memory. So far, our program
still looks as if it were written for people. The version the computer needs
to load into its memory is called an object code file. For Motorola
microcontrollers, the most common form of object code file is the
S-record file. The assembler can be directed to optionally produce a
listing file and/or an object code file.
An S-record file is an ASCII text file that can be viewed by a text editor
or word processor. You should not edit these files because the structure
and content of the files are critical to their proper operation.
TYPE
LENGTH
ADDRESS OBJECT CODE DATA CHECKSUM
S1 13 03 20 23 20 E3 B7 C0 A6 41 5F 5A 26 FD 4A 26 F9 B6 C0 8A
All of the numbers in an S-record file are in hexadecimal. The type field
Freescale Semiconductor, Inc...
is S0, S1, or S9 for the S-record files we will use. The length field is the
number of pairs of hexadecimal digits in the record excluding the type
and length fields. The address field is the 16-bit address where the first
data byte will be stored in memory. Each pair of hexadecimal digits in the
machine code data field represents an 8-bit data value to be stored in
successive locations in memory. The checksum field is an 8-bit value
that represents the ones complement of the sum of all bytes in the
S-record except the type and checksum fields. This checksum is used
during loading of the S-record file to verify that the data is complete and
correct for each record.
Figure 35 is the S-record file that results from assembling the example
program of Listing 3. Assembler Listing. The two bytes of machine
code data that are bold are the same two bytes that were highlighted in
Figure 16 and the text that follows Figure 16. These bytes were located
by looking in the listing and seeing that the address where this
instruction started was $0323. In the S-record file, we found the S1
record with the address $0320. Moving to the right, we found the data
$23 for address $0320, $20 for address $0321, $E3 for $0322, and
finally the bytes we wanted for address $0323 and $0324.
S1130300A680B700B704B600A40127FACD03231FC3
S113031000A614CD03234A26FA1E000000FDCD03D7
S11303202320E3B7C0A6415F5A26FD4A26F9B6C08A
S10403308147
S9030000FC
Assembler Directives
In this section we discuss six of the most important assembler directives.
Assemblers from varying vendors differ in the number and kind of
assembler directives that are supported. Always refer to the
documentation for the assembler you are using.
Originate (ORG) This directive is used to set the location counter for the assembler. The
location counter keeps track of the address where the next byte of
Freescale Semiconductor, Inc...
Every program has at least one ORG directive to establish the starting
place in memory for the program. Most complete programs also will have
a second ORG directive near the end of the program to set the location
counter to the address where the reset and interrupt vectors are located
($07F8–$07FF in the MC68HC705J1A). The reset vector must always
be specified, and it is good practice to also specify interrupt
vectors, even if you do not expect to use interrupts.
Equate (EQU) This directive is used to associate a binary value with a label. The value
may be either an 8-bit value or a 16-bit address value. This directive
does not generate any object code.
An assembler reads the source program twice. On the first pass, the
assembler just counts bytes of object code and internally builds the
cross reference table. On the second pass, the assembler generates the
listing file and/or the S-record object file. This 2-pass arrangement
allows the programmer to reference labels that are defined later in the
program.
16-bit offset addressing mode may be used where a more efficient 8-bit
or no offset indexed instruction could have been used.
In the example program, there were two EQU directives to equate the
labels PORTA and DDRA to their direct page addresses. Another use for
EQU directives is to identify a bit position with a label like this:
Form Constant The arguments for this directive are labels or numbers, separated by
Byte (FCB) commas, that can be converted into single bytes of data. Each byte
specified in an FCB directive generates a byte of machine code in the
object code file. FCB directives are used to define constants in a
program.
Form Double Byte The arguments for this directive are labels or numbers, separated by
(FDB) commas, that can be converted into 16-bit data values. Each argument
specified in an FDB directive generates two bytes of machine code in the
object code file.
Reserve Memory This directive is used to set aside space in RAM for program variables.
Byte (RMB) The RMB directive does not generate object code but it normally
generates an entry in the assembler’s internal cross reference table.
Set Default Some assemblers, such as the P & E Microcomputer Systems IASM
Number Base assembler, assume that any value that is not specifically marked
to Decimal otherwise should be interpreted as a hexadecimal value. The idea is to
simplify entry of numeric information by eliminating the need for a $
symbol before each value. If you want the assembler to assume that
unmarked values are decimal numbers, use the $BASE directive.
accomplish the same basic task, there are subtle differences. Usually
these differences are not significant, but sometimes they can save
execution time or program memory space. In a small microcontroller,
memory space can be an important consideration.
The numbers in square brackets are the number of CPU cycles required
for the instruction on that line of the program. The TOP1 sequence takes
six bytes of program space and eight cycles. The accumulator is $01
when the program falls through the BEQ statement. The TOP2
sequence takes only three bytes and five cycles, and the accumulator is
not disturbed. (This is probably the best sequence in most cases.) The
TOP3 sequence takes one less byte than the TOP1 sequence but also
takes one extra cycle to execute. After the TOP3 sequence, the
accumulator still holds the other seven bits from the port A read,
although they have been shifted one position to the right. The last
sequence takes six bytes and a total of eight cycles, but the loop itself is
only six cycles. By working through exercises like this, you will improve
your instruction set dexterity. This will be very helpful when you need to
reduce a program by a few bytes to fit it into the available memory space.
Application Development
A simple development system for the MC68HC705J1A is offered by
Freescale Semiconductor, Inc...
NOTE: Remember to put the original number back before programming the
finished program into the EPROM of a real MCU.
only see the input and output pins, and you cannot easily stop a program
between instructions. But with the simulator, you can execute a single
instruction at a time and look at registers and memory contents at every
step. This makes it easier to see which instructions failed to perform as
intended. A simulator can also inform you if the program attempts to use
the value of a variable before it has been initialized.
Review
The process of writing a program begins with a plan. A flowchart can be
used to document the plan. Mnemonic source code statements are then
written for each block of the flowchart. Mnemonic source code
statements can include any of the instructions from the instruction set of
the microcontroller. The next step is to combine all of the program
instructions with assembler directives to get a text source file.
the assembler rather than to the CPU. These instructions tell the
assembler things like where to locate instructions in the memory of the
microcontroller. Assembler directives can also inform the assembler of
the binary meaning of a mnemonic label. Six directives were discussed.
• ORG — Originate directives set the starting address for the object
code that follows.
• EQU — Equate directives associate a label with a binary number
or address.
• FCB — Form constant byte directives are used to introduce 8-bit
constant data values into a program.
• FDB — Form double byte directives are used to introduce 16-bit
data or address constants into a program.
• RMB — Reserve memory byte(s) directives are used to assign
labels (belonging to program variables) to RAM addresses.
• $BASE 10T — Change default number base to decimal.
An emulator is built around a real MCU so it can run at the full speed of
the final MCU. Emulators use RAM instead of ROM or EPROM so the
program under development can be modified easily during
development.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159
Freescale Semiconductor, Inc...
Introduction
This chapter presents a general-purpose software structure that may be
used as a framework for many microcontroller applications. Major
system tasks are written as subroutines. These subroutines are
organized into a loop so that each is called once per pass through the
loop. At the top of the loop there is a short routine that paces the loop so
that it is executed at regular intervals. A software clock is maintained as
the first task in the loop. This clock can be used as an input to the other
System Equates
Freescale Semiconductor, Inc...
Register The manufacturer’s recommended names for registers and control bits
Equates for are included in the paced loop program framework of Listing 4. Paced
MC68HC705J1A Loop Framework Program in this chapter. This allows you to write
program instructions using names that make sense to people instead of
obscure binary numbers and addresses.
Since you cannot equate the same name to two different binary values,
the second equate uses a period after the bit name. To get a bit name’s
bit number (7–0), use the name; to get a mask indicating the bit position,
use the name followed by a period. This convention is used in the paced
loop framework, but it is not necessarily a standard that is recommended
by Motorola or the assembler companies.
Bit# is a number between 7 and 0 that identifies the bit within the register
at location dd that is to be changed or tested.
Freescale Semiconductor, Inc...
In other cases, you may want to build up a mask with several bits set,
and then write this composite value to a register location. For example,
suppose you want to set RTIFR, RTIE, and RT1 bits in the TSCR
register. You could use these instructions.
Vector Setup
All MCU programs should set up the reset and interrupt vectors.
Vectors specify the address where the CPU will start processing
instructions when a reset or interrupt occurs. Reset and each interrupt
source expect to find their associated vector in a specific pair of memory
locations. For example, the reset vector is at the highest two locations in
memory ($07FE and $07FF in the MC68HC705J1A). If you do not place
values in these locations, the CPU will take whatever binary values it
Freescale Semiconductor, Inc...
finds there and treat them as if they were a 2-byte address you stored
there.
Reset Vector The usual way to define a vector is with an FDB directive.
The reset vector was set up to point at the label START. The in-circuit
simulator system that Motorola offers as a low-cost development tool
uses this information to set up the simulator screen. When a program is
loaded into the simulator, the simulator looks for the address in the reset
vector of the loaded program. If one is found, the simulator selects that
program instruction and displays it in the source program window of the
simulator. The simulator’s PC is also set to this address. If there is no
reset vector, the simulator displays a warning message, saying that the
reset vector was not initialized. You could still debug the program, but it
would not work if it was programmed into an EPROM MCU because the
program would not start at reset.
Unused Interrupts For interrupts that are used, the vectors can be defined just as the reset
vector was defined (with an FDB directive). In the paced loop framework
program, the timer interrupt is used for real-time interrupts (RTI). The
external interrupt and the SWI (software interrupt) are not used.
It is a good idea to set up the unused interrupt vectors just in case one
of these interrupts is requested unexpectedly. This is not to say that
unexpected interrupts can occur in a working computer system. Rather,
it says that when a programmer is first starting out, programming
mistakes could result in unintended interrupt sources being enabled and
Freescale Semiconductor, Inc...
triggered.
This listing shows how interrupt and reset vectors were set up in the
paced loop framework program.
*******************************************************
* RTIF interrupt service routine
*******************************************************
0345 3A E0 RTICNT DEC RTIFs ;On each RTIF
" " " " " " "
" " " " " " "
0351 80 AnRTI RTI ;Return from RTIF interrupt
*******************************************************
* Interrupt & reset vectors
*******************************************************
07F8 ORG $07F8 ;Start of vector area
The first lines in this partial listing show the first and last lines of the timer
interrupt service routine. The line
RAM Variables
Program variables change value during the course of executing the
program. These values cannot be specified before the program is written
and programmed into the MCU. The CPU must use program instructions
to initialize and modify these values. When the program is written, space
is reserved for variables in the RAM memory of the MCU, using reserve
memory byte(s) (RMB) directives.
First, you would put an originate (ORG) directive to set the assembler’s
Freescale Semiconductor, Inc...
location counter to the address of the start of RAM in the MCU ($00C0
in the MC68HC705J1A). Each variable or group of variables would be
set up with an RMB directive. The RMB line is identified by the name of
the variable. The assembler assigns the name (label) to the next
available address. After each new variable or group of variables is
assigned, the location counter is advanced to point at the next free
memory location.
Paced Loop
The paced loop is a general-purpose software structure that is suitable
for a wide variety of MCU applications. The main idea is to break the
overall application into a series of tasks such as keeping track of time,
reading system inputs, and updating system outputs. Each task is
written as a subroutine. A main loop is constructed out of
jump-to-subroutine (JSR) instructions for each task. At the top of the
loop is a software pacemaker. When the pacemaker triggers, the list of
task subroutines is executed once and a branch instruction takes you to
the top of the loop to wait for the next pacemaker trigger.
Figure 37 shows a flowchart for the main paced loop. The top block is a
loop that waits for the pacemaker trigger (every 100 milliseconds). The
next few blocks have to do with maintaining the TIC counter. The version
of this program in Listing 4. Paced Loop Framework Program has two
simple main tasks, TIME and BLINK. You would remove one or both of
these routines and substitute your own tasks. The only limitation on the
number of main tasks is that they must all finish quickly enough so no
pacemaker triggers are lost. The last block in the flowchart is just a
branch back to the top of the loop to wait for the next pacemaker trigger.
Freescale Semiconductor, Inc...
MAIN
PACED LOOP
MAIN
NO
MSB OF TIC = 1 ?
YES
TIC = TIC + 1
NO
TIC = 10 ?
YES
SET TIC = 0
ARNC1
Loop Trigger In the paced loop program of Listing 4. Paced Loop Framework
Program, the pacemaker is based on the on-chip real-time interrupt
(RTI). This RTI is set to generate an interrupt to the CPU every 32.8
milliseconds. The flowchart in Figure 37 shows what happens at each
RTI. This interrupt activity can be thought of as if it were taking place
asynchronously with respect to the main program. The most significant
bit of the TIC variable is used as a flag to tell the main program when it
is time to increment TIC and execute one pass through the paced loop.
Freescale Semiconductor, Inc...
BEGIN RTIF
INTERRUPT ROUTINE
RTICNT
RTIFs = RTIFs – 1
NO
RTIFs = 0 ?
YES
RTIFs = 3
ENDRTI
AnRTI
RETURN FROM
INTERRUPT
Every 32.8 ms the RTIF flag will get set, triggering a timer interrupt
request. One of the duties of an interrupt service routine is to clear the
flag that caused the interrupt before returning from the interrupt. If RTIF
Loop System The variable TIC is the most basic clock for the pacemaker. TIC counts
Clock from 0 to 10. As TIC is incremented from 9 to 10, the program recognizes
this and resets TIC to 0. Except within the pacemaker itself, TIC appears
to count from 0 to 9. TIC is equal to 0 on every tenth trigger of the
pacemaker.
The first task subroutine in the main loop is called TIME. This routine
Freescale Semiconductor, Inc...
maintains a slower clock called TOC. TOC is incremented each time the
paced loop executes and TIC is 0 (every tenth pass through the paced
loop). TOC is set up as a software counter that counts from 0 through
59. The remaining task routines after TIME can use the current values
of TIC and TOC to decide what needs to be done on this pass through
the paced loop.
Your Programs The task subroutines have few restrictions. Each task subroutine should
do everything it needs to do, as quickly as it can, and then execute a
return from subroutine (RTS). The total time required to execute one
pass through all of the task subroutines must be less than two
pacemaker triggers. (We will explain this in greater detail.) The important
point is that a task subroutine should not wait for the occurrence of some
external event like a switch to be pressed. This would defeat the
timekeeping aspects of the paced loop.
Timing Ideally, you should finish all of the task subroutines in the paced loop
Considerations before the next pacemaker trigger arrives. If a single pass through the
loop takes longer than the pacemaker trigger period, the flag that
indicates it is time to start the next pass through the main loop will
already be set when you get back to the top of the loop. Nothing bad
happens unless you get so far behind that a new pacemaker trigger
comes before the previous one has been recognized. The paced loop
remains valid unless any two consecutive passes take more than two
pacemaker trigger periods.
A little bit of planning can ensure that no two consecutive passes through
the loop take longer than two pacemaker periods. Especially long task
subroutines can be scheduled to execute during a particular paced loop
pass when very little other activity is scheduled. A simple check of one
of the time variables such as TIC or TOC can be used to decide whether
or not to perform a particularly slow routine. If there were several things
that needed to be done once per second, one could be scheduled for the
TIC = 0 pass, another could be scheduled for the TIC = 2 pass, and so
on.
Fortunately, an interrupt causes the interrupt mask (I) bit in the condition
code register to be set in response to any interrupt. This blocks
additional interrupts until the I bit is cleared (normally upon return from
the interrupt).
An Application-Ready Framework
The paced loop program of Listing 4. Paced Loop Framework
Program can be used as the basis for your own applications. This
framework provides these main parts:
• Equate statements for all MC68HC705J1A register and bit names
• Application-specific equate statements
• Program variables section
• Initialization section (START)
Freescale Semiconductor, Inc...
In its present form, the paced loop has only two simple task subroutines
(TIME and BLINK). The TIME task just maintains a 0 to 59 count (TOC)
which could be useful for measuring or generating longer time periods.
The BLINK task is just a dummy routine to demonstrate how a task can
use the time variable TOC to control a system action. In this case, the
action is to turn on an LED when TOC is even, and turn it off when TOC
is odd. To use the framework program for your own application, you
should remove the BLINK task and replace it with your own tasks.
$BASE 10T
*******************************************************
* Equates for MC68HC705J1A MCU
* Use bit names without a dot in BSET..BRCLR
* Use bit name preceded by a dot in expressions such as
* #.ELAT+.EPGM to form a bit mask
*******************************************************
PORTA EQU $00 ;I/O port A
PA7 EQU 7 ;Bit #7 of port A
PA6 EQU 6 ;Bit #6 of port A
PA5 EQU 5 ;Bit #5 of port A
PA4 EQU 4 ;Bit #4 of port A
Freescale Semiconductor, Inc...
*******************************************************
* Put program variables here (use RMBs)
Freescale Semiconductor, Inc...
*******************************************************
ORG $00C0 ;Start of 705J1A RAM
*******************************************************
* Program area starts here
*******************************************************
ORG $0300 ;Start of 705J1A EPROM
*******************************************************
* MAIN - Beginning of main program loop
* Loop is executed once every 100 ms (98.4 ms)
* A pass through all major task routines takes
* less than 100mS and then time is wasted until
* MSB of TIC set (every 3 RTIFs = 98.4 ms).
* At each RTIF interrupt, RTIF cleared & RTIFs
* gets decremented (3-0). When RTIFs = 0, MSB of
* TIC gets set and RTIFs is set back to 3.
* (3*32.8/RTIF = 98.4 ms).
*
* The variable TIC keeps track of 100mS periods
* When TIC increments from 9 to 10 it is cleared
Freescale Semiconductor, Inc...
*******************************************************
* TIME - Update TOCs
* If TIC = 0, increment 0->59
* If TIC not = 0, just skip whole routine
*******************************************************
TIME EQU * ;Update TOCs
TST TIC ;Check for TIC = zero
BNE XTIME ;If not; just exit
INC TOC ;TOC = TOC+1
LDA #60
CMP TOC ;Did TOC -> 60 ?
BNE XTIME ;If not, just exit
CLR TOC ;TOCs rollover
XTIME RTS ;Return from TIME
*******************************************************
* BLINK - Update LED
* If TOC is even, light LED
* else turn off LED
*******************************************************
BLINK EQU * ;Update LED
LDA TOC ;If even, LSB will be zero
LSRA ;Shift LSB to carry
BCS LEDOFF ;If not, turn off LED
BSET LED,PORTA ;Turn on LED
BRA XBLINK ;Then exit
Freescale Semiconductor, Inc...
*******************************************************
* RTIF interrupt service routine
*******************************************************
RTICNT DEC RTIFs ;On each RTIF decrement RTIFs
BNE ENDTOF ;Done if RTIFs not 0
LDA #3 ;RTIFs counts 3->0
STA RTIFs ;Reset TOFS count
BSET 7,TIC ;Set MSB as a flag to MAIN
ENDTOF BSET RTIFR,TSCR ;Clear RTIF flag
AnRTI RTI ;Return from RTIF interrupt
*******************************************************
* Interrupt & reset vectors
*******************************************************
ORG $07F8 ;Start of vector area
Review
Equate (EQU) directives are used to associate a label with a binary
value. The binary value may be an address or a numeric constant.
There are two different ways to equate a control bit, depending upon
how the label will be used. For bit set, clear, and branch instructions, you
want the equate to associate the label with a number between 7 and 0.
For building logical masks, you want the label to be equated to a bit mask
where the bit that is set is in the same bit position as the control bit.
Freescale Semiconductor, Inc...
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180
Freescale Semiconductor, Inc...
Introduction
To solve real world problems, a microcontroller must have more than just
a powerful CPU, a program, and data memory resources. In addition, it
must contain hardware allowing the CPU to access information from the
outside world. Once the CPU gathers information and processes the
data, it must also be able to effect change on some portion of the outside
world. These hardware devices, called peripherals, are the CPU’s
window to the outside.
Freescale Semiconductor, Inc...
Types of Peripherals
With the exception of general-purpose I/O ports, most peripherals
Freescale Semiconductor, Inc...
perform very specific tasks. These tasks can be diverse and may range
from time measurement and calculation to communication with other
microcontrollers or external peripherals. The following paragraphs
contain a general description of some types of peripherals found on
M68HC05 microcontrollers.
Timers Even though a wide variety of timers exist on the many members of the
M68HC05 Family, their basic functions relate to the measurement or
generation of time-based events. Timers usually measure time relative
to the internal clock of the microcontroller, although some may be
clocked from an external source. With the number of parts available in
the M68HC05 Family, the capabilities of the timers on each part can vary
greatly. For instance, the most sophisticated timer module present on
the MC68HC05Bx Family can simultaneously generate two PWM
outputs, measure the pulse width of two external signals, and generate
two additional output pulse trains. In comparison, the simplest timer
present on the MC68HC05Jx and MC68HC05Kx Families only
generates two periodic interrupts; one at a fixed rate and one at a
selectable rate.
Serial Ports Some M68HC05 Family members contain peripherals that allow the
CPU to communicate bit-serially with external devices. Using a bit-serial
format instead of a bit-parallel format requires fewer I/O pins to perform
the communication function.
As the name implies, the SPI port is used primarily to communicate with
inexpensive external peripherals. Because the SPI communicates
synchronously with other devices, bidirectional data transfers require at
least three MCU pins. In addition to one pin each for transmitted and
received data, a third pin provides the synchronization clock for the
communicating devices. This style of serial interface is usually used to
communicate with peripheral devices on the same board as the MCU.
A-to-D converters, display drivers, EEPROM, and shift registers are just
a few examples of available SPI peripherals.
Converters of an A-to-D converter. It allows the MCU to convert a digital number into
a proportional analog voltage or current that can be used to control
various output devices in a system. Later in this chapter, we will develop
an application showing how a D-to-A converter may be implemented
using an on-chip timer and a software program.
Controlling Peripherals
The control and status information for peripherals appears to the CPU
as data bits in a memory location. Using this type of arrangement for
peripheral control and status registers is known as memory mapped I/O.
There is a great advantage to having peripherals appear as memory
locations. Any CPU instruction that can operate on a memory location
can be used to control or check the status of a peripheral. This type of
I/O architecture is especially advantageous with the M68HC05 Family
because of the CPU's bit manipulation instructions. This group of
instructions gives a programmer the ability to individually set, clear, or
test the state of any bit in the peripheral control registers at addresses
$0000–$00FF.
control and status register is set, the ripple counter overflow will
generate a CPU interrupt. Therefore, the timer overflow function allows
a potential interrupt to be generated. The timer overflows every 1024
E-clock cycles (divide by four prescaler followed by an 8-bit, divide by
256-ripple counter).
INTERNAL FIXED
PROCESSOR CLOCK DIVIDE BY
(XTAL ÷ 2) 4
Freescale Semiconductor, Inc...
÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2
MSB LSB
÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2
COP TIMEOUT—
÷2 ÷2 ÷2 S GENERATE
Q
INTERNAL MCU RESET
SERVICE (CLEAR)
COP WATCHDOG R
0 1 16.4 ms 114.7 ms
1 0 32.8 ms 229.4 ms
1 1 65.5 ms 458.8 ms
The final stage of the multifunction timer system has a 3-bit counter that
forms the computer operating properly (COP) watchdog system. The
COP system is meant to protect against software failures. When
enabled, a COP reset sequence must be performed before the timeout
period expires so that the COP does not time out and initiate an MCU
reset. To prevent the COP from timing out and generating an MCU reset,
bit 0 at memory location $07F0 (COPR) must be written to 0 before the
COP reset period has expired. Because the input of the COP watchdog
timer is clocked by the output of the real-time interrupt circuit, changing
the RTI rate will affect the minimum COP reset period. Table 17 shows
the four COP reset periods available for corresponding RTI rates.
A Timer Example
In this section we will develop software that uses both the real-time
interrupt and the timer overflow interrupt to produce a low-frequency
pulse width modulated (PWM) signal on a general-purpose I/O pin.
PWM signals are useful for a variety of control functions. They may be
used to control the speed of a motor or can be easily converted to a dc
level to drive an analog output device or to form part of an A-to-D
converter.
Freescale Semiconductor, Inc...
A PWM signal, as the name implies, has a fixed frequency but varies the
width of the on and off times. Figure 40 shows three PWM signals with
different duty cycles. For each signal, the waveform period T1 is
constant but the on time varies (the period of time shown by T2). Duty
cycle is usually expressed as a percentage (the ratio of T2 to T1).
T1
T2
T1
T2
T1
T2
The basic strategy for the PWM software we will develop is as follows. A
real-time interrupt (RTIF) will be used to generate the PWM period, and
the timer overflow (TOF) will be used to determine the PWM high time.
The rest of this chapter is a detailed development of this basic idea into
a working application.
÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2 ÷2
MSB LSB
RTI INTERRUPTS
TOF INTERRUPTS
1 6.25%
2 12.5%
3 18.75%
4 25.0%
5 31.25%
6 37.5%
7 43.75%
Freescale Semiconductor, Inc...
8 50.0%
9 56.25%
10 62.5%
11 68.75%
12 75.0%
13 81.25%
14 87.5%
15 93.75%
— 100%
Obviously, much finer control of the PWM duty cycle is desired. One
approach might be to use a slower RTI rate. Using a slower RTI rate
would result in a greater number of TOF interrupts for each RTI. For
some applications, this may be an acceptable solution. However, for
many applications the resulting frequency of the PWM waveform would
be too low to be of practical use. Table 18 shows the four available RTI
rates and the corresponding PWM frequency, the number of TOF
interrupts between RTIs, and the minimum variation in duty cycle that is
possible.
Table 18 seems to suggest that we are stuck trading off PWM frequency
for duty cycle accuracy. However, the following software program can
deliver much better results than expected.
To make these two components easy for the software to use, the upper
four bits of the desired PWM duty cycle must be placed in the lower four
bits of a variable we will call PWMCoarse. This value will be used to
determine during which TOF interrupt the PWM output should be set
low. The lower four bits of the desired PWM duty cycle will be placed in
the upper four bits of a variable we will call PWMFine. This value is used
within the TOF interrupt to determine precisely when during the TOF
interrupt the PWM output should be set low. By comparing the value in
PWMFine to the upper four bits of the TCR, we can effectively divide
each TOF interrupt into 16 separate time intervals as shown in
Figure 43.
RTI INTERRUPTS
TOF INTERRUPTS
Freescale Semiconductor, Inc...
RTI
TOF INTERRUPTS
The flowcharts in Figure 44, Figure 45, and Figure 46 describe the
PWM software. The flowchart in Figure 45, although simple, is included
for completeness and clarity. Because the MC68HC05J1A contains only
one timer interrupt vector, a short routine must determine whether a
timer interrupt was caused by a TOF or an RTIF interrupt and then
branch to the appropriate service routine.
BEGIN TIMER
INTERRUPT SERVICE
GO EXECUTE TOF
YES
TOF INTERRUPT ? INTERRUPT ROUTINE
(FIGURE 46)
NO
GO EXECUTE RTIF
YES
RTIF INTERRUPT ? INTERRUPT ROUTINE
(FIGURE 45)
NO
Freescale Semiconductor, Inc...
RETURN
As shown in Figure 45, the RTIF interrupt routine checks for two special
conditions, 0% and 100% duty cycle. It then sets up the PWMFine and
PWMCoarse variables for use by the TOF interrupt service routine. If a
0% duty cycle is desired, the PWM output is set low and the RTIF
interrupt service routine immediately returns. If a 100% duty cycle is
desired, the PWM output is set high and the RTIF interrupt service
routine will return immediately. If a duty cycle between 0% and 100% is
desired, the variable DesiredPWM is split into the two components,
PWMFine and PWMCoarse. If the resulting value of PWMCoarse is 0
the program will jump to the second part of the TOF interrupt routine,
which continually compares the value in PWMFine to the upper four bits
of the TCR. If the value of PWMCoarse is not 0, TOF interrupts are
enabled and the RTIF interrupt routine returns.
BEGIN RTIF
INTERRUPT ROUTINE
RESET RTIF
INTERRUPT FLAG
YES
DesiredPWM = 0% ? PWM OUTPUT = 0
NO
PWM OUTPUT = 1
Freescale Semiconductor, Inc...
YES
DesiredPWM = 100% ?
NO
SEE FIGURE 46
RETURN FROM
INTERRUPT
The flowchart in Figure 46 describes the actions required for the TOF
interrupt routine. The first action is to decrement the value of
PWMCoarse. When PWMCoarse becomes 0, it means that the value in
the upper four bits of our counter is equal to the upper four bits of
DesiredPWM. Next, we continually compare the upper four bits of the
TCR with the value of PWMFine (which is the lower four bits of
DesiredPWM). When these two values match, the PWM output is set
low, the TOF interrupt is reset and disabled, and the TOF interrupt
returns.
Freescale Semiconductor, Inc...
BEGIN TOF
INTERRUPT ROUTINE
PWMCourse = PWMCourse – 1
NO RESET TOF
PWMCourse = 0 ? INTERRUPT FLAG
YES
FROM
A
FIGURE 45
NO
TCR ≥ PWMFine ?
YES
RETURN FROM
INTERRUPT
Using the PWM In normal circumstances, the PWM software of Listing 5. PWM
Software Program Listing would be used as a part of a larger program. The value
of DesiredPWM would be generated by some other part of the main
program. To demonstrate the PWM software, the value of DesiredPWM
was arbitrarily set to $80 (12810) by program instructions. If a simulator
or emulator is used to study this program, you can change the value of
DesiredPWM and observe the effect.
The PWM program is interrupt driven. This means that the timer
generates interrupt requests for the CPU to stop processing the main
program and respond to the interrupt request. Since the demonstration
version of this program in Listing 5. PWM Program Listing has no
other main program to perform, a “branch to here” instruction was
included after the clear interrupt mask (CLI) instruction. This instruction
is an infinite loop. Timer interrupts will cause the CPU to periodically
leave this infinite loop to respond to the timer requests and then return
to executing the infinite loop.
;********************************************************
;
0300 ORG ROMStart
;
0300 Start EQU *
0300 9C RSP ;Reset the stack pointer
0301 3F00 CLR PORTA ;Set Port A outputs to all 0's
0303 A6FF LDA #$FF ;Make all Port A's pins outputs
0305 B704 STA DDRA
;Clear out all of RAM
0307 AEC0 LDX #RAMStart ;Point to the start of RAM
0309 7F ClrLoop CLR ,X ;Clear a byte
030A 5C INCX ;Point to the next location
;Cleared the last location?
030B 26FC BNE ClrLoop ;No, Continue to clear RAM
;********************************************************
;TOF interrupt response - Decrement PWMCoarse, when 0...
;Compare PWMFine to TCR. When TCR passes PWMFine clear
;PWM output pin and disable further TOF. RTI re-enables.
;
031F TOFInt EQU *
031F 3AC1 DEC PWMCoarse ;Is PWMCoarse=0?
0321 260A BNE ExitTOF ;No. Clear TOF and return
0323 B6C2 TOFInt1 LDA PWMFine ;To compare to upper 4 of TCR
0325 B109 CmpMore CMPA TCR
0327 22FC BHI CmpMore ;Loop till PWMFine <= TCR
0329 1F00 BCLR PWM,PORTA ;Set the PWM output low (0V)
Freescale Semiconductor, Inc...
;********************************************************
;RTIF interrupt response - Set PWM out pin high, and
;enable TOF. Make PWMCoarse & PWMFine from DesiredPWM
;
0330 RTIInt EQU *
0330 1408 BSET RTIFR,TSCR ;Clear the RT Interrupt Flag
0332 B6C0 LDA DesiredPWM ;Get desired PWM level. =0?
0334 2719 BEQ RTIInt2 ;Yes. Leave PWM output low
0336 1E00 BSET PWM,PORTA ;No. Set PWM output high
0338 A1FF CMPA #Percent100 ;Desired PWM level 100%?
033A 2713 BEQ RTIInt2 ;Yes. Leave PWM output high
033C 5F CLRX ;No. Put upper 4 bits of
033D 48 LSLA ;DesiredPWM into lower 4 bits
033E 59 ROLX ;of A and the lower 4 bits of
033F 48 LSLA ;DesiredPWM into the upper
0340 59 ROLX ;4-bits of x.
0341 48 LSLA
0342 59 ROLX
0343 48 LSLA
0344 59 ROLX
0345 B7C2 STA PWMFine ;Save result into PWMFine.
0347 BFC1 RTIInt1 STX PWMCoarse ;Save result into PWMCoarse.
0349 27D8 BEQ TOFInt1 ;If PWMCoarse=0, go to 2nd
;half of the TOF routine
034B 1608 BSET TOFR,TSCR ;Clear Timer Overflow Flag
034D 1A08 BSET TOIE,TSCR ;re-enable the TOF interrupt
034F 80 RTIInt2 RTI ;return from RTIF interrupt
Theory DC motors are often the best choice for variable-speed motor
applications. Brush DC motors are the easiest to control electronically.
Electronic control of brushless DC, stepper, AC induction, and switched
reluctance motors all require more-complex control circuits in addition to
more power-switching devices. Small, low-cost brush DC motors are
available off the shelf for many low-volume applications where custom
designs would be too expensive. The reliability of brush motors is
adequate for most applications. However, eventually, the brushes will
wear out and need to be replaced.
To vary the speed of a brush DC motor, we must vary the voltage that is
applied to the motor. Several approaches can be used to accomplish
this. We will examine several of the methods, explaining the major
advantages and disadvantages of each.
The first and most obvious approach to varying the voltage applied to a
motor might be to place a variable resistor in series with the motor and
the power source, as shown in Figure 47. While this approach is very
simple, it has some serious disadvantages. First, the resistor’s power
dissipation capabilities must be matched to the power requirements of
the motor. For very small fractional-horsepower DC motors, the size of
the variable resistor will be quite modest. However, as the size of the
motor increases, the motor’s power requirement increases and the size
and cost of the variable resistor will increase.
M
MOTOR
M
MOTOR
RB
VBB
power transistor operating in its linear region will have to dissipate large
amounts of power under varying speed and load conditions. Even
though power transistors capable of handling high power levels are
widely available at relatively modest prices, the power dissipated by the
transistor will usually require a large heat sink to prevent the device from
destroying itself.
Figure 49, when the transistor is turned on, it will essentially behave as
a mechanical switch allowing electric current to pass through it and its
load virtually unimpeded. When turned off, no current passes through
the transistor or its load. Because the transistor dissipates very little
power when it is fully turned on or saturated, the device operates in an
efficient manner.
VCC M IC
VCC M IC = 0
VCE = VCC
RB RB
fully on and then fully off can control its speed, consider the PWM
waveforms in Figure 50.
T1
T2
+5 VOLTS
0 VOLTS
T1
T2
+5 VOLTS
0 VOLTS
b) DUTY CYCLE = T2/T1 = 80%
Motor Control As mentioned earlier, we will be using a slightly modified version of our
Circuit PWM routine to control the speed of a small motor. However, before
discussing the software involved, we need to take a look at the hardware
components required to drive the motor.
schematic and the conceptual ones used in Figure 48 and Figure 49.
We will describe these differences in the following paragraphs.
The most noticeable difference is the schematic symbol for the power
transistor that will be used as an electronic switch. This device is a power
MOSFET. Unlike the bipolar transistor shown in Figure 48 and
Figure 49, this special type of transistor is controlled by the magnitude
of a voltage applied to its gate. Additionally, this particular power
MOSFET, the MTP3055EL, may be completely saturated with only 5
volts applied to its gate. These two characteristics allow this device to be
Freescale Semiconductor, Inc...
+5 V
1N4001
0.1 F M
FROM PA7 OF
MC68HC705K1
10 k 15 V MTP3055EL
Freescale Semiconductor, Inc...
+5 V MC68HC705K1
10 k 27 pF
OSC1
(5)
10 M
RESET 4 MHz
MOTOR OSC2
CONTROL IRQ 27 pF
SWITCHES
ON/OFF PA0
PA7 TO GATE OF
MTP3055EL
SPEED
DOWN PA1
+5 V
SPEED PA2 VDD
UP VSS 0.1 F
One side of each switch is connected to circuit ground, while the other
side of the switch is connected to an I/O pin on the MC68HC705K1
microcontroller. Each of the input pins on the microcontroller is "pulled
up" through a 10-kΩ resistor to +5 volts. These 10-kΩ pullup resistors
keep each of the three input pins at a logic 1 when the pushbutton
switches are not pressed.
In this exampel circuit, the switch controls will operate in the following
manner. The motor on/off switch operates as an alternate-action control.
Each time the switch is pushed and released, the motor will alternately
Freescale Semiconductor, Inc...
be turned on or off. When the motor is turned on, its speed will be set to
the speed it was going the last time the motor was on.
Motor Control Figure 53 shows a flowchart that describes the new RTI interrupt
Software software. The only functional change to the PWM routine developed
earlier in this chapter is the addition of one instruction at the beginning
of the RTI interrupt service routine. This instruction decrements the
variable RTIDlyCnt. This variable is used by the three routines that read
the input switches to develop a switch debounce delay.
BEGIN RTIF
INTERRUPT ROUTINE
RTIDlyCnt = RTIDlyCnt – 1
RESET RTIF
INTERRUPT FLAG
YES
DesiredPWM = 0% ? PWM OUTPUT = 0
Freescale Semiconductor, Inc...
NO
PWM OUTPUT = 1
YES
DesiredPWM = 100% ?
NO
RETURN FROM
INTERRUPT
The flowchart in Figure 54 describes the main loop routine of our motor
control module. This module checks the state of each of the three input
switches. If any one of the three switches is pressed, a routine that
handles the actions for that switch is called. If there are no switches
pressed, the main loop is repeated.
BEGIN
MAIN PROGRAM
YES
MOTOR ON/OFF SW. PRESSED ? TURN MOTOR ON / OFF
NO
YES
SPEED UP SW. PRESSED ? INCREASE MOTOR SPEED
NO
YES
SPEED DOWN SW. PRESSED ? DECREASE MOTOR SPEED
NO
Figure 55, Figure 56, and Figure 57 are flowcharts for the three
routines that handle the actions of the three input switches. Each of
these routines begins with the execution of a 50-ms switch debounce
routine. As decribed in the Programming chapter, this delay is required
because the mechanical bounce produced by the closure of a switch is
seen by the microcontroller as multiple switch closures during the first
several milliseconds after the switch is pressed. This small section of
code stores the value DebounceDly into the variable RTIDlyCnt and then
waits until the value is decremented to zero by the RTI interrupt service
routine. When the value reaches zero, the switch is again checked to be
Freescale Semiconductor, Inc...
sure a valid switch closure occurred. The value used for the delay
constant (DebounceT) will produce a minimum delay of approximately
50 milliseconds.
TURN MOTOR
ON OR OFF
DEBOUNCE FOR 50 ms
NO
MOTOR ON/OFF SW. PRESSED ?
YES
Freescale Semiconductor, Inc...
YES
MOTOR ON/OFF SW. PRESSED ?
NO
NO
MOTOR ON ?
YES
RETURN
INCREASE
MOTOR SPEED
NO
MOTOR ON ?
YES
DEBOUNCE FOR 50 ms
NO
Freescale Semiconductor, Inc...
NO
MOTOR PWM AT 100% ? DELAY FOR ABOUT 25 ms
YES
MotorPWM = MotorPWM + 1
DesiredPWM = DesiredPWM +1
RETURN
DECREASE
MOTOR SPEED
NO
MOTOR ON ?
YES
DEBOUNCE FOR 50 ms
NO
SPEED DOWN SW. PRESSED ?
YES
NO
MOTOR PWM AT MinPWM ? DELAY FOR ABOUT 25 ms
YES
MotorPWM = MotorPWM – 1
DesiredPWM = DesiredPWM –1
RETURN
;*********************************************************
0200 ORG ROMStart
;*********************************************************
;Main program loop. Read motor control switches. If a
; switch is pressed, BSR to perform the requested action.
; Loop continuously looking for switch closures.
Freescale Semiconductor, Inc...
;
0216 00 00 02 Main BRSET MotorOnOff,PortA,Main1 ;On/Off pressed?
0219 AD 0C BSR DoOnOff ;If yes, go to DoOnOff
021B 02 00 02 Main1 BRSET SpeedUp,PortA,Main2 ;Speed Up pressed?
021E AD 25 BSR DoSpeedUp ;If yes, go to DoSpeedUp
0220 04 00 F3 Main2 BRSET SpeedDn,PortA,Main ;Speed Down ?
0223 AD 44 BSR DoSpeedDn ;If yes, go to DoSpeedDown
0225 20 EF BRA Main ;Repeat loop continuously
;*********************************************************
;DoOnOff handles the closure of the Motor On/Off switch
; Debounces switch and waits for release.
;
0227 DoOnOff EQU *
0227 A6 07 LDA #DebounceT ;DebounceT * RTI time = 50mS
0229 B7 E4 STA RTIDlyCnt ;Initialize software counter
022B 3D E4 DoOnOff1 TST RTIDlyCnt ;RTI interrupt decrements it
022D 26 FC BNE DoOnOff1 ;Loop till RTIDlyCnt = 0
022F 00 00 12 BRSET MotorOnOff,PortA,DoOnOff3 ;Then check sw
;If open, not a good press
0232 01 00 FD BRCLR MotorOnOff,PortA,* ;Wait for sw release
0235 3D E5 TST MotorOnFlg ;Motor already on?
0237 26 07 BNE DoOnOff2 ;Yes, turn the motor off.
0239 3C E5 INC MotorOnFlg ;No, Set ‘MotorOn’ flag
023B B6 E3 LDA MotorPWM ;And get last motor speed
023D B7 E0 STA DesiredPWM ;Turns on the PWM output
023F 81 RTS ;Return (1 of 2)
0240 3F E0 DoOnOff2 CLR DesiredPWM ;Turns the PWM output off
0242 3F E5 CLR MotorOnFlg ;Clear ‘MotorOn’ flag
0244 81 DoOnOff3 RTS ;Return (2 of 2)
;***********************************************************
;DoSpeedUp handles the closure of the Speed Up switch
; Debounces sw then increments duty cycle till release
; Duty cycle incremented approx every 24 ms.
; Adj across full speed range in approx 6 seconds
;
0245 DoSpeedUp EQU *
0245 3D E5 TST MotorOnFlg ;Motor currently on?
0247 26 01 BNE DoSpeedUp2 ;Yes, branch
0249 81 DoSpeedUp1 RTS ;No, sws don't work if off
024A A6 07 DoSpeedUp2 LDA #DebounceT ;Debounce delay approx 50 ms
Freescale Semiconductor, Inc...
;**********************************************************
;DoSpeedDn handles the closure of the Speed Down switch
; Debounces sw then increments duty cycle till release
; Duty cycle incremented approx every 24 ms.
; Adj across full speed range in approx 6 seconds
;
0269 DoSpeedDn EQU *
0269 3D E5 TST MotorOnFlg ;Motor currently on?
026B 26 01 BNE DoSpeedDn2 ;Yes, branch
026D 81 DoSpeedDn1 RTS ;No, sws don't work if off
026E A6 07 DoSpeedDn2 LDA #DebounceT ;Debounce delay approx 50 ms
0270 B7 E4 STA RTIDlyCnt ;Initialize software counter
0272 3D E4 DoSpeedDn3 TST RTIDlyCnt ;RTI interrupt decrements it
0274 26 FC BNE DoSpeedDn3 ;Loop till RTIDlyCnt = 0
0276 02 00 F4 DoSpeedDn4 BRSET SpeedUp,PortA,DoSpeedDn1 ;RTS if sw off
0279 B6 E3 LDA MotorPWM ;Sw pressed, do speed up
027B A1 10 CMPA #MinPWM ;Already at minimum speed?
027D 27 EE BEQ DoSpeedDn1 ;If yes just return
027F A6 03 LDA #RampTime ;No, get ramp time delay
;(3 * 8.2Ms = 24.6)
;**********************************************************
;Since RTI and TOF interrupts share 1 vector, TimerInt is
;used to decide which source was requesting service.
;TOFInt and RTIInt service routines are used together to
Freescale Semiconductor, Inc...
;*********************************************************
;TOF interrupt response - Decrement PWMCoarse, when 0...
;Compare PWMFine to TCR. When TCR passes PWMFine clear
;PWM output pin and disable further TOF. RTI re-enables.
;
0294 TOFInt EQU *
0294 3A E1 DEC PWMCoarse ;Is PWMCoarse=0?
0296 26 0A BNE ExitTOF ;No. Clear TOF and return
0298 B6 E2 TOFInt1 LDA PWMFine ;To compare to upper 4 of TCR
029A B1 09 CmpMore CMPA TCR
029C 22 FC BHI CmpMore ;Loop till PWMFine <= TCR
029E 1F 00 BCLR PWM,PortA ;Set the PWM output low (0V)
02A0 1B 08 BCLR TOIE,TSCR ;Disable the TOF Interrupt
02A2 16 08 ExitTOF BSET TOFR,TSCR ;Reset the TOF Interrupt Flag
02A4 80 RTI ;Return to the main program
;**********************************************************
;RTIF interrupt response - Set PWM out pin high, and
;enable TOF. Make PWMCoarse & PWMFine from DesiredPWM
;
02A5 RTIInt EQU *
02A5 3A E4 DEC RTIDlyCnt ;RTIDlyCnt = RTIDlyCnt - 1.
02A7 14 08 BSET RTIFR,TSCR ;Clear the RT Interrupt Flag
02A9 B6 E0 LDA DesiredPWM ;Get desired PWM level = 0?
02AB 26 03 BNE RTIInt2 ;No,. Go set the output high
02AD 1F 00 BCLR PWM,PortA ;Make out low, duty is 0%
02AF 80 RTI ;Return from interrupt
;**********************************************************
03F8 ORG Vectors ;Interrupt & reset vectors
Review
A peripheral is a specialized piece of computer hardware that allows the
CPU to gather information about and affect change on the system that a
microcontroller is part of.
logic 0.
Other Kinds Timers — Timers are peripherals that are used to measure or generate
of Peripherals time-related events in a microcontroller system. Timers are capable of
performing frequency measurements or generating variable width pulse
trains. Timers can be sophisticated or simple.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219
Freescale Semiconductor, Inc...
Introduction
This section contains complete detailed information for all M68HC05
instructions. The instructions are arranged in alphabetical order with the
instruction mnemonic set in larger type for easy reference.
(a) Operators
() = Contents of Register or Memory Location Shown inside
Freescale Semiconductor, Inc...
Parentheses
← = Is Loaded with (Read: gets)
↑ = Is Pulled from Stack
↓ = Is Pushed onto Stack
• = Boolean AND
+ = Arithmetic Addition (Except Where Used as Inclusive-OR
in Boolean Formula)
⊕ = Boolean Exclusive-OR
X = Multiply
: = Concatenate
– = Negate (Twos Complement)
Description Adds the contents of the C bit to the sum of the contents of ACCA and
M and places the result in ACCA.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 ↕ — ↕ ↕ ↕
H A3 • M3 + M3 • R3 + R3 • A3
Set if there was a carry from bit 3; cleared otherwise.
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C A7 • M7 + M7 • R7 + R7 • A7
Set if there was a carry from the MSB of the result; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ADC (opr) IMM A9 ii 2
ADC (opr) DIR B9 dd 3
ADC (opr) EXT C9 hh ll 4
ADC ,X IX F9 3
ADC (opr),X IX1 E9 ff 4
ADC (opr),X IX2 D9 ee ff 5
Description Adds the contents of M to the contents of ACCA and places the result in
ACCA.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 ↕ — ↕ ↕ ↕
H A3 • M3 + M3 • R3 + R3 • A3
Set if there was a carry from bit 3; cleared otherwise.
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C A7 • M7 + M7 • R7 + R7 • A7
Set if there was a carry from the MSB of the result; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ADD (opr) IMM AB ii 2
ADD (opr) DIR BB dd 3
ADD (opr) EXT CB hh ll 4
ADD,X IX FB 3
ADD (opr),X IX1 EB ff 4
ADD (opr),X IX2 DB ee ff 5
Description Performs the logical AND between the contents of ACCA and the
contents of M and places the result in ACCA. (Each bit of ACCA after the
operation will be the logical AND of the corresponding bits of M and of
ACCA before the operation.)
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles AND (opr) IMM A4 ii 2
AND (opr) DIR B4 dd 3
AND (opr) EXT C4 hh ll 4
AND,X IX F4 3
AND (opr),X IX1 E4 ff 4
AND (opr),X IX2 D4 ee ff 5
Operation
C b7 – – – – – – b0 0
Description Shifts all bits of the ACCA, X, or M one place to the left. Bit 0 is loaded
Freescale Semiconductor, Inc...
with a zero. The C bit in the CCR is loaded from the most significant bit
of ACCA, X, or M.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C b7
Set if, before the shift, the MSB of the shifted value was set; cleared
otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ASLA INH (A) 48 3
ASLX INH (X) 58 3
ASL (opr) DIR 38 dd 5
ASL ,X IX 78 5
ASL (opr),X IX1 68 ff 6
Operation
b7 – – – – – – b0 C
Description Shifts all of ACCA, X, or M one place to the right. Bit 7 is held constant.
Bit 0 is loaded into the C bit of the CCR. This operation effectively divides
a twos-complement value by two without changing its sign. The carry bit
can be used to round the result.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C b0
Set if, before the shift, the LSB of the shifted value was set; cleared
otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ASRA INH (A) 47 3
ASRX INH (X) 57 3
ASR (opr) DIR 37 dd 5
ASR ,X IX 77 5
ASR (opr),X IX1 67 ff 6
Description Tests the state of the C bit in the CCR and causes a branch if C is clear.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BCC (rel) REL 24 rr 3
Operation Mn ← 0
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BCLR 0,(opr) DIR (bit 0) 11 dd 5
BCLR 1,(opr) DIR (bit 1) 13 dd 5
BCLR 2,(opr) DIR (bit 2) 15 dd 5
BCLR 3,(opr) DIR (bit 3) 17 dd 5
BCLR 4,(opr) DIR (bit 4) 19 dd 5
BCLR 5,(opr) DIR (bit 5) 1B dd 5
BCLR 6,(opr) DIR (bit 6) 1D dd 5
BCLR 7,(opr) DIR (bit 7) 1F dd 5
Description Tests the state of the C bit in the CCR and causes a branch if C is set.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BCS (rel) REL 25 rr 3
Description Tests the state of the Z bit in the CCR and causes a branch if Z is set.
Following a CMP or SUB instruction, BEQ will cause a branch if the
arguments were equal.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BEQ (rel) REL 27 rr 3
Description Tests the state of the H bit in the CCR and causes a branch if H is clear.
This instruction is used in algorithms involving BCD numbers.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BHCC (rel) REL 28 rr 3
Description Tests the state of the H bit in the CCR and causes a branch if H is set.
This instruction is used in algorithms involving BCD numbers. See BRA
instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BHCS (rel) REL 29 rr 3
Description Causes a branch if both C and Z are cleared. If the BHl instruction is
executed immediately after execution of a CMP or SUB instruction, the
branch will occur if the unsigned binary number in ACCA was greater
than the unsigned binary number in M.
Freescale Semiconductor, Inc...
See BRA instruction for further details of the execution of the branch.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BHI (rel) REL 22 rr 3
See BRA instruction for further details of the execution of the branch.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BHS (rel) REL 24 rr 3
Description Tests the state of the external interrupt pin and causes a branch if the
pin is high.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BIH (rel) REL 2F rr 3
Description Tests the state of the external interrupt pin and causes a branch if the
pin is low.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BIL (rel) REL 2E rr 3
Description Performs the logical AND comparison of the contents of ACCA and the
contents of M and modifies the condition codes accordingly. Neither the
contents of ACCA nor M are altered. (Each bit of the result of the AND
would be the logical AND of the corresponding bits of ACCA and M).
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BIT (opr) IMM A5 ii 2
BIT (opr) DIR B5 dd 3
BIT (opr) EXT C5 hh ll 4
BIT,X IX F5 3
BIT (opr),X IX1 E5 ff 4
BIT (opr),X IX2 D5 ee ff 5
See BRA instruction for further details of the execution of the branch.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BLO (rel) REL 25 rr 3
See BRA instruction for further details of the execution of the branch.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BLS (rel) REL 23 rr 3
Description Tests the state of the I bit in the CCR and causes a branch if I is clear
(for instance., if interrupts are enabled). See BRA instruction for further
details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BMC (rel) REL 2C rr 3
Description Tests the state of the N bit in the CCR and causes a branch if N is set.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BMI (rel) REL 2B rr 3
Description Tests the state of the I bit in the CCR and causes a branch if I is set (for
instance., if interrupts are disabled).
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BMS (rel) REL 2D rr 3
Description Tests the state of the Z bit in the CCR and causes a branch if Z is clear.
Following a compare or subtract instruction, BEQ will cause a branch if
the arguments were not equal.
See BRA instruction for further details of the execution of the branch.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BNE (rel) REL 26 rr 3
Description Tests the state of the N bit in the CCR and causes a branch if N is clear.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BPL (rel) REL 2A rr 3
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BRA (rel) REL 20 rr 3
The C bit is set to the state of the bit tested. When used along with an
appropriate rotate instruction, BRCLR n provides an easy method for
performing serial to parallel conversions.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — ↕
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BRCLR 0,(opr),(rel) DIR (bit 0) 01 dd rr 5
BRCLR 1,(opr),(rel) DIR (bit 1) 03 dd rr 5
BRCLR 2,(opr),(rel) DIR (bit 2) 05 dd rr 5
BRCLR 3,(opr),(rel) DIR (bit 3) 07 dd rr 5
BRCLR 4,(opr),(rel) DIR (bit 4) 09 dd rr 5
BRCLR 5,(opr),(rel) DIR (bit 5) OB dd rr 5
BRCLR 6,(opr),(rel) DIR (bit 6) OD dd rr 5
BRCLR 7,(opr),(rel) DIR (bit 7) OF dd rr 5
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Opcode Operand(s) Cycles
Modes, Machine
Code, and Cycles BRN (rel) REL 21 rr 3
The C bit is set to the state of the bit tested. When used along with an
appropriate rotate instruction, BRSET n provides an easy method for
performing serial to parallel conversions.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — ↕
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BRSET 0,(opr),(rel) DIR (bit 0) 00 dd rr 5
BRSET 1,(opr),(rel) DIR (bit 1) 02 dd rr 5
BRSET 2,(opr),(rel) DIR (bit 2) 04 dd rr 5
BRSET 3,(opr),(rel) DIR (bit 3) 06 dd rr 5
BRSET 4,(opr),(rel) DIR (bit 4) 08 dd rr 5
BRSET 5,(opr), (rel) DIR (bit 5) 0A dd rr 5
BRSET 6,(opr),(rel) DIR (bit 6) 0C dd rr 5
BRSET 7,(opr),(rel) DIR (bit 7) 0E dd rr 5
Operation Mn ← 1
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BSET 0,(opr) DIR (bit 0) 10 dd 5
BSET 1,(opr) DIR (bit 1) 12 dd 5
BSET 2,(opr) DIR (bit 2) 14 dd 5
BSET 3,(opr) DIR (bit 3) 16 dd 5
BSET 4,(opr) DIR (bit 4) 18 dd 5
BSET 5,(opr) DIR (bit 5) 1A dd 5
BSET 6,(opr) DIR (bit 6) 1C dd 5
BSET 7,(opr) DIR (bit 7) 1E dd 5
Description The program counter is incremented by two from the opcode address,
Freescale Semiconductor, Inc...
for instance, so it points to the opcode of the next instruction which will
be the return address. The least significant byte of the contents of the
program counter (low-order return address) is pushed onto the stack.
The stack pointer is then decremented by one. The most significant byte
of the contents of the program counter (high-order return address) is
pushed onto the stack. The stack pointer is then decremented by one. A
branch then occurs to the location specified by the branch offset.
See BRA instruction for further details of the execution of the branch.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles BSR (rel) REL AD rr 6
Operation C bit ← 0
Description Clears the C bit in the CCR. CLC may be used to set up the C bit prior
to a shift or rotate instruction involving the C bit.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — 0
C 0
Cleared
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles CLC INH 98 2
Operation I bit ← 0
Description Clears the interrupt mask bit in the CCR. When the I bit is clear,
interrupts are enabled. There is a one E-clock cycle delay in the clearing
mechanism for the I bit so that, if interrupts were previously disabled, the
next instruction after a CLI will always be executed, even if there was an
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — 0 — — —
I 0
Cleared
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles CLI INH 9A 2
Condition Codes
Freescale Semiconductor, Inc...
and Boolean H I N Z C
Formulae 1 1 1 — — 0 1 —
I 0
Cleared
Z 1
Set
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Modes, Machine Forms Mode Opcode Operand(s) Cycles
Code, and Cycles CLRA INH (A) 4F 3
CLRX INH (X) 5F 3
CLR (opr) DIR 3F dd 5
CLR ,X IX 7F 5
CLR (opr),X IX1 6F ff 6
Description Compares the contents of ACCA to the contents of M and sets the
condition codes, which may be used for arithmetic and logical
conditional branching. The contents of both ACCA and M are
unchanged.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C A7 • M7 + M7 • R7 + R7 • A7
Set if absolute value of the contents of memory is larger than the ab-
solute value of the accumulator; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles CMP (opr) IMM A1 ii 2
CMP (opr) DIR B1 dd 3
CMP (opr) EXT C1 hh ll 4
CMP ,X IX F1 3
CMP (opr),X IX1 E1 ff 4
CMP (opr),X IX2 D1 ee ff 5
Operation ACCA ← (ACCA) = $FF – (ACCA) or: M ← (M) = $FF – (M) or:
X ← X = $FF – (X)
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ 1
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C 1
Set
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Modes, Machine Forms Mode Opcode Operand(s) Cycles
Code, and Cycles COMA INH (A) 43 3
COMX INH (X) 53 3
COM (opr) DIR 33 dd 5
COM ,X IX 73 5
COM (opr),X IX1 63 ff 6
Description Compares the contents of the index register with the contents of memory
and sets the condition codes, which may be used for arithmetic and
logical branching. The contents of both ACCA and M are unchanged.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C IX7 • M7 + M7 • R7 + R7 • IX7
Set if the absolute value of the contents of memory is larger than the
absolute value of the index register; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles I CPX (opr) IMM A3 ii 2
CPX (opr) DIR B3 dd 3
CPX (opr) EXT C3 hh ll 4
CPX,X IX F3 3
CPX (opr),X IX1 E3 ff 4
CPX (opr),X IX2 D3 ee ff 5
The N and Z bits in the CCR are set or cleared according to the result of
this operation. The C bit in the CCR is not affected; therefore, the only
Freescale Semiconductor, Inc...
branch instructions that are useful following a DEC instruction are BEQ,
BNE, BPL, and BMI.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Modes Source Addressing Machine Code HCMOS
Forms Mode Cycles
Machine Code, Opcode Operand(s)
and Cycles DECA INH (A) 4A 3
DECX INH (X) 5A 3
DEC (opr) DIR 3A dd 5
DEC ,X IX 7A 5
DEC (opr),X IX1 6A ff 6
DEX is recognized by the assembler as being equivalent to DECX.
Description Performs the logical exclusive-OR between the contents of ACCA and
the contents of M and places the result in ACCA. (Each bit of ACCA after
the operation will be the logical exclusive-OR of the corresponding bits
of M and ACCA before the operation.)
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles EOR (opr) IMM A8 ii 2
EOR (opr) DIR B8 dd 3
EOR (opr) EXT C8 hh ll 4
EOR ,X IX F8 3
EOR (opr),X IX1 E8 ff 4
EOR (opr),X IX2 D8 ee ff 5
Operation ACCA ← (ACCA) + $01 or: M ← (M) + $01 or: X ← (X) + $01
The N and Z bits in the CCR are set or cleared according to the results
of this operation. The C bit in the CCR is not affected; therefore, the only
Freescale Semiconductor, Inc...
branch instructions that are useful following an INC instruction are BEQ,
BNE, BPL, and BMI.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles INCA INH (A) 4C 3
INCX INH (X) 5C 3
INC (opr) DIR 3C dd 5
INC ,X IX 7C 5
INC (opr),X IX1 6C ff 6
INX is recognized by the assembler as being equivalent to INCX.
Description A jump occurs to the instruction stored at the effective address. The
effective address is obtained according to the rules for EXTended,
DIRect, or INDexed addressing.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles JMP (opr) DIR BC dd 2
JMP (opr) EXT CC hh ll 3
JMP ,X IX FC 2
JMP (opr), X IX1 EC ff 3
JMP (opr),X IX2 DC ee ff 4
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles JSR (opr) DIR BD dd 5
JSR (opr) EXT CD hh ll 6
JSR ,X IX FD 5
JSR (opr), X IX1 ED ff 6
JSR (opr),X IX2 DD ee ff 7
Description Loads the contents of memory into the accumulator. The condition
codes are set according to the data.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles LDA (opr) IMM A6 ii 2
LDA (opr) DIR B6 dd 3
LDA (opr) EXT C6 hh ll 4
LDA ,X IX F6 3
LDA (opr),X IX1 E6 ff 4
LDA (opr),X IX2 D6 ee ff 5
Operation X ← (M)
Description Loads the contents of the specified memory location into the index
register. The condition codes are set according to the data.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles LDX (opr) IMM AE ii 2
LDX (opr) DIR BE dd 3
LDX (opr) EXT CE hh ll 4
LDX ,X IX FE 3
LDX (opr),X IX1 EE ff 4
LDX (opr),X IX2 DE ee ff 5
Operation
C b7 – – – – – – b0 0
Description Shifts all bits of the ACCA, X, or M one place to the left. Bit 0 is loaded
with 0. The C bit in the CCR is loaded from the most significant bit of
ACCA, X, or M.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C b7
Set if, before the shift, the MSB of ACCA or M was set; cleared oth-
erwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles LSLA INH (A) 48 3
LSLX INH (X) 58 3
LSL (opr) DIR 38 dd 5
LSL ,X IX 78 5
LSL (opr),X IX1 68 ff 6
Operation
0 b7 – – – – – – b0 C
Description Shifts all bits of ACCA, X, or M one place to the right. Bit 7 is loaded with
0. Bit 0 is shifted into the C bit.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — 0 ↕ ↕
N 0
Cleared.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C b0
Set if, before the shift, the LSB of ACCA, X, or M was set; cleared oth-
erwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles LSRA INH (A) 44 3
LSRX INH (X) 54 3
LSR (opr) DIR 34 dd 5
LSR ,X IX 74 5
LSR (opr),X IX1 64 ff 6
Operation X:A ← X x A
Description Multiplies the eight bits in the index register by the eight bits in the
accumulator to obtain a 16-bit unsigned number in the concatenated
index register and accumulator. After the operation, X contains the upper
8 bits of the 16-bit result.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 0 — — — 0
H 0
Cleared
C 0
Cleared
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles MUL INH 42 11
Description Replaces the contents of ACCA, X, or M with its twos complement. Note
that the value $80 is left unchanged.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C R7 + R6 + R5 + R4 + R3 + R2 + R1 + R0
Set if there is a borrow in the implied subtraction from 0; cleared oth-
erwise. The C bit will be set in all cases except when the contents of
ACCA, X, or M (prior to the NEG operation) is $00.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles NEGA INH (A) 40 3
NEGX INH (X) 50 3
NEG (opr) DIR 30 dd 5
NEG ,X IX 70 5
NEG (opr),X IX1 60 ff 6
Description This is a single-byte instruction that causes only the program counter to
be incremented. No other registers are affected.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
Freescale Semiconductor, Inc...
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles NOP INH 9D 2
Description Performs the logical inclusive-OR between the contents of ACCA and
the contents of M and places the result in ACCA. Each bit of ACCA after
the operation will be the logical inclusive-OR of the corresponding bits of
M and of ACCA before the operation.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ORA (opr) IMM AA ii 2
ORA (opr) DIR BA dd 3
ORA (opr) EXT CA hh ll 4
ORA ,X IX FA 3
ORA (opr),X IX1 EA ff 4
ORA (opr),X 1X2 DA ee ff 5
Operation
C b7 – – – – – – b0 C
Description Shifts all bits of ACCA, X, or M one place to the left. Bit 0 is loaded from
the C bit. The C bit is loaded from the MSB of ACCA, X, or M. The rotate
instructions include the carry bit to allow extension of the shift and rotate
operations to multiple bytes. For example, to shift a 24-bit value left one
Freescale Semiconductor, Inc...
bit, the sequence {ASL LOW, ROL MID, ROL HIGH} could be used
where LOW, MID, and HIGH refer to the low-order, middle, and
high-order bytes of the 24-bit value, respectively.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C b7
Set if, before the rotate, the MSB of ACCA or M was set; cleared oth-
erwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles ROLA INH (A) 49 3
ROLX INH (X) 59 3
ROL (opr) DIR 39 dd 5
ROL ,X IX 79 5
ROL (opr),X IX1 69 ff 6
Operation
C b7 – – – – – – b0 C
Description Shift all bits of ACCA, X, or M one place to the right. Bit 7 is loaded from
the C bit. The rotate operations include the carry bit to allow extension
of the shift and rotate operations to multiple bytes. For example, to shift
a 24-bit value right one bit, the sequence {LSR HIGH, ROR MID, ROR
Freescale Semiconductor, Inc...
LOW} could be used where LOW, MID, and HIGH refer to the low-order,
middle, and high-order bytes of the 24-bit value, respectively.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C b0
Set if, before the rotate, the LSB of ACCA, X, or M was set; cleared
otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles RORA INH (A) 46 3
RORX INH (X) 56 3
ROR (opr) DIR 36 dd 5
ROR ,X IX 76 5
ROR (opr),X IX1 66 ff 6
Operation SP ← $00FF
Condition Codes
Freescale Semiconductor, Inc...
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Modes, Machine Forms Mode Opcode Operand(s) Cycles
Code, and Cycles RSP INH 9C 2
Description The condition codes, accumulator, the index register, and the program
Freescale Semiconductor, Inc...
counter are restored to the state previously saved on the stack. The 1-bit
will be reset if the corresponding bit stored on the stack is 0.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 ↕ ↕ ↕ ↕ ↕
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles RTI INH 80 9
Description The stack pointer is incremented by one. The contents of the byte of
memory that is pointed to by the stack pointer is loaded into the
high-order byte of the program counter. The stack pointer is again
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles RTS INH 81 6
Description Subtracts the contents of M and the contents of C from the contents of
ACCA and places the result in ACCA.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if result is $00; cleared otherwise.
C A7 • M7 + M7 • R7 + R7 • A7
Set if absolute value of the contents of memory plus previous carry
is larger than the absolute value of the accumulator; cleared
otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles SBC (opr) IMM A2 ii 2
SBC (opr) DIR B2 dd 3
SBC (opr) EXT C2 hh ll 4
SBC ,X IX F2 3
SBC (opr),X IX1 E2 ff 4
SBC (opr),X IX2 D2 ee ff 5
Operation C bit ← 1
Description Sets the C bit in the CCR. SEC may be used to set up the C bit prior to
a shift or rotate instruction that involves the C bit.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — 1
C 1
Set
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Modes, Machine Forms Mode Opcode Operand(s) Cycles
Code, and Cycles SEC INH 99 2
Operation I bit ← 1
Description Sets the interrupt mask bit in the CCR. The microprocessor is inhibited
from servicing interrupts while the I bit is set.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — 1 — — —
I 1
Set
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles SEI INH 9B 2
Operation M ← (ACCA)
Description Stores the contents of ACCA in memory. The contents of ACCA remain
unchanged.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N A7
Set if MSB of result is set; cleared otherwise.
Z A7 • A6 • A5 • A4 • A3 • A2 • A1 • A0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles STA (opr) DIR B7 dd 4
STA (opr) EXT C7 hh ll 5
STA ,X IX F7 4
STA (opr),X IX1 E7 ff 5
STA (opr),X IX2 D7 ee ff 6
When the RESET or IRQ input goes low, the oscillator is enabled, a
delay of 1920 processor clock cycles is initiated allowing the oscillator to
Freescale Semiconductor, Inc...
stabilize, the interrupt request vector or reset vector is fetched, and the
service routine is executed, depending on which signal was applied.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — 0 — — —
I 0
Cleared
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles STOP INH 8E 2
Operation M ← (X)
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N X7
Set if MSB of result is set; cleared otherwise.
Z X7 • X6 • X5 • X4 • X3 • X2 • X1 • X0
Set if result is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles STX (opr) DIR BF ii 4
STX (opr) EXT CF hh ii 5
STX ,X IX FF 4
STX (opr),X IX1 EF ff 5
STX (opr),X IX2 DF ee ff 6
Description Subtracts the contents of M from the contents of ACCA and places the
result in ACCA.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ ↕
N R7
Set if MSB of result is set; cleared otherwise.
Z R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0
Set if all bits of the result are cleared; cleared otherwise.
C A7 • M7 + M7 • R7 + R7 • A7
The C bit (carry flag) in the condition code register gets set if the ab-
solute value of the contents of memory is larger than the absolute
value of the accumulator; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles SUB (opr) IMM A0 ii 2
SUB (opr) DIR B0 dd 3
SUB (opr) EXT C0 hh ll 4
SUB ,X IX F0 3
SUB (opr),X IX1 E0 ff 4
SUB (opr),X IX2 D0 ee ff 5
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — 1 — — —
I 1
Set
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles SWI INH 83 10
Operation X ← (ACCA)
Description Loads the index register with the contents of the accumulator. The
contents of the accumulator are unchanged.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles TAX INH 97 2
Description Sets the condition codes N and Z according to the contents of ACCA, X,
or M. The contents of ACCA, X, and M are not altered.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — ↕ ↕ —
N M7
Set if the MSB of the contents of ACCA, X, or M is set; cleared oth-
erwise.
Z M7 • M6 • M5 • M4 • M3 • M2 • M1 • M0
Set if the contents of ACCA, X, or M is $00; cleared otherwise.
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles TSTA INH (A) 4D 3
TSTX INH (X) 5D 3
TST (opr) DIR 3D dd 4
TST ,X IX 7D 4
TST (opr),X IX1 6D ff 5
Description Loads the accumulator with the contents of the index register. The
contents of the index register are not altered.
Freescale Semiconductor, Inc...
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — — — — —
None affected
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles TXA INH 9F 2
When the RESET or IRQ input goes low or when any on-chip system
requests interrupt service, the processor clocks are enabled, and the
reset, IRQ, or other interrupt service request is processed.
Condition Codes
and Boolean H I N Z C
Formulae 1 1 1 — 0 — — —
I 0
Cleared
Source Forms,
Addressing Source Addressing Machine Code HCMOS
Forms Mode Cycles
Modes, Machine Opcode Operand(s)
Code, and Cycles WAIT INH 8F 2
Reference Tables
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287
Freescale Semiconductor, Inc...
Introduction
This section includes these conversion lookup tables:
• Hexadecimal to ASCII
• Hexadecimal to decimal
• Hexadecimal to M68HC05 instruction mnemonics
The first 32 codes contain device control codes such as carriage return
and the audible bell code. Many of these are special codes for old
teletype transmissions which have similar meanings on a modern
terminal or have slipped into disuse.
768
224
+ 7
= 999
$3E7 = 99910
15 12 11 8 7 4 3 0
4th Hex Digit 3rd Hex Digit 2nd Hex Digit 1st Hex Digit
0 0 0 0 0 0 0 0
1 4,096 1 256 1 16 1 1
2 8,192 2 512 2 32 2 2
Freescale Semiconductor, Inc...
3 12,288 3 768 3 48 3 3
4 16,384 4 1,024 4 64 4 4
5 20,480 5 1,280 5 80 5 5
6 24,576 6 1,536 6 96 6 6
The largest decimal number from Table 20, that is less than or equal to
77710, is 76810. This corresponds to a $3 in the third hexadecimal digit.
Subtract this 76810 from 77710 to get the remaining decimal value 910.
Next look in the column for the next lower order hexadecimal digit (2nd
hex digit in this case). Find the largest decimal value that is less than or
equal to the remaining decimal value. The largest decimal value in this
column that is less than or equal to 910 is 0, so you would place a 0 in
the second hex digit of your result.
Next look in the column for the next lower order hexadecimal digit (first
hex digit in this case). Find the largest decimal value that is less than or
equal to the remaining decimal value. The largest decimal value in this
column that is less than or equal to 910 is 9, so you would place a 9 in
the first hex digit of your result.
77710 = $309
Mode Mode
$00 BRSET0 Direct $20 BRA Relative
$01 BRCLR0 Direct $21 BRN Relative
$02 BRSET1 Direct $22 BHI Relative
$03 BRCLR1 Direct $23 BLS Relative
$04 BRSET2 Direct $24 BCC Relative
$05 BRCLR2 Direct $25 BCS Relative
$06 BRSET3 Direct $26 BNE Relative
$07 BRCLR3 Direct $27 BEQ Relative
$08 BRSET4 Direct $28 BHCC Relative
$09 BRCLR4 Direct $29 BHCS Relative
$0A BRSET5 Direct $2A BPL Relative
$0B BRCLR5 Direct $2B BMI Relative
$0C BRSET6 Direct $2C BMC Relative
$0D BRCLR6 Direct $2D BMS Relative
$0E BRSET7 Direct $2E BIL Relative
$0F BRCLR7 Direct $2F BIH Relative
$10 BSET0 Direct $30 NEG Direct
$11 BCLR0 Direct $31 — —
$12 BSET1 Direct $32 — —
$13 BCLR1 Direct $33 COM Direct
$14 BSET2 Direct $34 LSR Direct
$15 BCLR2 Direct $35 — —
$16 BSET3 Direct $36 ROR Direct
$17 BCLR3 Direct $37 ASR Direct
Glossary
addressing mode — The way that the CPU obtains (addresses) the
information needed to complete an instruction. The M68HC05
CPU has six addressing modes:
• Inherent — The CPU needs no additional information from
memory to complete the instruction.
• Immediate — The information needed to complete the
instruction is located in the next memory location(s) after
the opcode.
• Direct — The low-order byte of the address of the operand
is located in the next memory location after the opcode, and
the high-order byte of the operand address is assumed to
be $00.
• Extended — The high-order byte of the address of the
operand is located in the next memory location after the
opcode, and the low-order byte of the operand address is
located in the next memory location after that.
address bus — The set of conductors that are used to select a specific
memory location so the CPU can write information into the
memory location or read its contents. If a computer has 11 wires
Freescale Semiconductor, Inc...
ALU — Arithmetic logic unit. This is the portion of the CPU of a computer
where mathematical and logical operations take place. Other
circuitry decodes each instruction and configures the ALU to
perform the necessary arithmetic or logical operations at each
step of an instruction.
analog — A signal that can have voltage level values that are neither the
VSS level nor the VDD level. For a computer to use such signals,
they must be converted into a binary number that corresponds to
the voltage level of the signal. An analog-to-digital converter can
be used to perform this conversion. By contrast, a digital signal
has only two possible values, 1 (≈VDD) or 0 (≈VSS).
base 2 — Binary numbers that use only the two digits, 0 and 1. Base 2
is the numbering system used by computers.
condition code register — The CCR has five bits (H, I, N, Z, and C) that
can be used to control conditional branch instructions. The values
of the bits in the CCR are determined by the results of previous
operations. For example, after a load accumulator (LDA)
instruction, Z will be set if the loaded value was $00.
CPU cycles — A CPU clock cycle is one period of the internal bus-rate
clock. Normally, this clock is derived by dividing a crystal
oscillator source by two or more so the high and low times will be
equal. The length of time required to execute an instruction is
measured in CPU clock cycles.
CPU registers — Memory locations that are wired directly into the CPU
logic instead of being part of the addressable memory map. The
CPU always has direct access to the information in these
registers. The CPU registers in an M68HC05 are:
• A — 8-bit accumulator
• X — 8-bit index register
• CCR — condition code register containing the H, I, N, Z,
and C bits
• SP — stack pointer
• PC — program counter
digital — A binary logic system where signals can have only two states,
0 (≈VSS) or 1 (≈VDD).
direct address — Any address within the first 256 addresses of memory
($0000 through $00FF). The high-order byte of these addresses
is always $00. Special instructions allow these addresses to be
accessed using only the low-order byte of their address. These
instructions automatically fill in the assumed $00 value for the
high-order byte of the address.
direct page — The first 256 bytes of memory, $0000 through $00FF
inside.
half flip flop — A half flip flop (HFF) has a transparent condition and a
latched condition. In the transparent condition (clock input equal
logic 1), the Q output is always equal to the logic level presented
at the input. In the latched condition (clock input equals logic 0),
the output maintins the logic level that was present when the flip
Freescale Semiconductor, Inc...
index register (X) — An 8-bit CPU register in the M68HC05 that is used
in indexed addressing mode. X, its abbreviation, can also be used
as a general-
purpose 8-bit register (in addition to the 8-bit accumulator).
inverter — A simple logic circuit that produces an output logic level that
is the opposite of the level presented to its input.
kilobyte — One kilobyte is 102410 bytes. Similar to the use of the prefix
in kilogram, which means 1000 grams in the decimal numbering
system. 1024 is 210.
latch — A logic circuit that maintains a stable output state even after the
input has been removed or changed. A clock control input
determines when the latch will capture the input state and apply
it to the output.
listing — A program listing shows the binary numbers that the CPU
needs alongside the assembly language statements that the
programmer wrote. The listing is generated by an assembler in
the process of translating assembly language source statements
into the binary information that the CPU needs.
machine codes — The binary codes that are processed by the CPU as
instructions. Machine code includes both opcodes and operand
data.
the address bus, the data information on the data bus, and
asserts the write signal. To read information from a memory
location, the CPU places the address of the location on the
address bus and asserts the read signal. In response to the read
signal, the selected memory location places its data onto the data
bus.
NAND gate — A basic logic circuit. The output of a NAND gate is a logic
0 when all of its inputs are logic 1s. The output of a NAND gate is
a logic 1 if any of its inputs are logic 0.
non-volatile — A type of memory that does not forget its contents when
power is turned off. ROM, EPROM, and EEPROM are all
non-volatile memories.
NOR gate — A basic logic circuit. The output of a NOR gate is a logic 0
when any of its inputs are logic 1s. The output of a NOR gate is a
logic 1 if all of its inputs are logic 0.
object code file — A text file containing numbers that represent the
binary opcodes and data of a computer program. An object code
file can be used to load binary information into a computer
system. Motorola uses the S-record file format for object code
files. See Figure 35. S-Record File for Example Program.
program counter — The program counter (PC) is the CPU register that
holds the address of the next instruction or operand that the CPU
will use.
pulled — The act of reading a value from the stack. In the M68HC05, a
value is pulled by this sequence of operations: First, the stack
pointer register is incremented so that it points at the last value
that was saved on the stack. Next the value that is at the address
contained in the stack pointer register is read into the CPU.
registers — Memory locations that are wired directly into the CPU logic
instead of being part of the addressable memory map. The CPU
always has direct access to the information in these registers.
The CPU registers in an M68HC05 are:
• A — 8-bit accumulator
• X — 8-bit index register
• CCR — condition code register containing the H, I, N, Z,
and C bits
• SP — stack pointer
Freescale Semiconductor, Inc...
• PC — program counter
S-record — A Motorola standard format used for object code files. See
Figure 35. S-Record File for Example Program.
stack pointer — A CPU register that holds the address of the next
available storage location on the stack
tested value from a register. If the values were equal, the result of
this subtraction would be zero, so the Z bit would be set. After a
load accumulator instruction, the Z bit will be set if the loaded
value was $00.
Index
A
Accumulator (A). . . . . . . . . . . . . . . . . . . 68, 74, 75, 100, 102, 133, 299
Address bus. . . . . . . . . . . . . . . . . . . 53, 54, 56, 63, 66, 68, 74, 75, 300
Addressing mode. . . . . . . . . . . . . . . . . . . . 98, 104, 133, 146, 150, 299
Freescale Semiconductor, Inc...
direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
extended . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
immediate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75, 107
indexed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
inherent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Analog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 300
Analog switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Analog-to-digital converter (A-to-D). . . . . . . . . . . . . . . . . 183, 187, 215
Architecture
computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Von Neumann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arithmetic logic unit (ALU) . . . . . . . . . . . . . . . . . . . . . . . . . . 78, 98, 300
ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 36, 67, 105, 288, 300
code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
conversion to/from hexadecimal . . . . . . . . . . . . . . . . . 31, 288, 289
Assembler . . . . . . . . . . . . . . . . . . 32, 36, 105, 143, 146, 147, 156, 301
directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145, 149, 156
listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143, 144, 145, 156, 308
Assembly language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139, 301
B
Base 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 28, 301
Base 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28, 301
Base 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 28, 301
Base 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
C
C (bit in condition code register) . . . . . . . . . . . . . . . . 68, 102, 195, 302
Central processor unit (CPU) . . . . . . . . . . . . . . . . .18, 20, 25, 302, 303
Checksum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148, 302
Clock . . . . . . . . . . . . . . . . . . .21, 25, 69, 74, 77, 94, 105, 181, 184, 303
CMOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38, 39, 303
N-type transistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
P-type transistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Computer
architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
kinds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
playing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80, 94
program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 23, 303
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18, 303
Computer program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 23, 303
Computer system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18, 303
Freescale Semiconductor, Inc...
D
Data bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56, 66, 75, 304
Data multiplexer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Decimal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28, 34, 105, 152, 304
conversion to/from hexadecimal . . . . . . . . . . . . . 29, 290, 291, 292
conversion to/from hexadecimal, binary. . . . . . . . . . . . . . . . . 29, 35
Development tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154, 304
Dexterity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Digital. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 27, 304
Digital-to-analog converter (D-to-A). . . . . . . . . . . . . . . . . 183, 187, 215
Direct address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74, 76, 79, 304
Direct addressing mode. . . . . . . . . . . . . 60, 64, 74, 104, 110, 111, 120,
134, 146, 150, 304
E
EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . .22, 56, 63, 183, 216, 304
Effective address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100, 104, 305
Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 305
EPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22, 55, 63, 70, 155, 305
Equate directive (EQU) . . . . . . . . . . . . . . . . . . . . . . . . . . 145, 149, 160
Extended address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Freescale Semiconductor, Inc...
F
FCB directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
FDB directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150, 162, 178
Fetching a vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Fetching the reset vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Flip flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Flowchart . . . . . . . . . . . . . . . . . . . . . .76, 136, 137, 138, 147, 156, 305
G
Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37, 40
buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
NAND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 41
NOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 42
transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 49
Gigabyte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
H
H (bit in condition code register) . . . . . . . . . . . . . . . . 68, 101, 102, 306
Half flip flop (HFF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48, 49, 57, 306
Hexadecimal . . . . . . . . . . . . . . . . . . . . . . . . . . 28, 29, 36, 105, 148, 152, 306
conversion to /from decimal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
conversion to/from ASCII . . . . . . . . . . . . . . . . . . . . . . .31, 288, 289
conversion to/from decimal . . . . . . . . . . . . . . . . . . . . . . . . .291, 292
conversion to/from decimal, binary . . . . . . . . . . . . . . . . . . . . . . . 29
conversion to/from octal, binary . . . . . . . . . . . . . . . . . . . . . . . . . . 33
values vs. M68HC05 instructions. . . . . . . . . . . . . . . . . . . . . . . . 293
High order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86, 306
I
I (bit in condition code register) . . . . . . . . 68, 86, 88, 95, 101, 170, 306
Immediate addressing mode . . . . . . .75, 104, 107, 133, 146, 161, 306
In-circuit emulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
In-circuit simulator . . . . . . . . . . . . . . . . . . . . . . . . . . 155, 157, 160, 306
Index register (X) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68, 100, 112, 133
Indexed addressing mode . . . . . . . . . . . . . . . . 100, 104, 112, 134, 307
16-bit offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
8-bit offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
no offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Freescale Semiconductor, Inc...
read-modify-write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
register/memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
source form notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Interrupt . . . . . . . . . . . . . . . . . . . . . . . . 88, 95, 101, 103, 163, 170, 180
external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
latency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92, 95
nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93, 95
on-chip peripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92, 95
Freescale Semiconductor, Inc...
sources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
stacking order. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61, 149, 162, 178
Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 49, 308
J
Jump-to-subroutine (JSR) . . . . . . . . . . . . . . . 76, 82, 85, 141, 165, 261
K
Kilobyte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54, 63, 308
L
Label . . . . . . . . . . . . . . . . . . . . . . . . 145, 146, 149, 156, 162, 165, 308
Latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Least significant bit (LSB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195, 308
Listing . . . . . . . . . . . . . . . 70, 73, 76, 80, 143, 144, 145, 150, 156, 308
Logic
elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Logic 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Logic 0, see Zero
Logic 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Logic 1, see One
Logic level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19, 49
Low order. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86, 308
M
Machine code . . . . . . . . . . . 32, 75, 136, 143, 145, 147, 148, 150, 308
Mainframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18, 20, 23, 25, 308
Mass storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22, 309
MCU, see microcontroller
Megabyte. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21, 25, 52, 54
analogy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52
EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22, 56, 63
EPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22, 55, 63
Freescale Semiconductor, Inc...
N
N (bit in condition code register) . . . . . . . . . . . . . . 68, 75, 84, 101, 310
NAND gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 49, 310
Negative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Non-volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54, 64, 87, 310
NOR gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42, 49, 310
O
Object code file . . . . . . . . . . . . . . . . . . . . . . . . 143, 147, 150, 156, 310
S-record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Freescale Semiconductor, Inc...
P
Paced loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160, 161, 165
loop trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
program example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171, 172
software use. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169, 178
switch debouncing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
system clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Parity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288, 311
PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Peripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64, 180, 181, 215
analog-to-digital converter (ADC). . . . . . . . . . . . . . . . . . . . 183, 215
control of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
digital-to-analog converter (DAC). . . . . . . . . . . . . . . . . . . . 183, 215
R
RAM . . . . . . . . . . . . . .21, 55, 57, 63, 85, 142, 151, 156, 170, 178, 312
variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 57, 312
Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66, 80, 88, 313
accumulator (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68, 100, 133
condition code (CCR). . . . . . . . . . . . . . . . . . . 69, 75, 100, 133, 303
CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67, 68, 99, 133, 303
I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
index (X). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68, 100, 133, 307
internal status and control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68, 311
program counter (PC) . . . . . . . . . . . . . . . . . . . . . . . . . 68, 103, 133
stack pointer (SP). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94, 103, 133
S
Serial communications interface (SCI) . . . . . . . . . . . . . . . . . . . . . . 182
Serial peripheral interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Serial port
SCI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .182
SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85, 154, 157, 164, 314
Software
PWM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Software delay program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Software interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Software interrupt (SWI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61, 88, 95
Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156, 314
mnemonic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139, 156
Source program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143, 145, 314
S-record. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147, 148, 150, 156, 314
Stack . . . . . . . . . . . . . . . 69, 78, 79, 83, 88, 91, 94, 142, 170, 178, 314
Stack pointer (SP) . . . . . . . . . . . . . . . . . . 69, 76, 78, 94, 103, 133, 314
Subroutine . . . . . . . . . . . . 76, 77, 80, 94, 103, 139, 141, 142, 170, 314
T
Three-state buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46, 49, 315
Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .181, 215
example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Freescale Semiconductor, Inc...
V
Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165, 315
VDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 86, 315
Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61, 86, 162, 315
reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Volatile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54, 64, 315
VSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 315
W
Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22, 54, 316
Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 57, 75, 316
Z
Z (bit in condition code register) . . . . . . . . . . . . . . 68, 75, 84, 102, 316
Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 27, 38, 40, 49, 316
Zero crossing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168, 316
— NOTES —
Freescale Semiconductor, Inc...
— NOTES —
Freescale Semiconductor, Inc...
Motorola reserves the right to make changes without further notice to any products herein. Motorola makes no warranty, representation or guarantee regarding the suitability of its
products for any particular purpose, nor does Motorola assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability,
including without limitation consequential or incidental damages. "Typical" parameters which may be provided in Motorola data sheets and/or specifications can and do vary in different
applications and actual performance may vary over time. All operating parameters, including "Typicals" must be validated for each customer application by customer's technical experts.
Motorola does not convey any license under its patent rights nor the rights of others. Motorola products are not designed, intended, or authorized for use as components in systems
intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Motorola product could create a
situation where personal injury or death may occur. Should Buyer purchase or use Motorola products for any such unintended or unauthorized application, Buyer shall indemnify and hold
Motorola and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of,
directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Motorola was negligent regarding the
design or manufacture of the part. Motorola and are registered trademarks of Motorola, Inc. Motorola, Inc. is an Equal Opportunity/Affirmative Action Employer.
M68HC05TB/D
For More Information On This Product,
Go to: www.freescale.com