1. Hitachi neither warrants nor grants licenses of any rights of Hitachi’s or any third party’s
patent, copyright, trademark, or other intellectual property rights for information contained in
this document. Hitachi bears no responsibility for problems that may arise with third party’s
rights, including intellectual property rights, in connection with use of the information
contained in this document.
2. Products and product specifications may be subject to change without notice. Confirm that you
have received the latest product standards or specifications before final design, purchase or
use.
3. Hitachi makes every attempt to ensure that its products are of high quality and reliability.
However, contact Hitachi’s sales office before using the product in an application that
demands especially high quality and reliability or where its failure or malfunction may directly
threaten human life or cause risk of bodily injury, such as aerospace, aeronautics, nuclear
power, combustion control, transportation, traffic, safety equipment or medical equipment for
life support.
4. Design your application so that the product is used within the ranges guaranteed by Hitachi
particularly for maximum rating, operating supply voltage range, heat radiation characteristics,
installation conditions and other characteristics. Hitachi bears no responsibility for failure or
damage when used beyond the guaranteed ranges. Even within the guaranteed ranges,
consider normally foreseeable failure rates or failure modes in semiconductor devices and
employ systemic measures such as fail-safes, so that the equipment incorporating Hitachi
product does not cause bodily injury, fire or other consequential damage due to operation of
the Hitachi product.
5. This product is not designed to be radiation resistant.
6. No one is permitted to reproduce or duplicate, in any form, the whole or part of this document
without written approval from Hitachi.
7. Contact Hitachi’s sales office for any questions regarding this document or Hitachi
semiconductor products.
Page 3
Preface
The H8/3022 Series comprises high-performance single-chip microcomputers (MCUs) that
integrate system supporting functions together with an H8/300H CPU core.
The H8/300H CPU has a 32-bit internal architecture with sixteen 16-bit general registers, and a
concise, optimized instruction set designed for speed. It can address a 16-Mbyte linear address
space.
The on-chip system supporting functions include ROM, RAM, a 16-bit integrated timer unit
(ITU), a programmable timing pattern controller (TPC), a watchdog timer (WDT), a serial
communication interface (SCI), an A/D converter, I/O ports, and other facilities. Of the two SCI
channels, one has been expanded to support the ISO/IEC 7816-3 smart card interface. Functions
have also been added to reduce power consumption in battery-powered applications: individual
modules can be placed in standby, and the frequency of the system clock supplied to the chip can
be divided down under software control.
The five MCU operating modes offer a choice of expanded mode, single-chip mode, and address
space size, enabling the H8/3022 Series to adapt quickly and flexibly to a variety of conditions.
In addition to its masked-ROM versions, the H8/3022 Series has an F-ZTATTM* version with user
programmable on-chip flash memory that can be programmed on-board. These versions enable
users to respond quickly and flexibly to changing application specifications.
This manual describes the H8/3022 Series hardware. For details of the instruction set, refer to the
H8/300H Series Programming Manual.
Appendix HComparison of H8/300H Series Product Specifications.................. 663
H.1Differences between H8/3039F and H8/3022F.................................................................. 663
xi
Page 15
Section 1 Overview
1.1 Overview
The H8/3022 Series comprises microcomputers (MCUs) that integrate system supporting
functions together with an H8/300H CPU core featuring an original Hitachi architecture.
The H8/300H CPU has a 32-bit internal architecture with sixteen 16-bit general registers, and a
concise, optimized instruction set designed for speed. It can address a 16-Mbyte linear address
space. Its instruction set is upward-compatible at the object-code level with the H8/300 CPU,
enabling easy porting of software from the H8/300 Series.
The on-chip system supporting functions include ROM, RAM, a 16-bit integrated timer unit
(ITU), a programmable timing pattern controller (TPC), a watchdog timer (WDT), a serial
communication interface (SCI), an A/D converter, I/O ports, and other facilities.
The H8/3022 Series consists of four models: the H8/3022 with 256 kbytes of ROM and 8 kbytes
of RAM, the H8/3021 with 192 kbytes of ROM and 8 kbytes of RAM, and the H8/3020 with 128
kbytes of ROM and 4 kbytes of RAM.
The five MCU operating modes offer a choice of expanded mode, single-chip mode and address
space size.
In addition to the masked-ROM version of the H8/3022 Series, an F-ZTATTM* version with an onchip flash memory that can be freely programmed and reprogrammed by the user after the board is
installed is also available. This version enables users to respond quickly and flexibly to changing
application specifications, growing production volumes, and other conditions.
Table 1-1 summarizes the features of the H8/3022 Series.
Note:*F-ZTAT (Flexible ZTAT) is a trademark of Hitachi, Ltd.
1
Page 16
Table 1-1 Features
FeatureDescription
CPUUpward-compatible with the H8/300 CPU at the object-code level
General-register machine
• Sixteen 16-bit general registers
(also useable as sixteen 8-bit registers or eight 32-bit registers)
High-speed operation
• Maximum clock rate: 18 MHz
• Add/subtract: 111 ns
• Multiply/divide: 778 ns
Two CPU operating modes
• Normal mode (64-kbyte address space)*
• Advanced mode (16-Mbyte address space)
Instruction features
• 8/16/32-bit data transfer, arithmetic, and logic instructions
• Signed and unsigned multiply instructions (8 bits × 8 bits, 16 bits × 16 bits)
• Signed and unsigned divide instructions (16 bits ÷ 8 bits, 32 bits ÷ 16 bits)
• Bit accumulator function
• Bit manipulation instructions with register-indirect specification of bit positions
MemoryH8/3022
• ROM: 256 kbytes
• RAM: 8 kbytes
H8/3021
• ROM: 192 kbytes
• RAM: 8 kbytes
H8/3020
• ROM: 128 kbytes
• RAM: 4 kbytes
Interrupt
controller
• Five external interrupt pins: NMI, IRQ0, IRQ1, IRQ4, IRQ
• 25 internal interrupts
• Three selectable interrupt priority levels
Bus controller
• Address space can be partitioned into eight areas, with independent bus
specifications in each area
• Two-state or three-state access selectable for each area
• Selection of four wait modes
5
2
Page 17
FeatureDescription
16-bit integrated
timer unit (ITU)
• Five 16-bit timer channels, capable of processing up to 12 pulse outputs or 10
pulse inputs
• 16-bit timer counter (channels 0 to 4)
• Two multiplexed output compare/input capture pins (channels 0 to 4)
• Operation can be synchronized (channels 0 to 4)
• PWM mode available (channels 0 to 4)
• Phase counting mode available (channel 2)
• Buffering available (channels 3 and 4)
• Reset-synchronized PWM mode available (channels 3 and 4)
• Complementary PWM mode available (channels 3 and 4)
Programmable
timing pattern
controller (TPC)
Watchdog timer
(WDT), 1 channel
Serial
communication
interface (SCI),
2 channels
A/D converter
I/O ports
• Maximum 15-bit pulse output, using ITU as time base
• Up to three 4-bit pulse output groups and one 3-bit pulse output group (or one 15-
bit group, one 8-bit group, or one 7-bit group)
• Non-overlap mode available
• Reset signal can be generated by overflow
• Reset signal can be output externally (However, not available with the F-ZTAT
version.)
• Usable as an interval timer
• Selection of asynchronous or synchronous mode
• Full duplex: can transmit and receive simultaneously
Reset output (Masked ROM version):
Outputs WDT-generated reset signal to an
external device.
Write enable signal (F-ZTAT version):
Flash memory write control signal.
STBY47InputStandby: When driven low, this pin forces a
transition to hardware standby mode
InterruptsNMI49InputNonmaskable interrupt: Requests a
nonmaskable interrupt
IRQ
, IRQ
5
IRQ
, IRQ
1
Address bus A23 to A20,
A
to A8,
19
A
to A
7
0
Data busD7 to D
0
72, 11,
4
69, 68
0
77 to 80,
42 to 31,
29 to 22
20 to 13Input/
InputInterrupt request 5, 4, 1, 0: Maskable
interrupt request pins
OutputAddress bus: Outputs address signals
Data bus: Bidirectional data bus
output
Bus controlAS54OutputAddress strobe: Goes low to indicate valid
address output on the address bus
RD55OutputRead: Goes low to indicate reading from the
external address space.
WR56OutputWrite: Goes low to indicate writing to the
external address space indicates valid data
on the data bus.
WAIT43InputWait: Requests insertion of wait states in
bus cycles during access to the external
address space
16-bit
integrated
timer unit
(ITU)
TCLKD to
TCLKA
TIOCA4 to
TIOCA
0
76 to 73InputClock input A to D: External clock inputs
3, 1, 79,
77, 75
Input/
Output
Input capture/output compare A4 to A0:
GRA4 to GRA0 output compare or input
capture, or PWM output
ADTRG8InputA/D trigger: External trigger input for
AV
AV
I/O portsP1
0
0
0
0
CC
SS
to P1
7
70, 9OutputTransmit data:(channels 0 and 1): SCI
data output
71, 10InputReceive data:(channels 0 and 1): SCI
data input
72, 11Input/
output
Serial clock:(channels 0 and 1): SCI clock
input/output
66 to 59InputAnalog 7 to 0: Analog input pins
starting A/D conversion
67InputPower supply pin and reference voltage
input pin for the A/D converter Connect to
the system power supply when not using
the A/D converter
58InputGround pin for the A/D converter. Connect
to system power-supply (0 V).
29 to 22Input/
0
output
Port 1: Eight input/output pins. The
direction of each pin can be selected in the
port 1 data direction register (P1DDR).
P27 to P2
P37 to P3
P53 to P5
P65 to P63,
P6
0
P77 to P7
P81, P8
0
38 to 31Input/
0
output
Port 2: Eight input/output pins. The
direction of each pin can be selected in the
port 2 data direction register (P2DDR).
20 to 13Input/
0
output
Port 3: Eight input/output pins. The
direction of each pin can be selected in the
port 3 data direction register (P3DDR).
42 to 39Input/
0
output
Port 5: Four input/output pins. The
direction of each pin can be selected in the
port 5 data direction register (P5DDR).
56 to 54,43Input/
output
Port 6: Four input/output pins. The
direction of each pin can be selected in the
port 6 data direction register (P6DDR).
66 to 59InputPort 7: Eight input pins
0
69, 68Input/
output
Port 8: Two input/output pins. The
direction of each pin can be selected in the
port 8 data direction register (P8DDR).
13
Page 28
TypeSymbolPin No.I/OName and Function
I/O portsP9
P9
PA7 to
PA
PB7, PB
to PB
5
0
0
to
72, 11
71, 10
70, 9
80 to 73Input/
Input/
output
output
Port 9: Six input/output pins. The direction
of each pin can be selected in the port 9
data direction register (P9DDR).
Port A: Eight input/output pins. The
direction of each pin can be selected in the
port A data direction register (PADDR).
8, 6 to 1Input/
5
0
output
Port B: Seven input/output pins. The
direction of each pin can be selected in the
port B data direction register (PBDDR).
14
Page 29
Section 2 CPU
2.1 Overview
The H8/300H CPU is a high-speed central processing unit with an internal 32-bit architecture that
is upward-compatible with the H8/300 CPU. The H8/300H CPU has sixteen 16-bit general
registers, can address a 16-Mbyte linear address space, and is ideal for realtime control.
2.1.1 Features
The H8/300H CPU has the following features.
• Upward compatibility with H8/300 CPU
Can execute H8/300 series object programs without alteration
• General-register architecture
Sixteen 16-bit general registers (also usable as sixteen 8-bit registers or eight 32-bit registers)
• Sixty-two basic instructions
8/16/32-bit arithmetic and logic instructions
Multiply and divide instructions
Powerful bit-manipulation instructions
• Eight addressing modes
Register direct [Rn]
Register indirect [@ERn]
Register indirect with displacement [@(d:16, ERn) or @(d:24, ERn)]
Register indirect with post-increment or pre-decrement [@ERn+ or @–ERn]
Absolute address [@aa:8, @aa:16, or @aa:24]
Immediate [#xx:8, #xx:16, or #xx:32]
Program-counter relative [@(d:8, PC) or @(d:16, PC)]
Memory indirect [@@aa:8]
• 16-Mbyte linear address space
15
Page 30
• High-speed operation
All frequently-used instructions execute in two to four states
Maximum clock frequency:18 MHz
8/16/32-bit register-register add/subtract:111 ns
8 × 8-bit register-register multiply:778 ns
16 ÷ 8-bit register-register divide:778 ns
16 × 16-bit register-register multiply:1222 ns
32 ÷ 16-bit register-register divide:1222 ns
• Two CPU operating modes
Normal mode (cannot be used with this LSI)
Advanced mode
• Low-power mode
Transition to power-down state by SLEEP instruction
2.1.2 Differences from H8/300 CPU
In comparison to the H8/300 CPU, the H8/300H has the following enhancements.
• More general registers
Eight 16-bit registers have been added.
• Expanded address space
Advanced mode supports a maximum 16-Mbyte address space.
Normal mode supports the same 64-kbyte address space as the H8/300 CPU.
• Enhanced addressing
The addressing modes have been enhanced to make effective use of the 16-Mbyte address
space.
• Enhanced instructions
Data transfer, arithmetic, and logic instructions can operate on 32-bit data.
Signed multiply/divide instructions and other instructions have been added.
16
Page 31
2.2 CPU Operating Modes
The H8/300H CPU has two operating modes: normal and advanced. Normal mode supports a
maximum 64-kbyte address space. Advanced mode supports up to 16 Mbytes. See figure 2-1.
Unless specified otherwise, all descriptions in this manual refer to advanced mode.
Normal mode
CPU operating modes
Advanced mode
Note: * Normal mode cannot be used with this LSI.
Figure 2-1 CPU Operating Modes
*
Maximum 64 kbytes, program
and data areas combined
Maximum 16 Mbytes, program
and data areas combined
17
Page 32
2.3 Address Space
The maximum address space of the H8/300H CPU is 16 Mbytes. This LSI allows selection of a
normal mode and advanced mode 1-Mbyte mode or 16-Mbyte mode for the address space
depending on the MCU operation mode. Figure 2-2 shows the address ranges of the H8/3022
Series. For further details see section 3.6, Memory Map in Each Operating Mode.
The 1-Mbyte operating mode uses 20-bit addressing. The upper 4 bits of effective addresses are
ignored.
H'00000
H'FFFFF
(64-Kbyte mode)
H'00000
H'FFFFF
2. Advanced mode1. Normal mode
*
H'000000
H'FFFFFF
(b) 16-Mbyte mode(a) 1-Mbyte mode
Note: * Normal mode cannot be used with this LSI.
18
Figure 2-2 Memory Map
Page 33
2.4 Register Configuration
2.4.1 Overview
The H8/300H CPU has the internal registers shown in figure 2-3. There are two types of registers:
general registers and control registers.
General Registers (ERn)
0707015
ER0
ER1
ER2
ER3
ER4
ER5
ER6
ER7
Control Registers (CR)
PC
Legend
SP:
PC:
CCR:
I:
UI:
H:
U:
N:
Z:
V:
C:
Stack pointer
Program counter
Condition code register
Interrupt mask bit
User bit or interrupt mask bit
Half-carry flag
User bit
Negative flag
Zero flag
Overflow flag
Carry flag
E0
E1
E2
E3
E4
E5
E6
E7
230
(SP)
R0H
R1H
R2H
R3H
R4H
R5H
R6H
R7H
CCR
7
IUIHUNZVC
R0L
R1L
R2L
R3L
R4L
R5L
R6L
R7L
6543210
Figure 2-3 CPU Registers
19
Page 34
2.4.2 General Registers
The H8/300H CPU has eight 32-bit general registers. These general registers are all functionally
alike and can be used without distinction between data registers and address registers. When a
general register is used as a data register, it can be accessed as a 32-bit, 16-bit, or 8-bit register.
When the general registers are used as 32-bit registers or as address registers, they are designated
by the letters ER (ER0 to ER7).
The ER registers divide into 16-bit general registers designated by the letters E (E0 to E7) and R
(R0 to R7). These registers are functionally equivalent, providing a maximum sixteen 16-bit
registers. The E registers (E0 to E7) are also referred to as extended registers.
The R registers divide into 8-bit general registers designated by the letters RH (R0H to R7H) and
RL (R0L to R7L). These registers are functionally equivalent, providing a maximum sixteen 8-bit
registers.
Figure 2-4 illustrates the usage of the general registers. The usage of each register can be selected
independently.
• Address registers
• 32-bit registers• 16-bit registers• 8-bit registers
E registers
(extended registers)
E0 to E7
ER registers
ER0 to ER7
R registers
R0 to R7
RH registers
R0H to R7H
RL registers
R0L to R7L
Figure 2-4 Usage of General Registers
20
Page 35
General register ER7 has the function of stack pointer (SP) in addition to its general-register
function, and is used implicitly in exception handling and subroutine calls. Figure 2-5 shows the
stack.
Free area
SP (ER7)
Stack area
Figure 2-5 Stack
2.4.3 Control Registers
The control registers are the 24-bit program counter (PC) and the 8-bit condition code register
(CCR).
Program Counter (PC): This 24-bit counter indicates the address of the next instruction the CPU
will execute. The length of all CPU instructions is 2 bytes (one word) or a multiple of 2 bytes, so
the least significant PC bit is ignored. When an instruction is fetched, the least significant PC bit is
regarded as 0.
Condition Code Register (CCR): This 8-bit register contains internal CPU status information,
including the interrupt mask bit (I) and half-carry (H), negative (N), zero (Z), overflow (V), and
carry (C) flags.
Bit 7—Interrupt Mask Bit (I): Masks interrupts other than NMI when set to 1. NMI is accepted
regardless of the I bit setting. The I bit is set to 1 at the start of an exception-handling sequence.
Bit 6—User Bit or Interrupt Mask Bit (UI): Can be written and read by software using the
LDC, STC, ANDC, ORC, and XORC instructions. This bit can also be used as an interrupt mask
bit. For details see section 5, Interrupt Controller.
21
Page 36
Bit 5—Half-Carry Flag (H): When the ADD.B, ADDX.B, SUB.B, SUBX.B, CMP.B, or NEG.B
instruction is executed, this flag is set to 1 if there is a carry or borrow at bit 3, and cleared to 0
otherwise. When the ADD.W, SUB.W, CMP.W, or NEG.W instruction is executed, the H flag is
set to 1 if there is a carry or borrow at bit 11, and cleared to 0 otherwise. When the ADD.L,
SUB.L, CMP.L, or NEG.L instruction is executed, the H flag is set to 1 if there is a carry or
borrow at bit 27, and cleared to 0 otherwise.
Bit 4—User Bit (U): Can be written and read by software using the LDC, STC, ANDC, ORC, and
XORC instructions.
Bit 3—Negative Flag (N): Indicates the most significant bit (sign bit) of data.
Bit 2—Zero Flag (Z): Set to 1 to indicate zero data, and cleared to 0 to indicate non-zero data.
Bit 1—Overflow Flag (V): Set to 1 when an arithmetic overflow occurs, and cleared to 0 at other
times.
Bit 0—Carry Flag (C): Set to 1 when a carry occurs, and cleared to 0 otherwise. Used by:
• Add instructions, to indicate a carry
• Subtract instructions, to indicate a borrow
• Shift and rotate instructions, to store the value shifted out of the end bit
The carry flag is also used as a bit accumulator by bit manipulation instructions.
Some instructions leave flag bits unchanged. Operations can be performed on CCR by the LDC,
STC, ANDC, ORC, and XORC instructions. The N, Z, V, and C flags are used by conditional
branch (Bcc) instructions.
For the action of each instruction on the flag bits, see appendix A.1, Instruction List. For the I and
UI bits, see section 5, Interrupt Controller.
2.4.4 Initial CPU Register Values
In reset exception handling, PC is initialized to a value loaded from the vector table, and the I bit
in CCR is set to 1. The other CCR bits and the general registers are not initialized. In particular,
the stack pointer (ER7) is not initialized. The stack pointer must therefore be initialized by an
MOV.L instruction executed immediately after a reset.
22
Page 37
2.5 Data Formats
The H8/300H CPU can process 1-bit, 4-bit (BCD), 8-bit (byte), 16-bit (word), and 32-bit
(longword) data. Bit-manipulation instructions operate on 1-bit data by accessing bit n (n = 0, 1, 2,
…, 7) of byte operand data. The DAA and DAS decimal-adjust instructions treat byte data as two
digits of 4-bit BCD data.
2.5.1 General Register Data Formats
Figures 2-6 and 2-7 show the data formats in general registers.
General
Data TypeData Format
1-bit data
1-bit data
Register
RnH
RnL
70
7
6543210
Don’t care
Don’t care
70
76543210
4-bit BCD data
4-bit BCD data
Byte data
Byte data
Legend
RnH:
RnL:
General register RH
General register RL
70
RnH
RnL
70
RnH
MSBLSB
RnL
43
Lower digitUpper digit
Don’t care
Don’t care
Figure 2-6 General Register Data Formats
Don’t care
7
70
MSBLSB
43
Lower digitUpper digit
Don’t care
0
23
Page 38
Word data
General
RegisterData TypeData Format
150
Rn
MSBLSB
150
Word data
Longword data
Legend
ERn:
En:
Rn:
MSB:
LSB:
General register
General register E
General register R
Most significant bit
Least significant bit
En
ERn
MSBLSB
3116
MSB
150
LSB
Figure 2-7 General Register Data Formats
2.5.2 Memory Data Formats
Figure 2-8 shows the data formats on memory. The H8/300H CPU can access word data and
longword data on memory, but word or longword data must begin at an even address. If an attempt
is made to access word or longword data at an odd address, no address error occurs but the least
significant bit of the address is regarded as 0, so the access starts at the preceding address. This
also applies to instruction fetches.
24
Page 39
AddressData T ypeData Format
70
1-bit data
Byte data
Word data
Longword data
76543210Address
Address
Address 2m
MSBLSB
MSB
Address 2m + 1
Address 2n
MSB
Address 2n + 1
Address 2n + 2
Address 2n + 3
Figure 2-8 Memory Data Formats
LSB
LSB
When ER7 (SP) is used as an address register to access the stack, the operand size should be word
size or longword size.
25
Page 40
2.6 Instruction Set
2.6.1 Instruction Set Overview
The H8/300H CPU has 62 types of instructions, which are classified as shown in table 2-1.
2.6.3 Tables of Instructions Classified by Function
Tables 2-3 to 2-10 summarize the instructions in each functional category. The operation notation
used in these tables is defined as follows.
Operation Notation
RdGeneral register (destination)*
RsGeneral register (source)*
RnGeneral register*
ERnGeneral register (32-bit register or address register)
(EAd)Destination operand
(EAs)Source operand
CCRCondition code register
NN (negative) flag of CCR
ZZ (zero) flag of CCR
VV (overflow) flag of CCR
CC (carry) flag of CCR
PCProgram counter
SPStack pointer
#IMMImmediate data
dispDisplacement
+Addition
–Subtraction
×Multiplication
÷Division
∧Logical AND
∨Logical OR
⊕Exclusive logical OR
→Move
¬NOT (logical complement)
:3/:8/:16/:243-, 8-, 16-, or 24-bit length
Note: *General registers include 8-bit registers (R0H to R7H, R0L to R7L), 16-bit registers (R0 to
R7, E0 to E7), and 32-bit data or address registers (ER0 to ER7).
29
Page 44
Table 2-3 Data Transfer Instructions
InstructionSize*Function
MOVB/W/L(EAs) → Rd, Rs → (EAd)
Moves data between two general registers or between a general
register and memory, or moves immediate data to a general register.
MOVFPEB(EAs) → Rd
Cannot be used in the H8/3022 Series.
MOVTPEBRs → (EAs)
Cannot be used in the H8/3022 Series.
POPW/L@SP+ → Rn
Pops a general register from the stack. POP.W Rn is identical to
MOV.W @SP+, Rn. Similarly, POP.L ERn is identical to MOV.L
@SP+, ERn.
PUSHW/LRn → @–SP
Pushes a general register onto the stack. PUSH.W Rn is identical to
MOV.W Rn, @–SP. Similarly, PUSH.L ERn is identical to MOV.L
ERn, @–SP.
Note: *Size refers to the operand size.
B:Byte
W:Word
L:Longword
30
Page 45
Table 2-4 Arithmetic Operation Instructions
InstructionSize*Function
ADD,
SUB
B/W/LRd ± Rs → Rd, Rd ± #IMM → Rd
Performs addition or subtraction on data in two general registers, or on
immediate data and data in a general register. (Immediate byte data
cannot be subtracted from data in a general register. Use the SUBX or
ADD instruction.)
ADDX,
SUBX
BRd ± Rs ± C → Rd, Rd ± #IMM ± C → Rd
Performs addition or subtraction with carry on data in two general
registers, or on immediate data and data in a general register.
INC,
DEC
B/W/LRd ± 1 → Rd, Rd ± 2 → Rd
Increments or decrements a general register by 1 or 2. (Byte operands
can be incremented or decremented by 1 only.)
ADDS,
SUBS
DAA,
DAS
LRd ± 1 → Rd, Rd ± 2 → Rd, Rd ± 4 → Rd
Adds or subtracts the value 1, 2, or 4 to or from data in a 32-bit register.
BRd decimal adjust → Rd
Decimal-adjusts an addition or subtraction result in a general register
by referring to CCR to produce 4-bit BCD data.
MULXUB/WRd × Rs → Rd
Performs unsigned multiplication on data in two general registers: either
8 bits × 8 bits → 16 bits or 16 bits × 16 bits → 32 bits.
MULXSB/WRd × Rs → Rd
Performs signed multiplication on data in two general registers: either 8
bits × 8 bits → 16 bits or 16 bits × 16 bits → 32 bits.
31
Page 46
InstructionSize*Function
DIVXUB/WRd ÷ Rs → Rd
Performs unsigned division on data in two general registers: either 16
bits ÷ 8 bits → 8-bit quotient and 8-bit remainder or 32 bits ÷ 16 bits →
16-bit quotient and 16-bit remainder.
DIVXSB/WRd ÷ Rs → Rd
Performs signed division on data in two general registers: either 16 bits
÷ 8 bits → 8-bit quotient and 8-bit remainder, or 32 bits ÷ 16 bits → 16bit quotient and 16-bit remainder.
CMPB/W/LRd – Rs, Rd – #IMM
Compares data in a general register with data in another general
register or with immediate data, and sets CCR according to the result.
NEGB/W/L0 – Rd → Rd
Takes the two’s complement (arithmetic complement) of data in a
general register.
EXTSW/LRd (sign extension) → Rd
Extends byte data in the lower 8 bits of a 16-bit register to word data,
or extends word data in the lower 16 bits of a 32-bit register to
longword data, by extending the sign bit.
EXTUW/LRd (zero extension) → Rd
Extends byte data in the lower 8 bits of a 16-bit register to word data,
or extends word data in the lower 16 bits of a 32-bit register to
longword data, by padding with zeros.
Note: *Size refers to the operand size.
B:Byte
W:Word
L:Longword
32
Page 47
Table 2-5 Logic Operation Instructions
InstructionSize*Function
ANDB/W/LRd ∧ Rs → Rd, Rd ∧ #IMM → Rd
Performs a logical AND operation on a general register and another
general register or immediate data.
ORB/W/LRd ∨ Rs → Rd, Rd ∨ #IMM → Rd
Performs a logical OR operation on a general register and another
general register or immediate data.
XORB/W/LRd ⊕ Rs → Rd, Rd ⊕ #IMM → Rd
Performs a logical exclusive OR operation on a general register and
another general register or immediate data.
NOTB/W/L¬ Rd → Rd
Takes the one’s complement of general register contents.
Note: *Size refers to the operand size.
B:Byte
W:Word
L:Longword
Table 2-6 Shift Instructions
InstructionSize*Function
SHAL,
SHAR
SHLL,
SHLR
ROTL,
ROTR
ROTXL,
ROTXR
Note: *Size refers to the operand size.
B:Byte
W:Word
L:Longword
B/W/LRd (shift) → Rd
Performs an arithmetic shift on general register contents.
B/W/LRd (shift) → Rd
Performs a logical shift on general register contents.
B/W/LRd (rotate) → Rd
Rotates general register contents.
B/W/LRd (rotate) → Rd
Rotates general register contents through the carry bit.
33
Page 48
Table 2-7 Bit Manipulation Instructions
InstructionSize*Function
BSETB1 → (<bit-No.> of <EAd>)
Sets a specified bit in a general register or memory operand to 1. The
bit number is specified by 3-bit immediate data or the lower 3 bits of a
general register.
BCLRB0 → (<bit-No.> of <EAd>)
Clears a specified bit in a general register or memory operand to 0. The
bit number is specified by 3-bit immediate data or the lower 3 bits of a
general register.
BNOTB¬ (<bit-No.> of <EAd>) → (<bit-No.> of <EAd>)
Inverts a specified bit in a general register or memory operand. The bit
number is specified by 3-bit immediate data or the lower 3 bits of a
general register.
BTSTB¬ (<bit-No.> of <EAd>) → Z
Tests a specified bit in a general register or memory operand and sets
or clears the Z flag accordingly. The bit number is specified by 3-bit
immediate data or the lower 3 bits of a general register.
BANDBC ∧ (<bit-No.> of <EAd>) → C
ANDs the carry flag with a specified bit in a general register or memory
operand and stores the result in the carry flag.
BIANDBC ∧ [¬ (<bit-No.> of <EAd>)] → C
ANDs the carry flag with the inverse of a specified bit in a general
register or memory operand and stores the result in the carry flag.
The bit number is specified by 3-bit immediate data.
34
Page 49
InstructionSize*Function
BORBC ∨ (<bit-No.> of <EAd>) → C
ORs the carry flag with a specified bit in a general register or memory
operand and stores the result in the carry flag.
BIORBC ∨ [¬ (<bit-No.> of <EAd>)] → C
ORs the carry flag with the inverse of a specified bit in a general
register or memory operand and stores the result in the carry flag.
The bit number is specified by 3-bit immediate data.
BXORBC ⊕ (<bit-No.> of <EAd>) → C
Exclusive-ORs the carry flag with a specified bit in a general register or
memory operand and stores the result in the carry flag.
BIXORBC ⊕ [¬ (<bit-No.> of <EAd>)] → C
Exclusive-ORs the carry flag with the inverse of a specified bit in a
general register or memory operand and stores the result in the carry
flag.
The bit number is specified by 3-bit immediate data.
BLDB(<bit-No.> of <EAd>) → C
Transfers a specified bit in a general register or memory operand to the
carry flag.
BILDB¬ (<bit-No.> of <EAd>) → C
Transfers the inverse of a specified bit in a general register or memory
operand to the carry flag.
The bit number is specified by 3-bit immediate data.
BSTBC → (<bit-No.> of <EAd>)
Transfers the carry flag value to a specified bit in a general register or
memory operand.
BISTBC → ¬ (<bit-No.> of <EAd>)
Transfers the inverse of the carry flag value to a specified bit in a
general register or memory operand.
The bit number is specified by 3-bit immediate data.
Note: *Size refers to the operand size.
B:Byte
35
Page 50
Table 2-8 Branching Instructions
InstructionSizeFunction
Bcc—Branches to a specified address if a specified condition is true. The
branching conditions are listed below.
MnemonicDescriptionCondition
BRA (BT)Always (true)Always
BRN (BF)Never (false)Never
BHIHighC ∨ Z = 0
BLSLow or sameC ∨ Z = 1
Bcc (BHS)Carry clear (high or same)C = 0
BCS (BLO)Carry set (low)C = 1
BNENot equalZ = 0
BEQEqualZ = 1
BVCOverflow clearV = 0
BVSOverflow setV = 1
BPLPlusN = 0
BMIMinusN = 1
BGEGreater or equalN ⊕ V = 0
BLTLess thanN ⊕ V = 1
BGTGreater thanZ ∨ (N ⊕ V) = 0
BLELess or equalZ ∨ (N ⊕ V) = 1
JMP—Branches unconditionally to a specified address
BSR—Branches to a subroutine at a specified address
JSR—Branches to a subroutine at a specified address
RTS—Returns from a subroutine
36
Page 51
Table 2-9 System Control Instructions
InstructionSize*Function
TRAPA—Starts trap-instruction exception handling
RTE—Returns from an exception-handling routine
SLEEP—Causes a transition to the power-down state
LDCB/W(EAs) → CCR
Moves the source operand contents to the condition code register. The
condition code register size is one byte, but in transfer from memory,
data is read by word access.
STCB/WCCR → (EAd)
Transfers the CCR contents to a destination location. The condition
code register size is one byte, but in transfer to memory, data is written
by word access.
ANDCBCCR ∧ #IMM → CCR
Logically ANDs the condition code register with immediate data.
ORCBCCR ∨ #IMM → CCR
Logically ORs the condition code register with immediate data.
XORCBCCR ⊕ #IMM → CCR
Logically exclusive-ORs the condition code register with immediate
data.
NOP—PC + 2 → PC
Only increments the program counter.
Note: *Size refers to the operand size.
B:Byte
W:Word
37
Page 52
Table 2-10 Block Transfer Instruction
InstructionSizeFunction
EEPMOV.B—if R4L ≠ 0 then
repeat@ER5+ → @ER6+, R4L – 1 → R4L
untilR4L = 0
else next;
EEPMOV.W—if R4 ≠ 0 then
repeat@ER5+ → @ER6+, R4 – 1 → R4
untilR4 = 0
else next;
Transfers a data block according to parameters set in general registers
R4L or R4, ER5, and ER6.
R4L or R4: Size of block (bytes)
ER5:Starting source address
ER6: Starting destination address
Execution of the next instruction begins as soon as the transfer is
completed.
38
Page 53
2.6.4 Basic Instruction Formats
The H8/300H instructions consist of 2-byte (1-word) units. An instruction consists of an operation
field (OP field), a register field (r field), an effective address extension (EA field), and a condition
field (cc).
Operation Field: Indicates the function of the instruction, the addressing mode, and the operation
to be carried out on the operand. The operation field always includes the first 4 bits of the
instruction. Some instructions have two operation fields.
Register Field: Specifies a general register. Address registers are specified by 3 bits, data registers
by 3 bits or 4 bits. Some instructions have two register fields. Some have no register field.
Effective Address Extension: Eight, 16, or 32 bits specifying immediate data, an absolute
address, or a displacement. A 24-bit address or displacement is treated as 32-bit data in which the
first 8 bits are 0 (H'00).
Condition Field: Specifies the branching condition of Bcc instructions.
Figure 2-9 shows examples of instruction formats.
Operation field only
op
Operation field and register fields
oprnrm
Operation field, register fields, and effective address extension
oprnrm
EA (disp)
Operation field, effective address extension, and condition field
opccEA (disp)
NOP, RTS, etc.
ADD.B Rn, Rm, etc.
MOV.B @(d:16, Rn), Rm
BRA d:8
Figure 2-9 Instruction Formats
39
Page 54
2.6.5 Notes on Use of Bit Manipulation Instructions
The BSET, BCLR, BNOT, BST, and BIST instructions read a byte of data, modify a bit in the
byte, then write the byte back. Care is required when these instructions are used to access registers
with write-only bits, or to access ports.
StepDescription
1ReadRead one data byte at the specified address
2ModifyModify one bit in the data byte
3WriteWrite the modified data byte back to the specified address
Example 1: BCLR is executed to clear bit 0 in the port 4 data direction register (PADDR) under
the following conditions.
PA7, PA6:Input pins
PA5 – PA0:Output pins
The intended purpose of this BCLR instruction is to switch PA0 from output to input.
Explanation: To execute the BCLR instruction, the CPU begins by reading PADDR. Since
PADDR is a write-only register, it is read as H'FF, even though its true value is H'3F.
Next the CPU clears bit 0 of the read data, changing the value to H'FE.
Finally, the CPU writes this value (H'FE) back to PADDR to complete the BCLR instruction.
40
Page 55
As a result, PA0DDR is cleared to 0, making PA0 an input pin. In addition, PA7DDR and
PA6DDR are set to 1, making PA7 and PA6 output pins.
The BCLR instruction can be used to clear flags in the on-chip registers. In an interrupt-handling
routine, for example, if it is known that the flag is set to 1, it is not necessary to read the flag ahead
of time.
2.7 Addressing Modes and Effective Address Calculation
2.7.1 Addressing Modes
The H8/300H CPU supports the eight addressing modes listed in table 2-11. Each instruction uses
a subset of these addressing modes. Arithmetic and logic instructions can use the register direct
and immediate modes. Data transfer instructions can use all addressing modes except programcounter relative and memory indirect. Bit manipulation instructions use register direct, register
indirect, or absolute (@aa:8) addressing mode to specify an operand, and register direct (BSET,
BCLR, BNOT, and BTST instructions) or immediate (3-bit) addressing mode to specify a bit
number in the operand.
Table 2-11 Addressing Modes
No.Addressing ModeSymbol
1Register directRn
2Register indirect@ERn
3Register indirect with displacement@(d:16, ERn)/@d:24, ERn)
4Register indirect with post-increment
1 Register Direct—Rn: The register field of the instruction code specifies an 8-, 16-, or 32-bit
register containing the operand. R0H to R7H and R0L to R7L can be specified as 8-bit registers.
R0 to R7 and E0 to E7 can be specified as 16-bit registers. ER0 to ER7 can be specified as 32-bit
registers.
2Register Indirect—@ERn: The register field of the instruction code specifies an address
register (ERn), the lower 24 bits of which contain the address of the operand.
41
Page 56
3 Register Indirect with Displacement—@(d:16, ERn) or @(d:24, ERn): A 16-bit or 24-bit
displacement contained in the instruction code is added to the contents of an address register
(ERn) specified by the register field of the instruction, and the lower 24 bits of the sum specify the
address of a memory operand. A 16-bit displacement is sign-extended when added.
4 Register Indirect with Post-Increment or Pre-Decrement—@ERn+ or @–ERn:
• Register indirect with post-increment—@ERn+
The register field of the instruction code specifies an address register (ERn) the lower 24 bits
of which contain the address of a memory operand. After the operand is accessed, 1, 2, or 4 is
added to the address register contents (32 bits) and the sum is stored in the address register.
The value added is 1 for byte access, 2 for word access, or 4 for longword access. For word or
longword access, the register value should be even.
• Register indirect with pre-decrement—@–ERn
The value 1, 2, or 4 is subtracted from an address register (ERn) specified by the register field
in the instruction code, and the lower 24 bits of the result become the address of a memory
operand. The result is also stored in the address register. The value subtracted is 1 for byte
access, 2 for word access, or 4 for longword access. For word or longword access, the resulting
register value should be even.
5 Absolute Address—@aa:8, @aa:16, or @aa:24: The instruction code contains the absolute
address of a memory operand. The absolute address may be 8 bits long (@aa:8), 16 bits long
(@aa:16), or 24 bits long (@aa:24). For an 8-bit absolute address, the upper 16 bits are all
assumed to be 1 (H'FFFF). For a 16-bit absolute address the upper 8 bits are a sign extension. A
24-bit absolute address can access the entire address space. Table 2-12 indicates the accessible
address ranges.
Table 2-12 Absolute Address Access Ranges
Absolute
Address1-Mbyte Modes16-Mbyte Modes
8 bits (@aa:8)H'FFF00 to H'FFFFF
(1,048,320 to 1,048,575)
16 bits (@aa:16)H'00000 to H'07FFF,
H'F8000 to H'FFFFF
(0 to 32,767, 1,015,808 to
1,048,575)
24 bits (@aa:24)H'00000 to H'FFFFF
(0 to 1,048,575)
H'FFFF00 to H'FFFFFF
(16,776,960 to 16,777,215)
H'000000 to H'007FFF,
H'FF8000 to H'FFFFFF
(0 to 32,767, 16,744,448 to
16,777,215)
H'000000 to H'FFFFFF
(0 to 16,777,215)
6 Immediate—#xx:8, #xx:16, or #xx:32: The instruction code contains 8-bit (#xx:8), 16-bit
(#xx:16), or 32-bit (#xx:32) immediate data as an operand.
42
Page 57
The instruction codes of the ADDS, SUBS, INC, and DEC instructions contain immediate data
implicitly. The instruction codes of some bit manipulation instructions contain 3-bit immediate
data specifying a bit number. The TRAPA instruction code contains 2-bit immediate data
specifying a vector address.
7 Program-Counter Relative—@(d:8, PC) or @(d:16, PC): This mode is used in the Bcc and
BSR instructions. An 8-bit or 16-bit displacement contained in the instruction code is signextended to 24 bits and added to the 24-bit PC contents to generate a 24-bit branch address. The
PC value to which the displacement is added is the address of the first byte of the next instruction,
so the possible branching range is –126 to +128 bytes (–63 to +64 words) or –32766 to +32768
bytes (–16383 to +16384 words) from the branch instruction. The resulting value should be an
even number.
8 Memory Indirect—@@aa:8: This mode can be used by the JMP and JSR instructions. The
instruction code contains an 8-bit absolute address specifying a memory operand. This memory
operand contains a branch address. The memory operand is accessed by longword access. The first
byte of the memory operand is ignored, generating a 24-bit branch address. See figure 2-10. The
upper bits of the 8-bit absolute address are assumed to be 0 (H'0000), so the address range is 0 to
255 (H'000000 to H'0000FF). Note that the first part of this range is also the exception vector area.
For further details see section 5, Interrupt Controller.
When a word-size or longword-size memory operand is specified, or when a branch address is
specified, if the specified memory address is odd, the least significant bit is regarded as 0. The
accessed data or instruction code therefore begins at the preceding address. See section 2.5.2,
Memory Data Formats.
2.7.2 Effective Address Calculation
Table 2-13 explains how an effective address is calculated in each addressing mode. In the
1-Mbyte operating modes the upper 4 bits of the calculated address are ignored in order to
generate a 20-bit effective address.
The H8/300H CPU has four processing states: the program execution state, exception-handling
state, power-down state, and reset state. The power-down state includes sleep mode, software
standby mode, and hardware standby mode. Figure 2-11 classifies the processing states.
Figure 2-13 indicates the state transitions.
Processing statesProgram execution state
The CPU executes program instructions in sequence
Exception-handling state
A transient state in which the CPU executes a hardware sequence
(saving PC and CCR, fetching a vector, etc.) in response to a reset,
interrupt, or other exception
Reset state
The CPU and all on-chip supporting modules are initialized and halted
Power-down state
The CPU is halted to conserve power
Sleep mode
Software standby mode
Hardware standby mode
Figure 2-11 Processing States
47
Page 62
2.8.2 Program Execution State
In this state the CPU executes program instructions in normal sequence.
2.8.3 Exception-Handling State
The exception-handling state is a transient state that occurs when the CPU alters the normal
program flow due to a reset, interrupt, or trap instruction. The CPU fetches a starting address from
the exception vector table and branches to that address. In interrupt and trap exception handling
the CPU references the stack pointer (ER7) and saves the program counter and condition code
register.
Types of Exception Handling and Their Priority: Exception handling is performed for resets,
interrupts, and trap instructions. Table 2-14 indicates the types of exception handling and their
priority. Trap instruction exceptions are accepted at all times in the program execution state.
Table 2-14 Exception Handling Types and Priority
Type of
Priority
HighResetSynchronized with clockException handling starts
Low
Note: *Interrupts are not detected at the end of the ANDC, ORC, XORC, and LDC instructions, or
ExceptionDetection TimingStart of Exception Handling
immediately when RES changes
from low to high
InterruptEnd of instruction execution
or end of exception handling*
Trap instructionWhen TRAPA instruction is
executed
immediately after reset exception handling.
When an interrupt is requested,
exception handling starts at the
end of the current instruction or
current exception-handling
sequence
Exception handling starts when
a trap (TRAPA) instruction is
executed
Figure 2-12 classifies the exception sources. For further details about exception sources, vector
numbers, and vector addresses, see section 4, Exception Handling, and section 5, Interrupt
Controller.
Notes: 1.2.From any state except hardware standby mode, a transition to the reset state occurs
whenever goes low.
From any state, a transition to hardware standby mode occurs when goes low.
*1
RES
or IRQ interrupt
STBY high, RES low
01
2
SLEEP instruction
with SSBY = 1
Software standby mode
Hardware standby mode
Power-down state
STBY
*2
Figure 2-13 State Transitions
49
Page 64
2.8.4 Exception-Handling Sequences
Reset Exception Handling: Reset exception handling has the highest priority. The reset state is
entered when the RES signal goes low. Reset exception handling starts after that, when RES
changes from low to high. When reset exception handling starts the CPU fetches a start address
from the exception vector table and starts program execution from that address. All interrupts,
including NMI, are disabled during the reset exception-handling sequence and immediately after it
ends.
Interrupt Exception Handling and Trap Instruction Exception Handling: When these
exception-handling sequences begin, the CPU references the stack pointer (ER7) and pushes the
program counter and condition code register on the stack. Next, if the UE bit in the system control
register (SYSCR) is set to 1, the CPU sets this set to 1, the CPU sets the I bit in the condition code
register to 1. If the UE bit is cleared to 0, the CPU sets both the I bit and the UI bit in the condition
code register to 1. Then the CPU fetches a start address from the exception vector table and
execution branches to that address.
Figure 2-14 shows the stack after the exception-handling sequence.
SP–4
SP–3
SP–2
SP–1
SP (ER7)
Legend
CCR:
SP:
Notes: 1.2.PC is the address of the first instruction executed after the return from the
Condition code register
Stack pointer
exception-handling routine.
Registers must be saved and restored by word access or longword access,
starting at an even address.
Stack area
Before exception
handling starts
SP (ER7)
SP+1
SP+2
SP+3
SP+4
Pushed on stack
CCR
PC
After exception
handling ends
Even
address
Figure 2-14 Stack Structure after Exception Handling
50
Page 65
2.8.5 Reset State
When the RES input goes low all current processing stops and the CPU enters the reset state. The I
bit in the condition code register is set to 1 by a reset. All interrupts are masked in the reset state.
Reset exception handling starts when the RES signal changes from low to high.
The reset state can also be entered by a watchdog timer overflow. For details see section 10,
Watchdog timer.
2.8.6 Power-Down State
In the power-down state the CPU stops operating to conserve power. There are three modes: sleep
mode, software standby mode, and hardware standby mode.
Sleep Mode: A transition to sleep mode is made if the SLEEP instruction is executed while the
SSBY bit is cleared to 0 in the system control register (SYSCR). CPU operations stop
immediately after execution of the SLEEP instruction, but the contents of CPU registers are
retained.
Software Standby Mode: A transition to software standby mode is made if the SLEEP
instruction is executed while the SSBY bit is set to 1 in SYSCR. The CPU and clock halt and all
on-chip supporting modules stop operating. The on-chip supporting modules are reset, but as long
as a specified voltage is supplied the contents of CPU registers and on-chip RAM are retained.
The I/O ports also remain in their existing states.
Hardware Standby Mode: A transition to hardware standby mode is made when the STBY input
goes low. As in software standby mode, the CPU and clock halt and the on-chip supporting
modules are reset, but as long as a specified voltage is supplied, on-chip RAM contents are
retained.
For further information see section 17, Power-Down State.
51
Page 66
2.9 Basic Operational Timing
2.9.1 Overview
The H8/300H CPU operates according to the system clock (ø). The interval from one rise of the
system clock to the next rise is referred to as a “state.” A memory cycle or bus cycle consists of
two or three states. The CPU uses different methods to access on-chip memory, the on-chip
supporting modules, and the external address space. Access to the external address space can be
controlled by the bus controller.
2.9.2 On-Chip Memory Access Timing
On-chip memory is accessed in two states. The data bus is 16 bits wide, permitting both byte and
word access. Figure 2-15 shows the on-chip memory access cycle. Figure 2-16 indicates the pin
states.
Bus cycle
ø
Internal address bus
Internal read signal
Internal data bus
(read access)
Internal write signal
Internal data bus
(write access)
Figure 2-15 On-Chip Memory Access Cycle
T state
1
Address
Read data
Write data
T state
2
52
Page 67
T
1
T
2
ø
Address bus
, , AS
RD WR
Address
High
High impedance
D
to D0
7
Figure 2-16 Pin States during On-Chip Memory Access
2.9.3 On-Chip Supporting Module Access Timing
The on-chip supporting modules are accessed in three states. The data bus is 8 or 16 bits wide,
depending on the register being accessed. Figure 2-17 shows the on-chip supporting module
access timing. Figure 2-18 indicates the pin states.
Bus cycle
Read
access
Write
access
ø
Internal address bus
Internal read signal
Internal data bus
Internal write signal
Internal data bus
T state
1
T state
2
Address
Read data
Write data
Figure 2-17 Access Cycle for On-Chip Supporting Modules
T state
3
53
Page 68
T
1
T
2
T
3
ø
Address bus
RD WR
, , AS
Address
High
High impedance
to D
D
7
0
Figure 2-18 Pin States during Access to On-Chip Supporting Modules
2.9.4 Access to External Address Space
The external address space is divided into eight areas (areas 0 to 7). Bus-controller settings
determine whether each area accessed in two or three states. For details see section 6, Bus
Controller.
54
Page 69
Section 3 MCU Operating Modes
3.1 Overview
3.1.1 Operating Mode Selection
The H8/3022 Series has five operating modes (modes 1, 3, 5 to7) that are selected by the mode
pins (MD2 and MD0) as indicated in table 3-1. The input at these pins determines expanded mode
or single-chip mode.
Notes: 1. If the RAM enable bit (RAME) in the system control register (SYSCR) is cleared to 0,
these addresses become external addresses.
2. In mode 7, clearing bit RAME in SYSCR to 0 and reading the on-chip RAM always
return H’FF, and write access is ignored. For details, see section 14.3, Operation.
For the address space size there are two choices: 1 Mbyte, or 16 Mbytes.
Modes 1 and 3 are on-chip ROM disable expanded modes capable of accessing external memory
and peripheral devices.
Mode 1 supports a maximum address space of 1 Mbyte. Mode 3 supports a maximum address
space of 16 Mbytes.
Modes 5 and 6 are externally expanded mode that enables access to external memory and
peripheral devices and also enables access to the on-chip ROM. Mode 5 supports a maximum
address space of 1 Mbyte.
Mode 6 supports a maximum address space of 16 Mbyte.
55
Page 70
Mode 7 is single-chip modes that operate using the on-chip ROM, RAM, and registers. All I/O
ports are available. Mode 7 is an advanced mode with a maximum address space of 1 Mbyte.
The H8/3022 Series can be used only in modes 1, 3, or 5 to 7. The inputs at the mode pins must
select one of these seven modes. The inputs at the mode pins must not be changed during
operation.
3.1.2 Register Configuration
The H8/3022 Series has a mode control register (MDCR) that indicates the inputs at the mode pins
(MD2 and MD0), and a system control register (SYSCR). Table 3-2 summarizes these registers.
Table 3-2 Registers
Address*NameAbbreviationR/WInitial Value
H'FFF1Mode control registerMDCRRUndetermined
H'FFF2System control registerSYSCRR/WH'0B
Note: *The lower 16 bits of the address are indicated.
56
Page 71
3.2 Mode Control Register (MDCR)
MDCR is an 8-bit read-only register that indicates the current operating mode of the H8/3022
Series.
Bit
Initial value
Read/Write
Note: Determined by pins MD to MD .
7
—
1
—
6
—
1
—
5
—
0
—
Reserved bits
2
0
4
—
0
—
3
—
0
—
2
MDS2
—
R
Mode select 2 to 0
Bits indicating the current
operating mode
1
MDS1
— R***
MDS0
0
—
R
Bits 7 and 6—Reserved: These bits cannot be modified and are always read as 1.
Bits 5 to 3—Reserved: These bits cannot be modified and are always read as 0.
Bits 2 to 0—Mode Select 2 to 0 (MDS2 to MDS0): These bits indicate the logic levels at pins
MD2 to MD0 (the current operating mode). MDS2 to MDS0 correspond to MD2 to MD0. MDS1 and
MDS0 are read-only bits. The mode pin (MD2 to MD0) levels are latched when MDCR is read.
57
Page 72
3.3 System Control Register (SYSCR)
SYSCR is an 8-bit register that controls the operation of the H8/3022 Series.
Bit
Initial value
Read/Write
7
SSBY
0
R/W
6
STS2
0
R/W
Standby timer select 2 to 0
These bits select the waiting time at
recovery from software standby mode
5
STS1
0
R/W
4
STS0
0
R/W
User bit enable
Selects whether to use UI bit in CCR
as a user bit or an interrupt mask bit
3
UE
1
R/W
2
NMIEG
0
R/W
NMI edge select
Selects the valid edge
of the NMI input
1
—
1
—
RAM enable
Enables or
disables
on-chip RAM
Reserved bit
0
RAME
1
R/W
Software standby
Enables transition to software standby mode
Bit 7—Software Standby (SSBY): Enables transition to software standby mode. (For further
information about software standby mode see section 17, Power-Down State.)
When software standby mode is exited by an external interrupt, this bit remains set to 1. To clear
this bit, write 0.
Bit7
SSBYDescription
0SLEEP instruction causes transition to sleep mode (Initial value)
1SLEEP instruction causes transition to software standby mode
58
Page 73
Bits 6 to 4—Standby Timer Select (STS2 to STS0): These bits select the length of time the CPU
and on-chip supporting modules wait for the internal clock oscillator to settle when software
standby mode is exited by an external interrupt. Set these bits so that the waiting time will be at
least 7 ms at the system clock rate. For further information about waiting time selection, see
section 17.4.3, Selection of Oscillator Waiting Time after Exit from Software Standby Mode.
Bit6
STS2
000Waiting time = 8,192 states (Initial value)
001Waiting time = 16,384 states
010Waiting time = 32,768 states
011Waiting time = 65,536 states
100Waiting time = 131,072 states
101Waiting time = 1,024 states
11—Illegal setting
Bit5
STS1
Bit4
STS0Description
Bit 3—User Bit Enable (UE): Selects whether to use the UI bit in the condition code register as a
user bit or an interrupt mask bit.
Bit 3
UEDescription
0UI bit in CCR is used as an interrupt mask bit
1UI bit in CCR is used as a user bit (Initial value)
Bit 2—NMI Edge Select (NMIEG): Selects the valid edge of the NMI input.
Bit2
NMIEGDescription
0An interrupt is requested at the falling edge of NMI (Initial value)
1An interrupt is requested at the rising edge of NMI
Bit 1—Reserved: This bit cannot be modified and is always read as 1.
Bit 0—RAM Enable (RAME): Enables or disables the on-chip RAM. The RAME bit is
initialized by the rising edge of the RES signal. It is not initialized in software standby mode.
Bit 0
RAMEDescription
0On-chip RAM is disabled
1On-chip RAM is enabled (Initial value)
59
Page 74
3.4 Operating Mode Descriptions
3.4.1 Mode 1
Ports 1, 2, and 5 function as address pins A19 to A0, permitting access to a maximum 1-Mbyte
address space. The initial bus mode after a reset is 8 bits, with 8-bit access to all areas.
3.4.2 Mode 3
Ports 1, 2, and 5 and part of port A function as address pins A23 to A0, permitting access to a
maximum 16-Mbyte address space. The initial bus mode after a reset is 8 bits, with 8-bit access to
all areas. A23 to A21 are valid when 0 is written in bits 7 to 5 of the bus release control register
(BRCR). (In this mode A20 is always used for address output.)
3.4.3 Mode 5
Ports 1, 2, and 5 can function as address pins A19 to A0, permitting access to a maximum 1-Mbyte
address space, but following a reset they are input ports. To use ports 1, 2, and 5 as an address bus,
the corresponding bits in their data direction registers (P1DDR, P2DDR, and P5DDR) must be set
to 1. The address bus width can be selected freely by setting DDR of ports 1, 2, and 5. The initial
bus mode after a reset is 8 bits, with 8-bit access to all areas.
3.4.4 Mode 6
Ports 1, 2, and 5, and port A (PA7 to PA4) function as address pins A23 to A0, permitting access to a
maximum 16-Mbyte address space, but following a reset these pins, except for A20, are input ports.
To use ports 1, 2, and 5 as address bus pins A19 to A0, the corresponding bits in their data direction
registers (P1DDR, P2DDR, and P5DDR) must be set to 1 to select output mode. A23 to A21 are
enabled by writing 0 to bits 7 to 5 in the address control register (ADRCR). The address bus
width can be selected freely (excluding A20) by setting DDR of ports 1, 2, and 5, and ADRCR.
The initial bus mode after a reset is 8 bits, with 8-bit access to all areas.
3.4.5 Mode 7
This mode is an advanced mode with a 1-Mbyte address space which operates using the on-chip
ROM, RAM, and registers. All I/O ports are available.
Note: The H8/3022 Series cannot be used in mode 2 and 4.
60
Page 75
3.5 Pin Functions in Each Operating Mode
The pin functions of ports 1 to 3, port 5 and port A vary depending on the operating mode. Table
3-3 indicates their functions in each operating mode.
Notes: 1. H8/3022 Series cannot be used in these modes.
2. Initial state. These pins become address output pins when the corresponding bits in the
data direction registers (P1DDR, P2DDR, P5DDR) are set to 1.
3. Initial state A
A
output by writing 0 in bits 7 to 5 of ADRCR.
21
is always an address output pin. PA6 to PA4 are switched over to A23 to
20
3.6 Memory Map in Each Operating Mode
Figure 3-1 shows a memory map of the H8/3022. Figure 3-2 shows a memory map of the
H8/3021. Figure 3-3 shows a memory map of the H8/3020. The address space is divided into eight
areas.
0
0
0
0
4
Modes 1, 3, 5, and 6 are the 8-bit bus mode.
The address locations of the on-chip RAM and internal I/O registers differ between the 1-Mbyte
modes (modes 1, 5, and 7) and 16-Mbyte modes (mode 3 and 6). The address range specifiable by
the CPU in the 8- and 16-bit absolute addressing modes (@aa:8 and @aa:16) also differs.
Area 0
Area 1
Area 2
Area 3
Area 4
Area 5
Area 6
Area 7
H'00000
H'000FF
H'07FFF
H'1FFFF
Vector area
On-chip ROM
16-bit absolute
8-bit memory-indirect
addresses (first half)
addresses
H'F8000
H'FDF0F
H'FDF10
H'FEF0F
H'FEF10
Reserved
On-chip RAM
*1
*2
H'FFF00
H'FFF0F
H'FFF10
External
address
H'FFF1B
space
H'FFF1C
Internal I/O
registers
H'FFFFF
1.2.Do not access the reserved area.
Notes:
External addresses can be accessed by disabling on-chip RAM.
H'FFDF0F
H'FFDF10
H'FFEF0F
H'FFEF10
H'FFFF00
H'FFFF0F
H'FFFF10
H'FFFF1B
H'FFFF1C
16-bit absolute addresses
(second half)
8-bit absolute addresses
H'FFFFFF
On-chip RAM
Reserved
External
address
space
Internal I/O
registers
H'F8000
*1
*2
H'FEF10
On-chip RAM
H'FFF00
H'FFF0F
H'FFF1C
16-bit absolute addresses
(second half)
8-bit absolute addresses
H'FFFFF
Internal I/O
registers
16-bit absolute addresses
(second half)
8-bit absolute addresses
Figure 3-3 H8/3020 Memory Map in Each Operating Mode (2)
67
Page 82
Section 4 Exception Handling
4.1 Overview
4.1.1 Exception Handling Types and Priority
As table 4-1 indicates, exception handling may be caused by a reset, trap instruction, or interrupt.
Exception handling is prioritized as shown in table 4-1. If two or more exceptions occur
simultaneously, they are accepted and processed in priority order. Trap instruction exceptions are
accepted at all times in the program execution state.
Table 4-1 Exception Types and Priority
PriorityException TypeStart of Exception Handling
HighResetStarts immediately after a low-to-high transition at the
RES pin
InterruptInterrupt requests are handled when execution of the
current instruction or handling of the current exception is
completed
LowTrap instruction (TRAPA)Started by execution of a trap instruction (TRAPA)
4.1.2 Exception Handling Operation
Exceptions originate from various sources. Trap instructions and interrupts are handled as follows.
1. The program counter (PC) and condition code register (CCR) are pushed onto the stack.
2. The CCR interrupt mask bit is set to 1.
3. A vector address corresponding to the exception source is generated, and program execution
starts from the address indicated in the vector address.
For a reset exception, steps 2 and 3 above are carried out.
69
Page 83
4.1.3 Exception Vector Table
The exception sources are classified as shown in figure 4-1. Different vectors are assigned to
different exception sources. Table 4-2 lists the exception sources and their vector addresses.
Reset0H'0000 to H'0001H'0000 to H'0003
Reserved for system use1H'0002 to H'0003H'0004 to H'0007
2H'0004 to H'0005H'0008 to H'000B
3H'0006 to H'0007H'000C to H'000F
4H'0008 to H'0009H'0010 to H'0013
5H'000A to H'000BH'0014 to H'0017
6H'000C to H'000DH'0018 to H'001B
External interrupt (NMI)7H'000E to H'000FH'001C to H'001F
Trap instruction (4 sources)8H'0010 to H'0011H'0020 to H'0023
9H'0012 to H'0013H'0024 to H'0027
10H'0014 to H'0015H'0028 to H'002B
11H'0016 to H'0017H'002C to H'002F
External interruptIRQ
IRQ
0
1
12H'0018 to H'0019H'0030 to H'0033
13H'001A to H'001BH'0034 to H'0037
Reserved for system use14H'001C to H'001DH'0038 to H'003B
15H'001E to H'001FH'003C to H'003F
External interuptIRQ
IRQ
4
5
16H'0020 to H'0021H'0040 to H'0043
17H'0022 to H'0023H'0044 to H'0047
Reserved for system use18H'0024 to H'0025H'0048 to H'004B
19H'0026 to H'0027H'004C to H'004F
Internal interrupts*
2
20
to
60
H'0028 to H'0029
to
H'0078 to H'0079
H'0050 to H'0053
to
H'00F0 to H'00F3
Notes: 1. Lower 16 bits of the address.
2. For the internal interrupt vectors, see section 5.3.3, Interrupt Vector Table.
71
Page 85
4.2 Reset
4.2.1 Overview
A reset is the highest-priority exception. When the RES pin goes low, all processing halts and the
H8/3022 Series enters the reset state. A reset initializes the internal state of the CPU and the
registers of the on-chip supporting modules. Reset exception handling begins when the RES pin
changes from low to high.
The chip can also be reset by overflow of the watchdog timer. For details see section 10,
Watchdog Timer.
4.2.2 Reset Sequence
The H8/3022 Series enters the reset state when the RES pin goes low.
To ensure that the chip is reset, hold the RES pin low for at least 20 ms at power-up. To reset the
chip during operation, hold the RES pin low for at least 10 system clock (ø) cycles. When using
the flash memory version, hold at "Low" level for a least 1usec. See appendix D.2, Pin States at
Reset, for the states of the pins in the reset state.
When the RES pin goes high after being held low for the necessary time, the H8/3022 Series chip
starts reset exception handling as follows.
• The internal state of the CPU and the registers of the on-chip supporting modules are
initialized, and the I bit is set to 1 in CCR.
• The contents of the reset vector address (H'0000 to H'0003 in advanced mode) are read, and
program execution starts from the address indicated in the vector address.
Figure 4-2 shows the reset sequence in modes 5 and 7.
72
Page 86
Prefetch of
first program
instruction
Internal
processing
(5)(3)(1)
Vector fetch
ø
Figure 4-2 Reset Sequence (Modes 5 and 7)
RES
Internal
address bus
Internal read
signal
Internal write
signal
(2)(4)(6)
Address of reset vector: (1) = H'000000, (3) = H'000002
Internal data bus
(16-bit width)
(1), (3)
Start address (contents of reset vector)
Start address
First instruction of program
(2), (4)
(5)
(6)
73
Page 87
4.2.3 Interrupts after Reset
If an interrupt is accepted after a reset but before the stack pointer (SP) is initialized, PC and CCR
will not be saved correctly, leading to a program crash. To prevent this, all interrupt requests,
including NMI, are disabled immediately after a reset. The first instruction of the program is
always executed immediately after the reset state ends. This instruction should initialize the stack
pointer (example: MOV.L #xx:32, SP).
4.3 Interrupts
Interrupt exception handling can be requested by five external sources (NMI, IRQ0, IRQ1, IRQ4,
IRQ5) and 25 internal sources in the on-chip supporting modules. Figure 4-3 classifies the interrupt
sources and indicates the number of interrupts of each type.
The on-chip supporting modules that can request interrupts are the watchdog timer (WDT), 16-bit
integrated timer unit (ITU), serial communication interface (SCI), and A/D converter. Each
interrupt source has a separate vector address.
NMI is the highest-priority interrupt and is always accepted. Interrupts are controlled by the
interrupt controller. The interrupt controller can assign interrupts other than NMI to two priority
levels, and arbitrate between simultaneous interrupts. Interrupt priorities are assigned in interrupt
priority registers A and B (IPRA and IPRB) in the interrupt controller.
For details on interrupts see section 5, Interrupt Controller.
NMI (1)
IRQ , IRQ , IRQ , IRQ (4)
0 1 4 5
WDT* (1)
ITU (15)
SCI (8)
A/D converter (1)
Notes:
External interrupts
Interrupts
Internal interrupts
Numbers in parentheses are the number of interrupt sources.
* When the watchdog timer is used as an interval timer, it generates
an interrupt request at every counter overflow.
Figure 4-3 Interrupt Sources and Number of Interrupts
74
Page 88
4.4 Trap Instruction
Trap instruction exception handling starts when a TRAPA instruction is executed. If the UE bit is
set to 1 in the system control register (SYSCR), the exception handling sequence sets the I bit to 1
in CCR. If the UE bit is 0, the I and UI bits are both set to 1. The TRAPA instruction fetches a
start address from a vector table entry corresponding to a vector number from 0 to 3, which is
specified in the instruction code.
4.5 Stack Status after Exception Handling
Figure 4-4 shows the stack after completion of trap instruction exception handling and interrupt
exception handling.
SP-4
SP-3
SP-2
SP-1
SP (ER7)
Legend
PCE:
PCH:
PCL:
CCR:
SP:
Notes:PC indicates the address of the first instruction that will be executed after return.
→
Before exception handlingAfter exception handling
Bits 23 to 16 of program counter (PC)
Bits 15 to 8 of program counter (PC)
Bits 7 to 0 of program counter (PC)
Condition code register
Stack pointer
1.
Saving and restoring of registers must be conducted at even addresses in word-size
2.
or longword-size units.
Stack area
SP (ER7)
SP+1
SP+2
SP+3
SP+4
Save on stack
→
CCR
PC
PC
PC
E
H
L
Even address
Figure 4-4 Stack after Completion of Exception Handling (Advanced Mode)
75
Page 89
4.6 Notes on Stack Usage
When accessing word data or longword data, the H8/3022 Series regards the lowest address bit as
0. The stack should always be accessed by word access or longword access, and the value of the
stack pointer (SP, ER7) should always be kept even. Use the following instructions to save
registers:
Setting SP to an odd value may lead to a malfunction. Figure 4-5 shows an example of what
happens when the SP value is odd.
SP
Legend
CCR:
PC:
R1L:
SP:
CCR
SP
PC
TRAPA instruction executed
SP set to H'FFEFFData saved above SPCCR contents lost
Condition code register
Program counter
General register R1L
Stack pointer
MOV. B R1L, @-ER7
SP
R1L
PC
H'FFEFA
H'FFEFB
H'FFEFC
H'FFEFD
H'FFEFF
Note: The diagram illustrates modes 1, 3, 5, 6, and 7.
Figure 4-5 Operation when SP Value is Odd
76
Page 90
Section 5 Interrupt Controller
5.1 Overview
5.1.1 Features
The interrupt controller has the following features:
• Interrupt priority registers (IPRs) for setting interrupt priorities
Interrupts other than NMI can be assigned to two priority levels on a module-by-module basis
in interrupt priority registers A and B (IPRA and IPRB).
• Three-level masking by the I and UI bits in the CPU condition code register (CCR)
• Independent vector addresses
All interrupts are independently vectored; the interrupt service routine does not have to identify
the interrupt source.
• Five external interrupt pins
NMI has the highest priority and is always accepted; either the rising or falling edge can be
selected. For each of IRQ0 , IRQ1, IRQ4, and IRQ5, sensing of the falling edge or level sensing
can be selected independently.
77
Page 91
5.1.2 Block Diagram
Figure 5-1 shows a block diagram of the interrupt controller.
ISCRIERIPRA, IPRB
NMI
input
CPU
IRQ input
OVF
TME
.
.
.
.
.
.
.
ADI
ADIE
Legend
I:
IER:
IPRA:
IPRB:
ISCR:
ISR:
SYSCR:
UE:
UI:
IRQ input
section ISR
.
.
.
Interrupt controller
Interrupt mask bit
IRQ enable register
Interrupt priority register A
Interrupt priority register B
IRQ sense control register
IRQ status register
System control register
User bit enable
User bit/interrupt mask bit
Priority
decision logic
Interrupt
request
Vector
number
I
CCR
UI
UE
SYSCR
Figure 5-1 Interrupt Controller Block Diagram
78
Page 92
5.1.3 Pin Configuration
Table 5-1 lists the interrupt pins.
Table 5-1 Interrupt Pins
NameAbbreviationI/OFunction
Nonmaskable interruptNMIInputNonmaskable interrupt, rising edge or
falling edge selectable
External interrupt
request 5, 4, 1, and 0
IRQ
, IRQ4 ,
5
and IRQ
, IRQ
1
InputMaskable interrupts, falling edge or level
0
sensing selectable
5.1.4 Register Configuration
Table 5-2 lists the registers of the interrupt controller.
Table 5-2 Interrupt Controller Registers
Address*
H'FFF2System control registerSYSCRR/WH'0B
H'FFF4IRQ sense control registerISCRR/WH'00
H'FFF5IRQ enable registerIERR/WH'00
H'FFF6IRQ status registerISRR/(W)*
H'FFF8Interrupt priority register AIPRAR/WH'00
H'FFF9Interrupt priority register BIPRBR/WH'00
1
NameAbbreviationR/WInitial Value
2
H'00
Notes: 1. Lower 16 bits of the address.
2. Only 0 can be written, to clear flags.
79
Page 93
5.2 Register Descriptions
5.2.1 System Control Register (SYSCR)
SYSCR is an 8-bit readable/writable register that controls software standby mode, selects the
action of the UI bit in CCR, selects the NMI edge, and enables or disables the on-chip RAM.
Only bits 3 and 2 are described here. For the other bits, see section 3.3, System Control Register
(SYSCR).
SYSCR is initialized to H'0B by a reset and in hardware standby mode. It is not initialized in
software standby mode.
Bit
Initial value
Read/Write
7
SSBY
0
R/W
Software standby
6
STS2
0
R/W
Standby timer
select 2 to 0
5
STS1
0
R/W
4
STS0
0
R/W
3
UE
1
R/W
NMI edge select
Selects the NMI input edge
User bit enable
Selects whether to use the UI bit in CCR
as a user bit or interrupt mask bit
2
NMIEG
0
R/W
1
—
1
—
RAM enable
Reserved bit
0
RAME
1
R/W
80
Page 94
Bit 3—User Bit Enable (UE): Selects whether to use the UI bit in CCR as a user bit or an
interrupt mask bit.
Bit 3
UEDescription
0UI bit in CCR is used as interrupt mask bit
1UI bit in CCR is used as user bit(Initial value)
Bit 2—NMI Edge Select (NMIEG): Selects the NMI input edge.
Bit 2
NMIEGDescription
0Interrupt is requested at falling edge of NMI input(Initial value)
1Interrupt is requested at rising edge of NMI input
81
Page 95
5.2.2 Interrupt Priority Registers A and B (IPRA, IPRB)
IPRA and IPRB are 8-bit readable/writable registers that control interrupt priority.
Interrupt Priority Register A (IPRA): IPRA is an 8-bit readable/writable register in which
interrupt priority levels can be set.
Bit
Initial value
Read/Write
7
IPRA7
0
R/W
6
IPRA6
0
R/W
5
—
0
R/W
4
IPRA4
0
R/W
3
IPRA3
0
R/W
2
IPRA2
0
R/W
1
IPRA1
0
R/W
0
IPRA0
0
R/W
Priority
level A0
Selects the
priority level
of ITU
channel 2
interrupt
requests
Priority level A1
Selects the priority level
of ITU channel 1
interrupt requests
Priority level A2
Selects the priority level of
ITU channel 0 interrupt requests
Priority level A3
Selects the priority level of
WDT interrupt requests
Priority level A4
Selects the priority level of IRQ4 and IRQ
interrupt requests
Reserved bit
Priority level A6
Selects the priority level of IRQ1 interrupt requests
Priority level A7
Selects the priority level of IRQ interrupt requests
0
IPRA is initialized to H'00 by a reset and in hardware standby mode.
5
82
Page 96
Bit 7—Priority Level A7 (IPRA7): Selects the priority level of IRQ0 interrupt requests.
Bit7
IPRA7Description
0IRQ0 interrupt requests have priority level 0 (low priority)(Initial value)
1IRQ0 interrupt requests have priority level 1 (high priority)
Bit 6—Priority Level A6 (IPRA6): Selects the priority level of IRQ1 interrupt requests.
Bit6
IPRA6Description
0IRQ1 interrupt requests have priority level 0 (low priority)(Initial value)
1IRQ1 interrupt requests have priority level 1 (high priority)
Bit 5—Reserved bit: This bit can be written and read, but it does not affect interrupt priority.
Bit 4—Priority Level A4 (IPRA4): Selects the priority level of IRQ4 and IRQ
interrupt
5
requests.
Bit4
IPRA4Description
0IRQ4, IRQ
interrupt requests have priority level 0 (low priority)(Initial value)
5
1IRQ4, IRQ5 interrupt requests have priority level 1 (high priority)
Bit 3—Priority Level A3 (IPRA3): Selects the priority level of WDT interrupt requests.
Bit3
IPRA3Description
0WDT interrupt requests have priority level 0 (low priority)(Initial value)
1WDT interrupt requests have priority level 1 (high priority)
Bit 2—Priority Level A2 (IPRA2): Selects the priority level of ITU channel 0 interrupt requests.