All M68HC05 microcontroller units (MCUs) are customer-specified
modular designs. To meet customer requirements, Motorola is
constantly designing new modules and new versions of existing
modules. The following table shows the version levels of the modules in
the MC68HC705P9 MCU.
ModuleVersion
Central Processor Unit (CPU)HC05CPU
TimerTIM1IC1OC_A
Serial Input/Output Port (SIOP)SIOP_A
Computer Operating Properly Watchdog (COP)COP0COP
Analog-to-Digital Converter (ADC)ATD4X8NVRL
Revision History
The following table summarizes differences between this revision and
the previous revision of this Technical Data manual.
Previous
Revision
Current
Revision
Date11/95
ChangesFormat and organizational changes
LocationThroughout
VDD and VSSare the power supply and ground pins. The MCU operates
from a single 5-V power supply.
Very fast signal transitions occur
on the MCU pins, placing high
short-duration current demands
MCU
on the power supply. To prevent
noise problems, take special
care to provide good power
DD
V
C1
0.1 µF
SS
V
supply bypassing at the MCU as
Figure 2 shows. Place the
bypass capacitors as close as
possible to the MCU. C2 is an
V
DD
C2
+
optional bulk current bypass
capacitor for use in applications
that require the port pins to
Figure 2. Bypassing
Recommendation
source high current levels.
OSC1 and OSC2The OSC1 and OSC2 pins are the connections for the on-chip oscillator.
The oscillator can be driven by any of the following:
•Crystal
•Ceramic resonator
•External clock signal
The frequency of the on-chip oscillator is f
. The MCU divides the
OSC
internal oscillator output by two to produce the internal clock with a
frequency of f
3-mc68hc705p9
OP
.
MOTOROLAPin Descriptions15
Page 16
Pin Descriptions
Pin Functions
Crystal
Connections
NOTE:
The circuit in Figure 3 shows a
typical crystal oscillator circuit
MCU
for an AT-cut, parallel resonant
crystal. Follow the crystal
supplier’s recommendations, as
OSC1
10 MΩ
OSC2
the crystal parameters
determine the external
XTAL
component values required to
provide reliable startup and
maximum stability. The load
27 pF27 pF
capacitance values used in the
oscillator circuit design should
include all stray layout
Figure 3. Crystal Connections
capacitances. To minimize
output distortion, mount the
crystal and capacitors as close
as possible to the pins.
Use an AT-cut crystal. Do not use a strip or tuning fork crystal. The MCU
may overdrive or have the incorrect characteristic impedance for a strip
or tuning fork crystal.
Ceramic
Resonator
Connections
To reduce cost, use a ceramic
resonator in place of the crystal.
Figure 4 shows a ceramic
resonator circuit. For the values
of any external components,
follow the recommendations of
the resonator manufacturer. The
load capacitance values used in
the oscillator circuit design
should include all stray layout
capacitances. To minimize
output distortion, mount the
resonator and capacitors as
close as possible to the pins.
MCU
CERAMIC
RESONATOR
OSC1
OSC2
Figure 4. Ceramic Resonator
Connections
4-mc68hc705p9
16Pin DescriptionsMOTOROLA
Page 17
Pin Descriptions
Pin Functions
NOTE:
Because the frequency stability of ceramic resonators is not as high as
that of crystal oscillators, using a ceramic resonator may degrade the
performance of the ADC.
External Clock
Connections
An external clock from another
CMOS-compatible device can
drive the OSC1 input, with the
OSC2 pin unconnected, as
Figure 5 shows.
RESETA logic zero on the RESET pin
forces the MCU to a known
startup state. The
RESET pin
input circuit contains an internal
Schmitt trigger to improve noise
immunity.
MCU
OSC1
UNCONNECTED
EXTERNAL
CMOS CLOCK
OSC2
Figure 5. External Clock
Connections
IRQ/V
PP
The IRQ/VPP pin has the following functions:
•Applying asynchronous external interrupt signals
•Applying VPP, the EPROM/OTPROM programming voltage
PA7–PA0PA7–PA0 are general-purpose bidirectional I/O port pins. Use data
direction register A to configure port A pins as inputs or outputs.
PB7/SCK–
PB5/SDO
Port B is a 3-pin bidirectional I/O port that shares its pins with the SIOP.
Use data direction register B to configure port B pins as inputs or
outputs.
PC7/VRH–PC0Port C is an 8-pin bidirectional I/O port that shares five of its pins with the
ADC. Use data direction register C to configure port C pins as inputs or
outputs.
5-mc68hc705p9
MOTOROLAPin Descriptions17
Page 18
Pin Descriptions
Pin Functions
PD7/TCAP and PD5Port D is a 2-pin I/O port that shares one of its pins with the
capture/compare timer. Use data direction register D to configure port D
pins as inputs or outputs.
TCMPThe TCMP pin is the output compare pin for the capture/compare timer.
•2104 Bytes of EPROM/OTPROM
–48 Bytes of Page Zero EPROM/OTPROM
–Eight Locations for User Vectors
•128 Bytes of User RAM
•Bootloader ROM
MOTOROLAMemory19
Page 20
Memory Map
Memory
Memory Map
$0000
↓
$001F
$0020
↓
$004F
$0050
↓
$007F
$0080
↓
$00FF
$0100
↓
$08FF
$0900Mask Option Register$000F
$0901
↓
$1EFF
$1F00
↓
$1FEF
$1FF0COP Control RegisterOutput Compare Register High (OCRH)$0016
$1FF1
↓
$1FF7
$1FF8
↓
$1FFF
I/O Registers (32 Bytes)
Page Zero User EPROM (48 Bytes)
Unimplemented (48 Bytes)
RAM (128 Bytes)
User EPROM (2048 Bytes)
Unimplemented (5631 Bytes)
Bootloader ROM (240 Bytes)
Reserved
User Vector EPROM (8 Bytes)
Port A Data Register (PORTA)$0000
Port B Data Register (PORTB)$0001
Port C Data Register (PORTC)$0002
Port D Data Register (PORTD)$0003
Data Direction Register A (DDRA)$0004
Data Direction Register B (DDRB)$0005
Data Direction Register C (DDRC)$0006
Data Direction Register D (DDRD)$0007
Unimplemented
SIOP Control Register (SCR)$000A
SIOP Status Register (SSR)$000B
SIOP Data Register (SDR)$000C
Unimplemented
Timer Control Register (TCR)$0012
Timer Status Register (TSR)$0013
Input Capture Register High (ICRH)$0014
Input Capture Register Low (ICRL)$0015
Output Compare Register Low (OCRL)$0017
Timer Register High (TRH)$0018
Timer Register Low (TRL)$0019
Alternate Timer Register High (ATRH)$001A
Alternate Timer Register Low (ATRL)$001B
EPROM Programming Register (EPROG)$001C
ADC Data Register (ADDR)$001D
ADC Status/Control Register (ADSCR)$001E
Reserved$001F
$0008
$0009
$000D
$000E
$0010
$0011
Timer Interrupt Vector High$1FF8
Timer Interrupt Vector Low$1FF9
External Interrupt Vector High$1FFA
External Interrupt Vector Low$1FFB
Software Interrupt Vector High$1FFC
Software Interrupt Vector Low$1FFD
Reset Vector High$1FFE
Reset Vector Low$1FFF
Figure 1. Memory Map
2-mc68hc705p9
20MemoryMOTOROLA
Page 21
Memory
Input/Output Register Summary
Input/Output Register Summary
Addr.NameR/WBit 7654321Bit 0
$0000
Port A Data Register (PORTA)
Read:
Write:
Reset:
PA7PA6PA5PA4PA3PA2PA1PA0
Unaffected by reset
$0001
$0002
$0003
$0004
$0005
$0006
Port B Data Register (PORTB)
Port C Data Register (PORTC)
Port D Data Register (PORTD)
Data Direction Register A (DDRA)
Data Direction Register B (DDRB)
Data Direction Register C (DDRC)
Read:
Write:
PB7PB6PB5
Reset:
Read:
Write:
PC7PC6PC5PC4PC3PC2PC1PC0
Reset:
Read:
Write:
PD7
0
PD5
Reset:
Read:
DDRA7 DDRA6 DDRA5 DDRA4 DDRA3 DDRA2 DDRA1 DDRA0
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
00000000
DDRB7 DDRB6 DDRB5
00000000
DDRC7 DDRC6 DDRC5 DDRC4 DDRC3 DDRC2 DDRC1 DDRC0
00000000
00000
Unaffected by reset
Unaffected by reset
10000
Unaffected by reset
00000
$0007
$0008
$0009
Data Direction Register D (DDRD)
Unimplemented
Unimplemented
Read:
Write:
Reset:
00
00000000
= Unimplemented
DDRD5
00000
= ReservedU = Unaffected
R
Figure 2. I/O Register Summary
3-mc68hc705p9
MOTOROLAMemory21
Page 22
Memory
Input/Output Register Summary
Addr.NameR/WBit 7654321Bit 0
$000A
SIOP Control Register (SCR)
Read:
Write:
Reset:
0SPE0MSTR0000
00000000
$000B
$000C
$000D
$000E
$000F
$0010
$0011
$0012
$0013
SIOP Status Register (SSR)
SIOP Data Register (SDR)
Unimplemented
Unimplemented
Unimplemented
Unimplemented
Unimplemented
Timer Control Register (TCR)
Timer Status Register (TSR)
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
SPIFDCOL000000
00000000
Bit 7654321Bit 0
Unaffected by reset
ICIEOCIETOIE000IEDGOLVL
000000U0
ICFOCFTOF00000
Unaffected by reset00000
$0014
Input Capture Register High (ICRH)
Read:
Write:
Bit 1514131211109Bit 8
Reset:
$0015
$0016
Input Capture Register Low (ICRL)
Output Compare Register High (OCRH)
Read:
Write:
Reset:
Read:
Write:
Reset:
Bit 7654321Bit 0
Unaffected by reset
Bit 1514131211109Bit 8
Unaffected by reset
= Unimplemented
= ReservedU = Unaffected
R
Figure 2. I/O Register Summary (Continued)
4-mc68hc705p9
22MemoryMOTOROLA
Page 23
Memory
Input/Output Register Summary
Addr.NameR/WBit 7654321Bit 0
$0017
Output Compare Register Low (OCRL)
Read:
Write:
Reset:
Bit 7654321Bit 0
Unaffected by reset
$0018
$0019
$001A
$001B
$001C
$001D
Timer Register High (TRH)
Timer Register Low (TRL)
Alternate Timer Register High (ATRH)
Alternate Timer Register Low (ATRL)
EPROMProgramming Register (EPROG)
ADC Data Register (ADDR)
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
Read:
Write:
Reset:
Bit 1514131211109Bit 8
Reset initializes TRH to $FF
Bit 7654321Bit 0
Reset initializes TRL to $FC
Bit 1514131211109Bit 8
Reset initializes ATRH to $FF
Bit 7654321Bit 0
Reset initializes ATRL to $FC
00000
RRRRRR
Unaffected by reset
Bit 7654321Bit 0
Unaffected by reset
LATCH
0
EPGM
$001E
$001F
ADC Status/Control Register (ADSCR)
Reserved
Read:
Write:
Reset:
Read:
Write:
CCF
ADRCADON
00000000
RRRRRRRR
00
CH2CH1CH0
Reset:
= Unimplemented
= ReservedU = Unaffected
R
Figure 2. I/O Register Summary (Continued)
5-mc68hc705p9
MOTOROLAMemory23
Page 24
Memory
Addr.NameR/WBit 7654321Bit 0
RAM
$0900
$1FF0
RAM
Mask Option Register (MOR)
COP Register (COPR)
Figure 2. I/O Register Summary (Continued)
The 128 addresses from $0080–$00FF are RAM locations. The CPU
uses the top 64 RAM addresses, $00C0–$00FF, as the stack. Before
processing an interrupt, the CPU uses five bytes of the stack to save the
contents of the CPU registers. During a subroutine call, the CPU uses
two bytes of the stack to store the return address. The stack pointer
decrements when the CPU stores a byte on the stack and increments
when the CPU retrieves a byte from the stack.
Read:
Write:
Reset:
Read:
Write:
Reset:
00000SIOPIRQCOPE
Unaffected by reset0
RRRRRRRCOPC
Unaffected by reset
= Unimplemented
= ReservedU = Unaffected
R
NOTE:
Be careful when using nested subroutines or multiple interrupt levels.
The CPU may overwrite data in the RAM during a subroutine or during
the interrupt stacking operation.
6-mc68hc705p9
24MemoryMOTOROLA
Page 25
EPROM/OTPROM
Memory
EPROM/OTPROM
An MCU with a quartz window has 2104 bytes of erasable,
programmable ROM (EPROM). The quartz window allows EPROM
erasure with ultraviolet light.
NOTE:
Keep the quartz window covered with an opaque material except when
programming the MCU. Ambient light may affect MCU operation.
In an MCU without the quartz window, the EPROM cannot be erased
and serves as 2104 bytes of one-time programmable ROM (OTPROM).
The following addresses are user EPROM/OTPROM locations:
•$0020–$004F
•$0100–$08FF
•$1FF8–$1FFF (reserved for user-defined interrupt and reset
vectors)
The mask option register (MOR) is an EPROM/OTPROM location at
address $0900.
7-mc68hc705p9
MOTOROLAMemory25
Page 26
Memory
EPROM/OTPROM
EPROM/
OTPROM
Programming
EPROM
Programming
Register
The two ways to program the EPROM/OTPROM are:
•Manipulating the control bits in the EPROM programming register
to program the EPROM/OTPROM on a byte-by-byte basis
•Activating the bootloader ROM to download the contents of an
external memory device to the on-chip EPROM/OTPROM
The EPROM programming register contains the control bits for
programming the EPROM/OTPROM.
$001CBit 7654321Bit 0
Read:00000
LATCH
Write:RRRRRR
Reset:00000000
R = Reserved
0
EPGM
Figure 3. EPROM Programming Register (EPROG)
LATCH — EPROM Bus Latch
This read/write bit latches the address and data buses for
EPROM/OTPROM programming. Clearing the LATCH bit
automatically clears the EPGM bit. EPROM/OTPROM data cannot be
read while the LATCH bit is set. Resets clear the LATCH bit.
1 = Address and data buses configured for EPROM/OTPROM
programming
0 = Address and data buses configured for normal operation
EPGM bit— EPROM Programming
This read/write bit applies the voltage from the
IRQ/VPP pin to the
EPROM/OTPROM. To write the EPGM bit, the LATCH bit must
already be set. Clearing the LATCH bit also clears the EPGM bit.
Resets clear the EPGM bit.
1 = EPROM/OTPROM programming power switched on
0 = EPROM/OTPROM programming power switched off
8-mc68hc705p9
26MemoryMOTOROLA
Page 27
Memory
EPROM/OTPROM
NOTE:
Writing logic ones to both the LATCH and EPGM bits with a single
instruction sets LATCH and clears EPGM. LATCH must be set first by a
separate instruction.
Bits 7–3 and Bit 1— Reserved
Bits 7–3 and bit 1 are factory test bits that always read as logic zeros.
Take the following steps to program a byte of EPROM/OTPROM:
1.Apply 16.5 V to the
IRQ/VPP pin.
2.Set the LATCH bit.
3.Write to any EPROM/OTPROM address.
4.Set the EPGM bit for a time, t
, to apply the programming
EPGM
voltage.
5.Clear the LATCH bit.
Bootloader ROMThe bootloader ROM, located at addresses $1F00–$1FEF, contains
routines for copying an external EPROM to the on-chip
EPROM/OTPROM.
The bootloader copies to the following EPROM/OTPROM addresses:
•$0020–$004F
•$0100–$0900
•$1FF0–$1FFF
The addresses of the code in the external EPROM must match the
MC68HC705P9 addresses. The bootloader ignores all other addresses.
Figure 4 shows the circuit for downloading to the on-chip
EPROM/OTPROM from a 2764 EPROM. The bootloader circuit includes
an external 12-bit counter to address the external EPROM. Operation is
fastest when unused external EPROM addresses contain $00. The
bootloader function begins when a rising edge occurs on the
while the V
voltage is on the IRQ/VPP pin, and the PD7/TCAP pin is at
PP
RESETpin
logic one.
9-mc68hc705p9
MOTOROLAMemory27
Page 28
Memory
EPROM/OTPROM
MC14040B
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
Q9
Q10
Q11
Q12
RSTCLK
S1
2 MHz
10 MΩ
10 kΩ
1 µF
D0
D1
D2
D3
D4
D5
D6
D7
CE
OE
2764
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
MC68HC705P9
2
V
IRQ/V
PP
27
26
V
DD
PP
OSC1
OSC2
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
10
9
8
7
6
5
4
3
A10
1
RESET
PB5
PD7
11
25
A12
V
DD
A11
10 kΩ
17
PC5/AN1
V
DD
16
PC6/AN0
PC1
PC2
21
20
V
DD
PROGRAM
330 Ω
VERIFY
13
12
PB7/SCK
PB6/SDI
PC4
PC3
10 kΩ
18
19
10 kΩ
S2
S3
330 Ω
Figure 4. Bootloader Circuit
10-mc68hc705p9
28MemoryMOTOROLA
Page 29
EPROM/OTPROM
The logical states of the PC4/AN2 and PC3/AN3 pins select the
bootloader function, as Table 1 shows.
Table 1. Bootloader Function Selection
Memory
PC4/AN2PC3/AN3
11Program and Verify
10Verify Only
Function
Complete the following steps to bootload the MCU:
1.Turn off all power to the circuit.
2.Install the EPROM containing the code to be downloaded.
3.Install the MCU.
4.Select the bootloader function:
a.Open switches S2 and S3 to select the program and verify
function.
b.Open only switch S2 to select only the verify function.
5.Close switch S1.
6.Turn on the V
power supply.
DD
CAUTION:
Turn on the VDD power supply before turning on the VPP power supply.
7.Turn on the VPP power supply.
8.Open switch S1. The bootloader code begins to execute. If the
PROGRAM function is selected, the PROGRAM LED turns on
during programming. If the VERIFY function is selected, the
VERIFY LED turns on when verification is successful. The
PROGRAM and VERIFY functions take about 10 seconds.
9.Close switch S1.
10.Turn off the V
11-mc68hc705p9
MOTOROLAMemory29
power supply.
PP
Page 30
Memory
EPROM/OTPROM
CAUTION:
Turn off the VPP power supply before turning off the VDD power supply.
11.Turn off the VDD power supply.
EPROM ErasingThe erased state of an EPROM bit is zero. Erase the EPROM by
exposing it to 15 Ws/cm
2
of ultraviolet light with a wavelength of 2537
angstroms. Position the ultraviolet light source one inch from the
EPROM. Do not use a shortwave filter.
Cerdip packages have a transparent window for erasing the EPROM
with ultraviolet light. In the windowless PDIP and SOIC packages, the
2104 EPROM bytes function as one-time programmable ROM
(OTPROM).
12-mc68hc705p9
30MemoryMOTOROLA
Page 31
Mask Option Register
The mask option register (MOR) is an EPROM/OTPROM byte that is
programmable only with the bootloader function. The MOR controls the
following options:
To program the MOR, use the 5-step procedure given in the section
EPROM Programming Register on page 26. Write to address $0900 in
step 3.
$0900Bit 7654321Bit 0
Memory
Mask Option Register
•LSB first or MSB first SIOP data transfer
•Edge-triggered or edge- and level-triggered external interrupt pin
•Enabled or disabled COP watchdog
Read:00000SIOPIRQCOPE
Write:
Reset:Unaffected by reset
Erased:00000000
= Unimplemented
Figure 5. Mask Option Register (MOR)
SIOP — Serial I/O Port
The SIOP bit controls the shift direction into and out of the SIOP shift
register.
1 = SIOP data transferred LSB first (bit 0 first)
0 = SIOP data transferred MSB first (bit 7 first)
IRQ — Interrupt Request
The IRQ bit makes the external interrupt function of the
IRQ/VPP pin
level-triggered as well as edge-triggered.
1 = IRQ/VPP pin negative-edge triggered and low-level triggered
IRQ/VPP pin negative-edge triggered only
0 =
13-mc68hc705p9
MOTOROLAMemory31
Page 32
Memory
Mask Option Register
COPE — COP Enable
COPE enables the COP watchdog. In applications that have wait
cycles longer than the COP watchdog timeout period, the COP
watchdog can be disabled by not programming the COPE bit to logic
one.
•Power-Saving Stop, Wait, and Data-Retention Modes
Features
Introduction
The central processor unit (CPU) consists of a CPU control unit, an
arithmetic/logic unit (ALU), and five CPU registers. The CPU control unit
fetches and decodes instructions. The ALU executes the instructions.
The CPU registers contain data, addresses, and status bits that reflect
the results of CPU operations.
2-hc05cpu
34CPUMOTOROLA
Page 35
CPU
Introduction
CPU CONTROL UNIT
000000011
0
000
HALF-CARRY FLAG
INTERRUPT MASK
ARITHMETIC/LOGIC UNIT
04756321
04756321
0475632181215131411 10 9
0475632181215131411 10 9
04756321
111HINZC
ACCUMULATOR (A)
INDEX REGISTER (X)
STACK POINTER (SP)
PROGRAM COUNTER (PC)
CONDITION CODE REGISTER (CCR)
NEGATIVE FLAG
ZERO FLAG
CARRY/BORROW FLAG
Figure 1. CPU Programming Model
3-hc05cpu
MOTOROLACPU35
Page 36
CPU Control Unit
The CPU control unit fetches and decodes instructions during program
operation. The control unit selects the memory locations to read and
write and coordinates the timing of all CPU operations.
Arithmetic/Logic Unit
The arithmetic/logic unit (ALU) performs the arithmetic, logic, and
manipulation operations decoded from the instruction set by the CPU
control unit. The ALU produces the results called for by the program and
sets or clears status and control bits in the condition code register
(CCR).
CPU
CPU Control Unit
CPU Registers
The M68HC05 CPU contains five registers that control and monitor MCU
operation:
•Accumulator
•Index register
•Stack pointer
•Program counter
•Condition code register
CPU registers are not memory mapped.
4-hc05cpu
36CPUMOTOROLA
Page 37
CPU
CPU Registers
AccumulatorThe accumulator is a general-purpose 8-bit register. The CPU uses the
accumulator to hold operands and the results of arithmetic and logic
operations.
Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
Figure 2. Accumulator (A)
Index RegisterThe index register can be used for data storage or as a counter. In the
indexed addressing modes, the CPU uses the byte in the index register
to determine the effective address of the operand.
Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
Figure 3. Index Register (X)
Stack PointerThe stack pointer is a 16-bit register that contains the address of the next
stack location to be used. During a reset or after the reset stack pointer
instruction (RSP), the stack pointer is preset to $00FF. The address in
the stack pointer decrements after a byte is stacked and increments
before a byte is unstacked.
Bit
151413121110987654321
Read:0000000011
Write:
Bit
0
Reset:0000000011111111
= Unimplemented
Figure 4. Stack Pointer (SP)
5-hc05cpu
MOTOROLACPU37
Page 38
CPU
CPU Registers
The 10 most significant bits of the stack pointer are permanently fixed at
0000000011, so the stack pointer produces addresses from $00C0 to
$00FF. If subroutines and interrupts use more than 64 stack locations,
the stack pointer wraps around to address $00FF and begins writing
over the previously stored data. A subroutine uses two stack locations;
an interrupt uses five locations.
Program CounterThe program counter is a 16-bit register that contains the address of the
next instruction or operand to be fetched. The three most significant bits
of the program counter are ignored internally and appear as 000.
Normally, the address in the program counter automatically increments
to the next sequential memory location every time an instruction or
operand is fetched. Jump, branch, and interrupt operations load the
program counter with an address other than that of the next sequential
location.
Condition Code
Register
Bit
151413121110987654321
Read:
Write:
Reset:000Loaded with vector from $1FFE and $1FFF
Bit
0
Figure 5. Program Counter (PC)
The condition code register is an 8-bit register whose three most
significant bits are permanently fixed at 111. The condition code register
contains the interrupt mask and four flags that indicate the results of the
instruction just executed.
Bit 7654321Bit 0
Read:111
Write:
Reset:111U1UUU
HINZC
= UnimplementedU = Unaffected
Figure 6. Condition Code Register (CCR)
6-hc05cpu
38CPUMOTOROLA
Page 39
CPU Registers
H — Half-Carry Flag
The CPU sets the half-carry flag when a carry occurs between bits 3
and 4 of the accumulator during an ADD or ADC operation. The
half-carry flag is required for binary-coded decimal (BCD) arithmetic
operations.
I — Interrupt Mask
Setting the interrupt mask disables interrupts. If an interrupt request
occurs while the interrupt mask is logic zero, the CPU saves the CPU
registers on the stack, sets the interrupt mask, and then fetches the
interrupt vector. If an interrupt request occurs while the interrupt mask
is set, the interrupt request is latched. Normally, the CPU processes
the latched interrupt as soon as the interrupt mask is cleared again.
A return from interrupt (RTI) instruction pulls the CPU registers from
the stack, restoring the interrupt mask to its cleared state. After any
reset, the interrupt mask is set and can be cleared only by a software
instruction.
CPU
N — Negative Flag
The CPU sets the negative flag when an arithmetic operation, logical
operation, or data manipulation produces a negative result.
Z — Zero Flag
The CPU sets the zero flag when an arithmetic operation, logical
operation, or data manipulation produces a result of $00.
C — Carry/Borrow Flag
The CPU sets the carry/borrow flag when an addition operation
produces a carry out of bit 7 of the accumulator or when a subtraction
operation requires a borrow. Some logical operations and data
manipulation instructions also clear or set the carry/borrow flag.
7-hc05cpu
MOTOROLACPU39
Page 40
CPU
Instruction Set
Instruction Set
The MCU instruction set has 62 instructions and uses eight addressing
modes. The instructions include all those of the M146805 CMOS Family
plus one more: the unsigned multiply (MUL) instruction. The MUL
instruction allows unsigned multiplication of the contents of the
accumulator (A) and the index register (X). The high-order product is
stored in the index register, and the low-order product is stored in the
accumulator.
Addressing ModesThe CPU uses eight addressing modes for flexibility in accessing data.
The addressing modes provide eight different ways for the CPU to find
the data required to execute an instruction. The eight addressing modes
are:
•Inherent
•Immediate
•Direct
•Extended
•Indexed, no offset
•Indexed, 8-bit offset
•Indexed, 16-bit offset
•Relative
InherentInherent instructions are those that have no operand, such as return
from interrupt (RTI) and stop (STOP). Some of the inherent instructions
act on data in the CPU registers, such as set carry flag (SEC) and
increment accumulator (INCA). Inherent instructions require no operand
address and are one byte long.
ImmediateImmediate instructions are those that contain a value to be used in an
operation with the value in the accumulator or index register. Immediate
instructions require no operand address and are two bytes long. The
opcode is the first byte, and the immediate data value is the second byte.
8-hc05cpu
40CPUMOTOROLA
Page 41
CPU
Instruction Set
DirectDirect instructions can access any of the first 256 memory locations with
two bytes. The first byte is the opcode, and the second is the low byte of
the operand address. In direct addressing, the CPU automatically uses
$00 as the high byte of the operand address.
ExtendedExtended instructions use three bytes and can access any address in
memory. The first byte is the opcode; the second and third bytes are the
high and low bytes of the operand address.
When using the Motorola assembler, the programmer does not need to
specify whether an instruction is direct or extended. The assembler
automatically selects the shortest form of the instruction.
Indexed,
No Offset
Indexed,
8-Bit Offset
Indexed instructions with no offset are 1-byte instructions that can
access data with variable addresses within the first 256 memory
locations. The index register contains the low byte of the effective
address of the operand. The CPU automatically uses $00 as the high
byte, so these instructions can address locations $0000–$00FF.
Indexed, no offset instructions are often used to move a pointer through
a table or to hold the address of a frequently used RAM or I/O location.
Indexed, 8-bit offset instructions are 2-byte instructions that can access
data with variable addresses within the first 511 memory locations. The
CPU adds the unsigned byte in the index register to the unsigned byte
following the opcode. The sum is the effective address of the operand.
These instructions can access locations $0000–$01FE.
Indexed 8-bit offset instructions are useful for selecting the kth element
in an n-element table. The table can begin anywhere within the first 256
memory locations and could extend as far as location 510 ($01FE). The
k value is typically in the index register, and the address of the beginning
of the table is in the byte following the opcode.
9-hc05cpu
MOTOROLACPU41
Page 42
CPU
Instruction Set
Indexed,
16-Bit Offset
Indexed, 16-bit offset instructions are 3-byte instructions that can access
data with variable addresses at any location in memory. The CPU adds
the unsigned byte in the index register to the two unsigned bytes
following the opcode. The sum is the effective address of the operand.
The first byte after the opcode is the high byte of the 16-bit offset; the
second byte is the low byte of the offset.
Indexed, 16-bit offset instructions are useful for selecting the kth element
in an n-element table anywhere in memory.
As with direct and extended addressing, the Motorola assembler
determines the shortest form of indexed addressing.
RelativeRelative addressing is only for branch instructions. If the branch
condition is true, the CPU finds the effective branch destination by
adding the signed byte following the opcode to the contents of the
program counter. If the branch condition is not true, the CPU goes to the
next instruction. The offset is a signed, two’s complement byte that gives
a branching range of –128 to +127 bytes from the address of the next
location after the branch instruction.
When using the Motorola assembler, the programmer does not need to
calculate the offset, because the assembler determines the proper offset
and verifies that it is within the span of the branch.
10-hc05cpu
42CPUMOTOROLA
Page 43
Instruction TypesThe MCU instructions fall into the following five categories:
•Register/Memory Instructions
•Read-Modify-Write Instructions
•Jump/Branch Instructions
•Bit Manipulation Instructions
•Control Instructions
CPU
Instruction Set
Register/
Memory
Instructions
These instructions operate on CPU registers and memory locations.
Most of them use two operands. One operand is in either the
accumulator or the index register. The CPU finds the other operand in
memory.
Table 1. Register/Memory Instructions
InstructionMnemonic
Add Memory Byte and Carry Bit to AccumulatorADC
Add Memory Byte to AccumulatorADD
AND Memory Byte with AccumulatorAND
Bit Test AccumulatorBIT
Compare AccumulatorCMP
Compare Index Register with Memory ByteCPX
EXCLUSIVE OR Accumulator with Memory ByteEOR
Load Accumulator with Memory ByteLDA
Load Index Register with Memory ByteLDX
MultiplyMUL
OR Accumulator with Memory ByteORA
Subtract Memory Byte and Carry Bit from AccumulatorSBC
Store Accumulator in MemorySTA
Store Index Register in MemorySTX
Subtract Memory Byte from AccumulatorSUB
11-hc05cpu
MOTOROLACPU43
Page 44
CPU
Instruction Set
Read-ModifyWrite Instructions
NOTE:
These instructions read a memory location or a register, modify its
contents, and write the modified value back to the memory location or to
the register.
Do not use read-modify-write operations on write-only registers.
Table 2. Read-Modify-Write Instructions
InstructionMnemonic
Arithmetic Shift Left (Same as LSL)ASL
Arithmetic Shift RightASR
Bit ClearBCLR
Bit SetBSET
Clear RegisterCLR
Complement (One’s Complement)COM
DecrementDEC
IncrementINC
(1)
(1)
Logical Shift Left (Same as ASL)LSL
Logical Shift RightLSR
Negate (Two’s Complement)NEG
Rotate Left through Carry BitROL
Rotate Right through Carry BitROR
Test for Negative or ZeroTST
1. Unlike other read-modify-write instructions, BCLR and
BSET use only direct addressing.
2. TST is an exception to the read-modify-write sequence because it does not write a replacement value.
(2)
12-hc05cpu
44CPUMOTOROLA
Page 45
CPU
Instruction Set
Jump/Branch
Instructions
Jump instructions allow the CPU to interrupt the normal sequence of the
program counter. The unconditional jump instruction (JMP) and the
jump-to-subroutine instruction (JSR) have no register operand. Branch
instructions allow the CPU to interrupt the normal sequence of the
program counter when a test condition is met. If the test condition is not
met, the branch is not performed.
The BRCLR and BRSET instructions cause a branch based on the state
of any readable bit in the first 256 memory locations. These 3-byte
instructions use a combination of direct addressing and relative
addressing. The direct address of the byte to be tested is in the byte
following the opcode. The third byte is the signed offset byte. The CPU
finds the effective branch destination by adding the third byte to the
program counter if the specified bit tests true. The bit to be tested and its
condition (set or clear) is part of the opcode. The span of branching is
from –128 to +127 from the address of the next location after the branch
instruction. The CPU also transfers the tested bit to the carry/borrow bit
of the condition code register.
13-hc05cpu
MOTOROLACPU45
Page 46
CPU
Instruction Set
Table 3. Jump and Branch Instructions
InstructionMnemonic
Branch if Carry Bit ClearBCC
Branch if Carry Bit SetBCS
Branch if EqualBEQ
Branch if Half-Carry Bit ClearBHCC
Branch if Half-Carry Bit SetBHCS
Branch if HigherBHI
Branch if Higher or SameBHS
Branch if IRQ Pin HighBIH
Branch if IRQ Pin LowBIL
Branch if LowerBLO
Branch if Lower or SameBLS
Branch if Interrupt Mask ClearBMC
Branch if MinusBMI
Branch if Interrupt Mask SetBMS
Branch if Not EqualBNE
Branch if PlusBPL
Branch AlwaysBRA
Branch if Bit ClearBRCLR
Branch NeverBRN
Branch if Bit SetBRSET
Branch to SubroutineBSR
Unconditional JumpJMP
Jump to SubroutineJSR
14-hc05cpu
46CPUMOTOROLA
Page 47
CPU
Instruction Set
Bit Manipulation
Instructions
Control
Instructions
The CPU can set or clear any writable bit in the first 256 bytes of
memory, which includes I/O registers and on-chip RAM locations. The
CPU can also test and branch based on the state of any bit in any of the
first 256 memory locations.
Table 4. Bit Manipulation Instructions
InstructionMnemonic
Bit ClearBCLR
Branch if Bit ClearBRCLR
Branch if Bit SetBRSET
Bit SetBSET
These instructions act on CPU registers and control CPU operation
during program execution.
Table 5. Control Instructions
InstructionMnemonic
Clear Carry BitCLC
Clear Interrupt MaskCLI
No OperationNOP
Reset Stack PointerRSP
Return from InterruptRTI
Return from SubroutineRTS
Set Carry BitSEC
Set Interrupt MaskSEI
Stop Oscillator and Enable IRQ PinSTOP
Software InterruptSWI
Transfer Accumulator to Index RegisterTAX
Transfer Index Register to AccumulatorTXA
Stop CPU Clock and Enable Interrupts
WAIT
15-hc05cpu
MOTOROLACPU47
Page 48
Instruction Set
Summary
Source
Form
ADC #
opr
ADC
opr
ADC
opr
ADC
opr
ADC
opr
ADC ,X
ADD #
ADD
opr
ADD
opr
ADD
opr
ADD
opr
ADD ,X
AND #
AND
opr
AN
D opr
AND
opr
AND
opr
AND ,X
ASL
opr
ASLA
ASLX
ASL
opr
ASL ,X
ASR
opr
ASRA
ASRX
ASR
opr
ASR ,X
BCC
rel
BCLR
BCS
rel
BEQ
rel
BHCC
BHCS
,X
,X
opr
,X
,X
opr
,X
,X
,X
,X
n opr
rel
rel
Add with CarryA ← (A) + (M) + (C)↕— ↕ ↕ ↕
Add without CarryA ← (A) + (M)↕— ↕
Logical ANDA ← (A) ∧ (M)— — ↕↕—
Arithmetic Shift Left (Same as LSL)— — ↕
Arithmetic Shift Right— — ↕
Branch if Carry Bit ClearPC ← (PC) + 2 +
Clear Bit nMn ← 0————
Branch if Carry Bit Set (Same as BLO)PC ← (PC) + 2 +
Branch if EqualPC ← (PC) + 2 +
Branch if Half-Carry Bit ClearPC ← (PC) + 2 +
Branch if Half-Carry Bit SetPC ← (PC) + 2 +
CPU
Instruction Set
Table 6. Instruction Set Summary
OperationDescription
C
b7
b7
rel
rel
rel
rel
rel
Effect on
CCR
HINZC
↕↕
0
b0
C
b0
? C = 0————
? C = 1————— REL 25 rr 3
? Z = 1————— REL 27 rr 3
? H = 0————— REL 28 rr 3
? H = 1————— REL 29 rr 3
↕↕
↕↕
—
—
Mode
Opcode
Address
IMM
A9
DIR
B9
dd
EXT
C9
hh ll
IX2
D9
ee ff
IX1
E9
IX
F9
IMM
AB
DIR
BB
dd
EXT
CB
hh ll
IX2
DB
ee ff
IX1
EB
IX
FB
IMM
A4
DIR
B4
dd
EXT
C4
hh ll
IX2
D4
ee ff
IX1
E4
IX
F4
DIR
38
ddff5
INH
48
INH
58
IX1
68
IX
78
DIR
37
ddff5
INH
47
INH
57
IX1
67
IX
77
REL24rr3
DIR (b0)
DIR (b1)
DIR (b2)
DIR (b3)
DIR (b4)
DIR (b5)
DIR (b6)
DIR (b7)
11
13
15
17
19
1B
1D
1F
dd
dd
dd
dd
dd
dd
dd
dd
Operand
ii
ff
ii
ff
ii
ff
Cycles
2
3
4
5
4
3
2
3
4
5
4
3
2
3
4
5
4
3
3
3
6
5
3
3
6
5
5
5
5
5
5
5
5
5
16-hc05cpu
48CPUMOTOROLA
Page 49
Source
Form
BHI
rel
BHS
rel
BIH
rel
BIL
rel
BIT #
BIT
opr
BIT
opr
BIT
opr
BIT
opr
BIT ,X
BLO
rel
BLS
rel
BMC
rel
BMI
rel
BMS
rel
BNE
rel
BPL
rel
BRA
rel
BRCLR
BRN
rel
BRSET
BSET
opr
,X
,X
n opr rel
n opr rel
n opr
Table 6. Instruction Set Summary (Continued)
Effect on
OperationDescription
Branch if HigherPC ← (PC) + 2 +
Branch if Higher or SamePC ← (PC) + 2 +
Branch if IRQ Pin HighPC ← (PC) + 2 +
Branch if IRQ Pin LowPC ← (PC) + 2 +
Bit Test Accumulator with Memory Byte(A) ∧ (M)— — ↕↕—
Branch if Lower (Same as BCS)PC ← (PC) + 2 +
Branch if Lower orSamePC ← (PC) + 2 +
Branch if Interrupt Mask ClearPC ← (PC) + 2 +
Branch if MinusPC ← (PC) + 2 +
Branch if Interrupt Mask SetPC ← (PC) + 2 +
Branch if Not EqualPC ← (PC) + 2 +
Branch if PlusPC ← (PC) + 2 +
Branch AlwaysPC ← (PC) + 2 +
Branch if Bit n ClearPC ← (PC) + 2 +
Branch NeverPC ← (PC) + 2 +
Branch if Bit n SetPC ← (PC) + 2 +
Set Bit nMn ← 1—————
rel
? C ∨ Z = 0 ————— REL 22 rr 3
rel
? C = 0————— REL 24 rr 3
rel
? IRQ = 1————— REL 2F rr 3
rel
? IRQ = 0————— REL 2E rr 3
rel
? C = 1————— REL 25 rr 3
rel
? C ∨ Z = 1 ————— REL 23 rr 3
rel
? I = 0————— REL 2C rr 3
rel
? N = 1————— REL 2B rr 3
rel
? I = 1————— REL 2D rr 3
rel
? Z = 0————— REL 26 rr 3
rel
? N = 0————— REL 2A rr 3
rel
? 1 = 1————— REL 20 rr 3
rel
? Mn = 0 ———— ↕
rel
? 1 = 0————— REL 21 rr 3
rel
? Mn = 1 ———— ↕
CCR
HINZC
Instruction Set
Mode
Address
IMM
A5
DIR
B5
EXT
C5
IX2
D5
IX1
E5
IX
F5
DIR (b0)
DIR (b1)
DIR (b2)
DIR (b3)
DIR (b4)
DIR (b5)
DIR (b6)
DIR (b7)
DIR (b0)
DIR (b1)
DIR (b2)
DIR (b3)
DIR (b4)
DIR (b5)
DIR (b6)
DIR (b7)
DIR (b0)
DIR (b1)
DIR (b2)
DIR (b3)
DIR (b4)
DIR (b5)
DIR (b6)
DIR (b7)
,X
STA ,X
STOPStop Oscillator and Enable IRQ Pin— 0 — — —INH8E2
STX
opr
STX
opr
STX
opr
,X
STX
opr
,X
STX ,X
SUB #
opr
SUB
opr
SUB
opr
SUB
opr
,X
SUB
opr
,X
SUB ,X
Rotate Byte Left through Carry Bit— — ↕
Rotate Byte Right through Carry Bit— — ↕
Subtract Memory Byte and Carry Bit from
Accumulator
Store Accumulator in MemoryM ← (A)— — ↕↕—
Store Index Register In MemoryM ← (X)— — ↕↕—
Subtract Memory Byte from AccumulatorA ← (A) – (M)— —
OperationDescription
C
b7
b7
SP ← (SP) + 1; Pull (CCR)
SP ← (SP) + 1; Pull (A)
SP ← (SP) + 1; Pull (X)
SP ← (SP) + 1; Pull (PCH)
SP ← (SP) + 1; Pull (PCL)
SP ← (SP) + 1; Pull (PCH)
SP ← (SP) + 1; Pull (PCL)
A ← (A) – (M) – (C)— — ↕
b0
b0
C
CCR
HINZC
↕↕
↕↕
↕↕↕↕
↕
————— INH 816
↕↕
↕↕↕
Mode
Opcode
Address
DIR
INH
INH
IX1
IX
DIR
INH
INH
IX1
IX
INH809
IMM
DIR
EXT
IX2
IX1
IX
DIR
EXT
IX2
IX1
IX
DIR
EXT
IX2
IX1
IX
IMM
DIR
EXT
IX2
IX1
IX
39
49
59
69
79
36
46
56
66
76
A2
B2
C2
D2
E2
F2
B7
C7
D7
E7
F7
BF
CF
DF
EF
FF
A0
B0
C0
D0
E0
F0
Operand
ddff5
ddff5
ii
dd
hh ll
ee ff
ff
dd
hh ll
ee ff
ff
dd
hh ll
ee ff
ff
ii
dd
hh ll
ee ff
ff
3
3
6
5
3
3
6
5
2
3
4
5
4
3
4
5
6
5
4
4
5
6
5
4
2
3
4
5
4
3
Cycles
20-hc05cpu
52CPUMOTOROLA
Page 53
CPU
Instruction Set
Table 6. Instruction Set Summary (Continued)
Effect on
Source
Form
SWISoftware Interrupt
TAXTransfer Accumulator to Index RegisterX ← (A)————— INH972
TST
opr
TSTA
TSTX
TST
opr
,X
TST ,X
TXATransfer Index Register to AccumulatorA ← (X)————— INH 9F2
WAITStop CPU Clock and Enable Interrupts— 0 — — —INH8F2
AAccumulator
CCarry/borrow flagPCProgram counter
CCR Condition code registerPCH Program counter high byte
ddDirect address of operandPCL Program counter low byte
dd rr Direct address of operand and relative offset of branch instructionREL Relative addressing mode
DIRDirect addressing mode
ee ff High and low bytes of offset in indexed, 16-bit offset addressingrrRelative program counter offset byte
EXT Extended addressing modeSPStack pointer
ffOffset byte in indexed, 8-bit offset addressingXIndex register
HHalf-carry flagZZero flag
hh llHigh and low bytes of operand address in extended addressing#Immediate value
IInterrupt mask∧Logical AND
iiImmediate operand byte∨Logical OR
IMM Immediate addressing mode⊕Logical EXCLUSIVE OR
INHInherent addressing mode( )Contents of
IXIndexed, no offset addressing mode–( ) Negation (two’s complement)
IX1Indexed, 8-bit offset addressing mode←Loaded with
IX2Indexed, 16-bit offset addressing mode?If
MMemory location:Concatenated with
NNegative flag↕Set or cleared
A reset immediately stops the operation of the instruction being
executed, initializes certain control bits, and loads the program counter
with a user-defined reset vector address. The following sources can
generate resets:
•Power-on reset (POR) circuit
•
RESET pin
•COP watchdog
V
RESET
DD
POWER-ON RESET
COP WATCHDOG
(PROGRAMMABLE OPTION)
Figure 1. Reset Sources
Power-On ResetA positive transition on the V
NOTE:
The power-on reset is strictly for power-up conditions and cannot be
used to detect drops in power supply voltage.
A 4064 t
(internal clock cycle) delay after the oscillator becomes
CYC
active allows the clock generator to stabilize. If the
zero at the end of 4064 t
the signal on the
RESET pin goes to logic one.
, the MCU remains in the reset condition until
CYC
RST
S
DQ
INTERNAL CLOCK
pin generates a power-on reset.
DD
CK
RESET
LATCH
RESET pin is at logic
TO CPU AND
SUBSYSTEM
2-mc68hc705p9
56Resets and InterruptsMOTOROLA
Page 57
V
OSC1 PIN
INTERNAL
CLOCK
DD
(NOTE 1)
4064 t
Resets and Interrupts
Resets
CYC
INTERNAL
ADDRESS BUS
INTERNAL
DATA BUS
NOTES:
1. Power-on reset threshold is typically between 1 V and 2 V.
2. Internal clock, internal address bus, and internal data bus are not available externally.
1FFE
Figure 2. Power-On Reset Timing
External ResetA logic zero applied to the
generates an external reset. A Schmitt trigger senses the logic level at
the
RESET pin.
INTERNAL
CLOCK
INTERNAL
ADDRESS BUS
INTERNAL
DATA BUS
1FFE1FFE1FFE1FFE1FFFNEW PC
1FFE1FFE1FFE1FFE1FFE1FFF
NEW
PCH
RESET pin for one and one-half t
NEW
PCH
NEW
PCL
DUMMY
CYC
NEW PC
OP
CODE
NEW
PCL
t
RESET
NOTES:
1. Internal clock, internal address bus, and internal data bus are not available externally.
2. The next rising edge of the internal clock after the rising edge of
RL
RESET initiates the reset sequence.
Figure 3. External Reset Timing
Table 1. External Reset Timing
CharacteristicSymbolMinMaxUnit
RESET Pulse Widtht
3-mc68hc705p9
RL
MOTOROLAResets and Interrupts57
1.5—t
CYC
Page 58
Resets and Interrupts
Low-Voltage Protection
COP Watchdog
Reset
A timeout of the COP watchdog generates a COP reset. The COP
watchdog is part of a software error detection system and must be
cleared periodically to start a new timeout period. To clear the COP
watchdog and prevent a COP reset, write a logic zero to bit 0 (COPC) of
the COP register at location $1FF0.
Low-Voltage Protection
A drop in power supply voltage below the minimum operating V
voltage is called a brownout condition. A brownout while the MCU is in a
non-reset state can corrupt MCU operation and necessitate a power-on
reset to resume operation.
The best protection against brownout is an undervoltage sensing circuit
that pulls the
The undervoltage sensing circuit may be made of discrete components
or an integrated circuit can be used.
DD
RESET pin low when it detects a low-power supply voltage.
For information about brownout and the COP watchdog, see the
Computer Operating Properly Watchdog section.
4-mc68hc705p9
58Resets and InterruptsMOTOROLA
Page 59
Interrupts
Resets and Interrupts
Interrupts
The following sources can generate interrupts:
•SWI instruction
•IRQ/VPP pin
•Capture/compare timer
An interrupt temporarily stops normal program execution to process a
particular event. An interrupt does not stop the operation of the
instruction being executed, but takes effect when the current instruction
completes its execution. Interrupt processing automatically saves the
CPU registers on the stack and loads the program counter with a
user-defined interrupt vector address.
Software
Interrupt
External
Interrupt
The software interrupt (SWI) instruction causes a non-maskable
interrupt.
An interrupt signal on the
IRQ/VPP pin latches an external interrupt
request. When the CPU completes its current instruction, it tests the IRQ
latch. If the IRQ latch is set, the CPU then tests the I bit in the condition
code register. If the I bit is clear, the CPU then begins the interrupt
sequence.
The CPU clears the IRQ latch during interrupt processing, so that
another interrupt signal on the
IRQ/VPP pin can latch another interrupt
request during the interrupt service routine. As soon as the I bit is
cleared during the return from interrupt, the CPU can recognize the new
interrupt request. Figure 4 shows the
IRQ/VPP pin interrupt logic.
5-mc68hc705p9
MOTOROLAResets and Interrupts59
Page 60
Resets and Interrupts
IRQ/V
PP
Setting the I bit in the condition code register disables external interrupts.
Interrupts
LEVEL-SENSITIVE TRIGGER
(MOR OPTION)
V
DD
DQ
CK
CLR
Figure 4. External Interrupt Logic
(FROM CCR)
I
EXTERNAL
INTERRUPT
REQUEST
RESET
VECTOR FETCH
Interrupt triggering sensitivity of the
option. The
IRQ/VPP pin can be negative-edge triggered or
IRQ/VPP pin is a programmable
negative-edge- and low-level triggered. The level-sensitive triggering
option allows multiple external interrupt sources to be wire-ORed to the
IRQ/VPP pin. An external interrupt request, shown in Figure 5, is latched
as long as any source is holding the
should not be less than the number of interrupt service routine cycles
ILIL
.
H
= 5.0 Vdc)
DD
ILIH
ILIL
ILIH
ILIL
(1)
125—ns
(2)
Note
—t
(1)
250—ns
(2)
Note
—t
CYC
CYC
Timer InterruptsThe capture/compare timer can generate the following interrupts:
•Input capture interrupt
•Output compare interrupt
•Timer overflow interrupt
Setting the I bit in the condition code register disables timer interrupts.
Input Capture
Interrupt
An input capture interrupt request occurs if the input capture flag, ICF,
becomes set while the input capture interrupt enable bit, ICIE, is also set.
ICF is in the timer status register, and ICIE is in the timer control register.
Output Compare
Interrupt
An output compare interrupt request occurs if the output compare flag,
OCF, becomes set while the output compare interrupt enable bit, OCIE,
is also set. OCF is in the timer status register, and OCIE is in the timer
control register.
7-mc68hc705p9
MOTOROLAResets and Interrupts61
Page 62
Resets and Interrupts
Interrupts
Timer Overflow
Interrupt
Interrupt
Processing
A timer overflow interrupt request occurs if the timer overflow flag, TOF,
becomes set while the timer overflow interrupt enable bit, TOIE, is also
set. TOF is in the timer status register, and TOIE is in the timer control
register.
The CPU takes the following actions to begin servicing an interrupt:
•Stores the CPU registers on the stack in the order shown in
Figure 6
•Sets the I bit in the condition code register to prevent further
interrupts
•Loads the program counter with the contents of the appropriate
interrupt vector locations:
–$1FFC and $1FFD (software interrupt vector)
–$1FFA and $1FFB (external interrupt vector)
–$1FF8 and $1FF9 (timer interrupt vector)
The return from interrupt (RTI) instruction causes the CPU to recover the
CPU registers from the stack as shown in Figure 6.
8-mc68hc705p9
62Resets and InterruptsMOTOROLA
Page 63
)
UNSTACKING
ORDER
Resets and Interrupts
Interrupts
$00C0 (BOTTOM OF STACK
$00C1
$00C2
•
•
•
•
•
•
5
4
3
2
1
STACKING
ORDER
1
2
3
4
5
Figure 6. Interrupt Stacking Order
Table 4. Reset/Interrupt Vector Addresses
FunctionSource
Power-On
Reset
RESET Pin
COP Watchdog
CONDITION CODE REGISTER
ACCUMULATOR
INDEX REGISTER
PROGRAM COUNTER (HIGH BYTE)
PROGRAM COUNTER (LOW BYTE)
•
•
•
Local
Mask
Global
Mask
None
None
(1)
None
None
Priority
(1 = Highest)
1
1
1
•
•
•
$00FD
$00FE
$00FF (TOP OF STACK)
Vector
Address
$1FFE–$1FFF
9-mc68hc705p9
Software
Interrupt
User CodeNoneNone
(SWI)
External
Interrupt
Timer
Interrupts
1. The COP watchdog is programmable in the mask option register.
The STOP instruction puts the MCU in its lowest power-consumption
mode and has the following effects on the MCU:
•Stops the internal oscillator, the CPU clock, and the internal clock,
turning off the capture/compare timer, the COP watchdog, the
SIOP, and the ADC
1-mc68hc705p9
•Clears the I bit in the condition code register, enabling external
interrupts
•Clears the ICIE, OCIE, and TOIE bits in the timer control register,
disabling further timer interrupts
The STOP instruction does not affect any other registers or any I/O lines.
The following events bring the MCU out of stop mode:
•An external interrupt signal on the
transition on the
contents of locations $1FFA and $1FFB. The timer resumes
counting from the last value before the STOP instruction.
•External reset — A logic zero on the
and loads the program counter with the contents of locations
$1FFE and $1FFF. The timer begins counting from $FFFC.
IRQ/VPP pin loads the program counter with the
IRQ/VPP pin — A high-to-low
RESET pin resets the MCU
MOTOROLALow-Power Modes65
Page 66
Low-Power Modes
When the MCU exits stop mode, processing resumes after a
stabilization delay of 4064 oscillator cycles.
An active edge on the PD7/TCAP pin during stop mode sets the ICF flag
when an external interrupt brings the MCU out of stop mode. An external
interrupt also latches the value in the timer registers into the input
capture registers.
If a reset brings the MCU out of stop mode, then an active edge on the
PD7/TCAP pin during stop mode has no effect on the ICF flag or the
input capture registers.
See Figure 1 for stop recovery timing information.
OSC
(NOTE 1)
RESET
Stop Mode
t
RL
t
IRQ/V
PP
(NOTE 2)
IRQ/V
PP
(NOTE 3)
INTERNAL
CLOCK
INTERNAL
ADDRESS
BUS
NOTES:
1. Internal clocking from OSC1 pin
2. Edge-triggered external interrupt mask option
3. Edge- and level-triggered external interrupt mask option
4. Reset vector shown as example
ILIH
4064 t
CYC
1FFE
(NOTE 4)
1FFE1FFE1FFE1FFE1FFF
Figure 1. Stop Recovery Timing
RESET OR INTERRUPT
VECTOR FETCH
2-mc68hc705p9
66Low-Power ModesMOTOROLA
Page 67
Low-Power Modes
Stop Mode
Figure 2 shows the sequence of events caused by the STOP instruction.
STOP
CLEAR I BIT IN CCR
CLEAR TIMER INTERRUPT FLAGS AND TIMER INTERRUPT ENABLE BITS
CLEAR TIMER PRESCALER
TURN OFF OSCILLATOR
NO
NO
EXTERNAL
INTERRUPT?
YES
(1) LOAD PC WITH RESET VECTOR
(2) SERVICE INTERRUPT
a. SAVE CPU REGISTERS ON STACK
b. SET I BIT IN CCR
c. LOAD PC WITH INTERRUPT VECTOR
RESET?
YES
TURN ON OSCILLATOR
DELAY 4064 CYCLES
TO STABILIZE
OR
Figure 2. STOP Instruction Flowchart
3-mc68hc705p9
MOTOROLALow-Power Modes67
Page 68
Low-Power Modes
Wait Mode
Wait Mode
The WAIT instruction puts the MCU in an intermediate
power-consumption mode and has the following effects on the MCU:
•Clears the I bit in the condition code register, enabling interrupts
•Stops the CPU clock, but allows the internal clock to drive the
capture/compare timer, the COP watchdog, and the ADC
The WAIT instruction does not affect any other registers or any I/O lines.
The following conditions restart the CPU clock and bring the MCU out of
wait mode:
•External interrupt — A high-to-low transition on the IRQ/VPP pin
loads the program counter with the contents of locations $1FFA
and $1FFB.
•Timer interrupt — Input capture, output compare, and timer
overflow interrupt requests load the program counter with the
contents of locations $1FF8 and $1FF9.
•COP watchdog reset — A timeout of the COP watchdog resets the
MCU and loads the program counter with the contents of locations
$1FFE and $1FFF. Software can enable timer interrupts so that
the MCU can periodically exit wait mode to reset the COP
watchdog.
•External reset — A logic zero on the
RESET pin resets the MCU
and loads the program counter with the contents of locations
$1FFE and $1FFF.
4-mc68hc705p9
68Low-Power ModesMOTOROLA
Page 69
Low-Power Modes
Wait Mode
Figure 3 shows the sequence of events caused by the WAIT instruction.
WAIT
CLEAR I BIT IN CCR
STOP CPU CLOCK
RESET?
YES
YES
YES
RESTART CPU CLOCK
(1) FETCH RESET VECTOR
OR
(2) SERVICE INTERRUPT
a. SAVE CPU REGISTERS ON STACK
b. SET I BIT IN CCR
c. VECTOR TO INTERRUPT SERVICE ROUTINE
OTHER ON-CHIP
NO
EXTERNAL
INTERRUPT?
NO
TIMER
INTERRUPT?
NO
INTERRUPT
SOURCES?
NO
Figure 3. WAIT Instruction Flowchart
5-mc68hc705p9
MOTOROLALow-Power Modes69
Page 70
Low-Power Modes
Figure 4 shows the effect of the STOP and WAIT instructions on the
CPU clock and the timer clock.
Data-Retention Mode
In data-retention mode, the MCU retains RAM contents and CPU
register contents at V
feature allows the MCU to remain in a low-power consumption state
during which it retains data, but the CPU cannot execute instructions.
Data Direction Register D (DDRD) . . . . . . . . . . . . . . . . . . . . . . . . .83
1-mc68hc705p9
MOTOROLAParallel I/O Ports71
Page 72
Parallel I/O Ports
Introduction
Introduction
Twenty bidirectional pins and one input-only pin form four parallel
input/output (I/O) ports. All the bidirectional port pins are programmable
as inputs or outputs.
NOTE:
Connect any unused I/O pins to an appropriate logic level, either VDD or
V
. Although the I/O ports do not require termination for proper
SS
operation, termination reduces excess current consumption and the
possibility of electrostatic damage.
Addr.Name:R/WBit 7654321Bit 0
$0000Port A Data Register (PORTA)
$0001Port B Data Register (PORTB)
$0002Port C Data Register (PORTC)
$0003Port D Data Register (PORTD)
Read:
Write:
Reset:Unaffected by reset
Read:
Write:
Reset:Unaffected by reset
Read:
Write:
Reset:Unaffected by reset
Read:
Write:
Reset:Unaffected by reset
PA7PA6PA5PA4PA3PA2PA1PA0
PB7PB6PB5
PC7PC6PC5PC4PC3PC2PC1PC0
PD7
0
PD5
00000
10000
$0004 Data Direction Register A (DDRA)
$0005 Data Direction Register B (DDRB)
Read:
DDRA7 DDRA6 DDRA5 DDRA4 DDRA3 DDRA2 DDRA1 DDRA0
Write:
Reset:00000000
Read:
DDRB7 DDRB6 DDRB5
Write:
Reset:00000000
= Unimplemented
00000
Figure 1. Parallel I/O Port Register Summary
2-mc68hc705p9
72Parallel I/O PortsMOTOROLA
Page 73
Parallel I/O Ports
Port A
Addr.Name:R/WBit 7654321Bit 0
$0006 Data Direction Register C (DDRC)
Read:
DDRC7 DDRC6 DDRC5 DDRC4 DDRC3 DDRC2 DDRC1 DDRC0
Write:
Reset:00000000
$0007 Data Direction Register D (DDRD)
Figure 1. Parallel I/O Port Register Summary (Continued)
Port A
Port A Data
Register (PORTA)
Read:00
Write:
Reset:00000000
= Unimplemented
DDRD5
00000
Port A is an 8-bit general-purpose I/O port.
The port A data register contains a latch for each of the eight port A pins.
$0000Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
PA7PA6PA5PA4PA3PA2PA1PA0
Figure 2. Port A Data Register (PORTA)
PA[7:0] — Port A Data Bits
These read/write bits are software programmable. Data direction of
each port A pin is under the control of the corresponding bit in data
direction register A. Reset has no effect on port A data.
3-mc68hc705p9
MOTOROLAParallel I/O Ports73
Page 74
Parallel I/O Ports
INTERNAL DATA BUS
Port A
Data Direction
Register A (DDRA)
NOTE:
Data direction register A determines whether each port A pin is an input
or an output.
$0004Bit 7654321Bit 0
Read:
DDRA7DDRA6DDRA5DDRA4DDRA3DDRA2DDRA1DDRA0
Write:
Reset:00000000
Figure 3. Data Direction Register A (DDRA)
DDRA[7:0] — Data Direction Register A Bits
These read/write bits control port A data direction. Reset clears
DDRA[7:0], configuring all eight port A pins as inputs.
1 = Corresponding port A pin configured as output
0 = Corresponding port A pin configured as input
Avoid glitches on port A pins by writing to the port A data register before
changing data direction register A bits from 0 to 1.
Figure 4 shows the I/O logic of port A.
READ DATA DIRECTION REGISTER A ($0004)
WRITE DATA DIRECTION REGISTER A ($0004)
RESET
WRITE PORT A DATA REGISTER ($0000)
READ PORT A DATA REGISTER ($0000)
Figure 4. Port A I/O Circuit
DDRAx
PAx
PAx
4-mc68hc705p9
74Parallel I/O PortsMOTOROLA
Page 75
Parallel I/O Ports
Port A
Writing a logic one to a DDRA bit enables the output buffer for the
corresponding port A pin; a logic zero disables the output buffer.
When bit DDRAx is a logic one, reading address $0000 reads the PAx
data latch. When bit DDRAx is a logic zero, reading address $0000
reads the voltage level on the pin. The data latch can always be written,
regardless of the state of its data direction bit. Table 1 summarizes the
operation of the port A pins.
Table 1. Port A Pin Operation
Accesses to Data Bit
Data Direction BitI/O Pin Mode
ReadWrite
0Input, Hi-Z
1OutputLatchLatch
(1)
PinLatch
(2)
1. Hi-Z = high impedance
2. Writing affects data register, but does not affect input.
5-mc68hc705p9
MOTOROLAParallel I/O Ports75
Page 76
Port B
Parallel I/O Ports
Port B is a 3-bit I/O port that shares its pins with the serial I/O port
(SIOP).
Port B
NOTE:
Port B Data
Register (PORTB)
Do not use port B for general-purpose I/O while the SIOP is enabled.
The port B data register contains a latch for each of the three port B pins.
$0001Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
Alternate
Function:
PB7PB6PB5
SCKSDISDO
= Unimplemented
00000
Figure 5. Port B Data Register (PORTB)
PB[7:5] — Port B Data Bits
These read/write bits are software programmable bits. Data direction
of each port B pin is under the control of the corresponding bit in data
direction register B. Reset has no effect on port B data.
NOTE:
Writing to data direction register B does not affect the data direction of
port B pins that are being used by the SIOP. However, data direction
register B always determines whether reading port B returns the states
of the latches or the states of the pins.
SCK — Serial Clock
When the SIOP is enabled, SCK is the SIOP clock output (in master
mode) or the SIOP clock input (in slave mode).
6-mc68hc705p9
76Parallel I/O PortsMOTOROLA
Page 77
SDI — Serial Data Input
When the SIOP is enabled, SDI is the SIOP data input.
SDO — Serial Data Output
When the SIOP is enabled, SDO is the SIOP data output.
Parallel I/O Ports
Port B
Data Direction
Register B (DDRB)
NOTE:
Data direction register B determines whether each port B pin is an input
or an output.
Enabling and then disabling the SIOP configures data direction register
B for SIOP operation and can also change the port B data register. After
disabling the SIOP, initialize data direction register B and the port B data
register as your application requires.
$0005Bit 7654321Bit 0
Read:
DDRB7DDRB6DDRB5
Write:
Reset:00000000
= Unimplemented
00000
Figure 6. Data Direction Register B (DDRB)
DDRB[7:5] — Data Direction Register B Bits
These read/write bits control port B data direction. Reset clears
DDRB[7:5], configuring all three port B pins as inputs.
1 = Corresponding port B pin configured as output
0 = Corresponding port B pin configured as input
NOTE:
Avoid glitches on port B pins by writing to the port B data register before
changing data direction register B bits from 0 to 1.
Figure 7 shows the I/O logic of port B.
7-mc68hc705p9
MOTOROLAParallel I/O Ports77
Page 78
Parallel I/O Ports
INTERNAL DATA BUS
Port B
READ DATA DIRECTION REGISTER B ($0005)
WRITE DATA DIRECTION REGISTER B ($0005)
RESET
DDRBx
WRITE PORT B DATA REGISTER ($0001)
READ PORT B DATA REGISTER ($0001)
PBx
Figure 7. Port B I/O Logic
Writing a logic one to a DDRB bit enables the output buffer for the
corresponding port B pin; a logic zero disables the output buffer.
When bit DDRBx is a logic one, reading address $0001 reads the PBx
data latch. When bit DDRBx is a logic zero, reading address $0001
reads the voltage level on the pin. The data latch can always be written,
regardless of the state of its data direction bit. Table 1 summarizes the
operation of the port B pins.
Table 2. Port B Pin Operation
Accesses to Data Bit
Data Direction BitI/O Pin Mode
ReadWrite
0Input, Hi-Z
(1)
PinLatch
(2)
PBx
1OutputLatchLatch
1. Hi-Z = high impedance
2. Writing affects data register, but does not affect input.
8-mc68hc705p9
78Parallel I/O PortsMOTOROLA
Page 79
Port C
Parallel I/O Ports
Port C
Port C is an 8-bit I/O port that shares five of its pins with the A/D
converter (ADC). The five shared pins are available for general-purpose
I/O functions when the ADC is disabled.
Port C Data
Register (PORTC)
The port C data register contains a latch for each of the eight port C pins.
$0002Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
Alternate
Function:
PC7PC6PC5PC4PC3PC2PC1PC0
V
RH
AN0AN1AN2AN3
Figure 8. Port C Data Register (PORTC)
PC[7:0] — Port C Data Bits
These read/write bits are software programmable. Data direction of
each port C pin is under the control of the corresponding bit in data
direction register C. Reset has no effect on port C data.
V
— Voltage Reference High Bit
RH
When the ADC is turned on, the PC7/VRH pin is the positive ADC
reference voltage.
AN[3:0] — Analog Input Bits
When the ADC is turned on, the AN0–AN3 pins are
software-selectable analog inputs. Unused analog inputs can be used
as digital inputs, but pins PC3/AN3, PC4/AN2, PC5/AN1, and
PC6/AN0 cannot be used as digital outputs while the ADC is on. Only
pins PC0, PC1, and PC2 can be used as digital outputs when the
ADC is on.
9-mc68hc705p9
MOTOROLAParallel I/O Ports79
Page 80
Parallel I/O Ports
The port C data register reads normally while the ADC is on, except
that the bit corresponding to the currently selected ADC input pin
reads as logic zero.
Writing to bits PC7–PC3 while the ADC is on can produce
unpredictable ADC results.
Port C
Data Direction
Register C (DDRC)
NOTE:
Data direction register C determines whether each port C pin is an input
or an output.
$0006Bit 7654321Bit 0
Read:
DDRC7DDRC6DDRC5DDRC4DDRC3DDRC2DDRC1DDRC0
Write:
Reset:00000000
Figure 9. Data Direction Register C (DDRC)
DDRC[7:0] — Data Direction Register C Bits
These read/write bits control port C data direction. Reset clears
DDRC[7:0], configuring all port C pins as inputs.
1 = Corresponding port C pin configured as output
0 = Corresponding port C pin configured as input
Avoid glitches on port C pins by writing to the port C data register before
changing data direction register C bits from 0 to 1.
Writing to bits DDRC7–DDRC3 while the ADC is on can produce
unpredictable ADC results.
Figure 10 shows the I/O logic of port C.
10-mc68hc705p9
80Parallel I/O PortsMOTOROLA
Page 81
READ DATA DIRECTION REGISTER C ($0006)
INTERNAL DATA BUS
WRITE DATA DIRECTION REGISTER C ($0006)
RESET
Parallel I/O Ports
Port C
DDRCx
WRITE PORT C DATA REGISTER ($0002)
READ PORT C DATA REGISTER ($0002)
PCx
Figure 10. Port C I/O Logic
Writing a logic one to a DDRC bit enables the output buffer for the
corresponding port C pin; a logic zero disables the output buffer.
When bit DDRCx is a logic one, reading address $0002 reads the PCx
data latch. When bit DDRCx is a logic zero, reading address $0002
reads the voltage level on the pin. The data latch can always be written,
regardless of the state of its data direction bit. Table 1 summarizes the
operation of the port C pins.
Table 3. Port C Pin Operation
Accesses to Data Bit
Data Direction BitI/O Pin Mode
ReadWrite
0Input, Hi-Z
(1)
PinLatch
(2)
PCx
1OutputLatchLatch
1. Hi-Z = high impedance
2. Writing affects data register, but does not affect input.
11-mc68hc705p9
MOTOROLAParallel I/O Ports81
Page 82
Port D
Parallel I/O Ports
Port D is a 2-bit port with one I/O pin and one input-only pin. Port D
shares the input-only pin, PD7/TCAP, with the capture/compare timer.
PD7/TCAP is the timer input capture pin. The PD7/TCAP pin can always
be a general-purpose input, even if input capture interrupts are enabled.
Port D
Port D Data
Register (PORTD)
The port D data register contains a latch for each of the two port D pins.
$0003Bit 7654321Bit 0
Read:
Write:
Reset:Unaffected by reset
Alternate
Function:
PD7
TCAP
0
PD5
= Unimplemented
10000
Figure 11. Port D Data Register (PORTD)
PD7 and PD5 — Port D Data Bits
These read/write bits are software programmable. Data direction of
each port D pin is under the control of the corresponding bit in data
direction register D. Reset has no effect on port D data.
TCAP — Timer Capture
TCAP is the input capture pin for the timer.
12-mc68hc705p9
82Parallel I/O PortsMOTOROLA
Page 83
Parallel I/O Ports
INTERNAL DATA BUS
Port D
Data Direction
Register D (DDRD)
NOTE:
Data direction register D determines whether each port D pin is an input
or an output.
$0007Bit 7654321Bit 0
Read:00
DDRD5
Write:
Reset:00000000
= Unimplemented
00000
Figure 12. Data Direction Register D (DDRD)
DDRD5 — Data Direction Register D Bit
This read/write bit controls the data direction of pin PD5. Reset clears
DDRD5, configuring PD5 as an input.
1 = PD5 configured as output
0 = PD5 configured as input
Avoid glitches on port D pins by writing to the port D data register before
changing data direction register D bits from 0 to 1.
Figure 13 shows the I/O logic of port D.
READ DATA DIRECTION REGISTER D ($0007)
WRITE DATA DIRECTION REGISTER D ($0007)
RESET
WRITE PORT D DATA REGISTER ($0003)
READ PORT D DATA REGISTER ($0003)
DDRDx
PDx
Figure 13. Port D I/O Logic
Writing a logic one to a DDRD bit enables the output buffer for the
corresponding port D pin; a logic zero disables the output buffer.
PDx
13-mc68hc705p9
MOTOROLAParallel I/O Ports83
Page 84
Parallel I/O Ports
When bit DDRDx is a logic one, reading address $0003 reads the PDx
data latch. When bit DDRDx is a logic zero, reading address $0003
reads the voltage level on the pin. The data latch can always be written,
regardless of the state of its data direction bit. Table 1 summarizes the
operation of the port D pins.
Port D
Table 4. Port D Pin Operation
Accesses to Data Bit
Data Direction BitI/O Pin Mode
ReadWrite
0Input, Hi-Z
1OutputLatchLatch
1. Hi-Z = high impedance
2. Writing affects data register, but does not affect input.
•65.5-ms timeout period (with 2-MHz bus frequency)
•Wait mode operation
MOTOROLACOP85
Page 86
Introduction
Operation
COP
Introduction
The purpose of the computer operating properly (COP) watchdog is to
reset the MCU in case of software failure. Software that is operating
properly periodically services the COP watchdog and prevents the reset
from occurring. The COP watchdog function is programmable in the
mask option register.
COP Watchdog
Timeout
NOTE:
COP Watchdog
Timeout Period
The COP watchdog is a 16-bit counter that generates a reset if allowed
to time out. Periodically clearing the counter starts a new timeout period
and prevents the COP from resetting the MCU. A COP watchdog
timeout indicates that the software is not executing instructions in the
correct sequence.
The internal clock drives the COP watchdog. Therefore, the COP
watchdog cannot generate a reset for errors that cause the internal clock
to stop.
The COP watchdog also depends on a power supply voltage at or above
a minimum specification and is not guaranteed to protect against
brownout. For information about brownout protection, see the Resets
and Interrupts section.
Use the following formula to calculate the COP timeout period:
COP Timeout Period
131 072 cycles,
---------------------------------------=
f
BUS
where
f
BUS
86COPMOTOROLA
crystal frequency
-------------------------------------------- -=
2
2-cop0cop
Page 87
COP
Interrupts
Clearing the COP
Watchdog
NOTE:
Interrupts
To clear the COP watchdog and prevent a COP reset, write a logic zero
to bit 0 (COPC) of the COP register at location $1FF0.
If the main program executes within the COP timeout period, the clearing
routine needs to be executed only once. If the main program takes
longer than the COP timeout period, the clearing routine must be
executed more than once.
Place the clearing routine in the main program and not in an interrupt
routine. Clearing the COP watchdog in an interrupt routine might prevent
COP watchdog timeouts even though the main program is not operating
properly.
The COP watchdog does not generate interrupts.
COP Register
The COP register is a write-only register that returns the contents of
EPROM location $1FF0 when read.
$1FF0Bit 7654321Bit 0
Read:D7D6D5D4D3D2D1D0
Write:
Reset:UUUUUUU0
= UnimplementedU = Unaffected
COPC
Figure 1. COP Register (COPR)
COPC — COP Clear
COPC is a write-only bit. Periodically writing a logic zero to COPC
prevents the COP watchdog from resetting the MCU. Reset clears the
COPC bit.
3-cop0cop
MOTOROLACOP87
Page 88
COP
Low-Power Modes
Low-Power Modes
The STOP and WAIT instructions put the MCU in low-power
consumption standby modes.
Stop ModeThe STOP instruction clears the COP watchdog counter. Upon exit from
stop mode by external reset:
•The counter begins counting from $0000.
•The counter is cleared again after the 4064-cycle oscillator
stabilization delay.
Upon exit from stop mode by external interrupt:
•The counter begins counting from $0000.
•The counter is
not
cleared again after the oscillator stabilization
delay and has a count of 4064 when the program resumes.
Wait ModeThe COP watchdog continues to operate normally after a WAIT
instruction. Software should periodically take the MCU out of wait mode
and write to the COPC bit to prevent a COP watchdog timeout.
•Interrupt-Driven Operation with Three Maskable Interrupt Flags:
–Input Capture
–Output Compare
–Timer Overflow
Features
The timer provides a timing reference for MCU operations. The input
capture and output compare functions provide a means to latch the
times at which external events occur, to measure input waveforms, and
to generate output waveforms and timing delays. Figure 1 shows the
structure of the timer module.
2-tim1ic1oc_a
90TimerMOTOROLA
Page 91
TCAP
EDGE
SELECT/
DETECT
LOGIC
Timer
Introduction
ICRHICRL
INTERNAL
CLOCK
(XTAL ÷ 2)
÷ 4
INTERNAL
DATA BUS
IEDG
TRHTRL
16-BIT COUNTER
16-BIT COMPARATOR
OCRHOCRL
TIMER OVERFLOW
OCIE
OCF
TOIE
TOF
ICIE
ICF
PIN
CONTROL
LOGIC
OLVL
TIMER
INTERRUPT
REQUEST
ATRLATRH
TCMP
Figure 1. Timer Block Diagram
3-tim1ic1oc_a
MOTOROLATimer91
Page 92
Timer
Addr.NameR/WBit 7654321Bit 0
$0012Timer Control Register (TCR)
Introduction
Read:
Write:
Reset:000000U0
ICIEOCIETOIE000IEDGOLVL
$0013Timer Status Register (TSR)
$0014Input Capture Register High (ICRH)
$0015Input Capture Register Low (ICRL)
$0016 Output Compare Register High (OCRH)
$0017Output Compare Register Low (OCRL)
$0018Timer Register High (TRH)
Read:ICFOCFTOF00000
Write:
Reset:UUU00000
Read:Bit 1514131211109Bit 8
Write:
Reset:Unaffected by reset
Read:Bit 7654321Bit 0
Write:
Reset:Unaffected by reset
Read:
Write:
Reset:Unaffected by reset
Read:
Write:
Reset:Unaffected by reset
Read:Bit 1514131211109Bit 8
Write:
Reset:Reset initializes TRH to $FF
Bit 1514131211109Bit 8
Bit 7654321Bit 0
$0019Timer Register Low (TRL)
$001AAlternate Timer Register High (ATRH)
$001BAlternate Timer Register Low (ATRL)
Read:Bit 7654321Bit 0
Write:
Reset:Reset initializes TRL to $FC
Read:Bit 1514131211109Bit 8
Write:
Reset:Reset initializes ATRH to $FF
Read:Bit 7654321Bit 0
Write:
Reset:Reset initializes ATRL to $FC
= UnimplementedU = Unaffected
Figure 2. Timer I/O Register Summary
4-tim1ic1oc_a
92TimerMOTOROLA
Page 93
Operation
Operation
The timing reference for the input capture and output compare functions
is a 16-bit free-running counter. The counter is preceded by a divide-byfour prescaler and rolls over every 2
MHz crystal is 2 µs. Software can read the value in the counter at any
time without affecting the counter sequence.
Because of the 16-bit timer architecture, the I/O registers for the input
capture and output compare functions are pairs of 8-bit registers.
Pin FunctionsThe timer uses two pins.
PD7/TCAPPD7/TCAP is the input capture pin. When an active edge occurs on
PD7/TCAP, the timer transfers the current counter value to the input
capture registers. PD7/TCAP is also an I/O port pin.
18
cycles. Timer resolution with a 4-
Timer
TCMPTCMP is the output-only output compare pin. When the counter value
matches the value written in the output compare registers, the timer
transfers the output level bit, OLVL, to the TCMP pin.
Input CaptureThe input capture function is a means to record the time at which an
external event occurs. When the input capture circuitry detects an active
edge on the PD7/TCAP pin, it latches the contents of the timer registers
into the input capture registers. The polarity of the active edge is
programmable.
Latching values into the input capture registers at successive edges of
the same polarity measures the period of the input signal on the
PD7/TCAP pin. Latching the counter values at successive edges of
opposite polarity measures the pulse width of the signal.Figure 3 shows
the logic of the input capture function.
5-tim1ic1oc_a
MOTOROLATimer93
Page 94
Timer
Operation
EDGE
TCAP
SELECT/
DETECT
LOGIC
ICRHICRL
IEDG
ICIE
TRH
ICF
TIMER
INTERRUPT
REQUEST
TRL
Figure 3. Input Capture Operation
Output CompareThe output compare function is a means of generating an output signal
when the 16-bit counter reaches a selected value. Software writes the
selected value into the output compare registers. On every fourth
internal clock cycle the output compare circuitry compares the value of
the counter to the value written in the output compare registers. When a
match occurs, the timer transfers the programmable output level bit
(OLVL) from the timer control register to the TCMP pin.
Software can use the output compare register to measure time periods,
to generate timing delays, or to generate a pulse of specific duration or
a pulse train of specific frequency and duty cycle on the TCMP pin.
Figure 4 shows the logic of the output compare function.
16-BIT COUNTER
PIN
16-BIT COMPARATOR
OCRH ($0016)OCRL ($0017)
OCF
OCIE
CONTROL
LOGIC
OLVL
TCMP
TIMER
INTERRUPT
REQUEST
Figure 4. Output Compare Operation
6-tim1ic1oc_a
94TimerMOTOROLA
Page 95
Timing
Timer
Timing
Table 1. Timer Characteristics (V
= 5.0 Vdc)
DD
CharacteristicSymbolMinMaxUnit
Timer Resolution
Input Capture Pulse WidthtH, t
Input Capture Pulse Periodt
1. VDD = 5.0 Vdc ± 10%, TA = TL to TH unless otherwise noted.
2. A 2-bit prescaler in the timer is the limiting factor as it counts 4 t
3. The minimum t
plus 19 t
CYC
(2)
should not be less than the number of interrupt service routine cycles
TLTL
.
t
RESL
TLTL
L
Table 2. Timer Characteristics (VDD = 3.3 Vdc)
CharacteristicSymbolMinMaxUnit
Timer Resolution
Input Capture Pulse WidthtH, t
Input Capture Pulse Periodt
(2)
t
RESL
TLTL
L
(1)
4.0—t
CYC
125—ns
Note
(3)
CYC
.
—t
CYC
(1)
4.0—t
CYC
250—ns
Note
(3)
—t
CYC
7-tim1ic1oc_a
= 3.3 Vdc ± 10%, TA = TL to TH unless otherwise noted.
1. V
DD
2. A 2-bit prescaler in the timer is the limiting factor as it counts 4 t
3. The minimum t
plus 19 t
CYC
should not be less than the number of interrupt service routine cycles
TLTL
.
t
TLTL
t
TH
Figure 5. Input Capture Characteristics
CYC
.
t
TL
MOTOROLATimer95
Page 96
Timer
R
INTERNAL
INTERNAL
BUS CLOCK
INTERNAL
RESET
TIMER
CLOCKS
COUNTER
ESET (EXTERNAL
OR END OF POR)
T00
T01
T10
T11
16-BIT
Timing
$FFFC
$FFFD
Figure 6. Timer Reset Timing
$FFFE$FFFF
BUS CLOCK
T00
T01
TIMER
CLOCKS
INPUT CAPTURE
INPUT CAPTURE
INPUT CAPTURE
INPUT CAPTURE
NOTE:
T10
T11
16-BIT
COUNTER
REGISTER
If the input capture edge occurs in the shaded area between T10 states, then the input capture
flag becomes set during the next T11 state.
$FFEB$FFED$FFEE
EDGE
LATCH
PREVIOUSLY CAPTURED VALUE$FFED
FLAG
$FFEC
Figure 7. Input Capture Timing
$FFEF
8-tim1ic1oc_a
96TimerMOTOROLA
Page 97
INTERNAL
BUS CLOCK
TIMER
CLOCKS
Timer
Timing
T00
T01
T10
T11
16-BIT
COUNTER
OUTPUT COMPARE
REGISTERS
COMPARE
REGISTER LATCH
OUTPUT COMP ARE
FLAG AND TCMP
NOTES:
1. A write to the output compare registers may occur at any time, but a compare only occurs at
timer state T01. Therefore, the compare may follow the write by up to four cycles.
2. The output compare flag is set at the timer state T11 that follows the comparison latch.
$FFEB$FFED$FFEE
$FFEC
CPU WRITES $FFED
$FFED
Figure 8. Output Compare Timing
INTERNAL
BUS CLOCK
T00
T01
TIMER
CLOCKS
T10
T11
16-BIT
COUNTER
$FFFF$0001$0002
$0000
$FFEF
OVERFLOW
FLAG (TOF)
Figure 9. Timer Overflow Timing
9-tim1ic1oc_a
MOTOROLATimer97
Page 98
Interrupts
Timer
Interrupts
The following timer sources can generate interrupts:
•Input capture flag (ICF) — The ICF bit is set when an edge of the
selected polarity occurs on the input capture pin. The input
capture interrupt enable bit, ICIE, enables ICF interrupt requests.
•Output compare flag (OCF) — The OCF bit is set when the
counter value matches the value written in the output compare
registers. The output compare interrupt enable bit, OCIE, enables
OCF interrupt requests.
•Timer overflow flag (TOF) — The TOF bit is set when the counter
value rolls over from $FFFF to $0000. The timer overflow enable
bit (TOIE) enables timer overflow interrupt requests.
I/O Registers
Table 3 summarizes the timer interrupt sources.
Table 3. Timer Interrupt Sources
SourceLocal Mask
ICF Bit
OCF Bit
TOF Bit
ICIE Bit
OCIE Bit
TOIE Bit
Global
Mask
I Bit3
Priority
(1 = Highest)
The following registers control and monitor the operation of the timer:
•Timer control register (TCR)
•Timer status register (TSR)
•Timer registers (TRH and TRL)
•Alternate timer registers (ATRH and ATRL)
•Input capture registers (ICRH and ICRL)
•Output compare registers (OCRH and OCRL)
10-tim1ic1oc_a
98TimerMOTOROLA
Page 99
Timer
I/O Registers
Timer Control
Register
The timer control register (TCR) performs the following functions:
•Enables input capture interrupts
•Enables output compare interrupts
•Enables timer overflow interrupts
•Controls the active edge polarity of the TCAP signal
•Controls the active level of the TCMP output
$0012Bit 7654321Bit 0
Read:
ICIEOCIETOIE000IEDGOLVL
Write:
Reset:000000U0
U = Unaffected
Figure 10. Timer Control Register (TCR)
ICIE — Input Capture Interrupt Enable
This read/write bit enables interrupts caused by an active signal on
the PD7/TCAP pin. Reset clears the ICIE bit.
These are read/write bits that always read as logic zeros.
11-tim1ic1oc_a
MOTOROLATimer99
Page 100
Timer
I/O Registers
IEDG — Input Edge
The state of this read/write bit determines whether a positive or
negative transition on the PD7/TCAP pin triggers a transfer of the
contents of the timer registers to the input capture registers. Reset
has no effect on the IEDG bit.
The state of this read/write bit determines whether a logic one or a
logic zero appears on the TCMP pin when a successful output
compare occurs. Reset clears the OLVL bit.
1 = TCMP goes high on output compare
0 = TCMP goes low on output compare
Timer Status
Register
The timer status register (TSR) contains flags for the following events:
•An active signal on the PD7/TCAP pin, transferring the contents of
the timer registers to the input capture registers
•A match between the 16-bit counter and the output compare
registers, transferring the OLVL bit to the TCMP pin
•A timer rollover from $FFFF to $0000
$0013Bit 7654321Bit 0
Read:
Write:
Reset:UUU00000
ICFOCFTOF00000
= UnimplementedU = Unaffected
Figure 11. Timer Status Register (TSR)
12-tim1ic1oc_a
100TimerMOTOROLA
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.