Introduction To The 68Hc12 Microcontroller
Introduction To The 68Hc12 Microcontroller
Introduction to the
68HC12 Microcontroller
1.1 Objectives
After completing this chapter you should be able to:
• Define or explain the following terms:
computer, processor, microprocessor,
microcontroller, embedded system, hardware,
software, cross assembler, cross compiler,
RAM, DRAM, SRAM, ROM, PROM, EPROM,
EEPROM, flash memory, byte, word, nibble,
bus, KB, MB, mnemonic, opcode, and operand
• Explain the differences between the inherent,
immediate, direct, extended, relative, indexed,
and indirect indexed addressing modes
• Write a sequence of arithmetic and data transfer
instructions to perform simple operations
2 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
Processor
Datapath
Arithmetic
Logic Unit Memory
Output Input
Program Data Units Units
Registers Storage Storage
W H AT I S A M I C R O P R O C E S S O R ?
The processor in a very large computer is built from a number of integrated circuits. A
microprocessor is a processor fabricated on a single integrated circuit. A microcomputer is a
computer that uses a microprocessor as its CPU. Early microcomputers were quite simple and
slow. However, many of today’s desktop or notebook computers have become very sophisticated
and even faster than many larger computers were only a few years ago.
One way to classify microprocessors is to use the number of bits (referred to as word length)
that a microprocessor can manipulate in one operation. A microprocessor is 8-bit if it can only
work on 8 bits of data in one operation. Microprocessors in use today include 4-bit, 8-bit, 16-bit,
32-bit, and 64-bit. The first 4-bit microprocessor is the Intel 4004, which was introduced in
1971. Since then many companies have joined in the design and manufacturing of micro-
processors. Today 8-bit microprocessors are the most widely used among all microprocessors,
whereas 64-bit microprocessors emerged only a few years ago and are mainly used in high per-
formance workstations and servers.
Many 32-bit and 64-bit microprocessors also incorporate on-chip memory to enhance their
performance. Microprocessors must interface to input/output devices in many applications.
However, the characteristics and speed of the microprocessor and input/output devices are quite
different. Peripheral chips are required to interface input/output devices with the microproces-
sor. For example, the integrated circuit i8255 is designed to interface a parallel device such as a
printer or seven-segment display with the Intel 8-bit microprocessor 8085.
Microprocessors have been widely used since their invention. It is not an exaggeration to
say that the invention of microprocessors has revolutionized the electronics industry. However,
the following limitations of microprocessors have led to the development of microcontrollers:
4 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
W H AT I S A M I C R O C O N T R O L L E R ?
A microcontroller is a computer implemented on a single very large-scale integration (VLSI)
chip. A microcontroller contains everything a microprocessor contains plus one or more of the
following components:
• Memory. Memory is used to store data or programs. A microcontroller may incor-
porate certain amounts of SRAM, ROM, EEPROM, EPROM, or flash memory.
• Timer. Timer function is among the most useful and complicated functions in
most microcontrollers. The timer function of most 8-bit and 16-bit microcon-
trollers consists of input capture, output compare, counter, pulse accumulator, and
pulse width modulation (PWM) modules. They can be used to measure frequency,
period, pulse width, and duty cycle. They can also be used to create time delay and
generate waveforms.
• Analog-to-digital converter (ADC). The ADC is often used with a sensor. A sensor
can convert certain non-electric quantities into an electric voltage. The ADC can
convert a voltage into a digital value. Therefore, by combining an appropriate sen-
sor and the ADC, a data acquisition system that measures temperature, weight,
humidity, pressure, or airflow can be designed.
• Digital-to-analog converter (DAC). A DAC can convert a digital value into a volt-
age output. This function can be used in controlling DC motor speed, adjusting
brightness of the light bulb, the fluid level, and so on.
• Direct memory access (DMA) controller. DMA is a data transfer method that
requires the CPU to perform initial setup but does not require the CPU to execute
instructions to control the data transfer. The initial setup for a DMA transfer
includes the setup of source and destination addresses and transfer byte count.
This mechanism can speed up data transfer by several times.
• Parallel I/O interface (often called parallel port). Parallel ports are often used to
drive parallel I/O devices such as seven-segment displays, LCDs, or parallel printers.
• Asynchronous serial I/O interface. This transfer method transmits data bits seri-
ally without using a clock signal to synchronize the sender and receiver.
• Synchronous serial I/O interface. This interface transfers data bits serially and
uses a clock signal to synchronize the sender and receiver.
• Memory component interface circuitry. All memory devices require certain con-
trol signals to operate. This interface generates appropriate control signals to be
used by the memory chips.
• Digital signal processing (DSP) feature. Some microcontrollers (for example, the
Motorola HC16) provide features such as the multiply-accumulate instruction that
can execute in one clock cycle to support DSP computation.
1.2 ■ Basic Computer Concepts 5
VRH VRH
VFP 32-KBYTE FLASH EEPROM/ROM VRL VRL
VDDA VDDA
VSSA VSSA
1-KBYTE RAM
AN0 PAD0
768-BYTE EEPROM AN1 PAD1
ATD AN2 PAD2
PORT AD
CONVERTER AN3 PAD3
CPU12 AN4 PAD4
AN5 PAD5
AN6 PAD6
BKGD SMODN / TAGHI PERIODIC INTERRUPT AN7 PAD7
COP WATCHDOG
SINGLE-WIRE IOC0
BACKGROUND CLOCK MONITOR PT0
DEBUG MODULE IOC1 PT1
BREAK POINTS IOC2 PT2
TIMER AND
PORT T
DDRT
EXTAL IOC3 PT3
PULSE OC7
XTAL IOC4 PT4
RESET ACCUMULATOR IOC5 PT5
IOC6 PT6
PE0 XIRQ
PAI PT7
PE1 IRQ/VPP
PE2 PORT E R/W LITE
PE3 LSTRB / TAGLO RxD PS0
INTEGRATION SCI TxD
PE4 ECLK PS1
MODULE
PE5 IPIPE0 / MODA I/O PS2
(LIM) I/O
PORT S
PE6 IPIPE1 / MODB I/O PS3
DDRS
PE7 DBE
SDI/MISO PS4
SDO/MOSI PS5
VDD x 2 SPI
SCK PS6
VSS x 2 CS/SS PS7
POWER FOR
INTERNAL MULTIPLEXED ADDRESS/DATA BUS PW0 PP0
CIRCUITRY PW1 PP1
PWM
PW2 PP2
PORT P
PW3
DDRP
PP3
VDDX x 2 DDRA DDRB
VSSX x 2 I/O PP4
PORT A PORT B I/O PP5
I/O I/O PP6
POWER FOR
I/O DRIVERS I/O PP7
PB7
PB6
PB5
PB4
PB3
PB2
PB1
PB0
PA7
PA6
PA5
PA4
PA3
PA2
PA1
PA0
RxCAN RxCAN
msCAN TxCAN TxCAN
ADDR15
ADDR14
ADDR13
ADDR12
ADDR11
ADDR10
ADDR9
ADDR8
ADDR7
ADDR6
ADDR5
ADDR4
ADDR3
ADDR2
ADDR1
ADDR0
PORT CAN
I/O PCAN2
DDRCAN
I/O PCAN3
I/O I/O PCAN4
DATA15
DATA14
DATA13
DATA12
DATA11
DATA10
DATA9
DATA8
DATA7
DATA6
DATA5
DATA4
DATA3
DATA2
DATA1
DATA0
NARROW BUS
EMBEDDED SYSTEMS
A microcontroller is designed to be used in a product to provide certain control functions.
End users are interested in the features and functions of the product rather than the microcon-
troller. A product that incorporates one or more microcontrollers and has this nature is called
an embedded product or embedded system. A cell phone is a good example of an embedded sys-
tem. The cell phone contains a microcontroller that is responsible for making the phone call,
accepting incoming calls, accessing Internet Web sites, displaying Web pages, handling all user
input and output, keeping track of time, and so on.
Today’s automobiles are also good examples of embedded systems. Most of today’s new cars
incorporate several microcontrollers. One microcontroller is responsible for controlling the
instrument display. In order to carry out this function, the display microcontroller needs to col-
1.2 ■ Basic Computer Concepts 7
lect information using different sensors. These sensors are used to measure temperature, speed,
distance, fuel level, and so on. Other microcontrollers are responsible for fuel injection control,
cruise control, global positioning, giving warning when the car is too close to other cars or objects,
and many other safety features available in high-priced vehicles. These microcontrollers may need
to exchange information or even coordinate their operations. The Controller Area Network
(CAN) bus is designed for this purpose and this bus will be discussed in detail in Chapter 12.
Another example of an embedded system is the home security system. A typical home
security system consists of a microcontroller along with several sensors and actuators. Among
the list of sensors are the temperature sensor, smoke detector, humidity sensor, motion detec-
tors, and so on. When the security system detects the smoke, it may activate the alarm or even
call the fire department. When the temperature is lower than a certain degree, the system may
start the heater to warm the house. When the temperature is lower than a certain degree, it will
start the air conditioner. When the house owner is away from home, the security system can be
armed to call the neighbor or even the police department if the motion detector detects people
trying to open the door. A home security system can be as sophisticated as you want.
1.2.2 Memory
Memory is the place where software programs and data are stored. A computer may con-
tain semiconductor, magnetic, and/or optical memory. Only semiconductor memory will be
discussed in this chapter. Semiconductor memory may be further classified into two major
types: random access memory, or RAM, and read-only memory, or ROM.
R E A D - O N LY M E M O R Y ( R O M )
ROM is nonvolatile. When power is removed from ROM and then reapplied, the original
data will still be there. However, as its name implies, ROM data can only be read. If the proces-
sor attempts to write data to a ROM location, ROM will not accept the data, and the data in the
addressed ROM memory location will not be changed.
8 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
adds the contents of accumulator B and accumulator A together and leaves the sum in accu-
mulator A. The machine instruction
0100 0011
decrements the contents of accumulator A by 1. The machine instruction
1000 0110 0000 0110
places the value 6 in accumulator A.
Writing programs in machine language is extremely difficult and inefficient:
1. Program entering. The programmer will need to memorize the binary pattern of
every machine instruction, which can be very challenging because a microproces-
sor may have several hundred machine instructions, and each machine instruc-
tion can have different length. Constant table lookup will be necessary during the
program entering process. On the other hand, programmers are forced to work on
program logic at a very low level because each machine instruction implements
only a very primitive operation.
2. Program debugging. Whenever there are errors, it is extremely difficult to trace
the program because the program consists of only sequences of 0s and 1s. A pro-
grammer will need to identify each machine instruction and then think about
what operation is performed by that instruction. This is not an easy job.
3. Program maintenance. Most programs will need to be maintained in the long run.
A programmer who did not write the program will have a hard time reading the
program and following the program logic.
Assembly language was invented to simplify the programming job. An assembly program
consists of assembly instructions. An assembly instruction is the mnemonic representation of
a machine instruction. For example, in the 68HC12:
ABA stands for “add the contents of accumulator B to accumulator A.” The corre-
sponding machine instruction is 00011000 00000110.
DECA stands for “decrements the contents of accumulator A by 1.” The correspond-
ing machine instruction is 0100 0011.
A programmer no longer needs to scan through 0s and 1s in order to identify what instruc-
tions are in the program. This is a significant improvement over machine language programming.
The assembly program that the programmer enters is called source program or source code.
A software program called an assembler is then invoked to translate the program written in
assembly language into machine instructions. The output of the assembly process is called
object code. It is a common practice to use a cross assembler to translate assembly programs.
A cross assembler is an assembler that runs on one computer but generates machine instruc-
tions to be run on a different computer with a totally different instruction set. In contrast, a
native assembler runs on a computer and generates machine instructions to be executed by
machines that have the same instruction set. The freeware as12 is a cross assembler that runs
on an IBM PC and generates machine code that can be downloaded into a 68HC12-based com-
puter for execution. The list file generated by an assembler shows both the source code and
machine code (encoded in hexadecimal format). Here is an example:
10 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
The CPU registers of the 68HC12 are shown in Figure 1.3 and are listed below. Some of the
registers are 8-bit and others are 16-bit.
15 X 0 Index register X
15 Y 0 Index register Y
15 SP 0 Stack pointer
15 PC 0 Program counter
higher address
Program counter (PC). The 16-bit PC holds the address of the next instruction to be
executed. After the execution of an instruction, the PC is incremented by the number
of bytes of the executed instruction.
Condition code register (CCR). This 8-bit register is used to keep track of the program
execution status, control the execution of conditional instructions, and enable/disable
the interrupt handling. The contents of the CCR register are shown in Figure 1.3. The
function of each condition code bit will be explained in later sections and chapters.
The 68HC12 supports the following types of data:
• Bits
• 5-bit signed integers
• 8-bit signed and unsigned integers
• 8-bit, 2-digit binary-coded-decimal numbers
• 9-bit signed integers
• 16-bit signed and unsigned integers
• 16-bit effective addresses
• 32-bit signed and unsigned integers
Negative numbers are represented in two’s complement format. Five-bit and nine-bit
signed integers are formed during addressing mode computations. Sixteen-bit effective
addresses are formed during addressing mode computations. Thirty-two-bit integer dividends
are used by extended division instructions. Extended multiply and extended multiply-and-accu-
mulate instructions produce 32-bit products.
A multi-byte integer (16-bit or 32-bit) is stored in memory from most significant to least
significant bytes starting from low to higher addresses. A number can be represented in binary,
octal, decimal, or hexadecimal format. An appropriate prefix (shown in Table 1.1) is added in
front of the number to indicate its base:
Base Prefix Example
binary % %10001010
octal @ @1234567
decimal 12345678
Address Contents
Each location in memory has an address that must be supplied before its contents can be
accessed. The CPU communicates with memory by first identifying the location’s address and
then passing this address on the address bus. This is similar to when a UPS delivery person
needs an address to deliver a parcel. The data are transferred between memory and the CPU
along the data bus (see Figure 1.6). The number of bits that can be transferred on the data bus
at once is called the data bus width of the processor.
CPU Memory
Direct INST opr8a DIR Operand is the lower 8 bits of an address in the
range $0000-$00FF
Relative INST rel8 REL An 8-bit or 16-bit relative offset from the current PC
or is supplied in the instruction
INST rel16
Indexed (5-bit offset) INST oprx5,xysp IDX 5-bit signed constant offset from x,y,sp, or pc
Indexed (accumulator offset) INST abd,xysp IDX Indexed with 8-bit (A or B) or 16-bit (D) accumulator
offset from x, y, sp, or pc
Indexed (9-bit offset) INST oprx9,xysp IDX1 9-bit signed constant offset from x, y, sp, or pc
(lower 8-bits of offset in one extension byte)
Indexed (16-bit offset) INST oprx16,xysp IDX2 16-bit constant offset from x, y, sp, or pc (16-bit
offset in two extension bytes)
Indexed-Indirect (16-bit offset) INST [oprx16,xysp] [IDX2] Pointer to operand is found at 16-bit constant
offset from (x, y, sp, or pc)
Note
1. INST stands for the instruction mnemonic. 4. opr8a stands for 8-bit address
2. opr8i stands for 8-bit immediate value. 5. opr16a stands for 16-bit address
3. opr16i stands for 16-bit immediate value. 6. oprx3 stands for 3-bit value (amount to be incremented or decremented).
Each conditional branch instruction tests certain status bits in the condition code register.
If the bits are in a specified state, the offset is added to the address of the next memory location
after the offset to form an effective address, and execution continues at that address; if the bits
are not in the specified state, execution continues with the instruction immediately following
the branch instruction.
Both 8-bit and 16-bit offsets are signed two’s complement numbers to support branching
forward and backward in memory. The numeric range of short branch offset values is $80 (-128)
to $7F (127). The numeric range of long branch offset values is $8000 (-32768) to $7FFF (32767).
If the offset is zero, the CPU executes the instruction immediately following the branch instruc-
tion, regardless of the test result.
Branch offset is often specified using a label rather than a numeric value due to the difficulty
of calculating the exact value of the offset. For example, in the following instruction segment:
minus .
. ; if N (of CCR) = 1
. ; PC ← PC + branch offset
bmi minus ; else
… ; PC ← PC
The instruction bmi minus will cause the 68HC12 to execute the instruction with the label
minus if the N flag of the CCR register is set to 1.
The assembler will calculate the appropriate branch offset when the symbol that represents
the branch target is encountered. Using a symbol to specify the branch target makes the pro-
gramming task easier.
9 - B I T C O N S TA N T O F F S E T I N D E X E D A D D R E S S I N G
This indexed addressing mode uses a 9-bit signed offset, which is added to the base index
register (X, Y, SP, or PC) to form the effective address of the memory location affected by the
instruction. This gives a range of –256 through +255 from the value in the base index register.
For example:
LDAA $FF, X
loads the contents of the memory location located at the address, which is equal to 255 plus the
value in index register X.
LDAB -20, Y
loads the contents of the memory location with the address, which is equal to the value in index
register Y minus 20.
16 - B I T C O N S TA N T O F F S E T I N D E X E D A D D R E S S I N G
This indexed addressing mode specifies a 16-bit offset to be added to the base index regis-
ter (X, Y, SP, or PC) to form the effective address of the memory location affected by the instruc-
tion. This allows access to any location in the 64-KB address space. Since the address bus and
the offset are both 16 bits, it does not matter whether the offset value is considered to be a
signed or an unsigned value. The 16-bit offset is provided as two extension bytes after the
instruction postbyte in the instruction flow.
16 - B I T C O N S TA N T I N D I R E C T I N D E X E D A D D R E S S I N G
This indexed addressing mode adds a 16-bit offset to the base index register to form the
address of a memory location that contains a pointer to the memory location affected by the
instruction. The square brackets distinguish this addressing mode from 16-bit constant off-
set indexing.
For example:
LDAA [10, X]
In this example, index register X holds the base address of a table of pointers. Assume that X
has an initial value of $1000, and that $2000 is stored at addresses $100A and $100B. The
instruction first adds 10 to the value in X to form the address $100A. Next, an address pointer
($2000) is fetched from memory at $100A. Then the value stored in $2000 is read and loaded
into accumulator A.
ing execution time. This addressing mode is also used to perform operations on a series of data
structures in memory.
For example:
STAA 1, -SP
stores the contents of accumulator A at the memory location with the address equal to the value
of stack pointer SP minus 1. After the store operation, the contents of SP are decremented by 1.
LDX 2, SP+
loads the contents of the memory locations pointed to by the stack pointer SP and also incre-
ments the value of SP by 2 after the instruction execution.
AC C U M U L AT O R O F F S E T I N D E X E D A D D R E S S I N G
In this indexed addressing mode, the effective address is the sum of the values in the base
index register and an unsigned offset in one of the accumulators. The value in the base index
register itself is not changed. The base register can be X, Y, SP, or PC, and the accumulator can
be either of the 8-bit accumulators (A or B) or the 16-bit D accumulator.
For example, the instruction:
LDAA B,X
loads the contents of the memory location into accumulator A with the address equal to the
sum of the values of accumulator B and index register X. Both B and X are not changed after the
instruction execution.
AC C U M U L AT O R D I N D I R E C T I N D E X E D A D D R E S S I N G
This indexed addressing mode adds the value in accumulator D to the value in the base
index register to form the address of a memory location that contains a pointer to the memory
location affected by the instruction. The instruction operand does not point to the address of
the memory location to be acted upon, but rather to the location of a pointer to the location
to be acted upon. The square brackets distinguish this addressing mode from accumulator D
offset indexing.
For example, the following instruction sequence implements a computed GOTO statement:
JMP [D, PC]
GO1 DC.W target1 ; the keyword DC.W reserves two bytes to hold the
GO2 DC.W target2 ; value of the symbol that follows
GO3 DC.W target3 ; “
…
target1…
.
.
target2…
.
.
target3…
.
.
In this instruction segment, the names (also called labels) target1, target2, and target3 are
labels that represent the addresses of the memory locations that the JMP instruction may jump
to. The names GO1, GO2, and GO3 are also labels. They represent the memory locations that
hold the values of the labels target1, target2, and target3, respectively.
20 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
The values beginning at GO1 are addresses of potential destinations of the jump instruc-
tions. At the time the JMP [D, PC] instruction is executed, PC points to the address GO1, and
D holds one of the values $0000, $0002, or $0004 (determined by the program some time before
the JMP).
Assume that the value in D is $0002. The JMP instruction adds the values in D and PC to
form the address of GO2 and jumps to target2. The locations of target1 through target3 are
known at the time of program assembly but the destination of the JMP depends on the value in
D computed during program execution.
Store Instructions
Mnemonic Function Operation
STAA Store A A) ⇒ M
Transfer Instructions
Mnemonic Function Operation
TAB Transfer A to B (A) ⇒ B
Exchange Instructions
Mnemonic Function Operation
EXG Exchange register to register (A, B, CCR, D, X, Y, or SP) ⇔ A, B, CCR, D, X, Y, or SP
16-bit operations. The 8-bit number is copied from accumulator A, accumulator B, or the con-
dition code register to accumulator D, index register X, index register Y, or the stack pointer.
All the bits in the upper byte of the 16-bit result are given the value of the most significant bit
of the 8-bit number. For example,
SEX A,X
copies the contents of accumulator A to the lower byte of X and duplicates the bit 7 of A to
every bit of the upper byte of X.
SEX B,Y
copies the contents of accumulator B to the lower byte of Y and duplicates the bit 7 of B to every
bit of the upper byte of Y.
Transfer instructions allow operands to be placed in the right register so that the desired
operation can be performed. For example, if we want to compute the squared value of accumu-
lator A, we can use the following instruction sequence:
TAB ; B ⇐ (A)
MUL ; A:B ⇐ (A) ? (B)
Applications of other transfer and exchange instructions will be discussed in Chapters 2
and 4.
Transfer Instructions
Mnemonic Function Operation
MOVB Move byte (8-bit) (M1) ⇒ M2
Add Instructions
Mnemonic Function Operation
ABA Add B to A (A) + (B) ⇒ A
Subtract Instructions
Mnemonic Function Operation
SBA Subtract B from A (A) - (B) ⇒ A
Example 1.2
▼
Write an instruction sequence to add the byte pointed to by index register X with the fol-
lowing byte, and place the sum at the memory location pointed to by index register Y.
1.8 ■ Instruction Execution Cycle 25
Solution: The byte pointed to by index register X and the following byte can be accessed by using
the indexed addressing mode.
LDAA 0,X ; put the byte pointed to by X in A
ADDA 1,X ; add the following byte to A
STAA 0,Y ; store the sum at the location pointed to by Y
▲
Example 1.3
▼
Write an instruction sequence to add the numbers stored at $800 and $801 and store the
sum at $804.
Solution: To add these two numbers, we need to put one of them in an accumulator:
LDAA $800 ; copy the number in $800 to accumulator A
ADDA $801 ; add the second number to A
STAA $804 ; save the sum at $804
▲
cycle, the process of storing a value in a memory location is called a write cycle, and the process
of executing an instruction is called an instruction execution cycle.
When executing an instruction, the 68HC12 performs a combination of the following
operations:
• One or multiple read cycles to fetch instruction opcode byte(s) and addressing
information.
• One or more read cycles to fetch the memory operand(s) (optional).
• The operation specified by the opcode.
• One or more write cycles to write back the result to either a register or a memory
location (optional).
1.11 Summary
The invention of the microprocessor in 1971 resulted in the revolution of the electronics
industry. The first microprocessor, the Intel 4004, implemented a simplified CPU onto an inte-
grated circuit (IC). Following the introduction of the 4-bit 4004, Intel introduced the 8-bit 8008,
8080, and 8085 over three years. The introduction of the 8085 was a big success. The key to its
success lies in its programmability. Through this programmability, many products can be
designed and constructed. Other companies also joined in the design and manufacturing of
microprocessors. Zilog, Motorola, and Rockwell are among the more successful ones.
The earliest microprocessors still needed peripheral chips to interface with I/O devices
such as seven-segment displays, printers, timers, and so on. Memory chips were also needed to
hold the application program and dynamic data. Because of this, the products designed with
microprocessors could not be made as small as desired. Then came the introduction of micro-
controllers, which incorporated the CPU, some amount of memory, and peripheral functions
such as parallel ports, time instructions rs, and serial interface functions onto one chip. The
development of microcontrollers has had the following impacts:
• I/O interfacing issue is greatly simplified.
• External memory is no longer needed for many applications.
• System design time is greatly shortened.
A microcontroller is not designed to build a desktop computer. Instead, it is used as the con-
troller of many products. End users of these products do not care about what microcontrollers
are used in their appliances. They only care about the functionality of the product. A product
that uses a certain microcontroller as a controller and has this characteristic is called an embed-
ded system. Cell phones, automobiles, cable modems, HDTVs, and home security systems are
well-known embedded systems.
Over the last 20 years, we can see clearly how a microcontroller needs to incorporate some
or all of the following peripheral functions in order to be useful:
• Timer module that incorporates input capture, output compare, real-time inter-
rupt, and counting capability
• Pulse-width modulation function for easy waveform generation
• Analog-to-digital converter
• Digital-to-analog converter
• Temperature sensor
• Direct memory access (DMA) controller
1.11 ■ Exercises 27
1.12 Exercises
E1.1 What is a processor?
E1.2 What is a microprocessor? What is a microcomputer?
E1.3 What makes a microcontroller different from a microprocessor?
E1.4 How many bits can the 68HC12 CPU manipulate in one operation?
E1.5 How many different memory locations can the 68HC12 access?
E1.6 Why must every computer have some amount of nonvolatile memory?
E1.7 Why must every computer have some amount of volatile memory?
E1.8 What is source code? What is object code?
E1.9 Convert 5K, 8K, and 13K to decimal representation.
E1.10 Write an instruction sequence to swap the contents of memory locations at $800 and $801.
E1.11 Write an instruction sequence to add 10 to memory locations at $800 and $801, respectively.
E1.12 Write an instruction sequence to set the contents of memory locations at $800, $810, and
$820 to 10, 11, and 12 respectively.
28 Chapter 1 ■ Introduction to the 68HC12 Microcontroller
E1.13 Write an instruction sequence to perform the operations equivalent to those performed
by the following high-level language statements:
I := 11;
J := 33;
K = I + J – 5;
Assume variables I, J, and K are located at $800, $900, and $1000, respectively.
E1.14 Write an instruction sequence to subtract the number stored at $810 from that stored at
$800 and store the difference at $805.
E1.15 Write an instruction sequence to add the contents of accumulator B to the 16-bit word
stored at memory location $800 and $801. Treat the value stored in B as a signed number.
E1.16 Write an instruction sequence to copy four bytes starting from $800 to $900-$903.
E1.17 Write an instruction sequence to subtract the contents of accumulator B from the 16-bit word
at $800-$801 and store the difference at $900-$901. Treat the value stored in B as a signed value.
E1.18 Write an instruction sequence to swap the 16-bit word stored at $800-$801 with the
16-bit word stored at $900-$901.
E1.19 Give an instruction that can store the contents of accumulator D at the memory loca-
tion with an address larger than the contents of X by 8.
E1.20 Give an instruction that can store the contents of index register Y at the memory loca-
tion with an address smaller than the contents of X by 10.