NEC UPD17P136ACT

µPD17134A SUBSERIES
4-BIT SINGLE-CHIP MICROCONTROLLER
µPD17134A
µPD17135A
µPD17136A
µPD17137A
µPD17P136A
µPD17P137A
©
1993
Document No. U11607EJ3V0UM00 (3rd edition)
Date Published December 1996 N
Printed in Japan
NOTES FOR CMOS DEVICES
1
PRECAUTION AGAINST ESD FOR SEMICONDUCTORS
Note:
Strong electric field, when exposed to a MOS device, can cause destruction of the gate oxide and
ultimately degrade the device operation. Steps must be taken to stop generation of static electricity
as much as possible, and quickly dissipate it once, when it has occurred. Environmental control
must be adequate. When it is dry, humidifier should be used. It is recommended to avoid using
insulators that easily build static electricity. Semiconductor devices must be stored and transported
in an anti-static container, static shielding bag or conductive material. All test and measurement
tools including work bench and floor should be grounded. The operator should be grounded using
wrist strap. Semiconductor devices must not be touched with bare hands. Similar precautions
need to be taken for PW boards with semiconductor devices on it.
2
HANDLING OF UNUSED INPUT PINS FOR CMOS
Note:
No connection for CMOS device inputs can be cause of malfunction. If no connection is provided
to the input pins, it is possible that an internal input level may be generated due to noise, etc., hence
causing malfunction. CMOS devices behave differently than Bipolar or NMOS devices. Input
levels of CMOS devices must be fixed high or low by using a pull-up or pull-down circuitry. Each
unused pin should be connected to V DD or GND with a resistor, if it is considered to have a
possibility of being an output pin. All handling related to the unused pins must be judged device
by device and related specifications governing the devices.
3
STATUS BEFORE INITIALIZATION OF MOS DEVICES
Note:
Power-on does not necessarily define initial status of MOS device. Production process of MOS
does not define the initial operation status of the device. Immediately after the power source is
turned ON, the devices with reset function have not yet been initialized. Hence, power-on does
not guarantee out-pin levels, I/O settings or contents of registers. Device is not initialized until
the reset signal is received. Reset operation must be executed immediately after power-on for
devices having reset function.
Regional Information
Some information contained in this document may vary from country to country. Before using any NEC
product in your application, please contact the NEC office in your country to obtain a list of authorized
representatives and distributors. They will verify:
• Device availability
• Ordering information
• Product release schedule
• Availability of related technical literature
• Development environment specifications (for example, specifications for third-party tools and
components, host computers, power plugs, AC supply voltages, and so forth)
• Network requirements
In addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary
from country to country.
NEC Electronics Inc. (U.S.)
NEC Electronics (Germany) GmbH
NEC Electronics Hong Kong Ltd.
Santa Clara, California
Tel: 800-366-9782
Fax: 800-729-9288
Benelux Office
Eindhoven, The Netherlands
Tel: 040-2445845
Fax: 040-2444580
Hong Kong
Tel: 2886-9318
Fax: 2886-9022/9044
NEC Electronics (Germany) GmbH
Duesseldorf, Germany
Tel: 0211-65 03 02
Fax: 0211-65 03 490
NEC Electronics Hong Kong Ltd.
Velizy-Villacoublay, France
Tel: 01-30-67 58 00
Fax: 01-30-67 58 99
Seoul Branch
Seoul, Korea
Tel: 02-528-0303
Fax: 02-528-4411
NEC Electronics (France) S.A.
NEC Electronics Singapore Pte. Ltd.
Spain Office
Madrid, Spain
Tel: 01-504-2787
Fax: 01-504-2860
United Square, Singapore 1130
Tel: 253-8311
Fax: 250-3583
NEC Electronics (France) S.A.
NEC Electronics (UK) Ltd.
Milton Keynes, UK
Tel: 01908-691-133
Fax: 01908-670-290
NEC Electronics Italiana s.r.1.
Milano, Italy
Tel: 02-66 75 41
Fax: 02-66 75 42 99
NEC Electronics Taiwan Ltd.
NEC Electronics (Germany) GmbH
Scandinavia Office
Taeby, Sweden
Tel: 08-63 80 820
Fax: 08-63 80 388
Taipei, Taiwan
Tel: 02-719-2377
Fax: 02-719-5951
NEC do Brasil S.A.
Sao Paulo-SP, Brasil
Tel: 011-889-1680
Fax: 011-889-1689
J96. 8
SIMPLEHOST is a trademark of NEC Corp.
MS-DOS and Windows are trademarks of Microsoft Corp.
PC/AT and PC DOS are trademarks of IBM Corp.
The export of this product from Japan is prohibited without governmental license. To export or re-export this product from
a country other than Japan may also be prohibited without a license from that country. Please call an NEC sales
representative.
The information in this document is subject to change without notice.
No part of this document may be copied or reproduced in any form or by any means without the prior written
consent of NEC Corporation. NEC Corporation assumes no responsibility for any errors which may appear in
this document.
NEC Corporation does not assume any liability for infringement of patents, copyrights or other intellectual property
rights of third parties by or arising from use of a device described herein or any other liability arising from use
of such device. No license, either express, implied or otherwise, is granted under any patents, copyrights or other
intellectual property rights of NEC Corporation or others.
While NEC Corporation has been making continuous effort to enhance the reliability of its semiconductor devices,
the possibility of defects cannot be eliminated entirely. To minimize risks of damage or injury to persons or
property arising from a defect in an NEC semiconductor device, customers must incorporate sufficient safety
measures in its design, such as redundancy, fire-containment, and anti-failure features.
NEC devices are classified into the following three quality grades:
"Standard", "Special", and "Specific". The Specific quality grade applies only to devices developed based on a
customer designated “quality assurance program“ for a specific application. The recommended applications of
a device depend on its quality grade, as indicated below. Customers must check the quality grade of each device
before using it in a particular application.
Standard: Computers, office equipment, communications equipment, test and measurement equipment,
audio and visual equipment, home electronic appliances, machine tools, personal electronic
equipment and industrial robots
Special: Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster
systems, anti-crime systems, safety equipment and medical equipment (not specifically designed
for life support)
Specific: Aircrafts, aerospace equipment, submersible repeaters, nuclear reactor control systems, life
support systems or medical equipment for life support, etc.
The quality grade of NEC devices is "Standard" unless otherwise specified in NEC's Data Sheets or Data Books.
If customers intend to use NEC devices for applications other than those specified for Standard quality grade,
they should contact an NEC sales representative in advance.
Anti-radioactive design is not implemented in this product.
M7 96.5
Major Revisions in This Edition
Page
Description
Throughout
Change of name µPD1713XA to µPD17134A subseries
p. 5
Correction of (2) Program memory write/verify mode in 1.4 PIN CONFIGURATION
p. 18
Change of Figure 3-2 Value of Program Counter after Instruction
Partial correction of 3.2.2 On Execution of Branch Instruction (BR)
p. 19
Partial correction of 3.2.3 On During Execution of Subroutine Call
p. 23
Change of CHAPTER 4 PROGRAM MEMORY (ROM)
p. 31
Partial correction of Figure 5-1 Data Memory Configuration
p. 35
Change of CHAPTER 6 STACK
p. 43
Partial correction of 7.2.2 Address Register Functions
p. 47
Change of 7.5 INDEX REGISTER (IX) AND DATA MEMORY ROW ADDRESS
POINTER (MEMORY POINTER: MP)
p. 58
Partial change of 7.6.2 Functions of General Register Pointer
p. 59
Partial change of 7.7.1 Program Status Word Configuration
p. 61
Change of 7.7.4 Zero Flag (Z) and Compare Flag (CMP)
p. 61
Partial correction of 7.7.5 Carry Flag (CY)
p. 71
Partial correction of 9.2.3 Register File Manipulation Instructions
p. 111
Change of CHAPTER 13 PERIPHERAL HARDWARE
p. 149
Change of CHAPTER 14 INTERRUPT FUNCTIONS
p. 169
Change of CHAPTER 16 STANDBY FUNCTION
p. 179
Change of CHAPTER 17 RESET
p. 190
Partial change of Table 18-2 Differences between Mask ROM Version and OneTime PROM Version
p. 194
Partial change of 19.3 LIST OF THE INSTRUCTION SET
p. 198
Partial change of 19.5 INSTRUCTIONS
p. 255
Change of CHAPTER 20 ASSEMBLER RESERVED WORDS
p. 257
Partial change of 20.2 RESERVED SYMBOLS
p. 261
Addition of APPENDIX A DEVELOPMENT OF µPD171×× SUBSERIES
p. 263
Addition of APPENDIX B COMPARISON OF FUNCTIONS BETWEEN µPD17135A,
17137A, AND µPD17145 SUBSERIES
p. 267
Addition of APPENDIX D NOTES ON CONFIGURATION OF SYSTEM CLOCK
OSCILLATION CIRCUIT
The mark
shows major revisions made in this edition.
PREFACE
Target
: This manual is intended for user engineers who understand the functions of each product in
the µPD17134A subseries and try to design application systems using the µPD17134A
subseries.
Purpose
: The purpose of this manual is for the user to understand the hardware functions of the
µPD17134A subseries.
Use
: The manual assumes that the reader has a general knowledge of electricity, logic circuits,
microcomputers.
• To understand the functions of the µPD17134A subseries in a general way;
→ Read the manual from CONTENTS.
• To look up instruction functions in detail when you know the mnemonic of an
instruction;
→ Use APPENDIX E INSTRUCTION LIST.
• To look up an instruction when you do not know its mnemonic but know outlines of
the function;
→ Refer to 19.3 LIST OF THE INSTRUCTION SET for search for the mnemonic of the
instruction, then see 19.5 INSTRUCTIONS for the functions.
• To learn the electrical specifications of the µPD17134A subseries
→ Refer to the Data Sheet available separately.
• To learn the application examples of the functions of the µPD17134A subseries
→ Refer to the Application Note available separately.
Legend
: Data representation weight : High-order and low-order digits are indicated from left to right.
Active low representation
: ××× (pin or signal name is overlined)
Memory map address
: Top: low-order, bottom: high-order
Note
: Explanation of Note in the text
Caution
: Caution to which you should pay attention
Remark
: Supplementary explanation to the text
Number representation
: Binary number
Decimal number
...×××× or ××××B
...××××
Hexadecimal number ...××××H
Related Documents : The following documents are provided for the µPD17134A subseries.
The numbers listed in the table are the document numbers.
Product name
µPD17134A
µPD17135A
µPD17136A
µPD17137A
µPD17P136A
µPD17P137A
IF-1166
IF-1169
IF-1166
IF-1169
IF-1168
IF-1165
U10591E
U10592E
U10591E
U10592E
IC-2871
IC-2872
Document name
Brochure
Data sheet
User’s manual
IEU-1369
Application note
IEA-1297 (Introduction), IEA-1293 (Rice cooker, thermos bottle)
IE-17K (Ver. 1.6)
user’s manual
EEU-1467
IE-17K-ET (Ver. 1.6)
user’s manual
EEU-1466
SE board
user’s manual
EEU-1379
SIMPLEHOSTTM
user’s manual
EEU-1336 (Introduction), EEU-1337 (Reference)
AS17K assembler
EEU-1287
user’s manual
Device file
user’s manual
U10777E
Pin name and symbol name should be read according to the system clock type.
System clock
Pin name, symbol name
Pin for system clock oscillation
System clock
RC oscillation
µPD17134A
µPD17136A
µPD17P136A
Ceramic oscillation
µPD17135A
µPD17137A
µPD17P137A
OSC1
XIN
OSC0
XOUT
fCC
fX
TABLE OF CONTENTS
CHAPTER 1 GENERAL DESCRIPTION ................................................................................................. 1
1.1
FUNCTION LIST ........................................................................................................................................ 2
1.2
ORDERING INFORMATION ..................................................................................................................... 3
1.3
BLOCK DIAGRAM .................................................................................................................................... 4
1.4
PIN CONFIGURATION (TOP VIEW) ........................................................................................................ 5
CHAPTER 2 PIN FUNCTIONS ............................................................................................................... 9
2.1
PIN FUNCTIONS ....................................................................................................................................... 9
2.2
PIN INPUT/OUTPUT CIRCUIT ............................................................................................................... 11
2.3
PROCESSING OF UNUSED PINS ......................................................................................................... 14
2.4
NOTES ON USING RESET PIN AND P1B0 PIN ................................................................................... 15
CHAPTER 3 PROGRAM COUNTER (PC) ........................................................................................... 17
3.1
PROGRAM COUNTER CONFIGURATION ............................................................................................ 17
3.2
PROGRAM COUNTER OPERATION ..................................................................................................... 17
3.2.1
At Reset ..................................................................................................................................... 18
3.2.2
During Execution of the Branch Instruction (BR) ..................................................................... 18
3.2.3
During Execution of Subroutine Calls (CALL) .......................................................................... 19
3.2.4
During Execution of Return Instructions (RET, RETSK, RETI) ............................................... 20
3.2.5
During Table Reference (MOVT) .............................................................................................. 20
3.2.6
During Execution of Skip Instructions (SKE, SKGE, SKLT, SKNE, SKT, SKF) ...................... 21
3.2.7
When an Interrupt Is Received ................................................................................................. 21
CHAPTER 4
4.1
4.2
PROGRAM MEMORY (ROM).......................................................................................... 23
PROGRAM MEMORY CONFIGURATION ............................................................................................. 23
PROGRAM MEMORY USAGE ............................................................................................................... 24
4.2.1
Flow of the Program .................................................................................................................. 24
4.2.2
Table Reference ......................................................................................................................... 27
CHAPTER 5 DATA MEMORY (RAM) .................................................................................................... 31
5.1
DATA MEMORY CONFIGURATION ....................................................................................................... 31
5.1.1
System Register (SYSREG) ..................................................................................................... 32
5.1.2
Data Buffer (DBF) ...................................................................................................................... 32
5.1.3
General Register (GR) .............................................................................................................. 33
5.1.4
Port Registers ............................................................................................................................ 33
5.1.5
General Data Memory ............................................................................................................... 34
5.1.6
Unmounted Data Memory ......................................................................................................... 34
-i-
CHAPTER 6
STACK .............................................................................................................................. 35
6.1
STACK CONFIGURATION ...................................................................................................................... 35
6.2
FUNCTIONS OF THE STACK ................................................................................................................ 35
6.3
ADDRESS STACK REGISTERS (ASRs) ............................................................................................... 36
6.4
INTERRUPT STACK REGISTERS (INTSKs) ........................................................................................ 36
6.5
STACK POINTER (SP) AND INTERRUPT STACK REGISTERS ........................................................ 37
6.6
6.7
STACK OPERATION ............................................................................................................................... 38
6.6.1
On Execution of Instructions CALL, RET, RETSK ................................................................... 38
6.6.2
Table Reference (MOVT DBF, @AR Instruction) ..................................................................... 38
6.6.3
Operation on Execution of Interrupt Receipt and RETI Instruction......................................... 39
STACK NESTING LEVELS AND THE PUSH AND POP INSTRUCTIONS ......................................... 39
CHAPTER 7 SYSTEM REGISTER (SYSREG) .................................................................................... 41
7.1
SYSTEM REGISTER CONFIGURATION ............................................................................................... 41
7.2
ADDRESS REGISTER (AR) ................................................................................................................... 43
7.3
7.4
7.5
7.2.1
Address Register Configuration ................................................................................................ 43
7.2.2
Address Register Functions ...................................................................................................... 43
WINDOW REGISTER (WR) .................................................................................................................... 45
7.3.1
Window Register Configuration ................................................................................................ 45
7.3.2
Window Register Functions ...................................................................................................... 45
BANK REGISTER (BANK) ..................................................................................................................... 46
7.4.1
Bank Register Configuration ..................................................................................................... 46
7.4.2
Functions of Bank Register ....................................................................................................... 46
INDEX REGISTER (IX) AND DATA MEMORY ROW ADDRESS POINTER
(MEMORY POINTER: MP) ...................................................................................................................... 47
7.6
7.7
7.8
7.5.1
Index Register (IX) .................................................................................................................... 47
7.5.2
Data Memory Row Address Pointer (Memory Pointer: MP) .................................................... 47
7.5.3
IXE = 0 and MPE = 0 (No Data Memory Modification) ........................................................... 49
7.5.4
IXE = 0 and MPE = 1 (Diagonal Indirect Data Transfer) ......................................................... 51
7.5.5
IXE = 1 and MPE = 0 (Index Modification) ............................................................................... 53
GENERAL REGISTER POINTER (RP) .................................................................................................. 57
7.6.1
General Register Pointer Configuration ................................................................................... 57
7.6.2
Functions of the General Register Pointer ............................................................................... 58
PROGRAM STATUS WORD (PSWORD) ............................................................................................... 59
7.7.1
Program Status Word Configuration ......................................................................................... 59
7.7.2
Functions of the Program Status Word .................................................................................... 60
7.7.3
Index Enable Flag (IXE) ............................................................................................................ 61
7.7.4
Zero Flag (Z) and Compare Flag (CMP) .................................................................................. 61
7.7.5
Carry Flag (CY) ......................................................................................................................... 61
7.7.6
Binary-Coded Decimal Flag (BCD) ........................................................................................... 62
7.7.7
Notes Concerning Use of Arithmetic Operations ..................................................................... 62
NOTES CONCERNING USE OF THE SYSTEM REGISTER ............................................................... 63
7.8.1
Reserved Words for the System Register ................................................................................ 63
7.8.2
Handling of System Register Addresses Fixed at 0 ................................................................ 65
- ii -
CHAPTER 8 GENERAL REGISTER (GR) ........................................................................................... 67
8.1
GENERAL REGISTER CONFIGURATION ............................................................................................ 67
8.2
FUNCTIONS OF THE GENERAL REGISTER ....................................................................................... 67
CHAPTER 9 REGISTER FILE (RF) ...................................................................................................... 69
9.1
9.2
REGISTER FILE CONFIGURATION ...................................................................................................... 69
9.1.1
Configuration of the Register File ............................................................................................. 69
9.1.2
Relationship between the Register File and Data Memory ..................................................... 69
FUNCTIONS OF THE REGISTER FILE ................................................................................................. 70
9.2.1
Functions of the Register File ................................................................................................... 70
9.2.2
Functions of Control Register ................................................................................................... 70
9.2.3
Register File Manipulation Instructions .................................................................................... 71
9.3
CONTROL REGISTER ............................................................................................................................ 72
9.4
NOTES CONCERNING USE OF THE REGISTER FILE....................................................................... 73
9.4.1
Notes Concerning Operation of the Control Register (Read-Only and Unused Registers) ... 73
9.4.2
Register File Symbol Definitions and Reserved Words ........................................................... 73
CHAPTER 10
DATA BUFFER (DBF) ................................................................................................... 77
10.1 DATA BUFFER CONFIGURATION ........................................................................................................ 77
10.2 FUNCTIONS OF THE DATA BUFFER ................................................................................................... 78
10.2.1
Data Buffer and Peripheral Hardware ...................................................................................... 79
10.2.2
Data Transfer with Peripheral Hardware .................................................................................. 80
10.2.3
Table Reference ......................................................................................................................... 81
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU) ....................................................................... 83
11.1 ALU BLOCK CONFIGURATION ............................................................................................................ 83
11.2 FUNCTIONS OF THE ALU BLOCK ....................................................................................................... 83
11.2.1
Functions of the ALU ................................................................................................................. 83
11.2.2
Functions of Temporary Registers A and B .............................................................................. 88
11.2.3
Functions of the Status Flip-flop ............................................................................................... 88
11.2.4
Operations in 4-Bit Binary ......................................................................................................... 89
11.2.5
Operations in BCD ..................................................................................................................... 89
11.2.6
Operations in the ALU Block ..................................................................................................... 90
11.3 ARITHMETIC OPERATIONS (ADDITION AND SUBTRACTION IN 4-BIT BINARY AND BCD) ....... 91
11.3.1
Addition and Subtraction When CMP = 0 and BCD = 0 .......................................................... 91
11.3.2
Addition and Subtraction When CMP = 1 and BCD = 0 .......................................................... 91
11.3.3
Addition and Subtraction When CMP = 0 and BCD = 1 .......................................................... 92
11.3.4
Addition and Subtraction When CMP = 1 and BCD = 1 .......................................................... 92
11.3.5
Notes Concerning Use of Arithmetic Operations ..................................................................... 92
11.4 LOGICAL OPERATIONS ........................................................................................................................ 93
11.5 BIT JUDGEMENTS ................................................................................................................................. 94
11.5.1
TRUE (1) Bit Judgement ........................................................................................................... 94
11.5.2
FALSE (0) Bit Judgement ......................................................................................................... 95
- iii -
11.6 COMPARISON JUDGEMENTS .............................................................................................................. 96
11.6.1
“Equal to” Judgement ................................................................................................................ 96
11.6.2
“Not Equal to” Judgement ......................................................................................................... 97
11.6.3
“Greater Than or Equal to” Judgement .................................................................................... 97
11.6.4
“Less Than” Judgement ............................................................................................................ 98
11.7 ROTATIONS ............................................................................................................................................. 99
11.7.1
Rotation to the Right ................................................................................................................. 99
11.7.2
Rotation to the Left .................................................................................................................. 100
CHAPTER 12 PORTS ......................................................................................................................... 101
12.1 PORT 0A (P0A0, P0A1, P0A2, P0A3) .................................................................................................... 101
12.2 PORT 0B (P0B0, P0B1, P0B2, P0B3) .................................................................................................... 102
12.3 PORT 0C (P0C0/ADC0, P0C1/ADC1, P0C2/ADC2, P0C3/ADC3) .......................................................... 103
12.4 PORT 0D (P0D0/SCK, P0D1/SO, P0D2/SI, P0D3/TM0OUT) ................................................................ 104
12.5 PORT 1A (P1A0, P1A1, P1A2, P1A3) .................................................................................................... 105
12.6 PORT 1B (P1B0) .................................................................................................................................... 105
12.7 PORT CONTROL REGISTER ............................................................................................................... 106
12.7.1
Input/Output Switching by Group I/O ...................................................................................... 106
12.7.2
Input/Output Switching by Bit I/O ........................................................................................... 107
12.7.3
Specifying Pull-Up Resistor Incorporation Using Software ................................................... 109
CHAPTER 13 PERIPHERAL HARDWARE ......................................................................................... 111
13.1 8-BIT TIMERS/COUNTERS (TM0 and TM1) ........................................................................................ 111
13.1.1
8-Bit Timers/Counters Configuration ....................................................................................... 111
13.1.2
Operation of 8-Bit Timers/Counters ........................................................................................ 115
13.1.3
Selecting Count Pulse ............................................................................................................. 115
13.1.4
Setting Count Value to Modulo Register ................................................................................ 116
13.1.5
Reading Value of Count Register ........................................................................................... 117
13.1.6
Setting of Interval Time ........................................................................................................... 118
13.1.7
Error of Interval Time ............................................................................................................... 119
13.1.8
Timer 0 Output ......................................................................................................................... 121
13.2 BASIC INTERVAL TIMER (BTM) ......................................................................................................... 122
13.2.1
Basic Interval Timer Configuration .......................................................................................... 122
13.2.2
Registers Controlling Basic Interval Timer ............................................................................. 123
13.2.3
Operation of Basic Interval Timer ........................................................................................... 124
13.2.4
Watchdog Timer Function ....................................................................................................... 125
13.3 A/D CONVERTER ................................................................................................................................. 128
13.3.1
A/D Converter Configuration ................................................................................................... 128
13.3.2
Functions of A/D Converter ..................................................................................................... 129
13.3.3
Setting Values in the 8-bit Data Register (ADCR) ................................................................. 132
13.3.4
Reading Values from the 8-bit Data Register (ADCR) .......................................................... 133
13.3.5
A/D Converter Operation ......................................................................................................... 134
13.4 SERIAL INTERFACE (SIO) .................................................................................................................. 141
13.4.1
Functions of the Serial Interface ............................................................................................. 141
13.4.2
3-wire Serial Interface Operation Modes ................................................................................ 143
13.4.3
Setting Values in the Shift Register ........................................................................................ 147
13.4.4
Reading Values from the Shift Register ................................................................................. 148
- iv -
CHAPTER 14 INTERRUPT FUNCTIONS ............................................................................................ 149
14.1 INTERRUPT SOURCE TYPES AND VECTOR ADDRESSES ............................................................ 150
14.2 HARDWARE COMPONENTS OF THE INTERRUPT CONTROL CIRCUIT ....................................... 151
14.3 INTERRUPT SEQUENCE ..................................................................................................................... 158
14.3.1
Receiving an Interrupt ............................................................................................................. 158
14.3.2
Return from the Interrupt Routine ........................................................................................... 159
14.3.3
Interrupt Accepting Timing ...................................................................................................... 160
14.4 MULTI-INTERRUPT ............................................................................................................................... 163
14.5 PROGRAM EXAMPLE OF INTERRUPT ............................................................................................. 164
CHAPTER 15 AC ZERO CROSS DETECTION .................................................................................. 167
CHAPTER 16 STANDBY FUNCTION .................................................................................................. 169
16.1 OVERVIEW OF THE STANDBY FUNCTION ....................................................................................... 169
16.2 HALT MODE .......................................................................................................................................... 170
16.2.1
Setting HALT Mode ................................................................................................................. 170
16.2.2
Start Address after HALT Mode Is Released ......................................................................... 170
16.2.3
HALT Mode Setting Conditions ............................................................................................... 172
16.3 STOP MODE .......................................................................................................................................... 174
16.3.1
Setting of STOP Mode ............................................................................................................ 174
16.3.2
Start Address after STOP Mode Is Released ........................................................................ 174
16.3.3
STOP Mode Setting Conditions .............................................................................................. 176
CHAPTER 17 RESET ........................................................................................................................... 179
17.1 RESET FUNCTION ................................................................................................................................ 180
17.2 RESETTING ........................................................................................................................................... 181
17.3 POWER-ON/POWER-DOWN RESET FUNCTION .............................................................................. 182
17.3.1
Conditions Required to Enable the Power-On Reset Function ............................................. 182
17.3.2
Power-On Reset Function and Operation .............................................................................. 183
17.3.3
Condition Required for Use of the Power-Down Reset Function .......................................... 185
17.3.4
Power-Down Reset Function and Operation .......................................................................... 185
CHAPTER 18 ONE-TIME PROM WRITING/VERIFYING.................................................................... 189
18.1 DIFFERENCES BETWEEN MASK ROM VERSION AND ONE-TIME PROM MODEL..................... 189
18.2 OPERATION MODE WHEN PROGRAM MEMORY IS WRITTEN/VERIFIED ................................... 190
18.3 WRITING PROCEDURE OF PROGRAM MEMORY ........................................................................... 191
18.4 READING PROCEDURE OF PROGRAM MEMORY .......................................................................... 192
CHAPTER 19 INSTRUCTION SET ...................................................................................................... 193
19.1 OVERVIEW OF THE INSTRUCTION SET ........................................................................................... 193
19.2 LEGEND ................................................................................................................................................. 194
19.3 LIST OF THE INSTRUCTION SET ....................................................................................................... 195
19.4 ASSEMBLER (AS17K) EMBEDDED MACRO INSTRUCTIONS ........................................................ 197
-v-
19.5 INSTRUCTIONS .................................................................................................................................... 198
19.5.1
Addition Instructions ................................................................................................................ 198
19.5.2
Subtraction Instructions ........................................................................................................... 209
19.5.3
Logical Operation Instructions ................................................................................................ 216
19.5.4
Judgment Instructions ............................................................................................................. 221
19.5.5
Comparison Instructions .......................................................................................................... 223
19.5.6
Rotation Instructions ................................................................................................................ 226
19.5.7
Transfer Instructions ................................................................................................................ 227
19.5.8
Branch Instructions .................................................................................................................. 243
19.5.9
Subroutine Instructions ............................................................................................................ 246
19.5.10 Interrupt Instructions ................................................................................................................ 251
19.5.11 Other Instructions .................................................................................................................... 253
CHAPTER 20 ASSEMBLER RESERVED WORDS ............................................................................ 255
20.1 MASK OPTION DIRECTIVE ................................................................................................................. 255
20.1.1
Specifying Mask Option .......................................................................................................... 255
20.2 RESERVED SYMBOLS ......................................................................................................................... 257
APPENDIX A DEVELOPMENT OF µPD171×× SUBSERIES ............................................................. 261
APPENDIX B COMPARISON OF FUNCTIONS BETWEEN µPD17135A, 17137A, AND
µPD17145 SUBSERIES ................................................................................................ 263
APPENDIX C DEVELOPMENT TOOLS .............................................................................................. 265
APPENDIX D NOTES ON CONFIGURATION OF SYSTEM CLOCK OSCILLATION CIRCUIT ...... 267
APPENDIX E INSTRUCTION LIST ...................................................................................................... 269
E.1
INSTRUCTION LIST (by function) ...................................................................................................... 269
E.2
IINSTRUCTION LIST (alphabetical order) ......................................................................................... 270
APPENDIX F ORDERING MASK ROM ............................................................................................... 271
- vi -
LIST OF FIGURES (1/3)
Figure No.
Title
Page
3-1
Program Counter ...................................................................................................................................... 17
3-2
Value of the Program Counter after Instruction Execution .................................................................... 18
3-3
Value in the Program Counter after Reset ............................................................................................. 18
3-4
Value in the Program Counter during Execution of a BR addr Instruction ........................................... 18
3-5
Value in the Program Counter during Execution of an Indirect Branch Instruction .............................. 19
3-6
Value in the Program Counter during Execution of a CALL addr .......................................................... 19
3-7
Value in the Program Counter during Execution of an Indirect Subroutine Call .................................. 20
3-8
Value in the Program Counter during Execution of a Return Instruction .............................................. 20
4-1
Program Memory Map for the µPD17134A Subseries ........................................................................... 23
4-2
CALL addr Instruction .............................................................................................................................. 26
4-3
Table Reference (MOVT DBF, @AR) ...................................................................................................... 27
5-1
Data Memory Configuration ..................................................................................................................... 31
5-2
System Register Configuration ................................................................................................................ 32
5-3
Data Buffer Configuration ........................................................................................................................ 32
5-4
General Register (GR) Configuration ...................................................................................................... 33
5-5
Port Register Configuration ..................................................................................................................... 33
6-1
Stack Configuration .................................................................................................................................. 35
7-1
Allocation of System Register in Data Memory ...................................................................................... 41
7-2
System Register Configuration ................................................................................................................ 42
7-3
Address Register Configuration .............................................................................................................. 43
7-4
Address Register Used as a Peripheral Circuit ...................................................................................... 44
7-5
Window Register Configuration ............................................................................................................... 45
7-6
Example of Window Register Operation ................................................................................................. 45
7-7
Bank Register Configuration ................................................................................................................... 46
7-8
Index Register Configuration ................................................................................................................... 47
7-9
Modification of Data Memory Address by Index Register and Memory Pointer ................................... 48
7-10
Operation Example When IXE = 0 and MPE = 0 ................................................................................... 50
7-11
Operation Example When IXE = 0 and MPE = 1 ................................................................................... 52
7-12
Operation Example When IXE = 1 and MPE = 0 ................................................................................... 54
7-13
Operation Example When IXE = 1 and MPE = 0 ................................................................................... 55
7-14
Operation Example When IXE = 1 and MPE = 0 (Array Processing) ................................................... 56
7-15
General Register Pointer Configuration .................................................................................................. 57
7-16
General Register Configuration ............................................................................................................... 58
7-17
Program Status Word Configuration ....................................................................................................... 59
7-18
Outline of Functions of the Program Status Word ................................................................................. 60
8-1
General Register Configuration ............................................................................................................... 68
- vii -
LIST OF FIGURES (2/3)
Figure No.
Title
Page
9-1
Register File Configuration ...................................................................................................................... 69
9-2
Relationship Between the Register File and Data Memory ................................................................... 70
9-3
Accessing the Register File Using the PEEK and POKE Instructions .................................................. 72
9-4
Control Register Configuration ................................................................................................................ 75
10-1
Allocation of the Data Buffer ................................................................................................................... 77
10-2
Data Buffer Configuration ........................................................................................................................ 77
10-3
Relationship Between the Data Buffer and Peripheral Hardware ......................................................... 78
11-1
ALU Configuration .................................................................................................................................... 84
12-1
Input/Output Switching by Group I/O .................................................................................................... 106
12-2
Port Control Register of Bit I/O ............................................................................................................. 107
12-3
Specifying Pull-Up Resistor Incorporation Using Software .................................................................. 109
13-1
Configuration of the 8-Bit Timer Counters ............................................................................................ 112
13-2
Timer 0 Mode Register .......................................................................................................................... 113
13-3
Timer 1 Mode Register .......................................................................................................................... 114
13-4
Setting Count Value to Modulo Register ............................................................................................... 116
13-5
Reading Count Value of Count Register ............................................................................................... 117
13-6
Error When Count Register Is Cleared to 0 During Counting ............................................................. 119
13-7
Error When Counting Is Started from Count Stop Status .................................................................... 120
13-8
Timer 0 Output Setting Register ............................................................................................................ 121
13-9
Basic Interval Timer Configuration ........................................................................................................ 122
13-10
BTM Mode Register ............................................................................................................................... 123
13-11
Watchdog Timer Mode Register ............................................................................................................ 124
13-12
Timing Chart of Watchdog Timer (with WDTRES Flag Used) ............................................................. 126
13-13
Block Diagram of the A/D Converter ..................................................................................................... 128
13-14
A/D Converter Control Register ............................................................................................................ 130
13-15
Setting a Value in the 8-Bit Data Register (ADCR) .............................................................................. 132
13-16
Reading Values from the 8-bit Data Register (ADCR) ......................................................................... 133
13-17
Relationship between the Analog Input Voltage and Digital Conversion Result ................................ 134
13-18
Using the Successive Mode for the A/D Converter .............................................................................. 136
13-19
A/D Conversion Timing in the Continuous Mode ................................................................................. 137
13-20
Using the Single Mode for the A/D Converter ...................................................................................... 139
13-21
Single Mode Operation (Comparison) Timing ...................................................................................... 140
13-22
Block Diagram of the Serial Interface ................................................................................................... 142
13-23
Timing of 8-Bit Transmission and Reception Mode (Simultaneous Transmission and Reception) .. 143
13-24
Timing of the Clock Synchronization 8-Bit Reception Mode (SO Pin Output High Impedance) ........ 144
13-25
Serial Interface Control Register ........................................................................................................... 145
13-26
Setting a Value in the Shift Register ..................................................................................................... 147
13-27
Reading a Value from the Shift Register .............................................................................................. 148
- viii -
LIST OF FIGURES (3/3)
Figure No.
Title
Page
14-1
Interrupt Control Register ...................................................................................................................... 152
14-2
Interrupt Processing Procedure ............................................................................................................ 158
14-3
Return from Interrupt Processing .......................................................................................................... 159
14-4
Interrupt Accepting Timing (When INTE = 1, IP××× = 1) ..................................................................... 160
14-5
Example of Multi-interrupt ..................................................................................................................... 163
15-1
Block Diagram for the AC Zero Cross Detector ................................................................................... 167
15-2
Zero Cross Detection Signal ................................................................................................................. 168
16-1
Releasing HALT Mode ........................................................................................................................... 171
16-2
Releasing STOP Mode .......................................................................................................................... 175
17-1
Reset Block Configuration ..................................................................................................................... 181
17-2
Reset Operation ..................................................................................................................................... 181
17-3
Example of the Power-On Reset Operation ......................................................................................... 184
17-4
Example of the Power-Down Reset Operation ..................................................................................... 186
17-5
Example of Reset Operation during the Period from Power-Down Reset to Power Recovery ......... 187
18-1
Procedure of Program Memory Writing ................................................................................................ 191
18-2
Procedure of Program Memory Reading .............................................................................................. 192
D-1
External Circuit of System Clock Oscillation Circuit ............................................................................. 267
D-2
Example of Incorrect Oscillation Circuits .............................................................................................. 268
- ix -
LIST OF TABLES (1/2)
Table No.
Title
Page
2-1
Processing of Unused Pins ..................................................................................................................... 14
4-1
Program Memory Configuration .............................................................................................................. 23
4-2
Vector Address for the µPD17134A Subseries ...................................................................................... 24
6-1
Operation of Stack Pointer ...................................................................................................................... 37
6-2
Operation of the Instructions CALL, RET, and RETSK .......................................................................... 38
6-3
Stack Operation during Table Reference ................................................................................................ 38
6-4
Operation during Interrupt Receipt and RETI Instruction ...................................................................... 39
6-5
Stack Operation during the PUSH and POP Instructions ...................................................................... 39
7-1
Specifying the Bank in Data Memory ...................................................................................................... 46
7-2
Instructions Subject to Address Modification .......................................................................................... 48
7-3
Zero Flag (Z) and Compare Flag (CMP) ................................................................................................ 61
10-1
Peripheral Hardware ................................................................................................................................ 79
11-1
List of ALU Instructions ............................................................................................................................ 86
11-2
Results of Arithmetic Operations Performed in 4-Bit Binary and BCD .................................................. 89
11-3
Types of Arithmetic Operations ............................................................................................................... 91
11-4
Logical Operations ................................................................................................................................... 93
11-5
Table of True Values for Logical Operations .......................................................................................... 93
11-6
Bit Judgement Instructions ...................................................................................................................... 94
11-7
Comparison Judgement Instructions ....................................................................................................... 96
12-1
Writing into and Reading from the Port Register (0.70H) .................................................................... 101
12-2
Writing into and Reading from the Port Register (0.71H) .................................................................... 102
12-3
Switching the Port and A/D Converter .................................................................................................. 103
12-4
Register File Contents and Pin Functions ............................................................................................ 104
12-5
Contents Read from the Port Register (0.73H) .................................................................................... 105
12-6
Writing into and Reading from the Port Register (1.70H) .................................................................... 105
13-1
Data Conversion Time for the A/D Converter ....................................................................................... 138
13-2
Serial Clock List ..................................................................................................................................... 141
13-3
Operating Mode of the Serial Interface ................................................................................................. 143
14-1
Interrupt Source Types .......................................................................................................................... 150
14-2
Interrupt Request Flag and Interrupt Enable Flag ................................................................................ 151
16-1
Status in Standby Mode ........................................................................................................................ 169
16-2
HALT Mode Release Condition ............................................................................................................. 170
16-3
Start Address after HALT Mode Is Released ........................................................................................ 170
16-4
STOP Mode Release Condition ............................................................................................................ 174
16-5
Start Address after STOP Mode Is Released ....................................................................................... 174
-x-
LIST OF TABLES (2/2)
Table No.
Title
Page
17-1
Hardware Status at Reset ..................................................................................................................... 180
18-1
Pins Used for Writing/Verifying Program Memory ................................................................................ 189
18-2
Differences Between Mask ROM Version and One-Time PROM Version .......................................... 190
18-3
Setting Operation Modes ....................................................................................................................... 190
20-1
Mask Option Definition Directive ........................................................................................................... 256
- xi -
[MEMO]
- xii -
CHAPTER 1 GENERAL DESCRIPTION
1
The µPD17134A subseries is a 4-bit single-chip microcontroller employing the 17K architecture and containing an
8-bit A/D converter (4 channels), a timer (3 channels), an AC zero cross detector, a power-on reset circuit, and a serial
interface.
The µPD17P136A and 17P137A are the one-time PROM version of the µPD17136A and 17137A, respectively,
and are suitable for program evaluation at system development and for small-scale production.
The following are features of the µPD17134A subseries.
•
•
17K architecture: general-purpose register mode, instruction length: fixed to 16 bits
•
Program memory: µPD17134A
: 2K bytes (1024 × 16 bits)
µPD17135A
: 2K bytes (1024 × 16 bits)
µPD17136A
: 4K bytes (2048 × 16 bits)
µPD17137A
: 4K bytes (2048 × 16 bits)
Instruction execution time: 2 µs (fX = 8 MHz, ceramic oscillation)
8 µs (fCC = 2 MHz, RC oscillation)
µPD17P136A : 4K bytes (2048 × 16 bits, one-time PROM)
µPD17P137A : 4K bytes (2048 × 16 bits, one-time PROM)
•
•
•
•
•
Data memory (RAM): 112 × 4 bits
A/D converter: 4 channels (8-bit resolution, successive approximation type)
Timer: 3 channels (8-bit timer/counter × 2 channels, basic interval timerNote)
Serial interface: 1 channel (clocked 3-wire mode)
Supply voltage: VDD = 4.5 to 5.5 V (fX = 400 kHz to 8 MHz)
VDD = 2.7 to 5.5 V (fX = 400 kHz to 4 MHz)
VDD = 2.7 to 5.5 V (fCC = 400 kHz to 2 MHz) for µPD17134A and 17136A
Note
An internal reset signal can be generated by using the basic interval timer (watchdog timer function).
These features of the µPD17134A subseries are suitable for use as a controller or a slave device in the following
application fields;
•
•
•
•
•
•
Electronic thermos bottle
Rice cooker
Audio equipment
Battery charger
Printer
Plain Paper Copier
1
CHAPTER 1 GENERAL DESCRIPTION
1.1 FUNCTION LIST
Item
µPD17134A
µPD17135A
µPD17136A
ROM configuration
Mask ROM
ROM capacity
2KB (1024 ✕ 16 bits)
RAM capacity
112 ✕ 4 bits
Stack
Address stack × 5, interrupt stack × 3
Number of I/O port
22
A/D converter
Timer
µPD17137A
µPD17P136A
µPD17P137A
One-time PROM
4KB (2048 ✕ 16 bits)
• I/O
: 20
• Input only
:1
• Sensor inputNote : 1
8-bit resolution × 4 channels (shared with port pin), absolute precision ± 1.5 LSB or less
3 channels
• 8-bit timer counter
: 2 channels (16-bit timer 1 channel applicable)
• 7-bit basic interval timer : 1 channel (watchdog timer applicable)
Serial interface
1 channel (3 wires)
AC zero cross detection
function
Provided (can be used in application circuit at VDD = 5 V ± 10%)
Interrupt
• Nesting by hardware (up to 3 levels)
Rising edge detection
• External interrupts (INT) : 1
Falling edge detection
Both rising and falling edges detection
• Timer 0 (TM0)
• Timer 1 (TM1)
• Internal interrupts
:1
• Basic interval timer (BTM)
Selectable
• Serial interface (SIO)
System clock
RC
oscillation
Ceramic
oscillation
RC
oscillation
Ceramic
oscillation
RC
oscillation
Ceramic
oscillation
Instruction
execution time
8 µs
at fX = 2 MHz
2 µs
at fX = 8 MHz
8 µs
at fX = 2 MHz
2 µs
at fX = 8 MHz
8 µs
at fX = 2 MHz
2 µs
at fX = 8 MHz
Standby
HALT, STOP
Power-on/
power-down reset
Available (effective only for application circuit with VDD = 5 V ± 10 %, 400 kHz to 4 MHz)
Supply voltage
VDD = 2.7 to 5.5 V (5 V ±10 % when using A/D converter)
Package
28-pin plastic shrink DIP, 28-pin plastic SOP
Note
The INT pin can be used as an input pin (sense input) when the external interrupt function is not used. The
sense input function is to read the status of the pin by using the INT flag of a control register, instead of a port
register.
Caution The PROM model is highly compatible with the mask ROM model in terms of functions but its internal
ROM circuit and electrical characteristics are partially different from those of the mask ROM model.
To replace the PROM model with the mask ROM model, thoroughly evaluate the application by using
a sample of the mask ROM model.
2
CHAPTER 1 GENERAL DESCRIPTION
1.2 ORDERING INFORMATION
Part number
Package
Internal ROM
µPD17134ACT-×××
28-pin plastic shrink DIP (400 mil)
Mask ROM
µPD17135ACT-×××
28-pin plastic shrink DIP (400 mil)
Mask ROM
µPD17136ACT-×××
28-pin plastic shrink DIP (400 mil)
Mask ROM
µPD17137ACT-×××
28-pin plastic shrink DIP (400 mil)
Mask ROM
µPD17P136ACT
28-pin plastic shrink DIP (400 mil)
One-time PROM
µPD17P137ACT
28-pin plastic shrink DIP (400 mil)
One-time PROM
µPD17134AGT-×××
28-pin plastic SOP (375 mil)
Mask ROM
µPD17135AGT-×××
28-pin plastic SOP (375 mil)
Mask ROM
µPD17136AGT-×××
28-pin plastic SOP (375 mil)
Mask ROM
µPD17137AGT-×××
28-pin plastic SOP (375 mil)
Mask ROM
µPD17P136AGT
28-pin plastic SOP (375 mil)
One-time PROM
µPD17P137AGT
28-pin plastic SOP (375 mil)
One-time PROM
Remark ×××: ROM code number
3
CHAPTER 1 GENERAL DESCRIPTION
1.3 BLOCK DIAGRAM
VDD
POWER-ON/
POWER-DOWN
RESET
System clock
generator
Clock
divider
fX/2N
CPU CLOCK CLK STOP
RF
P0A0
P0A1
P0A2
P0A3
P0A
(CMOS)
P0B0
P0B1
P0B2
P0B3
P0B
(CMOS)
XIN (CLK)Note2
XOUT
INT
RAM
112 × 4 bits
Interrupt
controller
SYSTEM REG.
AC
ZEROCROSS
detector
IRQTM0
IRQTM1
IRQBTM
IRQSIO
IRQBTM
fX/2N
Basic interval timer
IRQTM1
ALU
P0C0/ADC0
P0C1/ADC1
P0C2/ADC2
P0C3/ADC3
Timer 1
P0C
(CMOS)
fX/2N
IRQTM0
A/D
Converter
P0D0/SCK
P0D1/SO
P0D2/SI
P0D3/TM0OUT
P0D
(N-ch)
Serial
Interface
TM0
P1A
(N-ch)
Note1
ROM/
One-Time
PROM
Instruction
decoder
P1B
P1A0
P1A1
P1A2
P1A3
P1B0
(VPP)
Program counter
IRQSIO
GND
Remarks 1.
fX/2N
Timer 0
RESET
StackNote2
The terms CMOS and N-ch in square brackets indicate the output form of the port.
CMOS : CMOS push-pull output
N-ch
: N-channel open-drain output (Each pin can contain pull-up resistor bit-wise as specified
using a mask option.)
2.
The devices in parentheses are effective only in the case of program memory write/verify mode of
the µPD17P136A and µPD17P137A.
Notes 1.
The ROM (or PROM) capacity of each product is as follows:
1024 × 16 bits : µPD17134A, 17135A
2048 × 16 bits : µPD17136A, 17137A, 17P136A, 17P137A
2.
4
The stack capacity of each product is as follows:
5 × 10 bits
: µPD17134A, 17135A
5 × 11 bits
: µPD17136A, 17137A
CHAPTER 1 GENERAL DESCRIPTION
1.4 PIN CONFIGURATION (TOP VIEW)
(1) Normal operating mode
28-pin plastic shrink DIP (400 mil)
µPD17134ACT-×××, µPD17135ACT-×××, µPD17136ACT-×××, µPD17137ACT-×××
µPD17P136ACT-×××, µPD17P137ACT-×××
28-pin plastic SOP (375 mil)
µPD17134AGT-×××, µPD17135AGT-×××, µPD17136AGT-×××, µPD17137AGT-×××
µPD17P136AGT-×××, µPD17P137AGT-×××
ADC0 to ADC3
VADC
1
28
VDD
P0C3/ADC3
2
27
XIN (OSC1)
P0C2/ADC2
3
26
XOUT (OSC0)
P0C1/ADC1
4
25
P0D0/SCK
P0C0/ADC0
5
24
P0D1/SO
P0B3
6
23
P0D2/SI
P0B2
7
22
P0D3/TM0OUT
P0B1
8
21
P1A0
P0B0
9
20
P1A1
P0A3
10
19
P1A2
P0A2
11
18
P1A3
P0A1
12
17
P1B0
P0A0
13
16
RESET
GND
14
15
INT
: Analog input for the A/D
converter
P1B0
: Port 1B
RESET
: Reset input
GND
: Ground
SCK
: Serial clock input/output
INT
: External interrupt input
SI
: Serial data input
OSC0, OSC1
: System clock oscillation
SO
: Serial data output
P0A0 to P0A3
: Port 0A
TM0OUT
: Timer 0 carry output
P0B0 to P0B3
: Port 0B
VADC
: Analog power supply
P0C0 to P0C3
: Port 0C
VDD
: Power supply
P0D0 to P0D3
: Port 0D
XIN, XOUT
: System clock oscillation
P1A0 to P1A3
: Port 1A
5
CHAPTER 1 GENERAL DESCRIPTION
(2) Program memory write/verify mode
28-pin plastic shrink DIP (400 mil)
µPD17P136ACT, 17P137ACT
28-pin plastic SOP (375 mil)
µPD17P136AGT, 17P137AGT
(VDD)
1
28
VDD
MD3
2
27
CLK
MD2
3
26
(Open)
MD1
4
25
MD0
5
24
D7
6
23
D6
7
22
D5
8
21
D4
9
20
D3
10
19
D2
11
18
D1
12
17
VPP
D0
13
16
RESET
GND
14
15
(L)
(L)
Caution ( ) represents processing of the pins which are not used in program memory write/verify
mode.
L
: Connect to GND via pull-down resistor one by one.
RESET : Set the same electric potential as VDD in program memory write/verify mode.
RESET pin is also used for system reset input before setting program memory
write/verify mode.
Therefore, RESET pin should be set to the same electric
potential as VDD 10 µs or later than that of VDD pin (For details, refer to CHAPTER
18 ONE-TIME PROM WRITING/VERIFYING).
6
Open
: Do not connect anything.
VDD
: Connect to VDD directly.
CHAPTER 1 GENERAL DESCRIPTION
CLK
: Clock input for address updating
D0-D7
: Data input/output
GND
: Ground
MD0-MD3 : Operation mode select
RESET
: Reset input
VDD
: Power supply
VPP
: Program voltage application
7
[MEMO]
8
CHAPTER 2 PIN FUNCTIONS
2.1 PIN FUNCTIONS
Pin No.
Pin name
1
VADC
2
|
5
P0C3/ADC3/MD3 Note1
|
P0C0/ADC0/MD0 Note1
Function
Output
At reset
Supplies power and reference voltage for the A/D converter
—
—
Constitute port 0C, serve as analog input pins of A/D
converter, or select operating mode when program memory
is written or verified.
P0C3 to P0C0
• 4-bit input/output port
• Input/output setting in 1-bit unit
ADC3 to ADC0
• Analog input for the A/D converter
MD3 to MD0
• Available for the µPD17P136A and µPD17P137A only
• Selects operating mode at program memory writing/
verification
CMOS
push-pull
Input
(P0C)
Used as port 0B, or data input/output pins in program
memory write/verify mode.
P0B3 to P0B0
• 4-bit input/output port
• Input/output setting in 4-bit unit
• Software-selectable pull-up resistor
D7 to D4
• Available for the µPD17P136A and µPD17P137A only
• 8-bit data input/output at program memory writing/
verification
CMOS
push-pull
Input
(P0B)
Used as port 0A, or data input/output pin in program memory
write/verify mode.
P0A3 to P0A0
• 4-bit input/output port
• Input/output setting in 4-bit unit
• Software-selectable pull-up resistor
D3 to D0
• Available for the µPD17P136A and µPD17P137A only
• 8-bit data input/output at program memory writing/
verification
CMOS
push-pull
Input
(P0A)
Ground
—
—
•
•
•
P0B3/D7 Note1
|
P0B0/D4 Note1
6
|
9
•
•
P0A3/D3 Note1
|
P0A0/D0 Note1
10
|
13
•
•
14
GND
15
INT
External interrupt request input or sensor signal input
—
Input
16
RESET
System reset input pin
A pull-up resistor can be internally connected by mask
option Note2
—
Input
Notes 1.
2.
The MD0-MD3 and D0-D7 pins are valid with the µPD17P136A and 17P137A only.
The µPD17P136A and 17P137A do not have a pull-up resistor connected by mask option.
9
CHAPTER 2 PIN FUNCTIONS
Pin No.
Pin name
17
P1B0/VPP Note1
Function
Used as port 1B, or programming voltage supply pin in
program memory write/verify mode.
P1B0
• 1-bit input port
• A pull-up resistor can be internally connected by mask
option Note2
VPP
• Available for the µPD17P136A and µPD17P137A only
• Applies programming voltage (+12.5 V) at program
memory writing/verification
Output
At reset
Input
Input
N-ch open
drain
Input
N-ch open
drain
Input
—
—
—
—
•
•
18
|
21
P1A3
|
P1A0
22
P0D3/TM0OUT
Port
•
•
•
1A
4-bit input/output port
Input/output setting in 4-bit unit
A pull-up resistor can be internally connected by mask
option Note2
Used as port 0D, or timer 0 carry output, serial data input,
serial data output, and serial clock input/output pins
A pull-up resistor can be internally connected by mask
option Note2
•
•
23
P0D2/SI
•
24
P0D1/SO
•
25
P0D0/SCK
•
26
27
XOUT
XIN/CLK Note3
P0D3 to P0D0
• 4-bit input/output port
• Input/output setting in 1 bit unit
TM0OUT
• Timer 0 carry output
SI
• Serial data input
SO
• Serial data output
SCK
• Serial clock input/output
In the case of the µPD17135A/17137A/17P137A
XIN, XOUT
• Connected to a resonator for system clock oscillation
• The ceramic resonator is connected.
CLK
• Available for the µPD17P137A only
• Clock input pin for address updating at program
memory writing/verification
•
•
26
27
OSC0
OSC1/CLK Note3
In the case of the µPD17134A/17136A/17P136A
OSC0, OSC1
• Connected to a resonator for system clock oscillation
• Resistor is connected between OSC0 and OSC1.
CLK
• Available for the µPD17P136A only
• Clock input pin for address updating at program
memory writing/verification
•
•
28
VDD
Notes 1.
10
Power supply
In the program memory write/verify mode of the
µPD17P136A/17P137A, +6 V is applied.
The VPP pin is valid only with the µPD17P136A and 17P137A.
2.
The µPD17P136A and 17P137A do not have a pull-up resistor connected by mask option.
3.
The CLK pin is valid only with the µPD17P136A and 17P137A.
CHAPTER 2 PIN FUNCTIONS
2.2 PIN INPUT/OUTPUT CIRCUIT
1
Below are simplified diagrams of the input/output circuits for each pin.
2
(1) P0A0-P0A3, P0B0-P0B3
VDD
3
VDD
P-ch
Output
latch
Data
4
Pull-up
flag
5
P-ch
6
N-ch
Output
disable
7
8
9
Selector
10
11
Input buffer
(2) P0C0/ADC0 - P0C3/ADC3
12
VDD
13
Data
Output
latch
P-ch
14
15
N-ch
Output
disable
16
Input
disable
17
18
19
Selector
20
Input buffer
A/D
converter
11
CHAPTER 2 PIN FUNCTIONS
(3) P0D0-P0D3, P1A0-P1A3
VDD
Data
Output
latch
Mask optionNote
N-ch
Output
disable
Selector
Input buffer
Note The µPD17P136A and 17P137A do not have a pull-up resistor as mask option.
(4) P1B0
VDD
Mask optionNote
Input buffer
Note The µPD17P136A and 17P137A do not have a pull-up resistor as mask option.
12
CHAPTER 2 PIN FUNCTIONS
(5) INT
1
2
3
Input buffer
4
(6) RESET
5
VDD
6
7
Mask optionNote
8
9
Input buffer
10
Note The µPD17P136A and 17P137A do not have a pull-up resistor as mask option.
11
12
13
14
15
16
17
18
19
20
13
CHAPTER 2 PIN FUNCTIONS
2.3 PROCESSING OF UNUSED PINS
The unused pins should be handled as follows:
Table 2-1. Processing of Unused Pins
Pin Name
Recommended Processing
Internal
Port
Input mode
P0A, P0B
P0C
P0D, P1A
P1B0Note2
Output mode
P0A, P0B, P0C
(CMOS port)
—
Pull-up resistor connected by mask
option
Open
Pull-up resistor not connected by mask
option
Directly connect to GND
—
Outputs low level without pull-up
resistor connected by mask option
drain ports)
Outputs high level without pull-up
resistor connected by mask option
when only internal power-ON/powerdown reset function is used
Open
Pull-up resistor not connected by mask
option
Directly connect to VDD or GND
Pull-up resistor connected by mask
option
Open
Pull-up resistor not connected by mask
option
Directly connect to VDD
Pull-up resistor connected by mask
option
—
Notes 1.
Connect each pin to VDD or GND via
resistorNote 1
Directly connect to GND
(N-ch open-
RESETNote3
Open
Pull-up resistor not connected by mask
option
P0D, P1A
External interrupt (INT)
VADC
Connect pull-up resistor by software
External
Directly connect to VDD
When connecting an external pull-up resistor (to VDD via resistor) or pull-down resistor (to GND via
resistor), make sure that the driving voltage and current consumption of the port are not exceeded. When
connecting a pull-up or pull-down resistor with a high resistance to a port pin, make sure that noise is not
superimposed on the pin. Generally, the resistance of the pull-up or pull-down resistor is about several
kΩ, though it varies depending on the application circuit.
2.
Because the P1B0 pin is multiplexed with a test mode setting function, do not connect a pull-up resistor
to this pin using the mask option. Directly connect it to GND.
3.
In an application circuit where high reliability is required, be sure to input the RESET signal from an external
source. Because the RESET pin is multiplexed with a mode setting function, directly connect it to VDD
if not use.
Caution It is recommended that the I/O mode, pull-up of resistors by software, and output levels of pins be
fixed by repeatedly setting in each loop of the program.
Remark The µPD17P136A and 17P137A do not have a pull-up resistor as mask option.
14
CHAPTER 2 PIN FUNCTIONS
2.4 NOTES ON USING RESET PIN AND P1B0 PIN
1
The RESET and P1B0 pins have a function for setting a test mode in which the internal operations of the µPD17134A
2
subseries are tested (for IC test), in addition to the functions described in 2.1 PIN FUNCTIONS.
When a voltage exceeding VDD is applied to either of these pins, the test mode is set. This means that, even during
the normal operation, the test mode is set if a noise exceeding VDD is applied. As a result, the operation may not be
performed normally.
This is especially true if the wiring length of the RESET or P1B0 pin is too long in which case a noise may be
superimposed on the wiring.
3
4
Therefore, perform wiring so that noise may not be superimposed, by keeping the wiring length as short as possible.
5
If noise is inevitable, take noise preventive measures by using an external component as illustrated below.
• Connect a diode with low VF between
6
• Connect a capacitor between
VDD and RESET/P1B0
VDD and RESET/P1B0
7
VDD
VDD
VDD
Diode with
low VF
8
VDD
9
RESET, P1B0
RESET, P1B0
10
11
12
13
14
15
16
17
18
19
20
15
[MEMO]
16
CHAPTER 3 PROGRAM COUNTER (PC)
The program counter is used to specify an address in program memory.
3.1 PROGRAM COUNTER CONFIGURATION
Figure 3-1 shows the configuration of the program counter.
The program counters of the µPD17134A and µPD17135A are 10-bit binary counters.
The program counters of the µPD17136A, µPD17137A, µPD17P136A, and µPD17P137A are 11-bit binary
counters.
This program counter is incremented whenever an instruction is executed.
Figure 3-1. Program Counter
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
PC
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2 PROGRAM COUNTER OPERATION
Normally, the program counter is automatically incremented each time a command is executed. The memory
address at which the next instruction to be executed is stored is assigned to the program counter under the following
conditions: At reset; when a branch, subroutine call, return, or table reference instruction is executed; or when an
interrupt is received.
3.2.1 to 3.2.7 explain program counter operation during execution of each instruction.
17
CHAPTER 3 PROGRAM COUNTER (PC)
Figure 3-2. Value of the Program Counter after Instruction Execution
Program counter
bit
Instruction
At reset
Program counter value
PC10 PC9
0
0
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
0
0
0
0
0
0
0
0
0
BR addr
Value set by the addr
CALL addr
BR @AR
CALL @AR
Value in the address register (AR)
(MOVT DBF, @AR)
RET
RETSK
Value in the address stack register location pointed to by the stack pointer
(return address)
RETI
During interrupt
Vector address for the interrupt
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2.1 At Reset
By setting the RESET pin to low, the program counter is set to 0000H.
Figure 3-3. Value in the Program Counter after Reset
LSB
MSB
0
0
0
0
0
0
0
0
0
0
0
All bits are set to 0
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2.2 During Execution of the Branch Instruction (BR)
There are two ways to specify branching using the branch instruction. One is to specify the branch address in the
operand using the direct branch instruction (BR addr). The other is branch to the address specified by the address
register using the indirect branch instruction (BR @AR).
The address specified by a BR addr instruction is placed in the program counter.
Figure 3-4. Value in the Program Counter during Execution of a BR addr Instruction
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
Value specified in the direct branch instruction
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
18
CHAPTER 3 PROGRAM COUNTER (PC)
An indirect branch instruction causes the address in the address counter to be placed in the program counter.
Figure 3-5. Value in the Program Counter during Execution of a BR @AR Instruction
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
AR10
AR9
AR8
AR7
AR6
AR5
AR4
AR3
AR2
AR1
AR0
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2.3 During Execution of Subroutine Calls (CALL)
There are two ways to specify branching using subroutine calls. One is to specify the branch address in the operand
using the direct subroutine call (CALL addr). The other is branch to the address specified by the address register
using the indirect subroutine call (CALL @AR).
A CALL addr causes the value in the program counter to be saved in the stack and then the address specified in
the operand to be placed in the program counter. CALL addr can specify 000H-03FFH in the µPD17134A and 17135A,
and 0000H-07FFH in the µPD17136A, 17137A, 17P136A, and 17P137A.
Figure 3-6. Value in the Program Counter during Execution of a CALL addr
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
Address specified in the addr
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
A CALL @AR causes the value in the program counter to be saved in the stack and then the value in the address
register to be placed in the program counter.
19
CHAPTER 3 PROGRAM COUNTER (PC)
Figure 3-7. Value in the Program Counter during Execution of an Indirect Subroutine Call
Address stack register n
(n = 0 to 4)
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
AR10
AR9
AR8
AR7
AR6
AR5
AR4
AR3
AR2
AR1
AR0
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2.4 During Execution of Return Instructions (RET, RETSK, RETI)
During execution of a return instruction (RET, RETSK, RETI), the program counter is restored to the value saved
in the address stack register.
Figure 3-8. Value in the Program Counter during Execution of a Return Instruction
LSB
MSB
PC10
PC9
PC8
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
Address stack register n
(n = 0 to 4)
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
3.2.5 During Table Reference (MOVT)
During execution of table reference (MOVT DBF, @AR), the value in the program counter is saved in the stack,
the address register is set by the program counter, then the contents stored at that program memory location is read
into the data buffer (DBF). After that, the program counter is restored to the value saved in the address stack register.
One level of the address stack is temporarily used during execution of table reference. Be careful of the stack level.
20
CHAPTER 3 PROGRAM COUNTER (PC)
3.2.6 During Execution of Skip Instructions (SKE, SKGE, SKLT, SKNE, SKT, SKF)
When skip conditions are met and a skip instruction (SKE, SKGE, SKLT, SKNE, SKT, SKF) is executed, the
instruction immediately following the skip instruction is treated as a no operation instruction (NOP). Therefore, whether
skip conditions are met or not, the number of instructions executed and instruction execution time remain the same.
3.2.7 When an Interrupt Is Received
When an interrupt is received, the value in the program counter is saved in the address stack. Next, the vector
address for the interrupt received is placed in the program counter.
21
[MEMO]
22
CHAPTER 4 PROGRAM MEMORY (ROM)
The program organization of the µPD17134A subseries is shown in Table 4-1.
Table 4-1. Program Memory Configuration
Product name
Program memory capacity
Program memory address
µPD17134A
2K bytes (1024 × 16 bits)
0000H-03FFH
4K bytes (2048 × 16 bits)
0000H-07FFH
µPD17135A
µPD17136A
µPD17137A
µPD17P136A
µPD17P137A
Program memory stores the program and the constant data table. The first area of the program memory is assigned
to reset start and interrupt vector addresses.
The program memory address is specified by the program counter.
4.1 PROGRAM MEMORY CONFIGURATION
Figure 4-1 shows the program memory map. Branch instructions, subroutine calls, and table references can specify
any address in program memory.
Figure 4-1. Program Memory Map for the µPD17134A Subseries
Address
16 bits
0000H
Reset start address
0001H
Serial interface interrupt vector
0002H
Basic interval timer interrupt vector
0003H
Timer 1 interrupt vector
0004H
Timer 0 interrupt vector
0005H
External (INT) interrupt vector
Subroutine entry
address for the CALL
addr instruction
Branch address for
the BR addr instruction
Branch address for
the BR @AR instruction
Subroutine entry
address for the CALL
@AR instruction
( mPD17134A/17135A)
Table reference address
for the MOVT DBF, @AR
instruction
03FFH
( mPD17136A/17137A/17P136A/17P137A)
07FFH
23
CHAPTER 4 PROGRAM MEMORY (ROM)
4.2 PROGRAM MEMORY USAGE
Program memory has the following two main functions:
(1) Storage of the program
(2) Storage of constant data
The program is made up of the instructions which operate the CPU (Central Processing Unit). The CPU executes
sequential processing according to the instructions stored in the program. In other words, the CPU reads each
instruction in the order stored by the program in program memory and executes it.
Since all instructions are 16-bit long words, each instruction is stored in a single address in program memory.
Constant data, such as display patterns, are set beforehand. The MOVT is used for reading constant data in
program memory to transfer data from program memory to the data buffer (DBF) in data memory. Reading the constant
data in program memory is called table reference.
Program memory is read-only (ROM: Read Only Memory) and therefore cannot be changed by any instructions.
4.2.1 Flow of the Program
The program is usually stored in program memory starting from address 0000H and executed sequentially one
address at a time. However, if for some reason a different kind of program is to be executed, it will be necessary to
change the flow of the program. In this case, the branch instruction (BR instruction) is used.
If the same program code is going to appear in a number of places, reproducing the code each time it needs to
be used will decrease the efficiency of the program. In this case, the program should be stored in only one place in
memory. Then, by using the CALL instruction, call the same program. Such a program is called a subroutine. As
opposed to a subroutine, code used during normal operation is called the main routine.
For cases completely unrelated to the flow of the program (in which a section of code is to be executed when a
certain condition arises), the interrupt function is used. Whenever a condition arises that is unrelated to the flow of
the program, the interrupt function can be used to branch the program to a prechosen memory location (called a vector
address).
Items (1) to (5) explain branching of the program using the interrupt function and instructions.
(1) Vector address
Table 4-2 shows the address to which the program is branched (vector address) when a reset or interrupt
occurs.
Table 4-2. Vector Address for the µPD17134A Subseries
Vector address
24
Cause of the interrupt
0000H
Reset
0001H
Serial interface interrupt
0002H
Basic interval timer interrupt
0003H
Timer 1 interrupt
0004H
Timer 0 interrupt
0005H
External (INT) interrupt
CHAPTER 4 PROGRAM MEMORY (ROM)
(2) Direct branch
A direct branch (BR addr) instruction branches a value of operand (addr) as an address. (In the case of the
µPD17134A and µPD17135A, the most significant bit must be 0. If an address is specified outside of this range,
an error will occur in the assembler.) A BR addr instruction can be used to branch to any address in program
memory.
(3) Indirect branch
When executing an indirect branch (BR @AR), the program branches to the address specified by the value
stored in the address register (AR). A BR @AR can be used to branch to any address in program memory.
Also see 7.2 ADDRESS REGISTER (AR).
(4) Subroutine
To branch execution to a subroutine, the subroutine call (CALL) instruction is used.
The CALL instruction can be used in two ways: as a direct subroutine call instruction (CALL addr) that causes
execution to branch using the value of the operand (addr) as an address, and as an indirect subroutine call
instruction (CALL @AR) that causes execution to branch using the contents of an address register as an
address.
To return from a subroutine, the RET or RETSK instruction is used. By executing the RET or RETSK instruction,
execution is returned to the program memory address next to the one at which the CALL instruction was
executed.
When the RETSK instruction is used, the first instruction after execution has returned from the subroutine is
executed as a NOP instruction.
25
CHAPTER 4 PROGRAM MEMORY (ROM)
<1> Direct subroutine call
When using a direct subroutine call (CALL addr), the 11-bit instruction operand is used to specify a
program memory address of the branched subroutine. (In the case of the µPD17134A and µPD17135A,
the most significant bit must be 0. If an address is specified outside of this range, an error will occur
in the assembler.)
Example
Figure 4-2. CALL addr Instruction
Program memory
Address
0000H
CALL SUB1
SUB1;
RET
07FFHNote
Note The program memory of the µPD17134A and µPD17135A is address 0000H to 03FFH.
<2> Indirect subroutine call
When using an indirect subroutine call (CALL @AR), the value in the address register (AR) should be
an address of the called subroutine. This instruction can be used to branch any address in program
memory.
Also see 7.2 ADDRESS REGISTER (AR).
26
CHAPTER 4 PROGRAM MEMORY (ROM)
4.2.2 Table Reference
Table reference is used to reference constant data in program memory.
The table reference instruction (MOVT DBF, @AR) is used to store the contents of the program memory address
specified by the address register in the data buffer.
Since each location in program memory contains 16 bits of information, the MOVT instruction causes
16 bits of data to be stored in the data buffer. The address register can be used to table reference any location
in program memory.
Caution Note that one level of the address stack is temporarily used when performing table reference.
Be sure not to exceed the stack level that can be used. Also see 7.2 ADDRESS REGISTER (AR)
and CHAPTER 10 DATA BUFFER (DBF).
Remark Two instruction cycles are required to execute the table reference instruction, but this is an exception.
Figure 4-3. Table Reference (MOVT DBF, @AR)
Data buffer
Program memory
DBF3
DBF2
DBF1
DBF0
b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
16-bit data read
Address register
AR3
AR2
AR1
AR0
b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0
0
0
0
0
0
Constant data
Note
Table address specification
Note This bit is fixed to 0 in the case of the µPD17134A and µPD17135A.
27
CHAPTER 4 PROGRAM MEMORY (ROM)
(1) Constant data table
Example 1 shows an example of code used to reference a constant data table.
Example 1. Program to read data in a constant data table.
OFFSET
MEM
0.00H
; Area to store the offset address.
ROMREF:
BANK0
; Stores the start address of the constant data
; table in the AR register.
MOV
AR3, #.DL.TABLE SHR 12 AND 0FH
MOV
AR2, #.DL.TABLE SHR 8 AND 0FH
MOV
AR1, #.DL.TABLE SHR 4 AND 0FH
MOV
AR0, #.DL.TABLE AND 0FH
MOV
RPH, #0
; Sets the register pointer to row address 7.
MOV
RPL, #7 SHL 1
;
ADD
AR0, OFFSET
ADDC
AR1, #0
ADDC
AR2, #0
ADDC
AR3, #0
MOVT
DBF, @AR
; Adds the offset address.
; Reads the constant data.
TABLE:
DW
0001H
DW
0002H
DW
0004H
DW
0008H
DW
0010H
DW
0020H
DW
0040H
DW
0080H
DW
0100H
DW
0200H
DW
0400H
DW
0800H
DW
1000H
DW
2000H
DW
4000H
DW
8000H
END
28
; When OFFSET = 0H
; When OFFSET = 0FH
CHAPTER 4 PROGRAM MEMORY (ROM)
(2) Branch address table
Example 2 shows an example of code used to reference a branch address table.
Example 2. Program to branch to the address of the branch address table.
OFFSET
MEM
0.00H
; Area to store the offset address.
ROMREF:
BANK0
; Stores the start address of the constant data
; table in the AR register.
MOV
AR3, #.DL.TABLE SHR 12 AND 0FH
MOV
AR2, #.DL.TABLE SHR 8 AND 0FH
MOV
AR1, #.DL.TABLE SHR 4 AND 0FH
MOV
AR0, #.DL.TABLE AND 0FH
MOV
RPH, #0
MOV
RPL, #7 SHL 1
ADD
AR0, OFFSET
ADDC
AR1, #0
; Sets the register pointer to row address 7.
; Adds the offset address.
MOVT
DBF, @AR
; Reads the branch address
PUT
AR, DBF
; AR ← Branch address
BR
@AR
TABLE:
DW
0001H
DW
0002H
DW
0004H
DW
0008H
DW
0010H
DW
0020H
DW
0040H
DW
0080H
DW
0100H
DW
0200H
; When OFFSET = 0H
; When OFFSET = 9H
END
29
[MEMO]
30
CHAPTER 5 DATA MEMORY (RAM)
Data memory stores data such as operation and control data. Data can be read from or written to data memory
with an instruction during normal operation.
5.1 DATA MEMORY CONFIGURATION
Figure 5-1 shows the configuration of data memory.
Data memory is divided into two areas called banks: BANK0 and BANK1.
An address is allocated to the data memory for each bank. An address consists of 4 bits of memory called “a nibble”.
The address of data memory consists of 7 bits. The high-order 3 bits are called “the row address”, and the loworder 4 bits are called “the column address”. For example, when the address of data memory is 1AH (0011010B),
the row address is 1H (001B), and the column address is AH (1010B).
5.1.1 to 5.1.6 describe functions of data memory other than its use as address space.
Figure 5-1. Data Memory Configuration
Column address
BANK0
0
1
2
3
4
5
6
7
8
9
A
B
0
C
D
E
F
DBF3 DBF2 DBF1 DBF0
Example
2
Address 1AH
of BANK0
3
4
5
6
7
P0A
(4 bits)
P0B
P0C
P0D
System register
(4 bits) (4 bits) (4 bits)
BANK1
0
1
2
3
4
5
6
7
8
9
A
0
1
2
Unmounted
3
4
5
B
C
D
E
F
The same system register is
allocated in each bank.
Row address
1
6
7
P1A
P1B
(4 bits) (4 bits)
Fixed Fixed
to 0
to 0
System register
Caution No hardware is assigned to addresses 00H through 6FH in BANK1. Do not use this area. If the
contents of this area are read, the value is undefined. An instruction to write data to this area
is invalid.
31
CHAPTER 5 DATA MEMORY (RAM)
5.1.1 System Register (SYSREG)
The system register (SYSREG) consists of the 12 nibbles allocated at addresses 74H to 7FH in data memory. The
system register (SYSREG) is allocated independently of the banks. This means that each bank has the same system
register at addresses 74H to 7FH.
Figure 5-2 shows the configuration of the system register.
For details, refer to CHAPTER 7 SYSTEM REGISTER (SYSREG).
Figure 5-2. System Register Configuration
System register (SYSREG)
Address
Name
(Symbol)
74H
75H
76H
77H
78H
79H
7AH
7CH
Index register (IX)
Window Bank
register register
(WR)
(BANK)
Address register
(AR)
7BH
Data memory
row address
pointer (MP)
7DH
7EH
General
register
pointer
(RP)
7FH
Program
status
word
(PSWORD)
5.1.2 Data Buffer (DBF)
The data buffer consists of four nibbles allocated at addresses 0CH to 0FH in BANK0 of data memory.
Figure 5-3 shows the configuration of the data buffer.
Figure 5-3. Data Buffer Configuration
Data buffer (DBF)
32
Address
0CH
0DH
0EH
0FH
Symbol
DBF3
DBF2
DBF1
DBF0
CHAPTER 5 DATA MEMORY (RAM)
5.1.3 General Register (GR)
The general register consists of 16 nibbles specified by an arbitrary row address in an arbitrary bank in data memory.
This arbitrary row address in an arbitrary bank is specified by the register pointer (RP) in the system register
(SYSREG).
Figure 5-4 shows the configuration of the general register (GR).
Figure 5-4. General Register (GR) Configuration
BANK0
Row address
0
0
1
2
3
4
5
6
7
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
General register
F
Area specifiable as general register
Port register
Pointed to by general register
pointer (RP) in system register.
Note that row addresses 0 to 6
of BANK1 are unmounted memory locations. The register
pointer (RP) should therefore
not specify a row address in this
area.
SYSREG
BANK1
0
1
2
3
4
5
6
7
Unmounted
Port register
The same register is allocated
for each bank.
SYSREG
5.1.4 Port Registers
A port register consists of eight nibbles allocated at addresses 70H to 73H in each bank of the data memory.
As shown in Figure 5-5, the high-order 3 bits of address 71H of BANK1 and all of addresses 72H and 73H of BANK1
are always set to 0.
Figure 5-5 shows the configuration of the port registers.
Figure 5-5. Port Register Configuration
Port register
Address
Symbol
BANK0
70H
71H
72H
73H
P0A
P0B
P0C
P0D
P
P
P
P
P
P
P
P
P
P
P
P
P
P
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
A
A
A
A
B
B
B
B
C
C
C
C
D
D
D
D
3
2
1
0
3
2
1
0
3
2
1
0
3
2
1
0
P1A
P
BANK1
P
P
P
P
P1B
P
1
1
1
1
A
A
A
A
3
2
1
0
P
Fixed to “0”
1
B
Fixed to “0”
Fixed to “0”
0
33
CHAPTER 5 DATA MEMORY (RAM)
5.1.5 General Data Memory
General data memory is all the data memory not used by the port and system registers (SYSREG). In other words,
general data memory consists of 112 nibbles in BANK0.
5.1.6 Unmounted Data Memory
There is no hardware mounted at addresses 00H to 6FH of BANK1. Any attempt to read this area will yield undefined
value. Writing data to this area is invalid and should therefore not be attempted.
34
CHAPTER 6 STACK
The stack is a register used to save information such as the program return address and the contents of the system
register during execution of subroutine calls or interrupts.
6.1 STACK CONFIGURATION
Figure 6-1 shows the stack configuration.
The stack consists of the following parts: one 3-bit binary counter stack pointer, five 10-bit (µPD17134A, 17135A)/
11-bit (µPD17136A, 17137A, 17P136A, 17P137A) address stack registers, and three 6-bit interrupt stack registers.
Figure 6-1. Stack Configuration
Stack pointer
(SP)
Address stack register
b2
b1
b0
SPb2
SPb1
SPb0
SP is initialized to
5H at reset
b10
b9
b8
b7
b6
b5
b4
b3
0H
Address stack register 0
1H
Address stack register 1
2H
Address stack register 2
3H
Address stack register 3
4H
Address stack register 4
b2
b1
b0
Interrupt stack register
0H BANKSK0 BCDSK0 CMPSK0
CYSK0
ZSK0
IXESK0
1H BANKSK1 BCDSK1 CMPSK1
CYSK1
ZSK1
IXESK1
2H BANKSK2 BCDSK2 CMPSK2
CYSK2
ZSK2
IXESK2
Remark The shaded part is effective only in the case of µPD17136A/17137A/17P136A/17P137A.
6.2 FUNCTIONS OF THE STACK
The stack is used to save the return address during execution of subroutine calls and table reference instructions.
When an interrupt occurs, the program return address, bank register (BANK), and the program status word (PSWORD)
are automatically saved in the stack.
35
CHAPTER 6 STACK
6.3 ADDRESS STACK REGISTERS (ASRs)
Five 11-bit address stack registers (ASRs) are provided as shown in Figure 6-1. The functions of these registers
are as follows:
• Store a return address when the CALL addr or CALL @AR instruction is executed, when the first instruction
cycle of the “MOVT DBF, @AR” instruction is executed, or when an interrupt is accepted.
• Store the contents of an address register (AR) when the PUSH AR instruction is executed. The ASR to which
the data is to be stored is specified by decrementing the value of the stack pointer (SP) by one when the
instruction is executed.
• Restore the contents of the ASR (return address) specified by the stack pointer to the program counter and
increment the value of the stack pointer by one when the RET or RETSK instruction is executed, when the second
instruction cycle of the “MOVT DBF, @AR” instruction is executed, or when the RETI instruction is executed.
• Transfer the value of the ASR specified by the stack pointer to an address register and decrement the value
of the stack pointer by one when the POP AR instruction is executed.
Caution If the stack pointer underflows as a result of executing the CALL addr or CALL @AR instruction
or servicing an interrupt, it is assumed that a hang-up occurs. Consequently, the internal reset
signal is generated, the hardware is initialized, and the program is started from address 0000H.
Remark The size of the ASR differs depending on the model. The µPD17134A and 17135A have five 10-bit
ASRs, while the µPD17136A, 17137A, 17P136A, and 17P137A have five 11-bit ASRs.
6.4 INTERRUPT STACK REGISTERS (INTSKs)
Three 5-bit interrupt stack registers (INTSKs) are provided as shown in Figure 6-1. The functions of these registers
are as follows:
• Five flags (BCD, CMP, CY, Z, and IXE) in the program status word (PSWORD) in the system register (SYSREG)
to be explained shortly are saved to the INTSK when an interrupt occurs. After the flags have been saved, all
the bits of the BANK and PSWORD are cleared to 0.
• The contents of INTSK are restored to the PSWORD when the RETI instruction is executed.
• INTSK saves data each time an interrupt has been accepted.
Caution If interrupts are accepted exceeding 3 levels, the first data is lost.
36
CHAPTER 6 STACK
6.5 STACK POINTER (SP) AND INTERRUPT STACK REGISTERS
The stack pointer is a 3-bit binary counter that specifies the addresses of the five address stack registers as shown
in Figure 6-1, and is assigned to address 01H of the register file. The value of the stack pointer is initialized to 5H
at reset.
• The value of SP is decremented by one when the CALL addr or CALL @AR instruction is executed, when the
first instruction cycle of the “MOVT DBF, @AR” instruction is executed, or when an interrupt is accepted.
• The value of SP is incremented by one when the RET or RETSK instruction is executed, when the second
instruction cycle of the “MOVT DBF, @AR” instruction is executed, when the POP AR instruction is executed,
or when the RETI instruction is executed.
When an interrupt is accepted, the counter of the interrupt stack registers is also decremented by one in addition
to the SP. The value of the counter of the interrupt stack registers is incremented by one only when the RETI instruction
is executed.
Table 6-1. Operation of Stack Pointer
Instruction
Value of stack pointer (SP)
Counter of interrupt stack registers
CALL addr
CALL @AR
MOVT, DBF @AR (1st instruction cycle)
PUSH AR
–1
RET
RETSK
MOVT DBF, @AR (2nd instruction cycle)
POP AR
+1
Accepting interrupt
–1
–1
RETI
+1
+1
Not affected
Remark Two instruction cycles are required to execute the “MOVT DBF, @AR” instruction, but this is an
exception.
Because the stack pointer (SP) is a 3-bit binary counter, it can take a value 0H to 7H. If the value of the stack pointer
is 6 or more, however, an internal reset signal is generated (to prevent a hang-up). This is because only five address
stack registers are available.
Because the stack pointer is located on the register file, its value can be directly read by manipulating the register
file with the POKE instruction. The value of the stack pointer is also changed at this time, but the values of the address
stack registers are not affected. Of course, the stack pointer can also be read by using the PEEK instruction.
The value of the stack pointer is 5H at reset.
37
CHAPTER 6 STACK
6.6 STACK OPERATION
Stack operation during execution of each instruction is explained in 6.6.1 to 6.6.3.
6.6.1 On Execution of Instructions CALL, RET, RETSK
Table 6-2 shows operation of the stack pointer (SP), address stack register, and the program counter (PC) during
execution of CALL, RET, and RETSK.
Table 6-2. Operation of the Instructions CALL, RET, and RETSK
Instruction
Operation
CALL addr
CALL @AR
(1) Stack pointer (SP) is decremented.
(2) Program counter (PC) is saved in the address stack register pointed to by the stack pointer
(SP).
(3) Value specified by the instruction operand (addr or @AR) is transferred to the program
counter.
RET
RETSK
(1) Value in the address stack register pointed to by the stack pointer (SP) is restored to the
program counter (PC).
(2) Stack pointer (SP) is incremented.
When the RETSK instruction is executed, the first instruction after data restoration becomes a NOP instruction.
6.6.2 Table Reference (MOVT DBF, @AR Instruction)
Table 6-3 shows the operation during table reference.
Table 6-3. Stack Operation during Table Reference
Instruction
MOVT DBF, @AR
Instruction cycle
First
Operation
(1) Stack pointer (SP) is decremented.
(2) Program counter (PC) is saved in the address stack register pointed to by
the stack pointer (SP).
(3) Value in the address register (AR) is transferred to the program counter (PC).
Second
(4) Contents of the program memory (ROM) pointed to by the program counter
(PC) is transferred to the data buffer (DBF).
(5) Value in the address stack register pointed to by the stack pointer (SP) is
restored to the program counter (PC).
(6) Stack pointer (SP) is incremented.
Caution When the “MOVT DBF, @AR” instruction is executed, one level of the address stack is temporarily
used. Exercise care not to exceed the usable stack level.
Remark Two instruction cycles are required to execute the “MOVT DBF, @AR” instruction. This is an exception.
38
CHAPTER 6 STACK
6.6.3 Operation on Execution of Interrupt Receipt and RETI Instruction
Table 6-4 shows stack operation during interrupt receipt and RETI instruction.
Table 6-4. Operation during Interrupt Receipt and RETI Instruction
Instruction
Operation
Receipt of interrupt
(1) Stack pointer (SP) is decremented.
(2) Value in the program counter (PC) is saved in the address stack register pointed to by the stack
pointer (SP).
(3) Values in the PSWORD flags (BCD, CMP, CY, Z, IXE) are saved in the interrupt stack.
(4) Vector address is transferred to the program counter (PC)
RETI
(1) Values in the interrupt stack register are restored to the PSWORD (BCD, CMP, CY, Z, IXE).
(2) Value in the address stack register pointed to by the stack pointer (SP) is restored to the program
counter (PC).
(3) Stack pointer (SP) is incremented.
6.7 STACK NESTING LEVELS AND THE PUSH AND POP INSTRUCTIONS
During execution of operations such as subroutine calls and returns, the stack pointer (SP) simply functions as
a 3-bit counter which is incremented and decremented by one. When the value in the stack pointer is 0H and a CALL
or MOVT instruction is executed or an interrupt is received, the stack pointer is decremented to 7H. The µPD17134A
subseries treat this condition as a fault and generates an internal reset signal.
In order to avoid this condition, when the address stack register is being used frequently, the PUSH and POP
instructions are used to save the address stack register.
Table 6-5 shows stack operation during the PUSH and POP instructions.
Table 6-5. Stack Operation during the PUSH and POP Instructions
Instruction
Operation
PUSH
(1) Stack pointer (SP) is decremented.
(2) Value in the address register (AR) is transferred to the address stack register pointed to by the
stack pointer (SP).
POP
(1) Value in the address stack register pointed to by the stack pointer (SP) is transferred to the
address register (AR).
(2) Stack pointer (SP) is incremented.
39
[MEMO]
40
CHAPTER 7 SYSTEM REGISTER (SYSREG)
The system register (SYSREG), located in data memory, is used for direct control of the CPU.
7.1 SYSTEM REGISTER CONFIGURATION
Figure 7-1 shows the allocation address of the system register in data memory. As shown in Figure 7-1, the system
register is allocated in addresses 74H to 7FH of data memory, independently of the banks. This means that each
bank has the same system register at addresses 74H to 7FH.
Since the system register is allocated in data memory, it can be manipulated using any of the data memory
manipulating instructions. Therefore, it is also possible to put the system register in the general register.
Figure 7-1. Allocation of System Register in Data Memory
Column address
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
Row address
1
2
Data memory
BANK0
3
4
5
6
7
Port register
BANK1
Port register
0
1
2
Unmounted
System register
3
4
5
6
7
8
9
A
B
C
D
E
F
Figure 7-2 shows the configuration of the system register. As shown in Figure 7-2, the system register consists
of the following seven registers.
• Address register
(AR)
• Window register
(WR)
• Bank register
(BANK)
• Index register
(IX)
• Data memory row address pointer
(MP)
• General register pointer
(RP)
• Program status word
(PSWORD)
41
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Figure 7-2. System Register Configuration
Address
74H
Bit
76H
77H
AR3
AR2
AR1
78H
79H
Window Bank
register register
(WR)
(BANK)
Address register
(AR)
Name
Symbol
75H
AR0
WR
7AH
7BH
7CH
Index register (IX)
Data memory
row address
pointer (MP)
IXH
IXM
MPH
MPL
IXL
BANK
7DH
7EH
General
register
pointer
(RP)
RPH
RPL
7FH
Program
status
word
(PSWORD)
PSW
b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0 b3 b2 b1 b0
(IX)
Data
0 0 0 0 0 Note
(AR)
M
0 0 0 P 0 0 0
E
(BANK)
(MP)
0 0 0
(RP)
BCC
I
CMY Z X
DP
E
Initial value
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Undefined 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
when
reset
Note This bit is fixed to 0 in the case of the µPD17134A and µPD17135A.
42
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.2 ADDRESS REGISTER (AR)
7.2.1 Address Register Configuration
Figure 7-3 shows the configuration of the address register.
As shown in Figure 7-3, the address register consists of the 16 bits in address 74H to 77H (AR3 to AR0) of the
system register. However, since the high-order 5 or 6 bits are always set to 0, the address register is actually 11 or
10 bits. When the system is reset, all 16 bits of the address register are reset to 0.
Figure 7-3. Address Register Configuration
Address
74H
75H
Name
77H
Address register (AR)
Symbol
Bit
76H
AR3
b3
b2
b1
AR2
b0
b3
b2
b1
AR1
b0
b3
b2
b1
AR0
b0
b3
b2
b1
b0
(AR)
Data
0
0
Initial value when
reset
0
0
0
0 Note
0
0
0
Note This bit is fixed to 0 in the case of the µPD17134A and µPD17135A.
7.2.2 Address Register Functions
The address register is used to specify an address in program memory when executing an indirect branch
instruction (BR @AR), indirect subroutine call (CALL @AR) or table reference (MOVT DBF, @AR). The address
register can also be put on and taken off the stack by using the stack manipulation instructions (PUSH AR, POP AR).
Items (1) to (4) explain address register operation during execution of each instruction.
The address register can be incremented by using the dedicated increment instruction (INC AR).
(1) Table reference (MOVT DBF, @AR)
When the “MOVT DBF, @AR” instruction is executed, the data in program memory (16-bit data) located
at the address specified by the value in the address register is read into the data buffer (addresses
0CH to 0FH of BANK0).
(2) Stack manipulation instructions (PUSH AR, POP AR)
When the PUSH AR instruction is executed, the stack pointer (SP) is first decremented and then the address
register is stored in the address stack pointed to by the stack pointer.
When the POP AR instruction is executed, the contents of the address stack pointed to by the stack pointer
is transferred to the address register and then the stack pointer is incremented.
Also see CHAPTER 6 STACK.
43
CHAPTER 7 SYSTEM REGISTER (SYSREG)
(3) Indirect branch instruction (BR @AR)
When the BR @AR instruction is executed, the program branches to the address in program memory specified
by the value in the address register.
(4) Indirect subroutine call (CALL @AR)
When the CALL @AR instruction is executed, the subroutine located at the address in program memory
specified by the value in the address register is called.
(5) Address register used as a peripheral hardware register
The address register can be manipulated 4 bits at a time by using data memory manipulation instructions. The
address register can also be used as a peripheral hardware register for transferring 16-bit data to the data
buffer. In other words, by using the PUT AR, DBF and GET DBF AR instructions, the address register can
be used to transfer 16-bit data to the data buffer.
Note that the data buffer is allocated in addresses 0CH to 0FH of BANK0 in data memory.
Figure 7-4. Address Register Used as a Peripheral Circuit
(BANK0)
0
1
2
3
4
5
Column address
6 7 8 9 A
B
C
D
E
DBF3 DBF2 DBF1DBF0 Data buffer
0
Row address
1
2
3
4
5
6
7
AR3 AR2 AR1 AR0
Address register
16-bit data transfer available
44
F
System register
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.3 WINDOW REGISTER (WR)
7.3.1 Window Register Configuration
Figure 7-5 shows the configuration of the window register.
As shown in Figure 7-5, the window register (WR) consists of four bits allocated at address 78H of the system
register. The contents of the window register is undefined after reset. However, when RESET is used to release the
system from HALT or STOP mode, the previous state is maintained.
Figure 7-5. Window Register Configuration
Address
78H
Name
Window register
Symbol
WR
Bit
b3
b2
b1
b0
Data
Initial value when reset
Undefined
7.3.2 Window Register Functions
The window register is used to transfer data to and from the register file (RF).
Data is transferred to and from the register file using the dedicated instructions “PEEK WR, rf” and “POKE rf, WR”.
(1) PEEK WR, rf
As shown in Figure 7-6, the “PEEK WR, rf” instruction is used to transfer the contents of the register file
specified by rf to the window register.
(2) POKE rf, WR
As shown in Figure 7-6, the “POKE rf, WR” instruction is used to transfer the contents of the window register
to the file specified by rf.
Figure 7-6. Example of Window Register Operation
0
1
2
3
4
5
Column address
6 7 8 9 A
B
C
D
E
F
0
Row address
1
POKE instruction
Control register
2
3
Register file
4
5
PEEK instruction
Data memory
6
7
WR
System register
45
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.4 BANK REGISTER (BANK)
7.4.1 Bank Register Configuration
Figure 7-7 shows the configuration of the bank register.
The bank register consists of four bits at address 79H (BANK) of the system register. However, since the three
high-order bits are always set to 0, only the least significant bit is actually used.
All bits are set to 0 at reset.
Figure 7-7. Bank Register Configuration
Address
79H
Bank register
Name
Symbol
BANK
Bit
b3
b2
b1
Data
0
0
0
b0
(BANK)
Initial value when
reset
0
7.4.2 Functions of Bank Register
The bank register is used to switch between the banks in data memory. Table 7-1 shows how the banks in data
memory are specified by the value in the bank register.
Table 7-1. Specifying the Bank in Data Memory
Bank register
Bank in data
b3
b2
b1
b0
memory
0
0
0
0
BANK0
0
0
0
1
BANK1
Data memory is effectively divided into two banks by the bank register. When a data memory manipulation
instruction is executed, the data memory in the bank specified by the bank register is manipulated.
Therefore, if the current bank is BANK0, in order to manipulate data memory in BANK1 (port registers), the bank
register must be used to switch the current bank to BANK1.
The system register can be manipulated regardless of the state of the bank register.
For example, whether the instruction MOV 78H, #0 is executed for BANK0 or BANK1, the effect is the same; 0
is written to address 78H of the system register.
In addition, BANK becomes 0 after saved to the interrupt stack register.
46
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.5 INDEX REGISTER (IX) AND DATA MEMORY ROW ADDRESS POINTER (MEMORY POINTER: MP)
7.5.1 Index Register (IX)
IX is used for address modification of the data memory. The difference between IX and MP is that IX modifies an
address specified by a bank and operand m.
IX is allocated to a total of 12 bits of system register addresses 7AH (IXH), 7BH (IXM), and 7CH (IXL), as shown
in Figure 7-8. Actually, however, only 11 bits, the low-order 3 bits of IXH, IXM, and IXL, function as IX. An index register
enable flag (IXE) which enables address modification by IX is assigned to the least significant bit of PSW.
When IXE = 1, the address of the data memory specified by operand m is not m, but the result of ORing between
m and IXM through IXL. The bank specified at this time is also indicated by ORing BANK and IXH.
Remark IXH of the µPD17134A subseries is fixed to “0”, and the bank is not modified even when IXE = 1 (to prevent
a bank other than 0 from being used).
7.5.2 Data Memory Row Address Pointer (Memory Pointer: MP)
MP is used for address modification of the data memory. The difference between IX and MP is that MP modifies
the row address of an address indirectly specified by bank and operand @r.
MPH and IXH and MPL and IXM are assigned to the same address (addresses 7AH and 7BH of the system register)
as shown in Figure 7-8. Actually, however, the low-order 3 bits of MPH and MPL, or a total of 7 bits, function as MP.
A memory pointer enable flag (MPE) which enables address modification by MP is assigned to the most significant
bit of MPH.
When MPE = 1, the bank and row address of the data memory indirectly specified by operand @r are not BANK
and mR, but the address specified by MP (the column address is specified by the contents of r independently of MPE).
At this time, the low-order 3 bits of MPH and the most significant bit of MPL indicate BANK, and the low-order 3 bits
of MPL indicate a row address.
Remark The low-order 3 bits of MPH and most significant bit of MPL of the µPD17134A subseries are fixed to
“0”, and bank 0 is always specified even when MPE = 1 (to prevent a bank other than 0 from being used).
Figure 7-8. Index Register Configuration
Address
7AH
7BH
7CH
7FH
Low-order 4
bits of program
status word
(PSWORD)
Index register (IX)
Name
Memory pointer (MP)
IXH
IXM
IXL
MPH
MPL
Symbolic name
PSW
Bit
b3
Flag name
M
P
E
b2
b1
b0
b3
b2
b1
b0
b3
b2
b1
b0
b3
b2
b1
b0
I
X
E
(IX)
Data
Initial value when reset
(MP)
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
47
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Figure 7-9. Modification of Data Memory Address by Index Register and Memory Pointer
Data memory address specified by m
IXE
Bank
MPE
b3
0
0
0
1
1
b2
b1
Row address Column address
b0
b2
b0
b3
m
BANK
m
BANK
m
b2
b1
b0
Bank
b3
b2
b1
Row address Column address
b0
b2
BANK
b1
b3
mR
BANK
IXM
IXH
IXL
1
b2
b1
(r)
(r)
mR
(r)
Logical OR
IXM
Setting prohibited
MP
BANK : Bank register
: Memory pointer
IX
: Index register
MPE : Memory pointer enable flag
IXE
: Index enable flag
MPH : High-order 3 bits of memory pointer
MPL : Low-order 4 bits of memory pointer
IXH : Bits 10 through 8 of index register
r
IXM : Bits 7 through 4 of index register
IXL
m
: General register column address
: Bits 3 through 0 of index register
RP
: General register pointer
: Data memory indicated by mR and mC
(×)
: Contents addressed by ×
mR
: Data memory row address
mC
: Data memory column address
×: Direct address such as r
Table 7-2. Instructions Subject to Address Modification
Arithmetic
ADD
operation
ADDC
SUB
SUBC
Logical
AND
operation
OR
XOR
r, m
–––––––––––––––––
m, #n4
r, m
–––––––––––––––––
m, #n4
Judgment
SKT
SKF
Compare
m, #n
SKE
SKGE
SKLT
m, #n4
SKNE
Transfer
LD
ST
MOV
r, m
m, r
m, #n4
–––––––––––––––––
@r, m
m, @r
48
b0
MPL
MPH
Logical OR
IXH
1
b1
BANK
0
Indirect transfer address specified by @r
b0
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.5.3 IXE = 0 and MPE = 0 (No Data Memory Modification)
As shown in Table 7-9, data memory addresses are not affected by the index register and the data memory row
address pointer.
(1) Data memory manipulation instructions
Example 1.
Execution of “ADD r, m” when general register is in row address 0
R003
MEM
0.03H
M061
MEM
0.61H
ADD
R003, M061
; Addition in memories (0.03H) ← (0.03H) + (0.61H)
As shown in Figure 7-10, when the above instructions are executed, the data in general register
address R003 and data memory address M061 are added together and the result is stored in
general register address R003.
(2) Indirect transfer of data in the general register (horizontal indirect transfer)
Example 2.
Execution of “MOV @r, m” when general register is in row address 0
R005
MEM
0.05H
M034
MEM
0.34H
MOV
R005, #8
MOV
@R005, M034 ; Indirect transfer of data in the register (0.38H) ← (0.34H)
; R005 ← 8 (Setting of column address of @r)
As shown in Figure 7-10, when the above instructions are executed, the data stored in data
memory address M034 is transferred to data memory location 38H.
The “MOV @r, m” instruction transfers the contents of the data memory specified by m to a data
memory address with the row address same as m and column address specified by @r.
In the above example, therefore, data at M034 is transferred to 38H whose row address is the
same as that of M034 (= 3) and column address is specified by the contents of R005 (= 8).
49
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Example 3.
Execution of “MOV m, @r” when general register is in row address 0
R00B
MEM
0.0BH
M034
MEM
0.34H
MOV
R00B, #0EH
; R00B ← 0EH (Setting column address of @r)
MOV
M034, @R00B
; Indirect transfer of data in the register (0.34H) ← (0.3EH)
As shown in Figure 7-10, when the above instructions are executed, the contents of data
memory stored at address 3EH is transferred to data memory location M034.
The “MOV m, @r” instruction transfers the contents of the data memory of the address which
the column address is specified by @r to a data memory address specified by m.
In the above example, therefore, data at 3EH is transferred to M034 whose row address is the
same as that of M034 (= 3) and column address is specified by the contents of R00B (= 0EH).
Figure 7-10. Operation Example When IXE = 0 and MPE = 0
Column address
0
1
2
3
Row address
2
5
6
7
8
9
8
0
1
4
A
B
C
D
E
F
General
register
E
Column address specified
as transfer destination
Example 2. MOV @R005, M034
Column address specified
as transfer source
3
4
5
Example 3. MOV M034, @R00B
Example 1. ADD R003, M061
6
7
System register
Addresses in Example 1
Addresses in Example 2
ADD R003, M061
MOV @R005, M034
Bank
Row
Column
address address
Bank
Row
Column
address address
Data memory address M
0000
110
0001
Data memory address M
0000
011
0100
General register address R
0000
000
0011
General register address R
0000
000
0101
Indirect transfer address @R
0000
011
1000
Same as M
50
Contents
of R
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.5.4 IXE = 0 and MPE = 1 (Diagonal Indirect Data Transfer)
As shown in Figure 7-9, the indirect data transfer bank and row address specified by @r become the data memory
row address pointer value only when general register indirect data transfer instructions (MOV @r, m and MOV m, @r)
are used.
Example 1. Execution of “MOV @r, m” when the general register is in row address 0
R005 MEM
0.05H
M034 MEM
0.34H
MOV
MPL, #0110B
; MP ← 6 (Setting row address of @r)
MOV
MPH, #1000B
; MPE ← 1, bank ← 0
MOV
R005, #8
; R005 ← 8 (Setting column address of @r)
MOV
@R005, M034
; Indirect transfer of data in the register (0.68H) ← (0.34H)
As shown in Figure 7-11, when the above instructions are executed, the contents of data memory
address M034 is transferred to data memory location 68H.
When the MOV @r, m instruction is executed when MPE = 1, the contents of the data memory
address specified by m is transferred to the column address pointed to by the row address @r being
pointed to by the memory pointer.
In this case, the indirect address specified by @r becomes the value used for the bank and row
address data memory pointer (above example uses row address 6). The column address is the value
in the general register address specified by r (above example uses column address 8).
Therefore the address in the above example is 68H.
This example is different from Example 2 in 7.5.3 when MPE = 0 for the following reasons: In this
example, the data memory row address pointer is used to point to the indirect address bank and
row address specified by @r. (In Example 2 in 7.5.3, the indirect address bank and row address
are the same as m.)
By setting MPE = 1, diagonal indirect data transfer can be performed using the general register.
51
CHAPTER 7 SYSTEM REGISTER (SYSREG)
2. Execution of “MOV m, @r” when general register is in row address 0
R00B
MEM
0.0BH
M034
MEM
0.34H
MOV
MPL, #0110B
MOV
MPH, #1000B
; MPE ← 1, bank ← 0
MOV
R00B, #0EH
; R00B ← 0EH (Setting column address of @r)
MOV
M034, @R00B
; Indirect transfer of data in the register (0.34H) ← (0.6EH)
; MP ← 6 (Setting row address of @r)
As shown in Figure 7-11, when the above instructions are executed, the data stored in address 6EH
is transferred to data memory location M034.
Figure 7-11. Operation Example When IXE = 0 and MPE = 1
0
1
2
3
4
0
5
8
A
B
C
D
E
F
General
register
E
Column address specified
as transfer destination
1
Row address
Column address
6
7
8
9
Column address specified
as transfer source
2
3
Example 2. MOV M034, @R00B
4
5 Example 1. MOV @R005, M034
Memory
pointer
= 00110B
6
7
System register
Addresses in Example 1
Addresses in Example 2
MOV @R005, M034
MOV M034, @R00B
Bank
Row
Column
Bank
address address
Row
Column
address address
Data memory address M
0000
011
0100
Data memory address M
0000
011
0100
General register address R
0000
000
0101
General register address R
0000
000
1011
Indirect transfer address @R
0000
110
1000
Indirect transfer address @R
0000
110
Contents of MP
52
Contents
of R
Contents of MP
1110
Contents
of R
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.5.5 IXE = 1 and MPE = 0 (Index Modification)
As shown in Figure 7-9, when a data memory manipulation instruction is executed, any bank or address in data
memory specified by m can be modified using the index register.
When indirect data transfer using the general register (MOV @r, m or MOV m, @r) is executed, the indirect transfer
bank and address specified by @r can be modified using the index register.
Address modification is done by performing an OR operation on the data memory address and the index register.
The data memory manipulation instruction being executed manipulates data in the memory location pointed to by the
result of the operation (called the real address).
An example is shown below.
Example 1. Execution of “ADD r, m” when the general register is in row address 0
R003
MEM
0.03H
M061
MEM
0.61H
MOV
IXL, #0010B
; IX ← 00000010010B
MOV
IXM, #0001B
;
MOV
IXH, #0000B
; MPE ← 0
OR
PSW, #.DF.IXE AND 0FH ; IXE ← 1
ADD
R003, M061
; (0.03H) ← (0.03H) + (0.73H)
As shown in Figure 7-12, when the instructions of example 1 are executed, the value in data memory
address 73H (real address) and the value in general register address R003 (address 03H) are added
together and the result is stored in general register address R003.
When the ADD r, m instruction is executed, the data memory address specified by m (address 61H
in above example) is index modified.
Modification is done by performing an OR operation on data memory location M061 (address 61H,
binary 00001100001B) and the index register (00000010010B in the above example). The result
of the operation (00001110011B) is used as a real address (address 73H) by the instruction being
executed.
As compared to when IXE = 0 (Examples in 7.5.3), in this example the data memory address being
directly specified by m is modified by performing an OR operation on m and the index register.
53
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Figure 7-12. Operation Example When IXE = 1 and MPE = 0
0
1
2
3
0
A
B
C
D
E
F
General
register
Example 1. ADD R003, M061
2
Index modification
3
M061 : 00001100001B
: 00000010010B
OR) IX
Real address 00001110011B
4
5
Column address
6
7
8
9
5
R003
1
Row address
4
M061
6
7
System register
Addresses in Example 1
ADD R003, M061
Bank
Column
address address
Row
Data memory address M
0000
110
0001
General register address R
0000
000
0011
Index modification
0000
110
0001
M061
BANK
IX
0000
IXH
Real address
(OR operation)
54
0000
m
001
IXM
111
0010
IXL
0011
Instruction is executed using this address.
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Example 2. Indirect data transfer using the general register (Execution of “MOV @r, m”)
R005 MEM
0.05H
M034 MEM
0.34H
; Column address ← 5 (OR of 4 and 1)
MOV
IXL, #0001B
MOV
IXM, #0000B
; Row address ← 3 (OR of 3 and 0)
MOV
IXH, #0000B
; MPE ← 0, bank ← 0 (OR of 0 and 0)
OR
PSW, #.DF.IXE AND 0FH ; IXE ← 1
MOV
R005, #8
MOV
@R005, M034
; R005 ← 8 (Setting column address of @r)
; Indirect data transfer using the register
; (0.38H) ← (0.35H)
As shown in Figure 7-13, when the above instructions are executed, the contents of data memory
address 35H is transferred to data memory location 38H.
When the MOV @r, m instruction is executed when IXE = 1, the data memory address specified
by m (direct address) is modified using the contents of the index register. The bank and row address
of the indirect address specified by @r are also modified using the index register.
The bank, row address, and column address specified by m (direct address) are all modified, and
the bank and row address specified by @r (indirect address) are modified.
Therefore, in the above example the direct address is 35H and the indirect address is 38H.
This example is different from Example 3 in 7.5.3 when IXE = 0 for the following reasons: In this
example, the bank, row address and column address of the direct address specified by m are
modified using the index register. The general register is transferred to the address specified by
the column address of the modified data memory address and the same row address. (In Example
3 in 7.5.3, the direct address is not modified.)
Figure 7-13. Operation Example When IXE = 1 and MPE = 0
0
1
2
3
4
0
5
Column address
6
7
8
9
8
R005
Row address
1
2
M034
3
Direct
4 Index modification
address
: 00000110100B
M034
5
: 00000000001B
OR) IX
6 Real address 00000110101B
A
B
C
D
E
F
General
register
Column address specified
as transfer destination
Example 2.
MOV @R005, M034
Indirect address
7
System register
55
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Example 3. Clearing data memory of 00H-0FH to 0
M000 MEM
0.00H
MOV
IXL, #0
; IX ← 0
MOV
IXM, #0
;
MOV
IXH, #0
; MPE ← 0
LOOP:
OR
PSW, #.DF.IXE AND 0FH ; IXE ← 1
MOV
M000, #0
; Set data memory specified by IX to 0
INC
IX
; IX ← IX + 1
AND
PSW, #1110B
; IXE ← 0, Remains address 7FH even if modified
SKE
IXM, #7
; Row address 7 ?
BR
LOOP
; If not 7 then LOOP (row address is not cleared)
; by IX because IXE is address 7FH.
4. Processing an array
As shown in Figure 7-14, when an operation
A(N) ← A(N) + 4 (0 ≤ N ≤ 15)
is executed to element A (N) of a one-dimensional array with each element 8 bits long, the following
instructions are executed.
M000 MEM
0.00H
M001 MEM
0.01H
MOV
IXH, #0
MOV
IXM, #N SHR 3
; Sets offset of row address
MOV
IXL, #N SHL 1 AND 0FH
; Sets offset of column address
OR
PSW, #.DF.IXE AND 0FH ; IXE ← 1
ADD
M000, #4
ADDC
M001, #0
; A(N) ← A(N) + 4
In the above example, the value of N shifted 1 bit to the left (i.e., the value of N multiplied by 2) is
set to the index register because one element is 8 bits long.
Figure 7-14. Operation Example When IXE = 1 and MPE = 0 (Array Processing)
Row address
0
1
2
3
4
5
6
Column address
7
8
9
A
B
D
E
F
0
A (0)
A (1)
A (2)
A (3)
A (4)
A (5)
A (6)
A (7)
1
A (8)
A (9)
A (10)
A (11)
A (12)
A (13)
A (14)
A (15)
2
A (0)
3
00H
01H
4
b3
b2
b1
b0
b7
b6
b5
b4
5
6
7
System register
56
C
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.6 GENERAL REGISTER POINTER (RP)
7.6.1 General Register Pointer Configuration
Figure 7-15 shows the configuration of the general register pointer.
Figure 7-15. General Register Pointer Configuration
Address
7DH
General register
pointer (RP)
Name
Symbol
Bit
7EH
RPH
b3
b2
b1
RPL
b0
b3
b2
b1
b0
B
Flag
C
D
0
0
0
Data
Initial value when
reset
(RP)
0
0
As shown in Figure 7-15, the general register pointer consists of seven bits; four bits in system register address
7DH (RPH) and the high-order 3 bits of system register address 7EH (RPL). However, since the high-order 3 bits
of address 7DH are always set to 0, the register effectively consists of four bits; the least significant bit of address
7DH and the high-order 3 bits of address 7EH.
All register bits are cleared to 0 at reset.
57
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.6.2 Functions of the General Register Pointer
The general register pointer is used to specify the location of the general register in data memory. For the general
register, see CHAPTER 8 GENERAL REGISTER (GR).
The general register consists of 16 nibbles in any single row of data memory. As shown in Figure 7-16, the general
register pointer is used to indicate which row address is being used as the general register.
Since the general register pointer effectively consists of four bits, the data memory row addresses in which the
general register can be placed are address 0H to 7H of BANK0 and BANK1. In other words, any row in data memory
can be specified as the general register.
With the general register allocated in data memory, data can be transferred to and from, and arithmetic operations
can be performed on the general register and data memory.
Note that row addressed 0H to 6H of BANK1 are unmounted memory locations and should therefore not be specified
as locations for the general register.
For example, when instructions such as
ADD r,m and LD r,m
are executed, instruction operand r can specify an address in the general register and m specifies an address in data
memory. In this way, operations like addition and data transfer can be performed on and between data memory and
the general register.
Figure 7-16. General Register Configuration
General register pointer
(RP)
RPH
This area
should not
be used.
Column address
BANK0
0
b0
b3
b2
b1
0
0
0
0
b0
0
0
0
0
1
1
0
0
1
0
2
0
0
1
1
3
0
1
0
0
4
0
1
0
1
0
1
1
0
0
1
1
1
Allocated to the flag BCD
b1
Fixed to 0
b2
Fixed to 0
Fixed to 0
b3
RPL
1
2
3
4
5
6
7
8
9
A
B
C
E
General register (16 nibbles)
F
Example
General register
with RP =
0000010B
5
6
7
System register
RP
Area in which
general register
can be specified
BANK1
0
1
0
0
0
1
0
0
1
1
0
1
0
2
1
0
1
1
3
1
1
0
0
4
1
1
0
1
5
1
1
1
0
6
1
1
1
1
7
1
Unmounted
Port register
System register
58
D
Both banks
have the
same system
register.
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.7 PROGRAM STATUS WORD (PSWORD)
7.7.1 Program Status Word Configuration
Figure 7-17 shows the configuration of the program status word.
Figure 7-17. Program Status Word Configuration
Address
7EH
Name
Program status
word (PSWORD)
(RP)
Symbol
Bit
7FH
RPL
b3
b2
b1
PSW
b0
b3
b2
b1
b0
B
C
D
C
M
P
C
Y
Z
I
X
E
Data
Initial value when
reset
0
0
As shown in Figure 7-17, the program status word consists of five bits; the least significant bit of system register
address 7EH (RPL) and all four bits of system register address 7FH (PSW).
The program status word is divided into the following 1-bit flags: Binary coded decimal flag (BCD), compare flag
(CMP), carry flag (CY), zero flag (Z), and the index enable flag (IXE).
All register bits are cleared to 0 at reset and after the contents of the interrupt stack register have been saved.
59
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.7.2 Functions of the Program Status Word
The flags of the program status word are used for setting conditions for arithmetic operations and data transfer
instructions and for reflecting the status of operation results. Figure 7-18 shows an outline of the functions of the
program status word.
Figure 7-18. Outline of Functions of the Program Status Word
Address
Bit
Symbol
7EH
7FH
b3 b2 b1 b0 b3 b2 b1 b0
RPL
PSW
B C C Z I
Flag
C M Y
D P
X
E
Flag
60
Function
IXE
Used to specify that index modification be performed on the data
memory address used when a data memory manipulation instruction
is executed.
0: Index modification disabled.
1: Index modification enabled.
Z
Set when the result of an arithmetic operation is 0.
0: Indicates that the result of the arithmetic operation is a value other
than 0.
1: Indicates that the result of the arithmetic operation is 0.
CY
Set when there is a carry in the result of an addition operation or
a borrow in the result of a subtraction operation.
0: Indicates there was no carry or borrow.
1: Indicates there was a carry or borrow.
CMP
Used to specify that the result of an arithmetic operation not be
stored in data memory or the general register but just be reflected
in the CY and Z flags.
0: Results of arithmetic operations are stored.
1: Results of arithmetic operations are not stored.
BCD
Used to specify how arithmetic operations are performed.
0: Arithmetic operations are performed in 4-bit binary.
1: Arithmetic operations are performed in BCD.
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.7.3 Index Enable Flag (IXE)
The IXE flag is used to specify index modification on the data memory address when a data memory manipulation
instruction is executed.
When the IXE flag is set to 1, an OR operation is performed on the data memory address and the index register
(IX), and executes an instruction to the data memory with the result of the OR operation as the real address.
For a more detailed explanation, see 7.5 INDEX REGISTER (IX) AND DATA MEMORY ROW ADDRESS POINTER
(MEMORY POINTER: MP).
7.7.4 Zero Flag (Z) and Compare Flag (CMP)
The Z flag indicates that the result of an arithmetic operation is 0. The CMP flag is used to specify that the result
of an arithmetic operation not be stored in data memory or the general register.
Table 7-3 shows how the CMP flag affects the setting and resetting of the Z flag.
Table 7-3. Zero Flag (Z) and Compare Flag (CMP)
Conditions
When CMP flag
When CMP flag is 1
When the result of an arithmetic operation is a value 0
Z←1
Z flag remains unchanged
When the result of an arithmetic operation is other than 0
Z←0
Z←0
The Z flag and the CMP flag are used for comparing values in the general register and data memory. The Z flag
is only affected by arithmetic operations. The CMP flag is only affected by bit evaluation.
Example of comparing 12-bit data
; Are 12-bit data stored in M001, M002, and M003 equal to 456H?
CMP456:
SET2
CMP, Z
SUB
M001, #4
SUB
M002, #5
; Data stored to M001, M002, and M003 are not lost
SUB
M003, #6
; CLR1
CMP
SKT1
Z
BR
DIFFER
; ≠ 456 H
BR
AGREE
; = 456 H
; CMP is automatically cleared by bit judgement instruction
7.7.5 Carry Flag (CY)
The CY flag shows that there is a carry in the result of an addition operation or a borrow in the result of a subtraction
operation.
The CY flag is set (CY = 1) when there is a carry or borrow in the result and reset (CY = 0) when there is no carry
or borrow in the result.
When the RORC r instruction (contents in the general register specified to by r is shifted right one bit) is executed,
the following occurs: the value in the CY flag just before execution of the instruction is shifted to the most significant
bit of the general register and the least significant bit is shifted to the CY flag.
The CY flag is also useful for when the user wants to skip the next instruction when there is a carry or borrow in
the result of an operation.
The CY flag is only affected by arithmetic operations and rotations and not affected by the CMP flag.
61
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.7.6 Binary-Coded Decimal Flag (BCD)
The BCD flag is used for BCD operations.
When the BCD flag is set (BCD = 1), all arithmetic operations will be performed in BCD. When the BCD flag is
reset (BCD = 0), arithmetic operations are performed in 4-bit binary.
The BCD flag does not affect logical operations, bit judgement, comparison judgement or rotations.
7.7.7 Notes Concerning Use of Arithmetic Operations
When performing arithmetic operations (addition and subtraction) on the program status word (PSWORD), the
following point should be kept in mind.
When an arithmetic operation is performed on the program status word, the result is stored in the program status
word.
Below is an example.
Example
MOV
PSW, #0001B
ADD
PSW, #1111B
When the above instructions are executed, a carry is generated which should cause bit 2 (CY flag) of
PSW to be set. However, the result of the operation (0000B) is stored in PSW, meaning that CY does
not get set.
62
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.8 NOTES CONCERNING USE OF THE SYSTEM REGISTER
7.8.1 Reserved Words for the System Register
Because the system register is allocated in data memory, it can be used in any of the data memory manipulation
instructions. As shown in Example 1 (using a 17K Series Assembler AS17K), because a data memory address can
not be directly coded in an instruction operand, it needs to be defined as a symbol beforehand.
The system register is data memory, but has specialized functions which make it different from general-purpose
data memory. Therefore, the system register is used by defining it beforehand with symbols (used as reserved words)
in the assembler (AS17K).
Reserved words for the system register are allocated in address 74H to 7FH. They are defined by the symbols
(AR3, AR2, ..., PSW) shown in Figure 7-2.
As shown in Example 2, if these reserved words are used, it is not necessary to define symbols.
For information concerning reserved words, see CHAPTER 20 ASSEMBLER RESERVED WORDS.
Example 1.
M037
2.
MOV
34H, #0101B
MOV
76H, #1010B
MEM 0.37H
; Using a data memory address like 34H or 76H will cause an
; error in the assembler.
; Addresses in general data memory need to be defined as
MOV
M037, #0101B ; symbols using the MEM directive.
MOV
AR1, #1010B
; By using the reserved word AR1 (address 6H), there is no need
; to define the address as a symbol.
; Reserved word AR1 is defined in a device file with the directive
; “AR1 MEM 0.76H”.
Assembler AS17K has the below flag symbol manipulation instructions defined internally as macros.
SETn
: Set a flag to 1
CLRn
: Reset a flag to 0
SKTn
: Skip when all flags are 1
SKFn
: Skip when all flags are 0
NOTn
: Invert a flag
INITFLG
: Initialize a flag
By using these embedded macro instructions, data memory can be handled as flags as shown below in Example
3.
The functions of the program status word and the memory pointer enable flag are defined in bit units (flag units)
and each bit has a reserved word defined for it. These reserved words are MPE, BCD, CMP, CY, Z and IXE.
If these flag reserved words are used, the embedded macro instructions can be used as shown in Example
4.
63
CHAPTER 7 SYSTEM REGISTER (SYSREG)
Example 3. F0003
FLG 0.00.3
; Flag symbol definition
SET1 F0003
; Embedded macro
Expanded macro
OR
.MF.F0003 SHR 4, #.DF.F0003 AND 0FH
; Set bit 3 of address 00H of BANK0
4.
SET1
BCD
; Embedded macro
Expanded macro
OR
.MF.BCD SHR 4, #.DF.BCD AND 0FH
; Set the BCD flag
; BCD is defined as “BCD FLG 0.7EH.0”
CLR2 Z, CY
; Identical address flag
Expanded macro
AND
.MF.Z SHR 4, #.DF. (NOT (Z OR CY) AND 0FH)
CLR2 Z, BCD
; Different address flag
Expanded macro
64
AND
.MF.Z SHR 4, #.DF. (NOT Z AND 0FH)
AND
.MF.BCD SHR 4, #.DF. (NOT BCD AND 0FH)
CHAPTER 7 SYSTEM REGISTER (SYSREG)
7.8.2 Handling of System Register Addresses Fixed at 0
In dealing with system register area fixed at 0 (see Figure 7-2), there are a few points for which caution should
be taken with regard to device, emulator and assembler operation.
Items (1), (2) and (3) explain these points.
(1) Concerning device operation
Trying to write data to an address fixed at 0 will not change the value (0) at that address. Any attempt to read
an address fixed at 0 will result in the value 0 being read.
(2) When using a 17K series in-circuit emulator (IE-17K or IE-17K-ET)
An error will be generated if a write instruction attempts to write 1 to an address fixed at 0.
Below is an example of the type of instructions that will cause the in-circuit emulator to generate an error.
Example 1.
MOV
BANK, #0100B
; Attempts to write 1 to bit 3 (an address fixed at 0).
2.
MOV
IXL, #1111B
;
MOV
IXM, #1111B
;
MOV
IXH, #0001B
; Attempts to write 1 to bit 0 (an address fixed at 0).
ADD
IXL, #1
;
ADDC
IXM, #0
;
ADDC
IXH, #0
; Attempts to write 1 to bit 0 (an address fixed at 0) as a result of
operation.
However, when all valid bits are set to 1 as shown in Example 2, executing the instructions INC AR or INC
IX will not cause an error to be generated by the in-circuit emulator. This is because when all valid bits of the
address register and index register are set to 1, executing the INC instruction causes all bits to be set to 0.
The only time the in-circuit emulator will not generate an error when an attempt is made to write the value 1
to an address fixed at 0 is when the address being written to is in the address register.
(3) When using a 17K series assembler (AS17K)
No error is output when an attempt is made to write 1 to an address fixed at 0. The instruction shown in
Example 1
MOV
BANK, #0100B
will not cause an assembler error. However, when the instruction is executed in the in-circuit emulator, an
error is generated.
The following is the reason why an error is not generated in the assembler: the assembler does not know what
data memory address is the object of the data memory manipulation instruction being executed.
The assembler generates an error only when the value n in the embedded macro BANKn is a value greater
than 2:
This is because the assembler judges that embedded macros other than BANK0 and 1 cannot be used in the
µPD17134A subseries.
65
[MEMO]
66
CHAPTER 8 GENERAL REGISTER (GR)
The general register (GR) is allocated in data memory. It can therefore be used directly for arithmetic operations
and transferring data.
8.1 GENERAL REGISTER CONFIGURATION
Figure 8-1 shows the configuration of the general register.
As shown in Figure 8-1, 16 nibbles in a single row address in data memory (16 × 4 bits) are used as the general
register.
The register pointer (RP) in the system register is used to indicate which row address is to be used as the general
register. Since the general register pointer effectively has four valid bits, the data memory row addresses in which
the general register can be allocated are addresses 0H to 7H of BANK0 and BANK1. However, note that row addresses
0H to 6H of BANK1 are unmounted area and should therefore not be specified as locations for the general register.
8.2 FUNCTIONS OF THE GENERAL REGISTER
The general register can be used in transferring data to and from data memory and in performing arithmetic
operations with data memory within an instruction. In effect, since the general register is data memory, this just means
that operations such as arithmetic operations and data transfer can be performed on and between locations in data
memory. In addition, because the general register is allocated in data memory, it can be controlled in the same manner
as other areas in data memory through the use of data memory manipulation instructions.
67
CHAPTER 8 GENERAL REGISTER (GR)
Figure 8-1. General Register Configuration
BANK0
0 1
0
2
3
4
5
Column address
6 7 8 9 A
B
C
D
E
F
Row address
1
The general register pointer
(RP) can be used to specify
any row address in address
locations 0H to 7H of BANK0
and BANK1. However, note
that row addresses 0H to 6H
of BANK1 are unmounted
memory locations and should
therefore not be specified.
2
General register
when RP = 00010B
General Register (16 nibbles)
3
4
5
6
System register
7
RP
BANK1
0
1
2
3
Unmounted
4
(Row addresses 0H to 6H of BANK1
are unmounted memory locations.
RP should therefore not specify a
row address in this area).
5
6
System register
7
7DH
Address
Name
General register pointer
(RP)
RPH
Symbol
Bits
68
7EH
RPL
b3 b2 b1 b0 b3 b2 b1 b0
Data
0
0
0
Reset
0
0
0
B
C
D
0
0
0
0
Both banks have
the same system
register.
CHAPTER 9 REGISTER FILE (RF)
The register file is a register used mainly for specifying conditions for peripheral hardware.
9.1 REGISTER FILE CONFIGURATION
9.1.1 Configuration of the Register File
Figure 9-1 shows the configuration of the register file.
As shown in Figure 9-1, the register file is a register consisting of 128 nibbles (128 words × 4 bits).
In the same way as with data memory, the register file is divided into addresses in 4-bit units. It has a total of 128
nibbles specified in row addresses from 0H to 7H and column addresses from 0H to 0FH.
Address 00H to 3FH define an area called the control register.
9.1.2 Relationship between the Register File and Data Memory
Figure 9-2 shows the relationship between the register file and data memory.
As shown in Figure 9-2, the register file overlaps with data memory in addresses 40H to 7FH.
This means that the same memory exists in register file addresses 40H to 7FH and in data memory bank addresses
40H to 7FH.
Assuming that the current bank is BANK0, register file addresses 40H to 7FH are equivalent to addresses 40H
to 7FH of BANK0 in data memory. When the current bank is BANK1, register file addresses 40H to 7FH are equivalent
to address 40H to 7FH of BANK1 in data memory.
Figure 9-1. Register File Configuration
Column address
0 1 2 3 4 5 6 7 8 9 A B C D E F
0
Row address
1
2
Control register
3
4
Register file
5
6
7
69
CHAPTER 9 REGISTER FILE (RF)
Figure 9-2. Relationship Between the Register File and Data Memory
Column address
0 1 2 3 4 5 6 7 8 9 A B C D E F
0
Data memory
Row address
1
2
3
4
5
6
Unmounted
BANK0
7 Port register
BANK1
Port register
System register
0
1
2
Control register
3
Register file
9.2 FUNCTIONS OF THE REGISTER FILE
9.2.1 Functions of the Register File
The register file is mainly used as a control register for specifying conditions for peripheral hardware.
This control register is allocated within the register file at addresses 00H to 3FH.
The rest of the register file (40H to 7FH) overlaps with data memory. As shown in 9.2.3, because of this overlap,
this area of the register file is the same as normal memory with one exception: The register file manipulation
instructions PEEK and POKE can be used with this area of memory but not with normal data memory.
9.2.2 Functions of Control Register
The peripheral hardware whose conditions can be controlled by control registers is listed below.
For details concerning peripheral hardware and the control register, see the section for the peripheral hardware
concerned.
• Stack pointer (SP)
• Basic interval timer (BTM)
• Power-down reset
• Ports
• 8-bit timer counter (TM0, TM1)
• Interrupt functions
• AC zero cross detector (ZCROSS)
• Serial interface (SIO)
• A/D converter
70
CHAPTER 9 REGISTER FILE (RF)
9.2.3 Register File Manipulation Instructions
Reading and writing data from and to the register file is done using the window register (WR: address 78H) located
in the system register.
Reading and writing of data is performed using the following dedicated instructions:
PEEK WR, rf: Read the data in the address specified by rf and put it into WR.
POKE rf, WR: Write the data in WR into the address specified by rf.
Below is an example using the PEEK and POKE instructions.
Example
RF02
MEM0.82H
; Symbol definition
RF1F
MEM0.9FH
; Register file addresses 00H to 3FH must be defined with
RF53
MEM0.53H
; symbols as BANK0 addresses 80H to BFH.
RF6D
MEM0.6DH
; See 9.4 NOTES CONCERNING USE OF THE REGISTER FILE
RF70
MEM1.70H
; for details.
RF71
MEM1.71H
;
BANK0
1
PEEK
WR, RF02
;
2
POKE
RF1F, WR
;
3
PEEK
WR, RF53
;
4
POKE
RF6D, WR
;
BANK1
;
5
PEEK
WR, RF02
;
6
POKE
RF1F, WR
;
7
PEEK
WR, RF70
;
8
POKE
RF72, WR
;
Figure 9-3 shows an example of register file operation.
As shown in Figure 9-3, reading and writing of data to and from the control register (addresses 00H to 3FH) is
performed using the “PEEK WR, rf” and “POKE rf, WR” instructions. Data within the control register specified using
rf can be read from and written to the control register, only by using these instructions with the window register.
The fact that the register file overlaps with data memory in addresses 40H to 7FH has the following effect: When
a “PEEK WR, rf” or “POKE rf, WR” instruction is executed, the effect is the same as if they were being executed on
the data memory address (in the current bank) specified by rf.
Addresses 40H to 7FH of the register file can be operated by normal memory manipulation instructions.
71
CHAPTER 9 REGISTER FILE (RF)
Figure 9-3. Accessing the Register File Using the PEEK and POKE Instructions
Column address
0
1
2
3
0
4
5
6
7
8
9
A
B
C
D
E
F
Data memory
Row address
1
2
BANK0
3
4
3 PEEK WR, RF53
5
4 POKE RF6D, WR
6
7
3
4
5
BANK1
Unmounted
7 PEEK WR, RF70
8 POKE RF72, WR
6
7
WR
System register
0
1
2
3
1 5 PEEK WR, RF02
2 6 POKE RF1F, WR
Control register
Register file for BANK0
Register file for BANK1
9.3 CONTROL REGISTER
Figure 9-4 shows the configuration of the control register.
As shown in Figure 9-4, the control register consists of 64 nibbles (64 ✕ 4 bits) allocated in register file addresses
00H to 3FH.
However, only 26 nibbles are actually used. The remaining 38 nibbles are allocated for registers which have not
yet been implemented. Data should not be read from or written to this area.
There are two types of registers, both of which occupy one nibble of memory. One type is read/write
(R/W), and the other is read-only (R).
Note that within the read/write (R/W) flags, there exists a flag that will always be read as 0.
The following read/write (R/W) flags are those flags which will always be read as 0:
72
CHAPTER 9 REGISTER FILE (RF)
• WDTRES (RF: 03H, bit 3)
• WDTEN
(RF: 03H, bit 0)
• TM0RES
(RF: 11H, bit 2)
• TM1RES
(RF: 12H, bit 2)
• BTMRES
(RE: 13H, bit 2)
• ADCSTRT (RF: 20H, bit 0)
Within the four bits of data in a nibble, there are bits which are fixed at 0 and will therefore always be read as 0.
These bits remain fixed at 0 even when an attempt is made to write to them.
Attempting to read data in the unused register address area (38 nibbles) will yield unpredictable values. In addition,
attempting to write to this area has no effect.
9.4 NOTES CONCERNING USE OF THE REGISTER FILE
9.4.1 Notes Concerning Operation of the Control Register (Read-Only and Unused Registers)
It is necessary to take note of the following notes concerning device operation and use of the 17K Series assembler
(AS17K) and in-circuit emulator (IE-17K or IE-17K-ET) with regard to the read-only (R) and unused registers in the
control register (register file addresses 00H to 3FH).
(1) Device operation
Writing to a read-only register has no effect.
Attempting to read data from an address in the unused data area will yield an undefined value. Attempting
to write to an address in the unused data area has no effect.
(2) During use of the assembler (AS17K)
An error will be generated if an attempt is made to write to a read-only register.
An error will also be generated if an attempt is made to read from or write to an address in the unused data
area.
(3) During use of the in-circuit emulator (IE-17K or IE-17K-ET) (operation during patch processing and
similar operations)
Attempting to write to a read-only register has no effect. No error is generated.
Attempting to read data from an address in the unused data area will yield an undefined value. Attempting
to write to an address in the unused data area has no effect. No errors are generated.
9.4.2 Register File Symbol Definitions and Reserved Words
Attempting to use a numerical value in a 17K Series assembler (AS17K) to specify a register file address in the
rf operand of the “PEEK WR, rf” or “POKE rf, WR” instructions will cause an error to be generated.
Therefore, as shown in Example 1, register file addresses need to be defined beforehand as symbols.
Example 1.
Case which causes an error to be generated
PEEK
WR, 02H
;
POKE
21H, WR
;
Case in which no error is generated
RF71
MEM0.71H
; Symbol definition
PEEK WR, RF71 ;
73
CHAPTER 9 REGISTER FILE (RF)
Caution should especially be taken with regard to the following point:
• When using a symbol to define the control register as an address in data memory, it needs to be defined
as addresses 80H to BFH of BANK0.
Since the control register is manipulated using the window register, any attempt to manipulate the control register
other than by using the “PEEK” and “POKE” instructions needs to cause an error in the assembler.
However, note that any address in the area of the register file overlapping with data memory (addresses 40H to
7FH) can be defined as a symbol in the same manner as with normal data memory.
An example is given below.
Example 2.
RF71
MEM
1.71H
; Register file overlapping with data memory
RF02
MEM
0.82H
; Control register
BANK0
PEEK
WR, RF71
; RF71 becomes address 71H in BANK0.
PEEK
WR, RF02
; RF02 becomes address 02H in the control register.
PEEK
WR, RF71
; RF71 becomes address 71H in BANK1.
PEEK
WR, RF02
; RF02 becomes address 02H in the control register.
BANK1
The assembler (AS17K) has the below flag symbol manipulation instructions defined internally as macros.
SETn
: Set a flag to 1
CLRn
: Reset a flag to 0
SKTn
: Skip when all flags are 1
SKFn
: Skip when all flags are 0
NOTn
: Invert a flag
INITFLG
: Initialize a flag
By using these embedded macro instructions, the contents of the register file can be manipulated in 1-bit unit.
Due to the fact that most of control register consists of 1-bit flags, the assembler (AS17K) has reserved words for
use with these flags.
However, note that there is no reserved word for the stack pointer for its use as a flag. The only reserved word
used for the stack pointer is the reserved word “SP”, for its use as data memory. For this reason, none of the above
flag manipulation instructions can be used with the stack pointer.
74
CHAPTER 9 REGISTER FILE (RF)
Figure 9-4. Control Register Configuration (1/2)
Column address
Row
address
Item
0
1
2
S
P
Symbol
0
When reset
0
0
(8)
Read/
Write
1
0
1
0
0
When reset 0
0
0
Symbol
1
(9)
Read/
Write
0
0
0
0
When reset 0
0
0
2
(A)
Read/
Write
R/W
0
0
0
0
R/W
0
T
M
0
C
K
0
T
M
1
E
N
T
M
1
R
E
S
T
M
1
C
K
1
T
M
1
C
K
0
B
T
M
I
S
E
L
B
T
M
R
E
S
B
T
M
C
K
1
B
T
M
C
K
0
0
0
0
0
1
0
0
0
0
0
0
0
R/W
A
D
C
C
H
3
A
D
C
C
H
2
A
D
C
C
H
1
A
D
C
C
H
0
0
0
0
0
0
R/W
0
R
7
R/W
A
A A
D
D D
C
C C
S 0 C E
O
M N
F
P D
T
0
6
R/W
T
M
0
C
K
1
0
5
0
T
M
0
R
E
S
R/W
0
Symbol
0
T
M
0
E
N
R/W
A
D
C
0 S
T
R
T
4
W
D
T
0 E
N
R/W
P
D
R
0 E
S
E
N
3
S S S S W
I I I I D
O O O O T
T H C C R 0
S I K K E
Z 1 0 S
R/W
Symbol
3
(B)
When reset
Read/
Write
Remark The address in parentheses apply when the AS17K assembler is used.
The names of all the flags in the control registers are assembler reserved words saved in the device
file.
Using these reserved words is useful in programming.
(See CHAPTER 20 ASSEMBLER
RESERVED WORDS.)
75
CHAPTER 9 REGISTER FILE (RF)
Figure 9-4. Control Register Configuration (2/2)
8
9
A
B
C
D
T
M
0
O 0
S
E
L
S
I
O
0 E 0
N
P
0
B
0 G
P
U
P
0
A
G
P
U
0
0
0
0
0
0
0
R/W
0
P
0
C
0
I
D
I
P
0
C
B
I
O
3
P
0
C
B
I
O
2
P
0
C
B
I
O
1
P
0
C
B 0
I
O
0
0
0
0
0
0
0
0
0
0
0
R/W
P
0
D
B
I
O
1
P
P
1
0
A
D
B 0 G
I
I
O
O
0
P
0
B
G
I
O
P
0
A
G
I
O
0
0
0
0
0
0
0
R/W
0
Z
C
R
0 O
S
S
0
0
0
0
0
0
0
0
0
0
0
R/W
0
0
0
0
0
0
0
0
I
R
Q
0 T 0
M
1
0
R/W
I
E
G
0 M
D
1
I
E
G
M
D
0
0
0
0
I
P
S
0 I
O
I
P
B
T
M
I
P
T
M
1
I I
P P
T
M
0
0
0
0
0
0
R/W
I
R
Q
0 B 0
T
M
0
1
0
0
0
I
R
Q
0 T 0
M
0
0
R/W
0
R/W
0
0
I
R
Q
0
0
0
0
R/W
Note The value of the INT flag changes every moment according to the status of the INT pin.
76
Note
R/W
R/W
I
R
Q
0 S 0
I
O
R/W
0
R/W
P
0
D
B
I
O
2
0
0
R/W
P
0
D
B
I
O
3
0
0
R
P
0
C
1
I
D
I
0
0
R/W
P
0
C
2
I
D
I
0
F
I
N
T
P
0
C
3
I
D
I
0
E
0
CHAPTER 10 DATA BUFFER (DBF)
The data buffer consists of four nibbles allocated in addresses 0CH to 0FH in BANK0.
The data buffer acts as a data storage area for the CPU peripheral circuit (address register, serial interface, timer
0, timer1, basic internal timer, and A/D converter) through use of the GET and PUT instructions. It also acts as data
storage used for receiving and transferring data. By using the MOVT, DBF, and @AR instructions, fixed data in
program memory can be read into the data buffer.
10.1 DATA BUFFER CONFIGURATION
Figure 10-1 shows the allocation of the data buffer in data memory.
As shown in Figure 10-1, the data buffer is allocated in address locations 0CH to 0FH in BANK0 and consists of
a total of 16 bits (4 × 4 bits).
Figure 10-1. Allocation of the Data Buffer
Column address
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Data buffer
(DBF)
0
1
Row address
Data memory
2
3
BANK0
4
5
6
7
System register (SYSREG)
Figure 10-2 shows the configuration of the data buffer. As shown in Figure 10-2, the data buffer is made up of
16 bits with its LSB in bit 0 of address 0FH and its MSB in bit 3 of address 0CH.
Figure 10-2. Data Buffer Configuration
Data memory
BANK0
Address
0CH
0DH
0EH
0FH
Bit
b3
b1
b0
b3
b2
b1
b0
b3
b2
b1
b0
Bit
b15 b14 b13 b12 b11 b10 b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
b2
b1
b0
b3
b2
Data buffer
DBF3
Symbol
Data
^
M
S
B
^
DBF2
Data
DBF1
DBF0
^
L
S
^B
Because the data buffer is allocated in data memory, it can be used in any of the data memory manipulation
instructions.
77
CHAPTER 10 DATA BUFFER (DBF)
10.2 FUNCTIONS OF THE DATA BUFFER
The data buffer has two separate functions.
The data buffer is used for data transfer with peripheral hardware. The data buffer is also used for reading constant
data (table reference) in program memory. Figure 10-3 shows the relationship between the data buffer and peripheral
hardware.
Figure 10-3. Relationship Between the Data Buffer and Peripheral Hardware
Data buffer
(DBF)
Internal bus
Peripheral
address
Peripheral hardware
01H
Shift register (SIOSFR)
02H
Timer 0 modulo register
(TM0M)
03H
Timer 1 modulo register
(TM1M)
04H
A/D converter data register
(ADCR)
40H
Address register (AR)
Program memory (ROM)
Constant data
45H
78
Timer 0/timer 1 count
register (TM0TM1C)
CHAPTER 10 DATA BUFFER (DBF)
10.2.1 Data Buffer and Peripheral Hardware
Table 10-1 shows data transfer with peripheral hardware using the data buffer.
Each unit of peripheral hardware has an individual address (called its peripheral address). By using this peripheral
address and the dedicated instructions GET and PUT, data can be transferred between each unit of peripheral
hardware and the data buffer.
GET DBF, p: Read the data in the peripheral hardware address specified by p into the data buffer (DBF).
PUT p, DBF: Write the data in the data buffer to the peripheral hardware address specified by p.
There are three types of peripheral hardware units: read/write (PUT/GET), write-only (PUT) and read-only (GET).
The following describes what happens when a GET instruction is used with write-only hardware (PUT only) and
when a PUT instruction is used with read-only hardware (GET only).
• Reading (GET) from write-only (PUT only) peripheral hardware will yield an undefined value.
• Writing (PUT) to read-only (GET only) peripheral hardware has no effect (same as a NOP instruction).
Table 10-1. Peripheral Hardware
(1) Peripheral hardware with input/output in 8-bit units
Peripheral
Name
Peripheral hardware
address
Direction of data
PUT
Actual
GET
bit length
01H
SIOSFR
Serial interface
8 bits
02H
TM0M
Timer 0
×
8 bits
03H
TM1M
Timer 1
×
8 bits
04H
ADCR
A/D converter
8 bits
(2) Peripheral hardware with input/output in 16-bit units
Peripheral
Name
Peripheral hardware
address
Note
Direction of data
PUT
40H
AR
45H
TM0TM1C
GET
bit length
10/11 bitsNote
Address register
Timer 0/timer 1 count register
Actual
×
16 bits
10 bits for the µPD17134A and 17135A, and 11 bits for the µPD17136A and 17137A.
79
CHAPTER 10 DATA BUFFER (DBF)
10.2.2 Data Transfer with Peripheral Hardware
Data can be transferred between the data buffer and peripheral hardware in 8- or 16-bit units. Instruction execution
time for a single PUT or GET instruction is the same regardless of whether 8 or 16 bits are being transferred.
Example 1.
PUT instruction (when the actual bits in peripheral hardware are the 8 bits from 0 to 7)
Data buffer
DBF3
Don’t care
DBF2
Don’t care
DBF1
b7
b6
b5
DBF0
b4
b3
b2
b1
b0
PUT
Data in peripheral
hardware
Actual bits
b7
b0
When only 8 bits of data are being written from the data buffer, the high-order 8 bits (DBF3, DBF2)
are “don’t care” (any value can be written).
2.
GET instruction (when the actual bits in peripheral hardware are the 8 bits from 0 to 7)
Data buffer
DBF3
Retained
DBF2
Retained
DBF1
DBF0
b7
b0
GET
Data in peripheral
hardware
Actual bits
b7
b0
When 8 bits of data are being read into the data buffer, the values in the high-order 8 bits (DBF3,
DBF2) remain unchanged.
80
CHAPTER 10 DATA BUFFER (DBF)
10.2.3 Table Reference
By using the MOVT instruction, constant data in program memory (ROM) can be read into the data buffer.
The MOVT instruction is explained below.
MOVT DBF, @AR: The contents of the program memory being specified by the address register (AR) is read into
the data buffer (DBF).
Data buffer
DBF3
DBF2
DBF1
DBF0
Program memory (ROM)
MOVT DBF, @AR
16 bits
b15
b0
81
[MEMO]
82
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
The ALU is used for performing arithmetic operations, logical operations, bit judgements, comparison judgements,
and rotations on 4-bit data.
11.1 ALU BLOCK CONFIGURATION
Figure 11-1 shows the configuration of the ALU block.
As shown in Figure 11-1, the ALU block consists of the main 4-bit data processor, temporary registers A and B
which are peripheral circuit of the ALU, the status flip-flop for controlling the status of the ALU, and the decimal
correction circuit for use during arithmetic operations in BCD.
As shown in Figure 11-1, the status flip-flop consists of the following flags: Zero flag FF, carry flag FF, compare
flag FF, and the BCD flag FF.
Each flag in the status flip-flop corresponds directly to a flag in the program status word (PSWORD: addresses
7EH, 7FH) in the system register. The flags in the program status word are the following: Zero flag (Z), carry flag
(CY), compare flag (CMP), and the BCD flag (BCD).
11.2 FUNCTIONS OF THE ALU BLOCK
Arithmetic operations, logical operations, bit judgements, comparison judgements, and rotations are performed
using the instructions in the ALU block. Table 11-1 lists each arithmetic/logical instruction, judgement instruction, and
rotation instruction.
By using the instructions listed in Table 11-1, 4-bit arithmetic/logical operations, judgements and rotations can be
performed in a single instruction. Arithmetic operations in decimal can also be performed in a single instruction.
11.2.1 Functions of the ALU
The arithmetic operations consist of addition and subtraction. Arithmetic operations can be performed on the
contents of the general register and data memory or on immediate data and the contents of data memory. Operations
in binary are performed on 4 bits of data and operations in decimal are performed on one place (BCD operation).
Logical operations include ANDing, ORing, and XORing. Their operands can be general register contents and data
memory contents, or data memory contents and immediate data.
Bit judgement is used to determine whether bits in 4-bit data in data memory are 0 or 1.
Comparison judgement is used to compare contents of data memory with immediate data. It is used to determine
whether one value is equal to or greater than the other, less than the other, or if both values are equal or not equal.
Rotation is used to shift 4-bit data in the general register one bit in the direction of its least significant bit (rotation
to the right).
83
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
Figure 11-1. ALU Configuration
Data bus
Temporary
register A
Temporary
register B
Status
flip-flop
ALU
• Arithmetic operations
• Logical operations
• Bit judgement
• Comparison
judgement
• Rotations
Decimal
correction circuit
Address
7EH
Program status word
(PSWORD)
Name
Bit
Flag
7FH
b0
b3
b2
b1
b0
BCD
CMP
CY
Z
IXE
BCD
flag
CMP
flag
CY
flag
Z
flag
FF
FF
FF
FF
Status flip-flop
Function outline
Indicates when the result of an arithmetic
operation is 0.
Stores the borrow or carry from an
arithmetic operation.
Used to indicate whether to store the result
of an arithmetic operation.
Used to indicate whether to perform
decimal correction for arithmetic operations.
84
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
[MEMO]
85
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
Table 11-1. List of ALU Instructions (1/2)
ALU function
Arithmetic
operations
Addition
Instruction
Operation
ADD r, m
(r) ← (r) + (m)
Adds contents of general register and data memory.
Result is stored in general register.
ADD m, #n4
(m) ← (m) + n4
Adds immediate data to contents of data memory.
Result is stored in data memory.
ADDC r, m
(r) ← (r) + (m) + CY
Adds contents of general register, data memory and carry
flag. Result is stored in general register.
ADDC m,
#n4
(m) ← (m) + n4 + CY
Adds immediate data, contents of data memory and carry
flag. Result is stored in data memory.
(r) ← (r) – (m)
Subtracts contents of data memory from contents of general
register. Result is stored in general register.
SUB m, #n4
(m) ← (m) – n4
Subtracts immediate data from data memory.
Result is stored in data memory.
SUBC r, m
(r) ← (r) – (m) – CY
Subtracts contents of data memory and carry flag from
contents of general register. Result is stored in general
register.
SUBC m,
(m) ← (m) – n4 – CY
Subtracts immediate data and carry flag from data memory.
Subtraction SUB r, m
#n4
Logical
OR
Logical
Result is stored in data memory.
OR r, m
(r) ← (r) v (m)
OR operation is performed on contents of general register
and data memory. Result is stored in general register.
OR m, #n4
(m) ← (m) v n4
OR operation is performed on immediate data and contents
of data memory. Result is stored in data memory.
AND r, m
(r) ← (r)
AND operation is performed on contents of general register
v
Logical
operations
(m)
AND
(m) ← (m)
XOR r, m
(r) ← (r) v (m)
XOR operation is performed on contents of general register
and data memory. Result is stored in general register.
XOR m, #n4
(m) ← (m) v n4
XOR operation is performed on immediate data and contents
of data memory. Result is stored in data memory.
SKT m, #n
CMP ← 0, if (m) n=n,
then skip
Skips next instruction if all bits in data memory specified by
n are TRUE (1). Result is not stored.
SKF m, #n
CMP ← 0, if (m) n=0,
then skip
Skips next instruction if all bits in data memory specified by
n are FALSE (0). Result is not stored.
SKE m, #n4
(m) – n4, skip if zero
Skips next instruction if immediate data equals contents of
data memory. Result is not stored.
Not equal
SKNE m,
#n4
(m) – n4, skip if not
zero
Skips next instruction if immediate data is not equal to
contents of data memory. Result is not stored.
≥
SKGE m,
#n4
(m) – n4, skip if not
borrow
Skips next instruction if contents of data memory is greater
than or equal to immediate data. Result is not stored.
<
SKLT m,
#n4
(m) – n4, skip if
borrow
Skips next instruction if contents of data memory is less
than immediate data. Result is not stored.
Rotate to
the right
RORC r
AND operation is performed on immediate data and contents
of data memory. Result is stored in data memory.
v
Comparison Equal
judgement
n4
v
False
v
Bit
True
Judgement
86
and data memory. Result is stored in general register.
AND m, #n4
Logical
XOR
Rotation
Explanation
CY→(r)b3→(r)b2→(r)b1→(r)b0
Rotate contents of the general register along with the CY
flag to the right. Result is stored in general register.
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
Table 11-1. List of ALU Instructions (2/2)
ALU Function
Difference in operation because of program status word (PSWORD)
Arithmetic
operation
Value of
Value of
BCD flag
CMP flag
0
0
0
Operation
0
Binary operation.
Set when
Set if operation result is 0000B;
Result is stored.
carry or
otherwise, reset
Binary operation.
borrow
Retains status if operation result
Result is not stored.
occurs;
is 0000B; otherwise, reset
BCD operation.
otherwise,
Set if operation result is 0000B;
reset
Result is stored.
1
1
Result is not stored.
is 0000B; otherwise, reset
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
(retained)
Executed
Don’t care
Don’t care
(retained)
(retained)
––––––
––––––
Executed
– – –– – – – – – – – – – –– – –
– – –– – – – – – – – – – –– – –
Not affected
– – –– – – – – – – – – – – –
Don’t care
(retained)
– – –– – – – – – – – – – –– – –
(retained)
– – –– – – – – – – – – – –– – –
Don’t care
(retained)
Executed
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
Not affected
– – –– – – – – – – – – – –– – –
– – –– – – – – – – – – – –– – –
Dont’care
Don’t care
––––––
(retained)
(retained)
––––––
Don’t care
(retained)
Don’t care
(retained)
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
Not affected
––––––
––––––
Dont’care
– – –– – – – – – – – – – –– – –
Rotation
––––––
Comparison
Don’t care
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
Reset
(retained)
Executed
– – –– – – – – – – – – – – –
Not affected
– – –– – – – – – – – – – – –
(retained)
Dont’care
Retains status if operation result
– – –– – – – – – – – – – – –
Don’t care
(retained)
Modification
otherwise, reset
BCD operation.
– – –– – – – – – – – – – – –
– – –– – – – – – – – – – – –
Dont’care
– – –– – – – – – – – – – – ––– – –– – – – – – – – –
Bit judgement
– – –– – – – – – – – – – – –
Logical
operation
Z flag
when IXE = 1
1
1
CY flag
Value of b0 of
Don’t care
general register
(retained)
Executed
87
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.2.2 Functions of Temporary Registers A and B
Temporary registers A and B are needed for processing of 4-bit data at a time. These registers are used for
temporary storage of the first and second data operands of an instruction.
11.2.3 Functions of the Status Flip-flop
The status flip-flop is used for controlling operation of the ALU and for storing data which has been processed. Each
flag in the status flip-flop corresponds directly to a flag in the program status word (PSWORD) located in the system
register. This means that when a flag in the system register is manipulated it is the same as manipulating a flag in
the status flip-flop. Each flag in the program status word is described below.
(1) Z flag
This flag is set (1) when the result of an arithmetic operation is 0000B, otherwise it is reset (0). However, depending
on the status of the CMP flag, the conditions which cause this flag to be set (1) can be changed.
(i)
When CMP = 0
Z flag is set (1) when the result of an arithmetic operation is 0000B, otherwise it is reset (0).
(ii) When CMP = 1
The previous state is maintained when the result of an arithmetic operation is 0000B, otherwise it is reset
(0). Only affected by arithmetic operations.
(2) CY flag
This flag is set (1) when a carry or borrow is generated as a result of an arithmetic operation, otherwise it is reset
(0).
When an arithmetic operation is being performed using a carry or borrow, the operation is performed using the
CY flag as the least significant bit.
When a rotation (RORC instruction) is performed, the contents of the CY flag becomes the most significant bit
(b3) of the general register and the least significant bit of the general register is stored in the CY flag.
Only affected by arithmetic operations and rotations.
(3) CMP flag
When the CMP flag is set (1), the result of an arithmetic operation is not stored in either the general register or
data memory.
When the bit evaluation instruction is performed, the CMP flag is reset (0).
The CMP flag does not affect comparison judgements, logical operations, or rotations.
(4) BCD flag
When the BCD flag is set (1), decimal correction is performed for all arithmetic operations. When the flag is reset
(0), 4-bit binary operation is performed.
The BCD flag does not affect logical operations, bit judgements, comparison judgements, or rotations.
These flags can also be set through direct manipulation of the values in the program status word. At this time,
the corresponding flag in the status flip-flop is also manipulated.
88
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.2.4 Operations in 4-Bit Binary
When the BCD flag is set to 0, arithmetic operations are performed in 4-bit binary.
11.2.5 Operations in BCD
When the BCD flag is set to 1, decimal correction is performed for arithmetic operations performed in 4-bit binary.
Table 11-2 shows the differences in the results of operations performed in 4-bit binary and in BCD. When the result
of an addition after decimal correction is equal to or greater than 20, or the result of a subtraction after decimal
correction is outside of the range –10 to +9, a value of 1010B (0AH) or higher is stored as the result (shaded area
in Table 11-2).
Table 11-2. Results of Arithmetic Operations Performed in 4-Bit Binary and BCD
Operation
result
Addition in 4bit binary
Addition in
BCD
Operation
Subtraction in
4-bit binary
Subtraction in
BCD
CY
Operation
result
CY
Operation
result
0
0
0000
0
0000
1
0
0001
0
0001
0010
2
0
0010
0
0010
0
0011
3
0
0011
0
0011
0100
0
0100
4
0
0100
0
0100
0101
0
0101
5
0
0101
0
0101
0
0110
0
0110
6
0
0110
0
0110
7
0
0111
0
0111
7
0
0111
0
0111
8
0
1000
0
1000
8
0
1000
0
1000
9
0
1001
0
1001
9
0
1001
0
1001
10
0
1010
1
0000
10
0
1010
1
1100
11
0
1011
1
0001
11
0
1011
1
1101
12
0
1100
1
0010
12
0
1100
1
1110
13
0
1101
1
0011
13
0
1101
1
1111
14
0
1110
1
0100
14
0
1110
1
1100
15
0
1111
1
0101
15
0
1111
1
1101
16
1
0000
1
0110
–16
1
0000
1
1110
17
1
0001
1
0111
–15
1
0001
1
1111
18
1
0010
1
1000
–14
1
0010
1
1100
19
1
0011
1
1001
–13
1
0011
1
1101
20
1
0100
1
1110
–12
1
0100
1
1110
21
1
0101
1
1111
–11
1
0101
1
1111
22
1
0110
1
1100
–10
1
0110
1
0000
23
1
0111
1
1101
–9
1
0111
1
0001
24
1
1000
1
1110
–8
1
1000
1
0010
25
1
1001
1
1111
–7
1
1001
1
0011
26
1
1010
1
1100
–6
1
1010
1
0100
27
1
1011
1
1101
–5
1
1011
1
0101
28
1
1100
1
1010
–4
1
1100
1
0110
29
1
1101
1
1011
–3
1
1101
1
0111
30
1
1110
1
1100
–2
1
1110
1
1000
31
1
1111
1
1101
–1
1
1111
1
1001
CY
Operation
result
CY
Operation
result
0
0
0000
0
0000
1
0
0001
0
0001
2
0
0010
0
3
0
0011
4
0
5
0
6
89
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.2.6 Operations in the ALU Block
When arithmetic operations, logical operations, bit judgements, comparison judgements or rotations in a program
are executed, the first data operand is stored in temporary register A and the second data operand is stored in
temporary register B.
The first data operand is 4-bit data used to specify the contents of an address in the general register or data memory.
The second data operand is 4-bit data used to either specify the contents of an address in data memory or to be used
as an immediate value. For example, in the instruction
ADD r, m
Second operand
First operand
the first operand, r, is used to specify the contents of an address in the general register. The second operand, m,
is used to specify the contents of an address in data memory. In the instruction
ADD m, #n4
the first operand, m, is used to specify an address in data memory. The second operand, #n4, is immediate data.
In the rotation instruction
RORC r
only the first operand, r (used to specify the contents of an address in the general register) is used.
Next, using the data stored in temporary registers A and B, the ALU executes the operation specified by the
instruction (arithmetic operation, logical operation, bit judgement, comparison judgement, or rotation). When the
instruction being executed is an arithmetic operation, logical operation, or rotation, the data processed by the ALU
is stored in the location specified by the first operand (general register address or data memory address) and the
operation terminates. When the instruction being executed is a bit judgement or comparison judgement, the result
processed by the ALU is used to determine whether or not to skip the next instruction (whether to treat next instruction
as a NOP instruction) and the operation terminates.
Caution should be taken with regard to the following points:
(1) Arithmetic operations are affected by the CMP and BCD flags in the program status word.
(2) Logical operations are not affected by the CMP or BCD flag in the program status word. Logical operations
do not affect the Z or CY flags.
(3) Bit judgement causes the CMP flag in the program status word to be reset.
(4) When an arithmetic operation, logical operation, bit judgement, comparison judgement, or rotation is being
executed and the IXE flag in the program status word is set (1), address modification is performed using the
index register.
90
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.3 ARITHMETIC OPERATIONS (ADDITION AND SUBTRACTION IN 4-BIT BINARY AND BCD)
As shown in Table 11-3, arithmetic operations consist of addition, subtraction, addition with carry, and subtraction
with borrow. These instructions are ADD, ADDC, SUB, and SUBC.
The ADD, ADDC, SUB, and SUBC instructions are further divided into addition and subtraction of the general
register and data memory and addition and subtraction of data memory and immediate data. When the operands
r and m are used, addition or subtraction is performed using the general register and data memory. When the operands
m and #n4 are used, addition or subtraction is performed using data memory and immediate data.
Arithmetic operations are affected by the status flip-flop and the program status word (PSWORD) in the system
register. The BCD flag in the program status word is used to specify whether arithmetic operations are to be performed
in 4-bit binary or in BCD. The CMP flag is used to specify whether or not the results of arithmetic operations are to
be stored.
11.3.1 to 11.3.4 explain the relationship between each command and the program status word.
Table 11-3. Types of Arithmetic Operations
Arithmetic
operation
Addition
Without carry ADD
With carry ADDC
Subtraction
Without borrow SUB
With borrow SUBC
General register and data memory
ADD r, m
Data memory and immediate data
ADD m, #n4
General register and data memory
ADDC r, m
Data memory and immediate data
ADDC m, #n4
General register and data memory
SUB r, m
Data memory and immediate data
SUB m, #n4
General register and data memory
SUBC r, m
Data memory and immediate data
SUBC m, #n4
11.3.1 Addition and Subtraction When CMP = 0 and BCD = 0
Addition and subtraction are performed in 4-bit binary and the result is stored in the general register or data memory.
When the result of the operation is greater than 1111B (carry generated) or less than 0000B (borrow generated),
the CY flag is set (1); otherwise it is reset (0).
When the result of the operation is 0000B, the Z flag is set (1) regardless of whether there is carry or borrow;
otherwise it is reset (0).
11.3.2 Addition and Subtraction When CMP = 1 and BCD = 0
Addition and subtraction are performed in 4-bit binary.
However, because the CMP flag is set (1), the result of the operation is not stored in either the general register
or data memory.
When there is a carry or borrow in the result of the operation, the CY flag is set (1); otherwise it is reset (0).
When the result of the operation is 0000B, the previous state of the Z flag is retained; otherwise it is reset (0).
91
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.3.3 Addition and Subtraction When CMP = 0 and BCD = 1
BCD operations are performed.
The result of the operation is stored in the general register or data memory. When the result of the operation is
greater than 1001B (9D) or less than 0000B (0D), the carry flag is set (1), otherwise it is reset (0).
When the result of the operation is 0000B (0D), the Z flag is set (1), otherwise it is reset (0).
Operations in BCD are performed by first computing the result in binary and then by using the decimal correction
circuit to convert the result to decimal. For information concerning the binary to decimal conversion, see Table
11-2.
In order for operations in BCD to be performed properly, note the following:
(1) Result of an addition must be in the range 0D to 19D.
(2) Result of a subtraction must be in the range 0D to 9D, or in the range –10D to –1D.
The following shows which value is considered the CY flag in the range 0D to 19D (shown in 4-bit binary):
0, 0000B to 1, 0011B
CY
CY
The following shows which value is considered the CY flag in the range –10D to –1D (shown in 4-bit binary):
1, 0110B to 1, 1111B
CY
CY
When operations in BCD are performed outside of the limits of (1) and (2) stated above, the CY flag is set (1) and
the result of operation is output as a value greater than or equal to 1010B (0AH).
11.3.4 Addition and Subtraction When CMP = 1 and BCD = 1
BCD operations are performed.
The result is not stored in either the general register or data memory.
In other words, the operations specified by CMP = 1 and BCD = 1 are both performed at the same time.
Example
MOV
RPL,
#0001B
; Sets the BCD flag (BCD = 1).
MOV
PSW,
#1010B
; Sets the CMP and Z flag (CMP = 1, Z = 1) and resets the CY flag
SUB
M1,
#0001B
; (1)
SUBC
M2,
#0010B
; (2)
SUBC
M3,
#0011B
; (3)
; (CY = 0).
By executing the instructions in steps numbered (1), (2), and (3), the 12 bits in memory locations M1,
M2, and M3 and the immediate data (321) can be compared in decimal.
11.3.5 Notes Concerning Use of Arithmetic Operations
When performing arithmetic operations with the program status word (PSWORD), caution should be taken with
regard to the result of the operation being stored in the program status word.
Normally, the CY and Z flags in the program status word are set (1) or reset (0) according to the result of the
arithmetic operation being executed. However, when an arithmetic operation is performed on the program status word
itself, the result is stored in the program status word. This means that there is no way to determine if there is a carry
or borrow in the result of the operation nor if the result of the operation is zero.
However, when the CMP flag is set (1), results of arithmetic operations are not stored. Therefore, even in the above
case, the CY and Z flags will be properly set (1) or reset (0) according to the result of the operation.
92
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.4 LOGICAL OPERATIONS
As shown in Table 11-4, logical operations consist of logical OR, logical AND, and logical XOR. Accordingly, the
logical operation instructions are OR, AND, and XOR.
The OR, AND, and XOR instructions can be performed on either the general register and data memory, or on data
memory and immediate data. The operands of these instructions are specified in the same way as for arithmetic
operations (“r, m” or “m, #n4”).
Logical operations are not affected by the BCD or CMP flags in the program status word (PSWORD). Logical
operations do not cause either the CY or Z flag in the program status word (PSWORD) to be set. However, when
the index enable flag (IXE) is set (1), index modification is performed using the index register.
Table 11-4. Logical Operations
Logical
operation
Logical OR
Logical AND
Logical XOR
General register and data memory
OR r, m
Data memory and immediate data
OR m, #n4
General register and data memory
AND r, m
Data memory and immediate data
AND m, #n4
General register and data memory
XOR r, m
Data memory and immediate data
XOR m, #n4
Table 11-5. Table of True Values for Logical Operations
Logical AND
Logical OR
Logical XOR
C = A AND B
C = A OR B
C = A XOR B
A
B
C
A
B
C
A
B
C
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
1
0
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
93
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.5 BIT JUDGEMENTS
As shown in Table 11-6, there are both TRUE (1) and FALSE (0) bit judgement instructions.
The TRUE (1) and FALSE (0) bit judgements use SKT and SKF instruction, respectively
The SKT and SKF instructions can only be used with data memory.
Bit judgements are not affected by the BCD flag in the program status word (PSWORD) and bit judgements do
not cause either the CY or Z flag in the program status word (PSWORD) to be set. However, when an SKT or SKF
instruction is executed, the CMP flag is reset (0). When the index enable flag (IXE) is set (1), index modification is
performed using the index register. For information concerning index modification using the index register, see
CHAPTER 7 SYSTEM REGISTER (SYSREG).
11.5.1 and 11.5.2 explain TRUE (1) and FALSE (0) bit judgements.
Table 11-6. Bit Judgement Instructions
Bit judgement
TRUE (1) bit judgement
SKT m, #n
FALSE (0) bit judgement
SKF m, #n
11.5.1 TRUE (1) Bit Judgement
The TRUE (1) bit judgement instruction (SKT m, #n) is used to determine whether or not the bits specified by n
in the 4 bits of data memory m are TRUE (1). When all bits specified by n are TRUE (1), this instruction causes the
next instruction to be skipped.
Example
MOV
M1,
#1011B
SKT
M1,
#1011B
; (1)
BR
A
BR
B
SKT
M1,
#1101B
; (2)
BR
C
BR
D
In this example, bits 3, 1, and 0 of data memory M1 are judged in step number (1). Because all the
bits are TRUE (1), the program branches to B. In step number (2), bits 3, 2, and 0 of data memory
M1 are judged. Since bit 2 of data memory M1 is FALSE (0), the program branches to C.
94
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.5.2 FALSE (0) Bit Judgement
The FALSE (0) bit judgement instruction (SKF m, #n) is used to determine whether or not the bits specified by n
in the 4 bits of data memory m are FALSE (0). When all bits specified by n are FALSE (0), this instruction causes
the next instruction to be skipped.
Example
MOV
M1,
#1001B
;
SKF
M1,
#0110B
; (1)
BR
A
;
BR
B
;
SKF
M1,
BR
C
#1110B
;
; (2)
BR
D
;
In this example, bits 2 and 1 of data memory M1 are judged in step number (1). Because both bits
are FALSE (0), the program branches to B. In step number (2), bits 3, 2, and 1 of data memory M1
are judged. Since bit 3 of data memory M1 is TRUE (1), the program branches to C.
95
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.6 COMPARISON JUDGEMENTS
As shown in Table 11-7, there are comparison judgement instructions for determining if one value is “equal to”,
“not equal to”, “greater than or equal to”, or “less than” another.
The SKE instruction is used to determine if two values are equal. The SKNE instruction is used to determine two
values are not equal. The SKGE instruction is used to determine if one value is greater than or equal to another and
the SKLT instruction is used to determine if one value is less than another.
The SKE, SKNE, SKGE, and SKLT instructions perform comparisons between a value in data memory and
immediate data. In order to compare values in the general register and data memory, a subtraction instruction is
performed according to the values in the CMP and Z flags in the program status word (PSWORD). For more
information concerning comparison of the general register and data memory, see 11.3 ARITHMETIC OPERATIONS.
Comparison judgements are not affected by the BCD or CMP flags in the program status word (PSWORD) and
comparison judgements do not cause either the CY or Z flags in the program status word (PSWORD) to be set.
11.6.1 to 11.6.4 explain the “equal to”, “not equal to”, “greater than or equal to”, and “less than” comparison
evaluations.
Table 11-7. Comparison Judgement Instructions
Comparison
judgement
Equal to
SKE m, #n4
Not equal to
SKNE m, #n4
Greater than or equal to
SKGE m, #n4
Less than
SKLT m, #n4
11.6.1 “Equal to” Judgement
The "equal to" judgement instruction (SKE m, #n4) is used to determine if immediate data and the contents of a
location in data memory are equal.
This instruction causes the next instruction to be skipped when the immediate data and the contents of data memory
are equal.
Example
MOV
M1,
#1010B
SKE
M1,
#1010B
; (1)
BR
A
BR
B
#1000B
; (2)
;
SKE
M1,
BR
C
BR
D
In this example, because the contents of data memory M1 and immediate data 1010B in step number
(1) are equal, the program branches to B. In step number (2), because the contents of data memory
M1 and immediate data 1000B are not equal, the program branches to C.
96
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.6.2 “Not Equal to” Judgement
The “not equal to” judgement instruction (SKNE m, #n4) is used to determine if immediate data and the contents
of a location in data memory are not equal.
This instruction causes the next instruction to be skipped when the immediate data and the contents of data memory
are not equal.
Example
MOV
M1,
#1010B
SKNE
M1,
#1000B
; (1)
BR
A
BR
B
#1010B
; (2)
;
SKNE
M1,
BR
C
BR
D
In this example, because the contents of data memory M1 and immediate data 1000B in step number
(1) are not equal, the program branches to B. In step number (2), because the contents of data memory
M1 and immediate data 1010B are equal, the program branches to C.
11.6.3 “Greater Than or Equal to” Judgement
The “greater than or equal to” judgement instruction (SKGE m, #n4) is used to determine if the contents of a location
in data memory is a value greater than or equal to the value of the immediate data operand. If the value in data memory
is greater than or equal to that of the immediate data, this instruction causes the next instruction to be skipped.
Example
MOV
M1,
#1000B
SKGE
M1,
#0111B
; (1)
BR
A
BR
B
#1000B
; (2)
#1001B
; (3)
;
SKGE
M1,
BR
C
BR
D
;
SKGE
M1,
BR
E
BR
F
In this example, the program will first branch to B since the value in data memory is larger than that
of the immediate data. Next it will branch to D since the value in data memory is equal to that of the
immediate data. Last it will branch to E since the value in data memory is less than that of the immediate
data.
97
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.6.4 “Less Than” Judgement
The “less than” judement instruction (SKLT m, #n4) is used to determine if the contents of a location in data memory
is a value less than that of the immediate data operand. If the value in data memory is less than that of the immediate
data, this instruction causes the next instruction to be skipped.
Example
MOV
M1,
#1000B
SKLT
M1,
#1001B
; (1)
BR
A
BR
B
#1000B
; (2)
#0111B
; (3)
;
SKLT
M1,
BR
C
BR
D
;
SKLT
M1,
BR
E
BR
F
In this example, the program will first branch to B since the value in data memory is less than that of
the immediate data. Next it will branch to C since the value in data memory is equal to that of the
immediate data. Last it will branch to E since the value in data memory is greater than that of the
immediate data.
98
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.7 ROTATIONS
There are rotation instructions for rotation to the right and for rotation to the left.
The RORC instruction is used for rotation to the right.
The RORC instruction can only be used with the general register.
Rotation using the RORC instruction is not affected by the BCD or CMP flags in the program status word (PSWORD)
and does not affect the Z flag in the program status word (PSWORD).
Rotation to the left is performed by using the addition instruction ADDC.
11.7.1 and 11.7.2 explain rotation.
11.7.1 Rotation to the Right
The instruction used for rotation to the right (RORC r) rotates the contents of the general register in the direction
of its least significant bit.
When this instruction is executed, the contents of the CY flag becomes the most significant bit of the general register
(bit 3) and the least significant bit of the general register is placed in the CY flag.
Example 1.
MOV
PSW,
#0100B
MOV
R1,
#1001B
RORC
R1
; Sets CY flag to 1.
When these instructions are executed, the following operation is performed.
CY flag
b3
b2
b1
b0
1
1
1
0
0
Basically, when rotation to the right is performed, the following operation is executed:
CY flag → b3, b3 → b2, b2 → b1, b1 → b0, b∞ → CY flag.
2.
MOV
PSW,
#0000B
; Resets CY flag to 0.
MOV
R1,
#1000B
; MSB
MOV
R2,
#0100B
MOV
R3,
#0010B
RORC
R1
RORC
R2
RORC
R3
; LSB
The program code above rotates the 13 bits in R1, R2, and R3 to the right.
99
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
11.7.2 Rotation to the Left
Rotation to the left is performed by using the addition instruction, “ADDC r, m”.
Example
MOV
PSW,
#0000B
; Resets CY flag to 0.
MOV
R1,
#1000B
; MSB
MOV
R2,
#0100B
MOV
R3,
#0010B
ADDC
R3, R3
ADDC
R2, R2
ADDC
R1, R1
SKF
CY
OR
R3,
; LSB
#0001B
The program code above rotates the 13 bits in R1, R2, and R3 to the left.
100
CHAPTER 12 PORTS
12.1 PORT 0A (P0A0, P0A1, P0A2, P0A3)
Port 0A is a 4-bit input/output port with an output latch. It is mapped into address 70H of BANK0 in data memory.
The output format is CMOS push-pull output.
Input or output can be specified in 4-bit units. Input/output is specified by P0AGIO (bit 0 at address 2CH) in the
register file.
When P0AGIO is 0, all pins of port 0A are used as input port. If a read instruction is executed for the port register,
pin statuses are read.
When P0AGIO is 1, all pins of port 0A are used as output port and the contents written in the output latch are output
to pins. If a read instruction is executed when pins are output ports, the contents of the output latch, rather than pin
statuses, are fetched.
Port 0A contains a software-controlled pull-up resistor. P0AGPU (bit 0 at address 0CH) of the register file is used
to determine whether port 0A contains the pull-up resistor. When P0AGPU is 1, all 4-bit pins are pulled up. If P0AGPU
is 0, the pull-up resistor is not contained.
At reset, P0AGIO and P0AGPU are set to 0 and all P0A pins become input ports without a pull-up resistor. The
contents of the port output latch are 0.
Table 12-1. Writing into and Reading from the Port Register (0.70H)
P0AGIO
RF: 2CH, bit 0
Pin input/output
0
Input
1
Output
BANK0 70H
Write
Possible
Write to the P0A latch
Read
P0A pin status
P0A latch contents
101
CHAPTER 12 PORTS
12.2 PORT 0B (P0B0, P0B1, P0B2, P0B3)
Port 0B is a 4-bit input/output port with an output latch. It is mapped into address 71H of BANK0 in data memory.
The output format is CMOS push-pull output.
Input or output can be specified in 4-bit units. Input/ output is specified by P0BGIO (bit 1 at address 2CH) in the
register file.
When P0BGIO is 0, all pins of port 0B are used as input ports. If a read instruction is executed for the port register,
pin statuses are read.
When P0BGIO is 1, all pins of port 0B are used as output ports. The contents written in the output latch are output
to pins. If a read instruction is executed when pins are used as output ports, the contents of the output latch, rather
than pin statuses, are fetched.
Port 0B contains a software-controlled pull-up resistor. P0BGPU (bit 1 at address 0CH) is used to determine
whether or not port 0B contains a pull-up resistor. When P0BGPU is 1, all 4-bit pins are pulled up. When P0BGPU
is 0, a pull-up resistor is not contained.
At reset, P0BGIO and P0BGPU are 0 and all P0B pins are input ports without a pull-up resistor. The value of the
port 0B output latch is 0.
Table 12-2. Writing into and Reading from the Port Register (0.71H)
102
P0BGIO
RF: 2CH, bit 1
Pin input/output
0
Input
1
Output
BANK0 71H
Write
Possible
Write to the P0B latch
Read
P0B pin status
P0B latch contents
CHAPTER 12 PORTS
12.3 PORT 0C (P0C0/ADC0, P0C1/ADC1, P0C2/ADC2, P0C3/ADC3)
Port 0C is a 4-bit input/output port with an output latch. It is mapped into address 72H of BANK0 in data memory.
The output format is CMOS push-pull output.
Input or output can be specified in 1-bit unit. Input/output can be specified by P0CBIO0 to P0CBIO3 (address 1CH)
in the register file.
If P0CBIOn is 0 (n = 0 to 3), the P0Cn pins are used as input port. If a data read instruction is executed for the
port register, the pin statuses are read. If P0CBIOn is 1 (n = 0 to 3), the P0Cn pins are used as output port and the
contents written in the output latch are output to pins. If a read instruction is executed when pins are used as output
ports, the contents of the latch, rather than pin statuses, are fetched.
At reset, P0CBIO0 to P0CBIO3 are 0 and all P0C pins are input ports. The contents of the port output latch are
0.
Port 0C can also be used as an analog input to the A/D converter. P0C0IDI to P0C3IDI (1BH address) in the register
file are used to switch the port and analog input pin.
If P0CnIDI is 0 (n = 0 to 3), the P0Cn/ADCn pin functions as a port. If P0CnIDI is 1 (n = 0 to 3), the P0Cn/ADCn
pin functions as the analog input pin of the A/D converter.
ADCCH0 and ADCCH1 (bits 1 and 0 at address 22H) in the register file are used to select the input pin for A/D
conversion.
To use P0C pins as A/D converter input pins, set P0CBIOn = 0 so that they are set as input ports. (See 13.3
A/D CONVERTER.)
At reset, P0CBIO0 to P0CBIO3, P0C0IDI to P0C3IDI, ADCCH0, and ADCCH1 are set to 0 and the P0C pins are
used as input ports.
Table 12-3. Switching the Port and A/D Converter
(n = 0 to 3)
BANK0 72H
P0CnIDI
RF: 1BH
P0CBIOn
RF: 1CH
0
0
Input port
Possible
P0C latch
Pin status
1
Port output
Possible
P0C latch
P0C latch contents
0
A/D converter analog
inputNote1
Possible
P0C latch
P0C latch contents
1
Output port and A/D
converter analog inputNote2
Possible
P0C latch
P0C latch contents
1
Notes 1.
2.
Function
Write
Read
Normal setting when the pins are used as A/D converter analog input pins.
Functions as an output port. At this time, the analog input voltage changes affected by the port output.
When using this pin as an analog input pin, be sure to set P0CBIOn to 0.
103
CHAPTER 12 PORTS
12.4 PORT 0D (P0D0/SCK, P0D1/SO, P0D2/SI, P0D3/TM0OUT)
Port 0D is a 4-bit input/output port with an output latch. It is mapped into address 73H of BANK0 in data memory.
The output format is N-ch open-drain output. The mask option can be used to specify that a pin contain a pull-up
resistor in 1-bit unit.
Input or output can be specified in 1-bit unit. Input/output is specified with P0DBIO0 to P0DBIO3 (address 2BH)
in the register file.
If P0DBIOn is 0 (n = 0 to 3), the P0Dn pins are used as input port. Pin statuses are read if a data read instruction
is executed for the port register. If P0DBIOn is 1, the P0Dn pins are used as output port and the value written in the
output latch are output to pins. If a data read instruction is executed when pins are used as output ports, the output
latch value, rather than pin statuses, is fetched.
At reset, P0DBIOn is set to 0 and all P0D pins become input ports. The contents of the port output latch become
0. The output latch contents remain unchanged even if P0DBIOn changes from 1 to 0.
Port 0D can also be used for serial interface input/output or timer 0 output. SIOEN (0BH bit 0) in the register file
is used to switch ports (P0D0 to P0D2) to serial interface input/output (SCK, SO, SI) and vice versa. TM0OSEL (bit
3 at address 0BH) in the register file is used to switch a port (P0D3) to timer 0 output (TM0OUT) and vice versa. If
TM0OSEL = 1 is selected, 1 is output at timer 0 reset. This output is inverted every time a timer 0 count value matches
the modulo register contents.
Table 12-4. Register File Contents and Pin Functions
(n = 0 to 3)
Register file value
TM0OSEL
RF: 0BH
Bit 3
SIOEN
RF: 0BH
Bit 0
0
Pin function
P0DBIOn
RF: 2BH
Bit n
P0D0/SCK
P0D1/SO
P0D2/SI
0
Input port
1
Output port
P0D3/TM0OUT
0
0
1
0
SCK
Input port
SO
SI
1
Output port
0
Input port
1
Output port
TM0OUT
1
0
1
104
1
SCK
SO
SI
CHAPTER 12 PORTS
Table 12-5. Contents Read from the Port Register (0.73H)
Port mode
Contents read from the port register (0.73H)
Input port
Pin status
Output port
Output latch contents
An internal clock is selected as a shift clock.
Output latch contents
An external clock is selected as a shift clock.
Pin status
SCK
SI
Pin status
SO
Not defined
TM0OUT
Output latch contents
Caution Using the serial interface causes the output latch for the P0D1/SO pin to be affected by the
contents of the SIOSFR (shift register). So, reset the output latch before using the pin as output
port.
12.5 PORT 1A (P1A0, P1A1, P1A2, P1A3)
Port 1A is a 4-bit input/output port with an output latch. It is mapped into address 70H of BANK1 in data memory.
The output format is N-ch open-drain output. The mask option can be used to specify that a pin contain a pull-up
resistor in 1-bit unit.
Input or output can be specified in 4-bit units. Input/output is specified by P1AGIO (bit 2 at address 2CH) in the
register file.
When P1AGIO is 0, each pin of port 1A is used as input port. If a read instruction is executed for the port register,
pin statuses are read. When P1AGIO is 1, each pin of port 1A is used as output port and the contents written in the
output latch are output to pins. If a read instruction is executed when pins are output ports, the contents of the output
latch, rather than pin statuses, are fetched.
At reset, P1AGIO is set to 0 and all P1A pins become input ports. The contents of the port output latch are
0.
Table 12-6. Writing into and Reading from the Port Register (1.70H)
(n = 0 to 3)
BANK1 70H
P1AGIOn
RF: 2CH, bit 2
Pin input/output
0
Input
1
Output
Write
Read
Possible
P1A pin status
Write to the P1A latch
P1A latch contents
12.6 PORT 1B (P1B0)
Port 1B is a 1-bit input-dedicated port. It is mapped into address 71H of BANK1 in data memory. The mask option
can be used to specify that pull-up resistors be contained in P1B0 pins.
Port 1B is the input-dedicated port. At reading, only the least significant bit is valid and a value is read into it. At
writing, no value changes. Value 0 is always read into the high-order 3 bits of the port register.
105
CHAPTER 12 PORTS
12.7 PORT CONTROL REGISTER
12.7.1 Input/Output Switching by Group I/O
Ports which switch input/output in 4-bit unit are called group I/O. Port 0A, port 0B, and port 1A are used as group
I/O. The register shown in the figure below is used for input/output switching.
Figure 12-1. Input/Output Switching by Group I/O
RF: 2CH
Bit 3
Bit 2
0
P1AGIO
Read/write
Initial value when reset
Bit 1
P0BGIO
Bit 0
P0AGIO
Read = R, write = W
R/W
0
0
0
0
P0AGIO
0
Sets port 0A to input mode.
1
Sets port 0A to output mode.
P0BGIO
Function
0
Sets port 0B to input mode.
1
Sets port 0B to output mode.
P1AGIO
106
Function
Function
0
Sets port 1A to input mode.
1
Sets port 1A to output mode.
CHAPTER 12 PORTS
12.7.2 Input/Output Switching by Bit I/O
Ports which switch input/output in 1-bit unit are called bit I/O. Port 0C and port 0D are used as bit I/O. The register
shown in the figure below is used for input/output switching.
Figure 12-2. Port Control Register of Bit I/O (1/2)
RF: 1CH
Bit 3
Bit 2
Bit 1
Bit 0
P0CBIO3
P0CBIO2
P0CBIO1
P0CBIO0
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
P0CBIO0
Function
0
Sets P0C0 to input mode.
1
Sets P0C0 to output mode.
P0CBIO1
Function
0
Sets P0C1 to input mode.
1
Sets P0C1 to output mode.
P0CBIO2
Function
0
Sets P0C2 to input mode.
1
Sets P0C2 to output mode
P0CBIO3
Function
0
Sets P0C3 to input mode.
1
Sets P0C3 to output mode.
107
CHAPTER 12 PORTS
Figure 12-2. Port Control Register of Bit I/O (2/2)
RF: 2BH
Bit 3
Bit 2
Bit 1
Bit 0
P0DBIO3
P0DBIO2
P0DBIO1
P0DBIO0
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
P0DBIO0
0
Sets P0D0 to input mode.
1
Sets P0D0 to output mode.
P0DBIO1
Function
0
Sets P0D1 to input mode.
1
Sets P0D1 to output mode.
P0DBIO2
Function
0
Sets P0D2 to input mode.
1
Sets P0D2 to output mode.
P0DBIO3
108
Function
Function
0
Sets P0D3 to input mode.
1
Sets P0D3 to output mode.
CHAPTER 12 PORTS
12.7.3 Specifying Pull-Up Resistor Incorporation Using Software
Pull-up resistor incorporation can be specified in 4-bit units using P0AGPU and P0BGPU (address 0CH) in the
register file.
Figure 12-3. Specifying Pull-Up Resistor Incorporation Using Software
RF: 0CH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
P0BGPU
P0AGPU
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
P0AGPU
Function
0
Does not contain pull-up
resistor in port 0A.
1
Contains pull-up resistor in
port 0A.
P0BGPU
Function
0
Does not contain pull-up
resistor in port 0B.
1
Contains pull-up resistor in
port 0B.
109
[MEMO]
110
CHAPTER 13 PERIPHERAL HARDWARE
13.1 8-BIT TIMERS/COUNTERS (TM0 AND TM1)
The µPD17134A subseries has two channels of 8-bit timers/counters: timer 0 (TM0) and timer 1 (TM1).
These two timers can be used in combination as a 16-bit timer by using the count up signal of timer 0 as the count
pulse for timer 1.
These timers are controlled by manipulating the hardware with the PUT/GET instruction and registers in the register
file with the PEEK/POKE instruction.
13.1.1 8-Bit Timers/Counters Configuration
Figure 13-1 shows the configuration of the 8-bit timers/counters. An 8-bit timer/counter consists of an 8-bit count
register, 8-bit modulo register, a comparator that compares the value of the count register and the value of the modulo
register, and a selector that selects a count pulse.
Cautions 1. The modulo register is a write-only register.
2. The count register is a read-only register.
111
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-1. Configuration of the 8-Bit Timer Counters
Data buffer
(DBF)
Internal bus
AC zero cross
detection circuit
control register
(RF : 1DH)
Interrupt
control
register
(RF : 0FH)
ZCROSS
Serial interface control
register
(RF : 0BH)
Timer 0 mode
register
(RF : 11H)
INT
TM0OSEL
TM0EN TM0RES TM0CK1 TM0CK0
Timer 0 modulo
register (8)
(TM0M)
Match
2
Bit I/O port
control
register
(RF : 2BH)
P0DBIO3
P0DB3
output latch
P0D3/
TM0OUT
Timer 0
comparator (8)
TM0OUT
F/F
Reset
Latch
fX/256
fX/64
fX/16
INT
D
Selector
AC zero cross
detection circuit
IRQTM0
set signal
Timer 0 count
register (8)
(TM0C)
Q
CLK
R
Clear
Timer 0 count up signal
(To timer 1 and basic
interval timer)
Reset
To basic
interval timer
Internal reset
IRQTM0
clear signal
Data buffer
(DBF)
Internal bus
Timer 1 mode register
(RF : 12H)
TM1EN TM1RES TM1CK1 TM1CK0
Timer 1
modulo register (8)
(TM1M)
Match
2
Timer 1
comparator (8)
IRQTM1 set signal
Latch
fX/512
fX/1024
fX/256
Timer 0 count up
D
Selector
Q
CLK
R
Reset
Timer 1
count register (8)
(TM1C)
Clear
Internal reset
IRQTM1 clear signal
112
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-2. Timer 0 Mode Register
RF : 11H
Bit 3
Bit 2
Bit 1
Bit 0
TM0EN
TM0RES
TM0CK1
TM0CK0
0
0
Read/write
R/W
Read = R, Write = W
Initial value when reset
0
0
TM0CK1
TM0CK0
0
0
fX/256
0
1
fX/64
1
0
fX/16
1
1
External clock from INT pin
TM0RES
0
1
Selects count pulse of timer 0
Resets timer 0
Does not affect timer 0
Resets timer 0 count register and
IRQTM0
Remark TM0RES is automatically cleared to 0 after it
has been set to 1.
This bit is always 0 when it is read.
TM0EN
Starts timer 0
0
Stops counting by timer 0
1
Starts counting by timer 0
Remark TM0EN can be used as a status flag that
detects the counting status of timer 0
(1: counting in progress, 0: counting is stopped).
113
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-3. Timer 1 Mode Register
RF : 12H
Bit 3
Bit 2
Bit 1
Bit 0
TM1EN
TM1RES
TM1CK1
TM1CK0
Read/write
Initial value when reset
R/W
1
0
0
0
TM1CK1
TM1CK0
0
0
fX/512
0
1
fX/1024
1
0
fX/256
1
1
Count up signal from timer 0
TM1RES
0
Selects count pulse of timer 1
Resets timer 1
Does not affect timer 1
Resets timer 1 count register and IRQTM
1
1
Remark TM1RES is automatically cleared to 0 after it
has been set to 1. This bit is always 0 when
it is read.
TM1EN
Starts timer 1
0
Stops counting by timer 1
1
Starts counting by timer 1
Remark TM1EN can be used as a status flag that
detects the counting status of timer 0
(1: counting in progress, 0: counting is stopped).
114
CHAPTER 13 PERIPHERAL HARDWARE
13.1.2 Operation of 8-Bit Timers/Counters
(1) Count register
The count register of timers 0 and 1 is an 8-bit up counter whose initial value is 00H, and is incremented each
time a count pulse has been input.
The count register is initialized to 00H in the following cases.
(1) When this product is reset (refer to CHAPTER 17 RESET).
(2) When the contents of the 8-bit modulo register and the value of the count register coincide, and the
comparator generates a coincidence signal.
(3) In the case of timer 0, when “1” is written to TM0RES of the register file.
In the case of timer 1, when “1” is written to TM1RES of the register file.
(2) Modulo register
The modulo register of timers 0 and 1 determines the count value of the count register and its initial value is
set to FFH.
A value is set to the modulo register by using the PUT instruction via DBF (data buffer).
(3) Comparator
The comparator of timers 0 and 1 outputs a coincidence signal when the value of the count register and the
value of the modulo register coincide. If the value of the modulo register is the initial value FFH, for example,
the comparator outputs the coincidence signal when the count register counts 256.
The coincidence signal output from the comparator clears the contents of the count register to 0, and
automatically sets interrupt request flags (IRQTM0 and IRQTM1) to “1”. If the EI instruction (that enables
accepting interrupts) is executed, and if the interrupt enable flags (IPTM0 and IPTM1) are set at this time,
interrupts are accepted. When an interrupt has been accepted, the interrupt request flag (IRQTM0 or IRQTM1)
is cleared to “0”, and program execution branches to a specified interrupt routine.
13.1.3 Selecting Count Pulse
The count pulse for timer 0 is selected by TM0CK0 and TM0CK1.
As the count pulse, a pulse resulting from dividing the system clock (fX) by 256, 64, or 16, or an external count pulse
input from the INT pin can be selected.
At reset, fX/256 is selected as a count pulse because TM0CK0 = 0 and TM0CK1 = 0.
The count pulse for timer 1 is selected by TM1CK0 and TM1CK1.
As the count pulse, a pulse resulting from dividing fX by 1024, 512, or 256, or the count up signal from timer 0 can
be selected.
Timer 1 is also used to generate oscillation stabilization time on power application or at reset. Therefore, the initial
values are TM1CK0 = 0 and TM1CK1 = 0, and fX/512 is selected as the count pulse.
Because TM1EN = 1 as the initial condition, the µPD17134A subseries starts program execution from address
0000H after it has been reset at fX = 8 MHz and after about 16.4 ms (about 65.5 ms at 2 MHz) (refer to CHAPTER
17 RESET).
115
CHAPTER 13 PERIPHERAL HARDWARE
13.1.4 Setting Count Value to Modulo Register
A value is set to the modulo register by using the PUT instruction via DBF (data buffer). The peripheral address
of the modulo register of timer 0 is assigned to 02H, and that of timer 1 is assigned to 03H.
To transfer a value by using the PUT instruction, the data of the low-order 8 bits of DBF (DBF1 and DBF0) are
transferred to the modulo register. Figure 13-4 shows an example of the modulo register of timer 0.
Figure 13-4. Setting Count Value to Modulo Register
Example of setting count value 64H to modulo register of timer 0
CONTDATL
CONTDATH
DAT
4H
; Assigns CONTDATL to 4H by using symbol definition instruction
; Assigns CONTDATH to 6H by using symbol definition instruction
DAT
6H
MOV
DBF0, #CONTDATL ;
MOV
DBF1, #CONTDATH ;
PUT
TM0M, DBF
; Transfers data by using reserved word “TM0M”
Data buffer
DBF2
DBF3
b3
b2
b1
b0
Don’t care
b3
b2
b1
Don’t care
DBF1
b0
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
0
1
1
0
0
1
0
0
8-bit data
PUT TM0M, DBF
TM0M (peripheral address 02H)
b7
b6
b5
b4
b3
b2
b1
b0
0
1
1
0
0
1
0
0
Caution The range of the value to that can be set to the modulo register is 01H to FFH. If 00H is set, the
normal count operation is not performed.
The modulo register is a write-only register. Therefore, the set value of the modulo register cannot be read. Even
if the “PUT TM0M, DBF” or “PUT TM1M, DBF” instruction is executed while the 8-bit timer/counter is operating, the
count is operating is not stopped.
116
CHAPTER 13 PERIPHERAL HARDWARE
13.1.5 Reading Value of Count Register
The values of the count registers of timers 0 and 1 are read simultaneously by using the GET instruction via DBF
(data buffer).
The values of the count registers of timers 0 and 1 are assigned to peripheral address 45H. The high-order 8 bits
of this address are assigned to the count value of timer 1, and the low-order 8 bits are assigned to the count value
of timer 0.
The values of the count registers can be read to DBF by using the GET instruction. While the GET instruction is
being executed, the count registers stop counting and hold the current count value. If a count pulse is input to the
timer while the timer is operating and the GET instruction is being executed, the count value is held, the value of the
count register is incremented by one after the GET instruction has been executed, and the timer continues counting.
Therefore, the timer does not count erroneously even if the GET instruction is executed while the timer is operating,
unless two or more count pulses are input to the timer in one instruction cycle.
Figure 13-5. Reading Count Value of Count Register
Example of using GET DBF, TM0TM1C; reserved word DBF and TM0TM1C
when count value of timer 0 is F0H and count value of timer 1 is A4H
Data buffer
DBF3
DBF2
DBF1
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
b3
b2
b1
b0
b3
b2
b1
b0
1
0
1
0
0
1
0
0
1
1
1
1
0
0
0
0
GET DBF, TM0TM1C
16-bit data
TM0TM1C (peripheral address)
b15 b14 b13 b12 b11 b10
1
0
1
0
0
1
Timer 1 count value
b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
0
0
1
1
1
1
0
0
0
0
Timer 0 count value
117
CHAPTER 13 PERIPHERAL HARDWARE
13.1.6 Setting of Interval Time
The time interval at which the comparator outputs the coincidence signal is determined by the value set to the
modulo register. The set value N of the modulo register is calculated from interval time T [sec] as follows:
T=
N+1
fCP
= (N + 1) × TCP
N = T × fCP – 1 or N =
fCP
T
– 1 (where, N = 1 to 255)
TCP
: Frequency of count pulse [Hz]
TCP : Cycle of count pulse [sec] (1/fCP = resolution)
•
Example of calculating count value from interval time and program
• Example of setting 7 ms to timer 1 as interval time (system clock: fX = 8 MHz)
Suppose one wanted to set the interval timer to 7 ms. It is impossible to set an interval time of exactly 7 ms
from an 8-MHz system clock. To set an interval time closest to 7 ms, therefore, calculate the count value
by selecting a count pulse (fX/256, resolution: 32 µs) at which the resolution is maximum.
Example of calculation
N =
=
T
(Resolution)
7 × 10–3
32 × 10–6
T = 7 ms, Resolution = 32 µs
–1
–1
.
= 217.75 =. 218 (= DAH)
The value of the modulo register at which the interval time is closest to 7 ms is DAH, and the interval time
at that time is 7.008 ms.
Program example
MOV
DBF0,
#0AH
; Stores DAH to DBF by using reserved words “DBF0” and “DBF1”
MOV
DBF1,
#0DH
; Storage
PUT
TMM,
DBF
; Transfers contents of DBF by using reserved word “TMM”
INITFLG TM1EN, TM1RES, TM1CK1, NOT TM1CK0
; Sets TM1EN and TM1RES, sets count pulse of timer 1 to “fX/256”, and starts
; counting, by using embedded macroinstruction “INITFLG”
118
CHAPTER 13 PERIPHERAL HARDWARE
13.1.7 Error of Interval Time
The interval time may include an error of up to –1.5 count, especially if the value set value of the modulo register
is low.
(1) Error when count register is cleared to 0 during counting (maximum error: –1 count)
The count register of the 8-bit timer/counter is cleared to 0 when the TMnRES flag is set to 1. However, the
divider circuit that generates a count pulse from the system clock is not reset.
Therefore, an error of 1 cycle of the count pulse may be generated at the first count if the TMnRES flag is set
to 1 and the count value is cleared to 0 during counting. An example of counting where 2 is set to the modulo
register is shown below.
Figure 13-6. Error When Count Register Is Cleared to 0 During Counting
Count cleared (TMnRES ← 0)
2 to 3 counts
Count pulse
Count register
1
2
0
1
2
Output of coincidence signal
In this example, the coincidence signal must be output each time the count value has reached 3. However,
the coincidence signal is output when the count value reaches 2 for the first time after the count has been
cleared.
The above error also occurs when TMnRES ← 1 at the same time as TMnEN = 1 ← 0.
119
CHAPTER 13 PERIPHERAL HARDWARE
(2) Error when counting is started from count stop status (maximum error: –1.5 count)
The count register of the 8-bit timer is cleared to 0 by setting the TMnRES flag to 1. However, the divider circuit
that generates a count pulse from the system clock is not reset.
If the TMnEN flag is set to 1 and counting is started from the count stop status, the timing of the first counting
differs as follows depending on whether the count pulse starts with a low level or a high level.
If count pulse starts with high level: First count at the next rising
If count pulse starts with low level: First count on starting of counting
Therefore, an error of –0.5 to 1.5 count occurs until the coincidence signal is output for the first time after
counting has been started. An example of counting where the modulo register is set to 1 is shown below.
Figure 13-7. Error When Counting Is Started from Count Stop Status
(a) If counting is started when count pulse is high (error: –0.5 to –1 count)
Count starts (TMnEN = 1 ← 0)
1 to 1.5 count
2 counts
Count pulse
Count register
0
1
0
1
Coincidence signal output
Coincidence signal output
(b) If counting is started when count pulse is low (error: –1 to –1.5 count)
Count starts (TMnEN = 1 ← 0)
2 counts
0.5 to 1 count
Count pulse
Count register
0
1
0
Coincidence signal output
1
0
Coincidence signal output
In this example, the coincidence signal must be output each time the count value has reached 2. However,
the first coincidence signal is output when the count value is 1.5 at maximum or 0.5 at minimum (error: –0.5
to –1.5 count).
The above error also occurs during oscillation stabilization wait time because the timer is also used to generate
the oscillation stabilization wait time.
120
CHAPTER 13 PERIPHERAL HARDWARE
13.1.8 Timer 0 Output
The POD3/TM0OUT pin functions as timer 0 output pin by setting the TM0OSEL flag to “1”. At this time, the value
of P0DBIO3 is irrelevant.
Timer 0 has an internal flip-flop for outputting a coincidence signal. The output of this flip-flop is inverted each time
the comparator has output the coincidence signal. If the TM0OSEL flag is set to “1”, the content of this flip-flop is
output to the P0D3/TM0OUT pin.
The P0D3/TM0OUT pin is an N-ch open-drain output pin and can be connected to a pull-up resistor by mask option.
If the pull-up resistor is not connected, the P0D3/TM0OUT pin goes into a high-impedance state as the initial status.
The internal timer 0 output flip-flop starts operating as soon as TM0EN has been set to 1. To make sure that timer
0 output always starts from the initial status, set TM0RES to 1 and reset the flip-flop before starting counting.
Figure 13-8. Timer 0 Output Setting Register
RF : 0BH
Bit 3
Bit 2
Bit 1
Bit 0
TM0OSEL
0
0
SIOEN
Initial value when reset
Read = R, write = W
R/W
Read/write
0
0
0
0
SIOEN
Function
P0D0/SCK, P0D1/SO, and P0D2/SI pins
0
function as port pins.
P0D0/SCK, P0D1/SO, and P0D2/SI pins
1
function as serial interface pins.
Caution This bit is not directly related to output
setting of timer 0.
TM0OSEL
Function
0
P0D3/TM0OUT pin functions as port pin.
P0D3/TM0OUT pin outputs coincidence
1
signal of timer 0.
121
CHAPTER 13 PERIPHERAL HARDWARE
13.2 BASIC INTERVAL TIMER (BTM)
The µPD17134A subseries has a 7-bit basic interval timer.
This basic interval timer has the following functions.
(1) Generates reference time.
(2) Selects and counts wait time when standby mode is released.
(3) Serves as watchdog timer that detects program hang-up.
13.2.1 Basic Interval Timer Configuration
Figure 13-9 shows the configuration of the basic interval timer.
Figure 13-9. Basic Interval Timer Configuration
Internal bus
BTM mode
register (RF: 13H)
Watchdog timer
mode register
(RF: 03H)
BTMISEL BTMRES BTMCK1 BTMCK0
WDTRES 0
0
WDTEN
2
Reset
fX/8192
fX/4096
Timer 0 count up
INT pin (ACZCROSS)
fBTM
26
Selector
fBTM
Selector
fBTM
Basic interval timer
(7-bit divider circuit)
(2)
27
(3)
Reset
1-bit
divider
circuit
R
1-shot pulse
generation
circuit
(1)
Q
IRQBTM
set signal
Watchdog
reset signal
(4)
S
Outputs 1 while counting 0 to 7
during count of 0 to 256
Remark (1) through (4) in the figure corresponding to the signals in the timing chart in Figure 13-12.
122
CHAPTER 13 PERIPHERAL HARDWARE
13.2.2 Registers Controlling Basic Interval Timer
The basic interval timer is controlled by the BTM mode register and watchdog timer mode register.
Figures 13-10 and 13-11 show the configuration of the respective registers.
Figure 13-10. BTM Mode Register
RF : 13H
Bit 3
Bit 2
BTMISEL BTMRES
Bit 0
BTMCK1
BTMCK0
Read = R, write = W
R/W
Read/write
Initial value when reset
Bit 1
0
0
0
0
BTMCK1
BTMCK0 Selects count pulse of BTM
fX/8192
0
0
(execution time of 512 instructions)
fX/4096
0
1
(execution time of 256 instructions)
1
0
Count up of timer 0
INT pin
1
1
(information on INT pin that
has gone through AC zero
cross detection circuit when
ZCROSS = 1)
BTMRES
Resets BTM
0
Does not affect basic interval timer (BTM).
1
Resets binary counter of basic interval
timer (BTM).
Remark BTMRES is automatically cleared to 0 after it
has been set to 1.
This bit is always “0” when it is read.
BTMISEL
Selects interval time
Sets count pulse divided by 128 as interval
0
time.
Sets count pulse divided by 32 as interval
1
time.
123
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-11. Watchdog Timer Mode Register
RF : 03H
Bit 3
Bit 2
Bit 1
Bit 0
WDTRES
0
0
WDTEN
Initial value at reset
Read = R, write = W
R/W
Read/write
0
0
0
0
WDTEN
Enables watchdog timer function
0
Watchdog timer stops.
1
Watchdog timer starts operating.
Remarks 1. WDTEN cannot be cleared to 0 by program.
2. WDTEN is automatically cleared to 0 after it
has been set to 1. This bit is always 0 when
it is read.
WDTRES
Resets watchdog timer
0
Does not affect watchdog timer.
1
Sets flip-flop that holds overflow carry of
BTM used by watchdog timer.
Remark WDTRES is automatically cleared to 0 after it
has been set to 1. This bit is always 0 when
it is read.
13.2.3 Operation of Basic Interval Timer
The basic interval timer is a 7-bit binary counter that always counts up by using a count pulse specified by the BTM
mode register. Counting operation cannot be stopped.
The interval time of the basic interval timer can be changed by using the BTMISEL bit of the BTM mode register.
When BTMISEL = 0, the interval time is the count pulse divided by 128 (128/fBTM); when BTMISEL = 1, the interval
time is the count pulse divided by 32 (32/fBTM).
The contents of the counter are not cleared to 0 even if the interval time is changed.
124
CHAPTER 13 PERIPHERAL HARDWARE
13.2.4 Watchdog Timer Function
The basic interval timer can also be used as a watchdog timer to detect a program hang-up.
(1) Function of watchdog timer
The watchdog timer is a counter that generates a reset signal at fixed intervals. By inhibiting the generation
of this reset signal each time through program, the system can be reset (and started from address 0000H)
if it has overrun due to an external noise (i.e., if the watchdog timer is not reset within the time set by program).
This function can prevent the system from overrunning even if the program is caused to jump to an unexpected
routine by an external noise and enter an infinite loop, because a reset signal is generated at fixed intervals.
(2) Operation of the watchdog timer
When “1” is set to WDTEN, the 1-bit divider is enabled to operate, and consequently, the basic interval timer
operates as an 8-bit watchdog timer.
Once the watchdog timer has been started, it cannot be stopped until the device is reset and WDTEN is cleared
to 0.
Generation of the reset signal by the watchdog timer can be inhibited in the following two ways:
(i)
Repeat setting WDTRES in program.
(ii) Repeat setting BTMRES in program.
In the case of (i), WDTRES must be set while the count value of the watchdog timer is between 8 and 191
(immediately before it reaches 192). Therefore, “SET1 WDTRES” must be executed at least once at a timing
shorter than the cycle in which the count value of the watchdog timer reaches 184.
In the case of (ii), BTMRES must be set until the count value of the basic interval timer (BTM) reaches 128.
Therefore, “SET BTMRES” must be executed at least once at a timing shorter than the cycle in which the count
value of BTM reaches 128. In this case, however, interrupt processing cannot be performed by BTM.
Caution BTM is not reset even if WDTEN is set. Therefore, be sure to set BTMRES and reset BTM
before setting WDTEN first.
Example
.
.
.
SET1
SET2
BTMRES
.
.
.
WDTEN, WDTRES
125
126
Watchdog reset signal
(active high)
fBTM/28(3)
(fl IRQBTM set)
fBTM/27(2)
(4)
1-shot pulse generator
circuit output (1)
WDTRES
WDTEN
0
Count value of
watchdog timer
8
WDTRES
accepting period
128
192
WDTRES
accepting period
128
192
Reset signal is not generated
8
255
8
255
WDTRES
accepting period
128
64
192
Figure 13-12. Timing Chart of Watchdog Timer (with WDTRES Flag Used)
128
192
255
CHAPTER 13 PERIPHERAL HARDWARE
CHAPTER 13 PERIPHERAL HARDWARE
(3) Program example of watchdog timer
Program Example
Start
Initialize
ORG
BR
0H
INITJOB
ORG
BR
2H
INTBTMJOB
INITJOB:
INITFLG
SET1
SET2
SET1
CLR1
EI
NOT BTMISEL, BTMRES, NOT BTMCK1, BTMCK0
BTMRES
WDTRES, WDTEN; Watchdog timer start
IPBTM
IRQBTM
; BTM interrupt enable
......
Main Processing
MAIN:
CALL
CALL
JOB1
JOB2
......
END
JOB1:
CLR1 IPBTM
JOB2:
CLR2 IPBTM
..........
.........................
..........
SET1 BTMRES
SET1 WDTRES
SET1 BTMRES
..........
..........
SET1 BTMRES
SET1 WDTRES
Reset BTM before its
count value reaches
to 128Note 1.
..........
..........
SET IPBTM
RET
INTBTMJOB:
SET1 WDTRES
EI
RETI
SET IPBTM
RET
Reset watchdog timer
before its count value
reaches to 184.
Reset watchdog timer by
using interrupt processing
of BTMNote 2.
Notes 1.
Interrupt processing by BTM cannot be performed in the method to reset counter before BTM overflows.
2.
Although the method of resetting the watchdog timer by using the BTM interrupt processing is easier
to program than the other two methods, its program hang-up detection rate is lower than that of the
other two.
127
CHAPTER 13 PERIPHERAL HARDWARE
13.3 A/D CONVERTER
µPD17134A subseries contains an 8-bit resolution A/D converter with 4-channel analog input (P0C0/ADC0 - P0C3/
ADC3).
The A/D converter uses the successive approximation method. The following two operation modes are available:
(1) Successive mode: 8-bit A/D conversion occurs starting at high-order bits.
(2) Single mode: Comparison occurs with an arbitrary voltage value set in the 8-bit data register.
13.3.1 A/D Converter Configuration
Figure 13-13 shows the A/D converter configuration.
Figure 13-13. Block Diagram of the A/D Converter
Remark n = 0 to 3
Internal bus
RF: 22H
Read signal
RF: 20H
0 0 ADCCH1 ADCCH0
P0CnIDI
P0CBIOn
RF: 21H
0 0 0 ADCSTRT
Output
latch
Selector
ADCSOFT 0 ADCCMP ADCEND
Control circuit
8
Comparator
4
P0Cn/ADCn
Selector
8-bit data register
(ADCR)
A/D end signal
STOP instruction signal
Tap decoder
8
VADC
Analog power of
A/D converter
3R/2
R
R
R/2
D/A converter
Cautions 1. The 8-bit data register (ADCR) is cleared to 00H when the STOP instruction has been
executed.
2. If the HALT instruction is executed during A/D conversion, a current keeps flowing between
VADC and GND.
128
CHAPTER 13 PERIPHERAL HARDWARE
13.3.2 Functions of A/D Converter
(1) ADC0 – ADC3
These pins are used to input 4-channel analog voltage to the A/D converter. The A/D converter contains a
sample hold circuit. Analog input voltage is internally retained during A/D conversion.
(2) VADC
This pin is used to input the power supply and the reference voltage for the A/D converter.
A signal input to ADC0 to ADC3 is converted to a digital signal based on voltage applied across VADC and GND.
To reduce the current consumption of the microcontroller, the A/D converter has a function for automatically
stopping the current which flows into the VADC pin when the converter is not operating. Current flows into the
VADC pin in the following cases.
<1> Successive mode (ADCSOFT=0)
From when the ADCSTRT flag is set (1) until the ADCEND flag is set (1).
<2> Single mode (ADCSOFT=1)
From when the ADCSTRT flag is set (1) or from when a value of the 8-bit data register is written until
the result of comparison by the comparator is written in the ADCCMP flag.
Caution If the HALT Instruction is executed while the A/D conversion is in progress, the A/D
converter stops conversion. Note that, in this case, the HALT mode is set with current
flowing to the VADC pin. When the HALT mode has been released, the A/D conversion
is resumed. At this time, however, the value of ADCR is undefined, and the correct
conversion result cannot be obtained.
Remark A/D conversion is stopped if the STOP instruction is executed while the conversion is in
progress. In this case, the A/D converter is initialized, and the current to the VADC pin is also
cut. The A/D converter remains stopped even if the STOP mode has been released.
(3) 8-bit data register (ADCR)
In the successive mode, this 8-bit data register stores A/D conversion results for successive approximation.
It is read by the GET instruction. In the single mode, the data in this register is converted to analog voltage
by the internal D/A converter and the comparator compares this voltage with an analog signal input from the
ADCn pin. A value can be written in this register by using the PUT instruction.
(4) Comparator
The comparator compares an analog input voltage from a pin with voltage output from the D/A converter. Value
1 is output if analog input voltage from the pin is high. Value 0 is output if this voltage is low. The comparison
result is stored in the 8-bit data register (ADCR) in the successive mode. It is stored in the ADCCMP flag in
the single mode.
(5) A/D converter control register
Figure 13-14 shows the A/D converter control register.
129
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-14. A/D Converter Control Register (1/2)
RF: 21H
Bit 3
Bit 2
ADCSOFT
0
Read/write
Initial value when reset
Bit 1
ADCCMP ADCEND
R/W
0
Bit 0
Read = R, write = W
R
0
0
0
ADCEND
0
End of A/D conversion
Initial status or during A/D conversion.
Indicates the end of A/D conversion in
1
successive mode.
Cleared to 0 by setting (1) or resetting
ADCSTRT.
ADCCMP Compare result (valid only in the single mode)
0
Analog input voltage is lower than output
voltage of the internal D/A converter.
1
Analog input voltage is higher than output
voltage of the internal D/A converter.
Remarks 1.
In the single mode, the flag content is
valid for the third and subsequent instructions after ADCSTRT is set (1) or
data is set in ADCR until ADCSTRT or
ADCR is set again.
2.
In the successive mode, a value changes
according to an A/D conversion value.
However, the bit for this value cannot be
identified.
3.
ADCCMP is automatically cleared to 0
when “PUT ADCR, DBF” instruction is
executed.
ADCSOFT
130
A/D operation mode selection flag
0
Successive mode
1
Single mode
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-14. A/D Converter Control Register (2/2)
RF: 20 H
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
ADCSTRT
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
Start of A/D operation
ADCSTRT
Initial status or during A/D conversion.
0
Cleared to 0 automatically after A/D
1
Note
conversion (successive or single
modeNote) starts.
With the µPD17134A subseries, ADCR is reset
to 0 if the ADCSTRT flag is set, regardless of
the A/D conversion mode. In the single mode,
start conversion by writing a value to ADCR.
RF: 22H
Bit 3
Bit 2
Bit 1
Bit 0
ADCCH3 ADCCH2 ADCCH1 ADCCH0
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
ADCCH1 ADCCH0
Analog input channel selection
0
0
ADC0 is selected.
0
1
ADC1 is selected.
1
0
ADC2 is selected.
1
1
ADC3 is selected.
Fixed to 0. (Dummy flag)
131
CHAPTER 13 PERIPHERAL HARDWARE
13.3.3 Setting Values in the 8-bit Data Register (ADCR)
A value is set in the 8-bit data register via the data buffer (DBF) using the PUT instruction in the same way as for
comparison voltage setting in the single mode.
The peripheral address for the 8-bit data register (ADCR) of the A/D converter is assigned to 04H. If a value is
sent to ADCR by the PUT instruction, only the low-order 8 bits (DBF1, DBF0) of DBF are valid. DBF3 and DBF2 values
do not affect ADCR.
Figure 13-15. Setting a Value in the 8-Bit Data Register (ADCR)
Example of setting 6CH in ADCR
CONTDATL
CONTDATH
DAT
0CH
; CONTDATL is assigned to 0CH by using a symbol definition instruction.
; CONTDATH is assigned to 06H by using a symbol definition instruction.
DAT
06H
MOV
DBF0, #CONTDATL;
MOV
DBF1, #CONTDATH;
PUT
ADCR, DBF
; Data is transferred using reserved words ADCR and DBF.
Data buffer
DBF3
b3
b2
b1
Don’t care
DBF2
b0
b3
b2
b1
Don’t care
DBF1
b0
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
0
1
1
0
1
1
0
0
8-bit data
PUT ADCR, DBF
ADCR (Peripheral address 04H)
132
b7
b6
b5
b4
b3
b2
b1
b0
0
1
1
0
1
1
0
0
CHAPTER 13 PERIPHERAL HARDWARE
13.3.4 Reading Values from the 8-bit Data Register (ADCR)
A value is read from the 8-bit data register (ADCR) via the data buffer (DBF) using the GET instruction.
The 8-bit data register (ADCR) of the A/D converter has peripheral address 04H and only its low-order 8 bits (DBF1,
DBF0) are valid. Execution of the GET instruction does not affect the high-order 8 bits of DBF.
Figure 13-16. Reading Values from the 8-bit Data Register (ADCR)
The result from 8-bit A/D conversion is E2H.
GET DBF, ADCR
; Example of using reserved words DBF and ADCR
Data buffer
DBF3
b3
b2
b1
Retained
DBF2
b0
b3
b2
b1
Retained
DBF1
b0
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
1
1
1
0
0
0
1
0
GET DBF, ADCR
8-bit data
ADCR (Peripheral address 04H)
b7
b6
b5
b4
b3
b2
b1
b0
1
1
1
0
0
0
1
0
133
CHAPTER 13 PERIPHERAL HARDWARE
13.3.5 A/D Converter Operation
The A/D converter operates in two modes: successive mode and single mode. The mode can be switched by setting
the ADCSOFT flag.
ADCSOFT
Operation mode of A/D converter
0
Successive mode (A/D conversion)
1
Single mode (Compare operation)
Figure 13-17. Relationship between the Analog Input Voltage and Digital Conversion Result
Ideal conversion result
FFH
Digital conversion result
FEH
FDH
N
03H
02H
01H
00H
0
(× VDD)
1
256
2
256
N
256
Analog input voltage (V)
134
254
256
255
256
256
256
CHAPTER 13 PERIPHERAL HARDWARE
(1) Successive mode
(a) Outline of successive mode
In the successive mode, the A/D converter performs conversion in 8-bit units by means of successive
approximation, and the result of the conversion is automatically stored to an 8-bit data register (ADCR).
An analog input voltage and the voltage output by the internal D/A converter are compared by the internal
comparator, and data for conversion is sequentially obtained from 8 bits of data, starting from the most
significant bit. A time of 25 instructions is required to complete converting the 8 bits of data. The
completion of the 8-bit A/D conversion is indicated by setting of the ADCEND flag to 1.
(b) Operation in successive mode
When ADCSOFT = 0, the A/D converter is set in the successive mode.
By setting P0CnIDI to 1 before starting A/D conversion, use of a pin used as an analog input pin of the
A/D converter as a port pin is prohibited. This is to prevent an increase in the through current of the input
buffer of the port if the voltage of the pin specified as an analog input pin reaches the intermediate level.
After that, an analog input signal is selected by ADCCH1 and ADCCH0. A/D conversion is started by
setting the ADCSTRT flag to 1. The ADCSTRT flag is cleared to 0 immediately after A/D conversion has
been started.
While A/D conversion is in progress, the internal hardware performs successive approximation, starting
from the most significant bit of the 8 bits of data. The conversion result is stored to an 8-bit data register
on a bit-by-bit basis. Converting 1 bit of data requires a time of three instructions. If a resolution of 8 bits
is not required, therefore, the time required can be calculated from the number of instructions executed,
and the data being converted can be extracted before the ADCEND flag is set.
The completion of the A/D conversion is indicated by setting of the ADCEND flag which takes place as
soon as data has been stored to the least significant bit of the 8-bit data register.
135
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-18. Using the Successive Mode for the A/D Converter
Set the successive mode (ADCSOFT = 0)
Set the port input disable flag of the pin used for
analog input
(Set P0CnIDI to 1. n = 0 to 3)
Select the analog input channel
(Set ADCCH1 or ADCCH0)
Start A/D conversion
(Set ADCSTRT to 1)
Wait for the completion of A/D conversion
(Wait for ADCEND to be set)
Read the A/D conversion results
(Execute GET for the 8-bit data register)
136
CHAPTER 13 PERIPHERAL HARDWARE
(c) Successive mode A/D conversion timing
Figure 13-16 shows the A/D conversion timing in the successive mode.
Figure 13-19. A/D Conversion Timing in the Continuous Mode
Number of instruction to be executed (Instruction cycle)
POKE
1
2
Sampling
3
4
5
6
Sampling
7
8
9
24
GET
Sampling
Set ADCSTRT
Read ADCR
ADCSTRT
ADCEND
8-bit data
register
Previous
data
Initial value
80H
Most significant
bit determined
High-order 2 bits
are determined
All eight bits
are vaild.
Caution Sampling is executed eight times while A/D conversion is performed once. Therefore, if the
analog input voltage changes substantially during A/D conversion, conversion is not performed
accurately. To obtain the accurate conversion result, it is necessary to keep changes in the
analog input voltage as small as possible during A/D conversion.
One sampling time = 14/fx (1.75 µs, 8 MHzNote)
Sampling repeat cycle = 48/fx (6 µs, 8 MHzNote)
Note
The guaranteed oscillation range of the µPD17134A, 17136A, and 17P136A is 400 kHz to 2.4 MHz.
137
CHAPTER 13 PERIPHERAL HARDWARE
Table 13-1. Data Conversion Time for the A/D Converter
Number of instructions
executed after
ADCSTRT is set to 1Note
Bits for which A/D conversion is
completed (valid bits when ADCR is read)
4 instructions
Most significant bit
7 instructions
High-order 2 bits
10 instructions
High-order 3 bits
13 instructions
High-order 4 bits
16 instructions
High-order 5 bits
19 instructions
High-order 6 bits
22 instructions
High-order 7 bits
25 instructions
All 8 bits
Note Includes GET instruction to read data from ADCR.
(2) Single Mode
(a) Overview of single mode
In the single mode, data in the 8-bit data register (ADCR) is compared with voltage subjected to D/A
conversion and with an analog input signal from a pin.
The comparison result appears in the ADCCMP flag.
(b) Explanation of single mode operation
If ADCSOFT is 1, the A/D converter function enters the single mode.
Before single mode operation starts, port input is disabled for the pin to be used for analog input by setting
P0CnIDI to 1. (This is done for the same reason as in the successive mode.)
To start single mode operation, execute a write instruction (PUT ADCR, DBF) for the 8-bit data register
(ADCR) when ADCSOFT is 1.
The comparison result in single mode appears in ADCCMP at the execution of the third instruction after
a PUT instruction is executed to write to the 8-bit data register (ADCR). At this time, the ADCEND flag
becomes undefined.
138
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-20. Using the Single Mode for the A/D Converter
Set single mode
(ADCSOFT = 1)
Disable port input for pin to
be used for analog input
(Set P0CnIDI to 1)
Select analog input channel
(Set ADCCH0 or ADCCH1)
NO
Comparison data
in ADCR?
YES
Read the contents of ADCR
into DBF
(GET DBF, ADCR)
Set comparison data in DBF
Execute write instruction for
8-bit data register
(PUT ADCR, DBF)
Read ADCCMP flag when third
instruction is executed and read
comparison result
139
CHAPTER 13 PERIPHERAL HARDWARE
(c) Single mode operation (comparison) timing
Figure 13-21. Single Mode Operation (Comparison) Timing
Number of instruction executed (instruction cycle)
PUT
1
2
PEEK
PUT
ADCEND
ADCCMP
2
PEEK
Sampling
Sampling
Set comparison
data in ADCR.
1
Read ADCCMP.
Set comparison
data in ADCR.
Read ADCCMP.
Undefined
Previous data
Comparison result
Comparison result
In the single mode, comparison is started when compare data is set to ADCR (by executing the PUT
instruction), and the result of conversion can be read by using the PEEK instruction after execution of the
third instruction.
The ADCCMP flag is cleared to 0 when an instruction that writes ADCR is executed.
Caution Before setting a value to ADCR, be sure to set ADCSOFT to 1. A value cannot be set to
ADCR while ADCSOFT is 0 (the “PUT ADCR, DBF” instruction is invalidated).
One sampling time = 14/fX (1.75 µs, fX = 8 MHz)
140
CHAPTER 13 PERIPHERAL HARDWARE
13.4 SERIAL INTERFACE (SIO)
The serial interface consists of an shift register (SIOSFR, 8 bits), serial mode register, and serial clock counter.
It is used for serial data input/output.
13.4.1 Functions of the Serial Interface
This serial interface provides three signal lines: serial clock input pin (SCK), serial data output pin (SO), and serial
data input pin (SI). It allows 8 bits to be sent or received in synchronization with clocks. It can be connected to
peripheral input/output devices using any method with a mode compatible to that used by the µPD7500 series or 75X
series.
(1) Serial clock
Three types of internal clocks and one type of external clock are able to be selected. If an internal clock is
selected as a shift clock, it is automatically output to the P0D0/SCK pin.
Table 13-2. Serial Clock List
SIOCK1
SIOCK0
Serial clock to be selected
0
0
External clock from SCK pin
0
1
fX/16
1
0
fX/128
1
1
fX/1024
fX: System Clock oscillation frequency
(2) Transfer operation
Each pin of port 0D (P0D0/SCK, P0D1/SO, and P0D2/SI) functions as a serial interface pin when SIOEN is set
to 1. If SIOTS is set to 1 at this time, the operation is started in synchronization with the falling of the external
or internal clock. If SIOTS is set, IRQSIO is automatically cleared.
Transfer is started from the most significant bit of the shift register in synchronization with the falling of the
serial clock, and the information on the SI pin is stored to the shift register, starting from the least significant
bit, in synchronization with the rising of the serial clock.
When transfer of 8-bit data has been completed, SIOTS is automatically cleared, and IRQSIO is set.
Remark When executing serial transfer, transfer is started only from the most significant bit of the shift
register. It cannot be started from the least significant bit. The status of the SI pin is loaded to the
shift register in synchronization with the rising of the serial clock.
141
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-22. Block Diagram of the Serial Interface
P0D2/SI
LSB
MSB
Shift register (SIOSFR)
Clear
P0D1/SO
Output
latch
SIOHIZ
SIOCK1
Serial start
SIOTS
Note
SIOCK0
IRQSIO
clear signal
Single
shot
Serial clock counter
P0D0/SCK
Carry
IRQSIO
set signal
Clear
Selector
S
Q
R
P0D0
output
latch
fSYS/16
fSYS/128
fSYS/1024
Selector
SIOEN
P0DBIO0
P0DBIO1
Note The output latch of the shift register is shared with P0D1. If an output instruction is executed to P0D1,
therefore, the status of the output latch of the shift register is accordingly changed.
142
CHAPTER 13 PERIPHERAL HARDWARE
13.4.2 3-wire Serial Interface Operation Modes
Two modes can be used for the serial interface. If the serial interface function is selected, the P0D2/SI pin always
takes in data in synchronization with the serial clock.
• 8-bit transmission reception mode (simultaneous transmission and reception)
• 8-bit reception mode (SO pin: in the high-impedance state)
Table 13-3. Operating Mode of the Serial Interface
SIOEN
SIOHIZ
P0D2/SI pin
P0D1/SO pin
Operating mode of the serial interface
1
0
SI
SO
8-bit transmission/reception mode
1
1
SI
P0D1 (input)
8-bit reception mode
0
×
P0D2 (I/O)
P0D1 (I/O)
General-purpose port mode
×: Don’t care
(1) Clock synchronization 8-bit transmission and reception mode (simultaneous transmission and
reception)
Serial data input/output is controlled by a serial clock. The MSB of the shift register is output from the SO line
at a falling edge of the serial clock (SCK pin signal). The contents of the shift register is shifted one bit at a
rising edge and at the same time, data on the SI line is loaded into the LSB of the shift register.
Every time the serial clock counter (3-bit counter) counts eight serial clocks, the interrupt request flag
(IRQSIO←1) is set to 1.
Figure 13-23. Timing of 8-Bit Transmission and Reception Mode
(Simultaneous Transmission and Reception)
SCK pin
1
2
3
4
5
6
7
8
SI pin
DI7
DI6
DI5
DI4
DI3
DI2
DI1
DI0
SO pin
DO7
DO6
DO5
DO4
DO3
DO2
DO1
DO0
IRQSIO
Transmission starts in synchronization with the SCK pin falling edge.
Transmission
completion
An instruction which writes 1 into SIOTS is executed.
(Transmission start indication)
Remark DI: Serial data input
DO: Serial data output
143
CHAPTER 13 PERIPHERAL HARDWARE
(2) Clock synchronization 8-bit transmission and reception mode (SO pin output high impedance)
The P0D1/SO pin goes into a high-impedance state when SIOHIZ = 1. If supply of the serial clock is started
by writing “1” to SIOTS at this time, only the reception function of the serial interface is enabled.
Because the P0D1/SO pin goes into a high-impedance state, it can be used as an input port pin (P0D1).
Figure 13-24. Timing of the Clock Synchronization 8-Bit Reception Mode
SCK pin
SI pin
1
2
DI7
3
DI6
4
DI5
5
DI4
6
DI3
7
DI2
8
DI1
DI0
Hi-Z
SO pin
IRQSIO
Transmission starts in synchronization with an SCK pin falling edge.
Transmission
completion
An instruction which writes 1 into SIOTS is executed.
(Transmission start indication)
Remark DI: Serial data input
(3) Operation stop mode
If the value in SIOTS (RF: address 02H, bit 3) is 0, the serial interface enters operation stop mode. In this
mode, no serial transfer occurs.
In this mode, the shift register does not perform shifting and can be used as an ordinary 8-bit register.
144
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-25. Serial Interface Control Register (1/2)
RF: 02H
Bit 3
Bit 2
Bit 1
Bit 0
SIOTS
SIOHIZ
SIOCK1
SIOCK0
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
SIOCK1 SIOCK0
Selection of the serial clock
0
0
External clock (SCK pin)
0
1
fX/16
1
0
fX/128
1
1
fX/1024
SIOHIZ
Function selection of the P0D1/SO pin
0
Serial data output (SO pin)
1
Input port output high impedance (P0D1 pin)
SIOTS
Start and stop of serial transmission (at writing)
0
Forced termination of the shift register (Disables
intermediate restart).
Start of serial transfer operation
• At internal clock selection
1
Starts operation specifying the internal division
signal of the system clock as a serial clock.
• At external clock selection
Starts operation in synchronization with an SCK
pin falling edge.
Remark SIOTS is automatically cleared to 0 when
serial transmission is completed.
145
CHAPTER 13 PERIPHERAL HARDWARE
Figure 13-25. Serial Interface Control Register (2/2)
RF: 0BH
Bit 3
Bit 2
Bit 1
Bit 0
TM0OSEL
0
0
SIOEN
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
SIO operation enable
SIOEN
0
1
The pins P0D0/SCK, P0D1/SO, P0D2/SI
function as ports.
The pins P0D0/SCK, P0D1/SO, P0D2/SI
function as the serial interface.
Remark See also CHAPTER 12.
TM0OSEL
Selecting function of the P0D3/TM0OUT pin
0
The P0D3/TM0OUT pin is used as a port.
1
The P0D3/TM0OUT pin is used for timer 0 output.
Caution This is not related to the serial interface
directly.
146
CHAPTER 13 PERIPHERAL HARDWARE
13.4.3 Setting Values in the Shift Register
Values are set in the shift register via the data buffer (DBF) using the PUT instruction.
The peripheral address of the shift register is 01H. When sending a value to the shift register using the PUT
instruction, only the low-order 8 bits (DBF1, DBF0) of DBF are valid. The DBF3 and DBF2 values do not affect the
shift register.
Figure 13-26. Setting a Value in the Shift Register
Example of setting value 64H in the shift register
SIODATL
DAT 4H
; SIODATL is assigned to 4H using symbol definition.
SIODATH DAT 6H
; SIODATH is assigned to 6H using symbol definition.
MOV DBF0, #SIODATL
;
MOV DBF1, #SIODATH
;
PUT SIOSFR, DBF
; Value is transmitted using reserved word SIOSFR.
Data buffer
DBF3
b3
b2
b1
Don’t care
DBF2
b0
b3
b2
b1
Don’t care
DBF1
b0
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
0
1
1
0
0
1
0
0
8-bit data
PUT SIOSFR, DBF
SIOSFR (Peripheral address 01H)
b7
b6
b5
b4
b3
b2
b1
b0
0
1
1
0
0
1
0
0
147
CHAPTER 13 PERIPHERAL HARDWARE
13.4.4 Reading Values from the Shift Register
A value is read from the shift register via the data buffer (DBF) using the GET instruction. The shift register has
peripheral address 01H and only the low-order 8 bits (DBF1, DBF0) are valid. Executing the GET instruction does
not affect the high-order 8 bits of DBF.
Figure 13-27. Reading a Value from the Shift Register
GET DBF, SIOSFR; Example of using reserved words DBF and SIOSFR
Data buffer
DBF3
b3
b2
b1
Retained
DBF2
b0
b3
b2
b1
Retained
DBF1
b0
DBF0
b3
b2
b1
b0
b3
b2
b1
b0
0
1
1
0
0
1
0
0
GET DBF, SIOSFR
8-bit data
SIOSFR (Peripheral address 01H)
148
b7
b6
b5
b4
b3
b2
b1
b0
0
1
1
0
0
1
0
0
CHAPTER 14
INTERRUPT FUNCTIONS
The µPD17134A subseries has four internal interrupt functions and one external interrupt function. It can be used
in various applications.
The interrupt control circuit of the µPD17134A subseries has the features listed below. This circuit enables very
high-speed interrupt processing.
(a) Used to determine whether an interrupt can be accepted with the interrupt mask enable flag (INTE) and
interrupt enable flag (IP×××).
(b) The interrupt request flag (IRQ×××) can be tested or cleared. (Interrupt generation can be checked by
software.)
(c) Multiple interrupts are possible (up to three levels).
(d) Standby mode (STOP, HALT) can be released by an interrupt request. (Release source can be selected by
the interrupt enable flag.)
Caution In interrupt processing, the bank register and the BCD, CMP, CY, Z, and IXE flags are saved in
the stack automatically by the hardware for up to three levels of multiple interrupts. The DBF
and WR are not saved by the hardware when peripheral hardware such as the timers or A/D
converter is accessed in interrupt processing. It is recommended that the DBF and WR be saved
in RAM by the software at the beginning of interrupt processing. Saved data can be loaded back
into the DBF and WR immediately before the end of interrupt processing.
149
CHAPTER 14 INTERRUPT FUNCTIONS
14.1 INTERRUPT SOURCE TYPES AND VECTOR ADDRESSES
For every interrupt in the µPD17134A subseries, when the interrupt is accepted, a branch occurs to the vector
address associated with the interrupt source. This method is called the vectored interrupt method. Table 14-1 lists
the interrupt source types and vector addresses.
If two or more interrupts occur simultaneously, or if two or more pending interrupts are enabled at the same time,
processing is performed according to the priorities shown in Table 14-1.
Table 14-1. Interrupt Source Types
Interrupt source
Priority
Vector
address
INT pin (RF: 0FH, bit 0)
1
0005H
Timer 0
2
0004H
Timer 1
3
0003H
IRQ flag
IP flag
IEG flag
IRQ
RF: 3FH,
bit 0
IP
RF: 2FH,
bit 0
IEGMD0,1
RF: 1FH
IRQTM0
IPTM0
RF: 3EH,
bit 0
RF: 2FH,
bit 1
IRQTM1
RF: 3DH,
bit 0
IPTM1
RF: 2FH,
bit 2
Internal/
external
External
Internal
–
Internal
–
Basic interval timer
4
0002H
IRQBTM
RF: 3CH,
bit 0
IPBTM
RF: 2FH,
bit 3
–
Internal
Serial interface
5
0001H
IRQSIO
RF: 3BH,
bit 0
IPSIO
RF: 2EH,
bit 0
–
Internal
150
Remarks
Rising edge or falling edge
can be selected.
CHAPTER 14 INTERRUPT FUNCTIONS
14.2 HARDWARE COMPONENTS OF THE INTERRUPT CONTROL CIRCUIT
The flags of the interrupt control circuit are explained below.
(1) Interrupt Request Flag and the Interrupt Enable Flag
The interrupt request flag (IRQ×××) is set to 1 when an interrupt request occurs. When interrupt processing
is executed, the flag is automatically cleared to 0.
An interrupt enable flag (IP×××) is provided for each interrupt request flag. If the flag is 1, an interrupt is enabled.
If it is 0, the interrupt is disabled.
(2) EI/DI instruction
The EI/DI instruction is used to determine whether an accepted interrupt is to be executed.
If the EI instruction is executed, the interrupt enable flag (INTE) for enabling interrupt reception is set. If the
interrupt is accepted, INTE is cleared to 0. Since the INTE flag is not registered in the register file, flag status
cannot be checked by instructions.
The DI instruction clears the INTE flag to 0 and disables all interrupts.
At reset the INTE flag is cleared to 0 and all interrupts are disabled.
Table 14-2. Interrupt Request Flag and Interrupt Enable Flag
Interrupt
request flag
Signal for setting the interrupt request flag
Interrupt
enable flag
IRQ
Set by edge detection of an INT pin input signal. A
detection edge is selected by IEGMD0 or IEGMD1.
IP
IRQTM0
Set by a match signal from timer 0.
IPTM0
IRQTM1
Set by a match signal from timer 1.
IPTM1
IRQBTM
Set by an overflow (reference time interval signal)
from the basic interval timer.
IPBTM
IRQSIO
Set by a serial data transmission end signal from
the serial interface.
IPSIO
151
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (1/6)
RF: 0FH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
INT
Read/write
Read = R, write = W
R
Initial value when reset
0
0
0
Note
INT
Status of the INT pin
0
Sets logical status to 0 during PEEK instruction
execution.
1
Sets logical status to 1 during PEEK instruction
execution.
Note
Values are not latched and so change momentarily
according to pin logic. Once the IRQ flag is set,
however, it remains set until an interrupt is accepted.
The POKE instruction to address 0FH is invalid.
RF: 1FH
Bit 3
Bit 2
0
0
Read/write
Initial value when reset
Bit 1
Bit 0
IEGMD1 IEGMD0
Read = R, write = W
R/W
0
0
0
0
IEGMD1 IEGMD0
Selection of the interrupt
detection edge of the INT pin
0
0
Interrupt at the rising edge
0
1
Interrupt at the falling edge
1
0
1
1
Interrupt at both edges
152
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (2/6)
RF: 3FH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
IRQ
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
When read
INT pin interrupt request
IRQ
No interrupt request has been issued from the INT
0
pin or an INT pin interrupt is being processed.
An interrupt request from the INT pin occurs or
1
an INT pin interrupt is being held.
When write
INT pin interrupt request
IRQ
0
1
An interrupt request from the INT pin is forcibly
released.
An interrupt request from the INT pin is forced to
occur.
RF: 3EH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
IRQTM0
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
When read
IRQTM0
TM0 interrupt request
0
No interrupt request has been issued from
timer 0 or a timer 0 interrupt is being processed.
1
The contents of the timer 0 count register
matches that of the timer 0 modulo register and
an interrupt request occurs. Or a timer 0 interrupt
request is being held.
When write
IRQTM0
TM0 interrupt request
0
An interrupt request from timer 0 is forcibly
released.
1
An interrupt request from timer 0 is forced to
occur.
Remark If TM0RES is set to 1, IRQTM0 is cleared to 0.
153
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (3/6)
RF: 3DH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
IRQTM1
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
1
When read
TM1 interrupt request
IRQTM1
0
No interrupt request has been issued from timer
1 or a timer 1 interrupt is being processed.
1
The contents of the timer 1 count register
matches that of the timer 1 modulo register
and an interrupt request occurs. Or a timer 1
interrupt request is being held.
When write
IRQTM1
TM1 interrupt request
0
An interrupt request from timer 1 is forcibly
released.
1
An interrupt request from timer 1 is forced to
occur.
Remark If TM1RES is set to 1, IRQTM1 is cleared to 0.
IRQTM1 is cleared to 0 also immediately after
RF: 3CH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
IRQBTM
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
the execution of the STOP instruction.
0
0
When read
IRQBTM
BTM interrupt request
0
No interrupt request has been issued from the
basic interval timer or a basic interval timer
interrupt is being processed.
1
The basic interval timer overflows and an
interrupt request occurs. Or a basic interval
timer interrupt request is being held.
When write
IRQBTM
BTM interrupt request
0
An interrupt request from the basic interval timer
is forcibly released.
1
An interrupt request from the basic interval timer
is forced to occur.
Remark If BTMRES is set to 1, IRQBTM is cleared to 0.
154
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (4/6)
RF: 3BH
Bit 3
Bit 2
Bit 1
0
0
0
Read/write
Initial value when reset
Bit 0
IRQSIO
Read = R, write = W
R/W
0
0
0
0
When read
IRQSIO
SIO interrupt request
0
No interrupt request has been issued from the
serial interface or a serial interface interrupt is
being processed.
1
Serial interface transmission is completed and
an interrupt request occurs. Or, a serial
interface
When write
IRQSIO
SIO interrupt request
0
An interrupt request from the serial interface is
forcibly released.
1
An interrupt request from the serial interface is
forced to occur.
155
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (5/6)
RF: 2FH
Bit 3
Bit 2
Bit 1
Bit 0
IPBTM
IPTM1
IPTM0
IP
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
IP
156
INT pin interrupt enable
0
Disables an interrupt from the INT pin.
Holds an interrupt even if the IRQ flag is set to 1.
1
Enables an interrupt from the INT pin.
Executes the EI instruction. If the IRQ flag is set
to 1, executes interrupt processing.
IPTM0
TM0 interrupt enable
0
Disables an interrupt from timer 0.
Holds an interrupt even if the IRQTM0 flag is set
to 1.
1
Enables an interrupt from timer 0.
Executes the EI instruction. If the IRQTM0 flag is
set to 1, executes interrupt processing.
IPTM1
TM1 interrupt enable
0
Disables an interrupt from timer 1.
Holds an interrupt even if the IRQTM1 flag is set
to 1.
1
Enables an interrupt from timer 1.
Executes the EI instruction. If the IRQTM1 flag is
set to 1, executes interrupt processing.
IPBTM
BTM interrupt enable
0
Disables an interrupt from the basic interval timer.
Holds an interrupt even if the IRQBTM flag is set
to 1.
1
Enables an interrupt from the basic interval timer.
Executes the EI instruction. If the IRQBTM flag is
set to 1, executes interrupt processing.
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-1. Interrupt Control Register (6/6)
RF: 2EH
Bit 3
Bit 2
Bit 1
Bit 0
0
0
0
IPSIO
Read/write
Initial value when reset
Read = R, write = W
R/W
0
0
0
0
IPSIO
SIO interrupt enable
Disables an interrupt from the serial interface.
0
1
Holds an interrupt even if the IRQSIO flag is set
to 1.
Enables an interrupt from the serial interface.
Executes the EI instruction. If the IRQSIO flag is
set to 1, executes interrupt processing.
157
CHAPTER 14 INTERRUPT FUNCTIONS
14.3 INTERRUPT SEQUENCE
14.3.1 Receiving an Interrupt
When an interrupt is accepted, interrupt processing starts after the instruction cycle of the instruction being
executed is completed. The program flow is transferred to a vector address. However, if an interrupt occurs during
MOVT or EI instruction, or if an instruction that satisfies the skip condition is executed, the interrupt processing is
started two instruction cycles later.
When interrupt processing starts, one level of the address stack register is consumed to store the program return
address, and one level of the interrupt stack register is consumed to save BANK and PSWORD in the system register.
If two or more interrupts occur or are enabled, interrupt processing is executed in descending order of priority. A
lower-priority interrupt is held until a higher-priority interrupt is processed.
See priorities shown in Table 14-1.
Figure 14-2. Interrupt Processing Procedure
Interrupt request generation
Set IRQ×××
IP××× set?
NO
Hold interrupt until IP××× is set
YES
EI instruction executed?
(INTE = 1?)
NO
YES
Clear INTE flag and IRQ××× associated with
accepted interrupt to 0
Decrement stack pointer by 1 (SP _ 1)
Save contents of program counter in stack
pointed to by stack pointer
Load vector address into program counter
Save PSWORD content in interrupt stack
158
Hold interrupt until EI instruction
is executed
CHAPTER 14 INTERRUPT FUNCTIONS
14.3.2 Return from the Interrupt Routine
Execute the RETI instruction to return from the interrupt processing routine. During the RETI instruction cycle,
processing in the figure below occurs.
Figure 14-3. Return from Interrupt Processing
Execute RETI instruction
Load contents of stack pointed to by stack
pointer into program counter
Load contents of interrupt-dedicated stack
into PSWORD
Increment stack pointer value by one
Caution The INTE flag is not set for the RETI instruction.
Interrupt processing is completed. To handle a pending interrupt successively, execute the EI
instruction immediately before the RETI instruction and set the INTE flag to 1.
To execute the RETI instruction following the EI instruction, no interrupt is accepted between EI
instruction execution and RETI instruction execution. This is because the EI instruction sets the
INTE flag to 1 after the execution of the subsequent instruction is completed.
Example
EI instruction execution
Single interrupt
Timer 0 interrupt processing
Timer 0 interrupt generation
Timer 1 interrupt generation
(held)
EI
RETI
Timer 1 interrupt processing
Timer 0 interrupt generation
(held)
RETI
159
CHAPTER 14 INTERRUPT FUNCTIONS
14.3.3 Interrupt Accepting Timing
Figure 14-4 shows a timing chart that illustrates how interrupts are accepted.
The µPD17134A subseries xecutes one instruction in 16 clocks or in 1 instruction cycle. One instruction cycle
consists of four states, M0 to M3, with each state made up of 4 clocks.
An interrupt occurs asynchronously in respect to the program operation. The program recognizes the occurrence
of the interrupt at the leading edge of state M2.
Figure 14-4. Interrupt Accepting Timing (When INTE = 1, IP××× = 1) (1/3)
(1) If interrupt occurs before M2 of instruction other than MOVT and EI
Machine cycle
Instruction
M0
M1
M2
M3
M0
M1
M2
M3
INT cycle
Instruction other than MOVT and EI
M0
M1
M2
M3
M0
M1
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
(2) If skip condition of skip instruction is satisfied in (1)
Machine cycle
M0
Instruction
M1
M2
M3
M0
Skip instruction
M1
M2
M3
M0
Treated as NOP
M1
M2
M3
INT cycle
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
(3) If interrupt occurs after M2 of instruction other than MOVT and EI
Machine cycle
Instruction
M0
M1
M2
M3
M0
M1
M2
M3
Instruction other than MOVT and EI Instruction other than MOVT and EI
M0
M1
INT cycle
Occurrence of interrupt is recognized.
IRQ×××
160
M2
M3
M0
M1
Instruction of vector address
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-4. Interrupt Accepting Timing (When INTE = 1, IP××× = 1) (2/3)
(4) If interrupt occurs before M2 of MOVT instruction
Machine cycle
M0
M1
M2
Instruction
M3
M0'
M1'
M2'
M3'
M0
MOVT instruction
M1
M2
M3
INT cycle
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
(5) If interrupt occurs before M2’ of MOVT instruction
Machine cycle
M0
M1
M2
Instruction
M3
M0'
M1'
M2'
M3'
M0
MOVT instruction
M1
M2
M3
INT cycle
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ···
(6) If interrupt occurs before M2 of EI instruction
Machine cycle
M0
Instruction
M1
M2
M3
EI instruction
M0
M1
M2
M3
M0
Instruction other than MOVT and EI
M1
M2
M3
INT cycle
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
(7) If interrupt occurs after M2 of EI instruction
Machine cycle
Instruction
M0
M1
M2
EI instruction
M3
M0
M1
M2
M3
Instruction other than MOVT and EI
M0
M1
M2
INT cycle
M3
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
161
CHAPTER 14 INTERRUPT FUNCTIONS
Figure 14-4. Interrupt Accepting Timing (When INTE = 1, IP××× = 1) (3/3)
(8) If interrupt occurs during skip of skip instruction (treated as NOP)
Machine cycle
M0
Instruction
M1
M2
M3
M0
Skip instruction
M1
M2
Treated as NOP
M3
M0
M1
M2
INT cycle
M3
M0
M1
Instruction of vector address
Occurrence of interrupt is recognized.
IRQ×××
Remarks 1.
The INT cycle is for preparation of an interrupt. In this cycle, the contents of PC and PSWORD are
saved, and IRQ××× is cleared.
2.
The MOVT instruction exceptionally requires 2 instruction cycles.
3.
The EI instruction is designed so that multiplexed interrupt does not occur when program execution
returns from interrupt processing.
162
CHAPTER 14 INTERRUPT FUNCTIONS
14.4 MULTI-INTERRUPT
Multi-interrupt is a method that executes interrupt processing of other interrupt source B and C during the interrupt
processing for an interrupt source A as shown in Figure 14-5.
Nesting level at this time is also called interrupt level.
Pay attention to the following points when using multi-interrupt.
(1) Priority of interrupt source
(2) Limit of interrupt levels by interrupt stack (maximum 3 levels for the µPD17134A subseries)
Figure 14-5. Example of Multi-interrupt
Main processing
Interrupt processing A
EI
Interrupt processing B
EI (enables multi-interrupt)
Interrupt disabled
Interrupt disabled
Achievement of
interrupt B
Enables interrupt in
interrupt processing A
EI
RETI
Achievement of
interrupt A
Interrupt enabled
Interrupt processing C
Enables interrupt in
interrupt processing A
Achievement of
interrupt C
Interrupt enabled
Interrupt disabled
EI
RETI
EI
RETI
163
CHAPTER 14 INTERRUPT FUNCTIONS
As shown in Figure 14-5, INTE flag is cleared automatically and becomes interrupt disable state when interrupt
has been achieved. Therefore, when executing multi-interrupt processing, execute EI instruction during interrupt
processing.
Caution Maximum number of interrupt levels is 3. When achieving interrupt, interrupt stack register and
address stack register are consumed by one level. Address stack register is consumed by MOVT
instruction and PUSH instruction other than CALL instruction. Pay attention to the nesting level
of address stack.
14.5 PROGRAM EXAMPLE OF INTERRUPT
• Program example of countermeasure for noise reduction of external interrupt (INT pin)
This example assumes the case of assigning INT pin for key input, etc.
When taking into the microcomputer data in kind of switch such as key input processing, it takes some time for
the level of input voltage to be stabilized after pushing the key or switch. Accordingly, the countermeasures
for removing the noise generated by key, etc. should be executed by software.
In the following program, after generating external interrupt, the signal from INT pin becomes effective after
confirming that there is no change in the level of INT pin two times in every 100 µs.
Example
WAITCNT
MEM
0.00H
; Counter of wait processing
CHKRAM
MEM
0.01H
KEYON
FLG
0.01H.3
; If key turns ON (even just once), KEYON = 1
; CHK100U = 1 only when passing 100 µs during WAIT loop
CHK100U
FLG
0.01H.0
ORG
0H
BR
JOB_INIT
ORG
5H
BR
.
.
.
.
.
INT_JOB
MOV
WAITCNT, #0
; Clears RAM and the flag on RAM
MOV
CHKRAM, #0
;
INITFLG
NOT IEGMD1, IEGMD0
JOB_INIT:
; Rising edge is effective for the interrupt from INT pin
CLR1
IRQ
SET1
IP
EI
.
.
.
.
.
MAIN:
164
CALL
55JOB
CALL
.
.
.
.
.
BR
55JOB
MAIN
CHAPTER 14 INTERRUPT FUNCTIONS
INT_JOB:
NOP
; Loop which executes waiting for 100 µs at 8 MHz
NOP
; 2 µs (1 instruction) × 5 instructions × 10 times
; (count value at WAIT)
ADD
WAITCNT, #01
;
SKE
WAITCNT, #0A ;
BR
INT_JOB
;
SKF1
INT
; Check the level of INT pin
BR
KEY_NO
; If INT pin is high level, interrupt is invalid, and returns
SKF1
CHK100U
BR
WAIT_END
; to main processing
; First wait? (CHK100U = 0?)
; If it is the first time, wait again after setting CHK100U.
; In the case of the second time, finish wait processing
SET1
CHK100U
BR
INT_JOB
;
SET1
KEY_ON
; Judges that there is key input
CLR1
CHK100U
; CHK100U ← 0
WAIT_END:
KEY_NO:
EI
RETI
165
[MEMO]
166
CHAPTER 15 AC ZERO CROSS DETECTION
The INT pin is the interrupt signal input pin and timer count clock input pin. It also used as an AC zero cross detector
input pin. This pin can be selected by writing 1 in ZCROSS (RF: 1DH bit 0).
Figure 15-1. Block Diagram for the AC Zero Cross Detector
Internal bus
RF : 1DH
0 0 0 ZCROSS
INT
AC zero cross detector
Zero cross detection signal
(To INT, TM0, BTM)
AC
External coupling
capacitor
Caution When the AC zero cross detection circuit is used, the current consumption slightly increases (to
15 µA TYP.) even in the standby mode. To prevent an increase in the current consumption, clear
ZCROSS to 0, and fix the input voltage of the INT pin to the high or low level.
The zero cross detector consists of a high gain amplifier which uses the self-bias method. It biases the input to
the switching point and causes digital displacement in response to slight displacement of INT pin input. It detects
changes of an AC signal from minus to plus and vice versa. This signal is input through the external coupling capacitor.
The signal changes 0 to 1 and vice versa at each displacement point.
167
CHAPTER 15 AC ZERO CROSS DETECTION
Figure 15-2. Zero Cross Detection Signal
0V
AC input waveform
( A )
VP-PNote
Zero cross detection
signal
( B )
Note
The range of the input voltage when the INT pin is used as the input pin of the AC zero cross circuit is 1.0
VP-P to 3.0 VP-P.
Because the AC zero cross circuit does not have a function to reject noise, input a signal from which noise
has been eliminated in advance to this circuit.
A pulse generated in the zero cross detector can be used as a timer 0 count clock and basic interval timer count
clock in the same way as when the pulse does not go through the zero cross detector. The pulse is sent to the interrupt
control circuit. Interrupt processing starts if an INT pin interrupt is enabled. To accept an interrupt, set IEGMD0 (RF:
1FH bit 0) and IEGMD1 (RF: 1FH bit 1) to select a signal rising edge, falling edge, or both rising and falling edges.
168
CHAPTER 16 STANDBY FUNCTION
16.1 OVERVIEW OF THE STANDBY FUNCTION
The µPD17134A subseries has a standby function to reduce the current consumption. The standby function can
be used in two modes which can be selected as the application requires: STOP and HALT modes.
In the STOP mode, the system clock is stopped. Therefore, the current consumption of the CPU in this mode is
only the leakage current. This mode is effective for holding the contents of the data memory without the CPU operating.
In the HALT mode, oscillation of the system clock continues, but the CPU is stopped because supply of the clock
to the CPU is stopped. The current consumption in this mode is greater than in the STOP mode. However, operation
can be resumed immediately after the HALT mode has been released because the system clock is oscillating. In both
the STOP and HALT Modes, the contents of the data memory and registers, and the status of the output latch of the
output port immediately before the standby mode is set are retained (except STOP 0000B). Therefore, set the port
status to reduce the overall current consumption of the system before setting a standby mode.
Table 16-1. Status in Standby Mode
STOP mode
HALT mode
Setting instruction
STOP instruction
HALT instruction
System clock oscillation circuit
Oscillation stops
Oscillation continues
Operating
CPU
• Operation stops
status
RAM
• Retains previous status
Port
• Retains previous statusNote
TM0
• Can operate only when INT input is
selected as count pulse
• Stops if system clock is selected (count
value is retained)
• Can operate
TM1
• Operation stops
(count value is reset to “0”)
• Can operate
(count up is also disabled)
Note
BTM
• Operation stops
(count value is retained)
• Can operate
SIO
• Can operate only when external clock is
selected as serial clockNote
• Can operate
A/D
• Operation stopsNote (ADCR ← 00H)
• Can operate
INT
• Can operate
• Can operate
When STOP 0000B is executed, these pins are set in the input port mode including when the multiplexed
function of the pin is used.
Cautions 1. Be sure to place a NOP instruction immediately before the STOP or HALT instruction.
2. The standby mode is not set if both the interrupt request flag and interrupt enable flag are
set and the interrupt is specified as the condition to release the standby mode.
169
CHAPTER 16 STANDBY FUNCTION
16.2 HALT MODE
16.2.1 Setting HALT Mode
The HALT mode is set when the HALT instruction is executed.
Operand b3b2b1b0 of the HALT instruction specifies the condition under which the HALT mode is released.
Table 16-2. HALT Mode Release Condition
Format: HALT b3b2b1b0
HALT mode release conditionNote 1
Bit
b3
Enables release by IRQ×××× when 1Notes 2, 4
b2
Fixed to “0”
b1
Enables forced release by IRQTM1 when 1Notes 3, 4
b2
Fixed to “0”
Notes 1.
HALT 0000B enables only reset (RESET input, power-ON/power-down reset).
2.
IP××× must be 1.
3.
The HALT mode is released regardless of the status of IPTM1.
4.
Even if the HALT instruction is executed while IRQ××× = 1, the HALT instruction is ignored (treated
as a NOP instruction), and the HALT mode is not set.
16.2.2 Start Address after HALT Mode Is Released
The address from which program execution is started after the HALT mode has been released differs depending
on the release condition and interrupt enable condition.
Table 16-3. Start Address after HALT Mode Is Released
Release condition
ResetNote 1
IRQ×××Note 2
Notes 1.
2.
170
Start address after HALT mode is released
Address 0
Address next to HALT instruction in DI status
Interrupt vector in EI status (if two or more IRQ××× are set, interrupt vector with highest priority)
RESET input and power-ON/power-down reset are valid.
IP××× must be 1 except when the HALT mode is forcibly released by IRQTM1.
CHAPTER 16 STANDBY FUNCTION
Figure 16-1. Releasing HALT Mode
(a) By RESET input
HALT instruction executed
TM1 counts up
RESET
Operation mode
System reset status
HALT Mode
WAIT
Operation mode
(starts from address 0)
WAIT: Wait time until TM1 counts 256 clocks divided by 512
256 × 512/fCC + α (approx. 65 ms + α, fCC = 2 MHz)
α: Oscillation growth time (differs depending on resonator)
(b) By IRQ××× (in DI status)
HALT instruction executed
IRQ×××
Operation mode
HALT mode
Operation mode
(c) By IRQ××× (in EI status)
HALT instruction executed
Interrupt processing accepted
IRQ×××
Operation mode
HALT mode
Operation mode
171
CHAPTER 16 STANDBY FUNCTION
16.2.3 HALT Mode Setting Conditions
(1) Forced releasing by IRQTM1
Setting conditions
Release by external clock
• Timer 0 and timer 1 are used as 16-bit timer (TM0CK1 = 1, TM0CK0 = 1, TM1CK1 = 1,
TM1CK0 = 1)
Timer 0 and timer 1 are enabled to operate (TM0EN = 1, TM1EN = 1)
Interrupt flag of timer 1 is cleared (IRQTM1 = 0)
Release by internal clock
•
•
• Timer 1 is enabled to operate
• Interrupt request flag of timer 1 is cleared (IRQTM1 = 0)
(2) Release by interrupt request flag (IRQ×××)
• Peripheral hardware used to release HALT mode is enabled to operate in advance.
•
•
Timer 0
Operation enabled (TM0EN = 1)
Timer 1
Operation enabled (TM1EN = 1)
Timer 0 + timer 1
Timer 1 selects count up signal from timer 0 as count pulse (TM1CK1 = 1, TM1CK0 = 1).
Timer 0 and timer 1 are enabled to operate (TM0EN = 1, TM1EN = 1)
Basic interval timer
Always enabled to operate
Serial interface
Serial interface circuit is enabled to operate (SIOTS = 1, SIOEN = 1)
INT pin
Edge selected
Clear the interrupt request flag (IRQ×××) of the peripheral hardware used to release the HALT mode to 0.
Set the interrupt enable flag (IP×××) of the peripheral hardware used to release the HALT mode to 1.
Caution Be sure to include a NOP instruction immediately before the HALT instruction.
By doing so, a time of one instruction is created between the IRQ××× manipulation instruction
and HALT instruction. Consequently, clearing IRQ××× is correctly reflected on the HALT
instruction in the case, for example, of the CLR1 IRQ××× instruction (refer to Example 1
below). Unless a NOP instruction is described immediately before the HALT instruction, the
CLR1 IRQ××× instruction is not correctly reflected on the HALT instruction, and the HALT
mode is not set (Example 2).
172
CHAPTER 16 STANDBY FUNCTION
Example 1.
Correct program
..
..
.
(Setting of IRQ×××)
..
..
.
CLR1
IRQ×××
NOP
; Describe NOP instruction immediately before HALT instruction.
; (Clearing of IRQ××× is correctly reflected on HALT instruction.)
HALT .
..
..
..
..
.
2.
1000B
; Correctly execute HALT instruction (HALT mode is set).
Incorrect program
..
..
.
(Setting of IRQ×××)
..
..
.
CLR1
IRQ×××
; Clearing of IRQ××× is not reflected on HALT instruction.
; (It is reflected on instruction next to HALT instruction.)
HALT
..
..
..
..
..
1000B
; HALT instruction is ignored (HALT mode is not set).
173
CHAPTER 16 STANDBY FUNCTION
16.3 STOP MODE
16.3.1 Setting of STOP Mode
The STOP mode is set by executing the STOP instruction.
The operand b3b2b1b0 of the STOP instruction specifies the condition under which the STOP mode is to be released.
Table 16-4. STOP Mode Release Condition
Format: STOP b3b2b1b0
STOP mode release conditionNote 1
Bit
b3
Enables release of STOP mode by IRQ××× when 1Note 2
b2
Fixed to “0”
b1
Fixed to “0”
b0
Fixed to “0”
Notes 1.
STOP 0000B enables only reset (RESET input or power-ON/power-down reset). The internal circuitry
of the microcontroller is initialized to the status immediately after reset when STOP 0000B is executed.
2.
IP××× must be 1. The STOP mode cannot be released by IRQTM1.
Even if the STOP instruction is executed when IRQ××× = 1, the STOP instruction is ignored (treated
as NOP), and the STOP mode is not set.
16.3.2 Start Address After STOP Mode Is Released
The address from which program execution is started after the STOP mode has been released differs depending
on the release condition and interrupt enable condition.
Table 16-5. Start Address after STOP Mode Is Released
Release condition
ResetNote 1
IRQ×××Note 2
Start address after STOP mode is released
Address 0
Address next to that of STOP instruction in DI status
Interrupt vector in EI status
(If two or more IRQ××× are set, interrupt vector with highest priority)
Notes 1.
2.
174
Only RESET input and power-ON/power-down reset are valid.
IP××× must be 1. The STOP mode cannot be released by IRQTM1.
CHAPTER 16 STANDBY FUNCTION
Figure 16-2. Releasing STOP Mode
(a) Releasing STOP mode by RESET input
STOP instruction executed
TM1 counts up
RESET
Operation mode
STOP mode
System reset status
WAIT
Operation mode
(starts from address 0)
WAIT: Wait time until TM1 counts 256 clocks divided by 512
256 × 512/fCC + α (approx. 65 ms + α, fCC = 2 MHz)
α: Oscillation growth time (differs depending on resonator)
(b) Releasing STOP mode by IRQ××× (in DI status)
STOP instruction executed
TM1 counts up
IRQ×××
Operation mode
WAIT
STOP mode
Operation mode
WAIT: Wait time until TM1 counts (n + 1) clocks divided by m
(n + 1) × m/fCC + α (n and m are values immediately before STOP mode is set)
α: oscillation growth time (differs depending on resonator)
(c) Releasing STOP mode by IRQ××× (in EI status)
STOP instruction executed
TM1 counts up, interrupt processing accepted
IRQ×××
Operation mode
STOP mode
WAIT
Operation mode
WAIT: Wait time until TM1 counts (n + 1) clocks divided by m (n + 1) × m/fCC + α
(n and m are values immediately before STOP mode is set)
α: oscillation growth time (differs depending on resonator)
175
CHAPTER 16 STANDBY FUNCTION
16.3.3 STOP Mode Setting Conditions
When STOP mode is to be released by IRQ×××
Releasing by IRQ
Releasing by IRQSIO
Releasing by IRQTM0
176
• Selects edge of signal to be input from INT pin (IEGMD1, IEGMD0).
• Sets modulo register value of timer 1 (that creates oscillation stabilization wait time).
• Clears interrupt request flag (IRQ) of INT pin to 0.
• Sets interrupt enable flag (IP) of INT pin to 1.
• Selects external clock input from SCK pin as source clock (SIOCK1 = 0, SIOCK0 = 0).
• Enables serial interface to operate (SIOTS = 1).
• Sets modulo register value of timer 1 (that sets oscillation stabilization time).
• Clears interrupt request flag of serial interface (IRQSIO) to 0.
• Sets interrupt enable flag of serial interface (IPSIO) to 1.
• Selects external clock input from INT pin as source clock of timer 0 (TM0CK1 = 1, TM0CK0 = 1).
• Sets modulo register value of timer 0.
• Sets modulo register value and source clock of timer 1 (that creates oscillation stabilization time).
• Enables timer 0 to operate (TM0EN = 1).
• Clears interrupt request flag (IRQTM0) to 0
• Sets interrupt enable flag of timer 0 (IPTM0) to 1.
CHAPTER 16 STANDBY FUNCTION
Caution Be sure to include a NOP instruction before the STOP instruction. By doing so, a time of one
instruction is created between the IRQ××× manipulation instruction and STOP instruction. As
a result, clearing IRQ×××, for example, is correctly reflected on the STOP instruction when the
IRQ××× instruction is executed (refer to Example 1 below). Unless a NOP instruction is described
immediately before the STOP instruction, the CLR1 IRQ××× instruction is not reflected on the
STOP instruction, and the STOP mode is not set (Example 2).
Example 1.
Correct program
..
..
.
(Setting of IRQ×××)
..
..
.
CLR1
NOP
IRQ×××
; Describe NOP instruction immediately before the STOP instruction.
; (Clearing IRQ××× is correctly reflected on the STOP instruction.)
2.
STOP .
1000B
..
..
..
..
.
Incorrect program
; STOP instruction is correctly executed (STOP mode is set).
..
..
.
(Setting of IRQ×××)
..
..
.
CLR1
IRQ×××
; Clearing IRQ××× is not reflected on the STOP instruction.
; (It is reflected on the instruction next to the STOP instruction.)
STOP
..
..
..
..
..
1000B
; The STOP instruction is ignored (STOP mode is not set).
177
[MEMO]
178
CHAPTER 17 RESET
The µPD17134A subseries is reset in the following four ways.
(1) By RESET input
(2) Power-ON/power-down reset that resets the microcontroller on power application or when supply voltage
drops
(3) Watchdog timer that resets the microcontroller in case of a program hang-up
(4) Reset because of overflow/underflow of address stack
The power-ON/power-down reset function is effective when the supply voltage is 4.5 to 5.5 V.
179
CHAPTER 17 RESET
17.1 RESET FUNCTION
The reset function is used to initialize the device operation. How the device is initialized differs depending on the
type of reset effected.
Table 17-1. Hardware Status at Reset
Reset method
Hardware
•
RESET input in
standby mode
•
Overflow of
watchdog timer
•
Internal power-ON/
power-DOWN
reset during
operation
•
Internal power-ON/
power-DOWN
reset in standby
mode
•
Overflow and
underflow of stack
0000H
0000H
Input
Input
Input
0
0
Undefined
Other than DBF
Undefined
Retains previous
status
Undefined
DBF
Undefined
Undefined
Undefined
0
0
0
Undefined
Retains previous
status
Undefined
I/O mode
Output latch
General-purpose
data memory
RESET input
during operation
0000H
Program counter
Port
•
Other than WR
System register
WR
SP = 5H, IRQTM1 = 1, TM1EN = 1, IRQBTM =
0, and INT = status of INT pin at that time.
Others are 0.
Control register
Refer to CHAPTER 9 REGISTER FILE (RF).
SP = 5H, INT = status
of INT pin at that time.
Others retain previous
status.
Count register
00H
00H
Timer 0: 00H,
timer 1: undefined
Modulo register
FFH
FFH
FFH
Counter of basic interval timer
Undefined
Undefined
Undefined
(40H if watchdog timer
overflows)
Shift register of serial interface (SIOSFR)
Undefined
Retains previous
status
Undefined
00H
00H
00H
Timer 0 and timer 1
Data register of A/D converter (ADCR)
180
CHAPTER 17 RESET
Figure 17-1. Reset Block Configuration
1
2
Internal bus
RF : 10H
0
0
0
PDRESEN
3
Clear
4
Internal reset signal
Power-down reset circuit
VDD
5
Power-on reset circuit
6
Mask option
7
RESET
8
17.2 RESETTING
9
Operation when system reset is caused by the RESET pin is shown in the figure below.
If the RESET pin is set from low to high, system clock oscillation starts and an oscillation stabilization wait occurs
10
with the timer 1. Program execution starts from address 0000H.
If power-on reset is used, the reset signals shown in Figure 17-2 are internally generated. Operation is the same
11
as that when reset is caused externally by the RESET pin.
At watchdog timer overflow reset or stack overflow and underflow reset, oscillation stabilization wait time (WAIT)
does not occur. Operation starts from address 0000H after initial statuses are internally set.
12
Figure 17-2. Reset Operation
13
14
RESET
15
TM1EN
16
TM1RES
17
Operating mode
Reset
WAITNote
Operating mode
18
Note This is oscillation stabilization wait time. Operating mode is set when timer 1 counts system clocks (fCC)
19
512 × 256 counts approx. 65 ms at fCC = 2 MHz).
20
181
CHAPTER 17 RESET
17.3 POWER-ON/POWER-DOWN RESET FUNCTION
The µPD17134A subseries is provided with two reset functions to prevent malfunctions from occurring in the
microcontroller. They are the power-on reset function and power-down reset function. The power-on reset function
resets the microcontroller when it detects that power was turned on. The power-down reset function resets the
microcontroller when it detects drops in the power voltage.
These functions are implemented by the power monitoring circuit whose operating voltage has a different range
than the logic circuits in the microcontroller and the oscillation circuit (which stops oscillation at reset to put the
microcontroller in a temporary stop state). Conditions required to enable these functions and their operations will be
described next.
Caution When designing an application circuit that calls for high reliability, do not depend on the internal
power-ON/power-DOWN reset function only. Make sure that an external RESET signal is input.
17.3.1 Conditions Required to Enable the Power-On Reset Function
This function is effective when used together with the power-down reset function.
The following conditions are required to validate the power-on reset function:
(1) The power voltage must be within 4.5 to 5.5 V during normal operation, including the standby state.
(2) The frequency of the system clock oscillator must be 400 kHz to 4 MHz. Note
(3) The power-down reset function must be enabled during normal operation, including the standby state.
(4) The power voltage must rise from 0 V to the specified voltage.
(5) The time it takes for the power voltage to rise from 0 to 2.7 V must be shorter than the oscillation stabilization
wait time (system clock fCC = 512 × 256 counts, about 65 ms, at fCC = 2 MHz) counted in timer 1.
Note
Applies to the µPD17135A, 17137A, and 17P137A.
When the µPD17134A, 17136A, or 17P136A is used, fCC = 400 kHz to 2 MHz.
Cautions 1. If the above conditions are not satisfied, the power-on reset function will not operate
effectively. In this case, an external reset circuit needs to be added.
2. In the standby state, even if the power-down reset function operates normally, generalpurpose data memory (except DBF) retains data up to VDD = 2.7 V. If, however, data is changed
due to an external error, the data in memory is not guaranteed.
182
CHAPTER 17 RESET
17.3.2 Power-On Reset Function and Operation
The power-on reset function resets the microcontroller when it detects that power was turned on in the hardware,
1
regardless of the software state.
The power-on reset circuit operates under a lower voltage than the other internal circuits. It initializes the
2
microcontroller regardless whether the oscillation circuit is operating. When the reset is terminated, timer 1 counts
the number of oscillation pulses sent from the oscillator until it reaches the specified value. Within this period,
oscillation becomes stable and the power voltage applied to the microcontroller enters the range (VDD = 2.7 to 5.5
3
V at 400 kHz to 4 MHz) in which the microcontroller is guaranteed to operate.
When this period elapses, the microcontroller enters normal operation mode. Figure 17-3 shows an example of
4
the power-on reset operation.
5
Functions of the power-on reset
(1) This circuit always monitors the voltage applied to the VDD pin.
(2) This circuit resets the internal circuit of the microcomputer, regardless of whether the oscillator circuit operates
6
or not, when the supply voltage rises, until the voltage reaches the power-ON reset clear voltage (VDD = 1.5
7
V TYP.).Note
(3) This circuit stops oscillation during the reset operation.
(4) When reset is released, timer 1 counts oscillation pulses. The microcontroller waits until oscillation becomes
8
stable and the power voltage becomes VDD = 2.7 V or higher.
Note
The internal circuit of the microcontroller is not reset until the supply voltage reaches the level at which the
9
internal circuit can operate (i.e., internal reset signal can be accepted).
10
11
12
13
14
15
16
17
18
19
20
183
CHAPTER 17 RESET
Figure 17-3. Example of the Power-On Reset Operation
VDD
(V)
5.0
2.7
A : Voltage at which
oscillation starts
B : Voltage at which the
power-on reset operation
terminates
A
VDD
RESETNote 4
µ PD17134A subseries
B
GND
0
Time (t)
Oscillating
State of
oscillation
Oscillation stop
Oscillation start
Timer 1 finishes counting
Period in which
the microcontroller is guaranteed to
operate
Guaranteed periodNote 2
Undefined periodNote 1
Power-on
reset signal
Operation state
of the microcontroller
Operation stopNote 3
Waiting until
oscillation
becomes stable
Operating mode
Power-on reset termination
Notes 1.
During the operation-undefined period, not all of the operations specified for the µPD17134A subseries
are guaranteed. The power-on reset operation is guaranteed in this period.
2.
The operation-guaranteed period refers to the time in which all the operations specified for the
3.
An operation stop state refers to the state in which all of the functions of the microcontroller are stopped.
µPD17134A subseries are guaranteed.
184
CHAPTER 17 RESET
17.3.3 Condition Required for Use of the Power-Down Reset Function
The power-down reset function can be enabled or disabled using software. The following condition is required to
1
use this function:
2
• The power voltage must be within 4.5 to 5.5 V during normal operation, including the standby state.
• The frequency of the system clock oscillator must be 400 kHz to 4 MHz.
3
Caution When the microcontroller is used with a power voltage of 2.7 to 4.5 V, add an external reset circuit
instead of using the internal power-down reset circuit. If the internal power-down reset circuit
4
is used with a power voltage of 2.7 to 4.5 V, reset operation may not terminate.
5
17.3.4 Power-Down Reset Function and Operation
This function is enabled by setting the power-down reset enable flag (PDRESEN) using software.
6
When this function detects a power voltage drop, it issues the reset signal to the microcontroller. It then initializes
the microcontroller. Stopping oscillation during reset prevents the power voltage in the microcontroller from fluctuating
out of control. When the specified power voltage recovers and the power-down reset operation is terminated, the
7
microcontroller waits the time required for stable oscillation using the timer. The microcontroller then enters normal
8
operation (starts from address 0).
Figure 17-4 shows an example of the power-down operation. Figure 17-5 shows an example of reset operation
during the period from power-down reset to power recovery.
9
Functions of the power-down reset
10
(1) This circuit always monitors the voltage applied to the VDD pin.
(2) When this circuit detects a power voltage drop, it issues a reset signal to the other parts of the microcontroller.
It continues to send this reset signal until the power voltage recovers or all the functions in the microcontroller
11
stop.
12
(3) This circuit stops oscillation during the reset operation to prevent software crashes.
When the power voltage recovers to the low-voltage detection level (3.5 V TYP., 4.5 V MAX.) before the powerdown reset function stops, the microcontroller waits the time required for stable oscillation using timer 1, then
13
enters normal operation mode.
(4) When the power voltage recovers from 0 V, the power-on reset function has priority.
(5) After the power-down reset function stops and the power voltage recovers before it reaches 0 V, the
14
microcontroller waits using timer 1 until oscillation becomes stable and the power voltage (VDD) reaches 2.7
15
V. The microcontroller then enters normal operation mode.
16
17
18
19
20
185
CHAPTER 17 RESET
Figure 17-4. Example of the Power-Down Reset Operation
VDD
(V)
5.0
Maximum voltage detected by the
power-down reset function: 4.5 V
4.5
Typical voltage detected by the
power-down reset function: 3.5 V
3.5
Voltage at which the power-down
reset function terminates =
power-on reset voltage (B): C
2.7
C
VDD
RESET
µ PD17134A subseries
GND
0
Time (t)
Oscillating
State of
oscillation
Period in which
the microcontroller is guaranteed to
operate
Oscillation stop
Undefined periodNote
Guaranteed period
Power-down
reset signal
Power-on
reset signal
Operation state
of the microcontroller
Note
Operating
mode
Reset state
Power-down reset
In the operation-undefined period, not all the operations specified for the µPD17134A subseries are
guaranteed. The power-down reset operation, which continues to issue a reset signal until all the functions
in the microcontroller stop, is guaranteed in this period.
186
CHAPTER 17 RESET
Figure 17-5. Example of Reset Operation during the Period from
1
Power-Down Reset to Power Recovery
VDD
(V)
2
3
5.0
4
4.5
5
Maximum voltage detected by the
power-down reset function: 4.5 V
3.5
6
Typical voltage detected by the
power-down reset function: 3.5 V
2.7
C
Voltage at which the power-down
reset function terminates =
power-on reset voltage (B): C
0
Time (t)
Oscillating
Oscillating
7
8
9
VDD
Oscillation stop
State of
oscillation
Period in which
the microcontroller is guaranteed to
operate
RESET
µ PD17134A subseries
Guaranteed
period
Undefined periodNote
Timer 1 finishes counting
Guaranteed period
10
11
GND
12
13
Power-down
reset signal
14
Power-on
reset signal
15
Operation state
of the microcontroller
16
Operating
mode
Reset state
Power-down reset
Operating mode
17
Waiting until oscillation
becomes stable
18
Note
In the operation-undefined period, not all the operations specified for the µPD17134A subseries are
guaranteed. The power-down reset operation, which continues to issue the reset signal until all the
19
functions in the microcontroller stop, is guaranteed in this period.
20
187
[MEMO]
188
CHAPTER 18 ONE-TIME PROM WRITING/VERIFYING
The on-chip program memories of the µPD17P136A and 17P137A are is a 2048 × 16-bit one-time PROM.
Pins listed in Table 18-1 are used for one-time PROM writing/verifying. The address is updated by the clock signal
input from the CLK pin.
Caution PIB0/VPP pin is used as VPP pin in program writing/verifying mode. Therefore, there is a possibility
of overrunning of the microcontroller when higher voltage than VDD + 0.3 V is applied to PIB0/VPP
pin in normal operation mode. Pay careful attention to pin protection.
Table 18-1. Pins Used for Writing/Verifying Program Memory
Pin
Function
VPP
Applies program voltage. Apply +12.5 V to this pin.
VDD
Power supply pin. Apply +6 V to this pin.
RESET
System reset input pin. Used for initializing all states
before setting program memory writing/verifying mode.
CLK
Clock input for updating address. Updates program
memory address by inputting four pulses.
MD0-MD3
Select operation mode.
D0-D7
8-bit data I/O pins.
18.1 DIFFERENCES BETWEEN MASK ROM VERSION AND ONE-TIME PROM MODEL
The µPD17P136A and 17P137A are microcontrollers replacing the program memory of the on-chip mask ROM
version µPD17136A and 17137A to one-time PROM. Table 18-2 shows the differences between mask ROM version
and one-time PROM version.
Differences between each product are only its program memory, program size, address register size, and whether
it can specify mask option or not. The CPU function and internal peripheral hardware of each product are the same.
Therefore, the µPD17P136A can be used for evaluating program of the µPD17134A/17136A in system development.
Also, the µPD17P137A can be used for evaluating the µPD17135A/17137A in the same way.
189
CHAPTER 18 ONE-TIME PROM WRITING/VERIFYING
Table 18-2. Differences Between Mask ROM Version and One-Time PROM Version
µPD17134A/17135A
Item
ROM
µPD17136A/17137A
µPD17P136A/17P137A
Mask ROM
One-time PROM
1024 × 16 bits
(0000H to 03FFH)
2048 × 16 bits
(0000H to 07FFH)
10 bits
11 bits
Program counter
Address register
Address stack register
P0D, P1A, and P1B pins and
pull-up resistor of RESET pin
Mask option
Not available
VPP pin and operating mode select
pin
Not available
Provided
Quality grade
Standard
Special [(A), (A1)]
Standard
Caution The PROM model is highly compatible with the mask ROM model in terms of functions but its
internal ROM circuit and electrical characteristics are partially different from those of the mask
ROM model. To replace the PROM model with the mask ROM model, thoroughly evaluate the
application by using a sample of the mask ROM model.
18.2 OPERATION MODE WHEN PROGRAM MEMORY IS WRITTEN/VERIFIED
The µPD17P136A and 17P137A enter a program memory write/verify mode when they have been reset for a fixed
time (VDD = 5 V, RESET = 0 V) and then +6 V is applied to the VDD pin and +12.5 V to the VPP pin. In this mdoe, the
operation modes shown in the table below can be selected depending on the setting of the MD0 through MD3 pins.
Connect VADC directly to VDD. Connect all the other pins to GND via pull-down resistor.
Table 18-3. Setting Operation Modes
Setting operation mode
VPP
+12.5 V
VDD
+6 V
MD1
MD2
MD3
H
L
H
L
Program memory address 0 clear
L
H
H
H
Write mode
L
L
H
H
Verify mode
H
×
H
H
Program inhibit mode
Remark ×: don’t care (L or H)
190
Operation mode
MD0
CHAPTER 18 ONE-TIME PROM WRITING/VERIFYING
18.3 WRITING PROCEDURE OF PROGRAM MEMORY
1
The program memory can be written at high speeds in the following procedure.
2
(1)
Pull down the unused pins to GND. Make the CLK pin low.
(2)
Apply 5 V to the VDD pin. Make VPP pin and RESET pin low.
(3)
Wait for 10 µs. Then, apply 5 V to RESET pin.
(4)
Set the program memory address 0 clear mode using mode selector pins.
(5)
Apply 6 V to VDD and RESET, and 12.5 V to VPP.
(6)
Set the program inhibit mode.
(7)
Write data in mode for 1 ms writing.
(8)
Set the program inhibit mode.
(9)
Set the verify mode. If the program has been correctly written, proceed to (10). If not, repeat (7) through
3
4
5
6
(9).
(10) Additional writing of (number of times (×) the program has been written in (7) through (9)) × 1 ms.
7
(11) Set the program inhibit mode.
(12) Input four pulses to the CLK pin to update the program memory address by one.
8
(13) Repeat (7) through (12) until the last address is programmed.
(14) Set the program memory address 0 clear mode.
(15) Change the voltage of VDD and VPP pins to 5 V.
9
(16) Turn off the power.
10
Figure 18-1 shows the procedures of (2) through (12).
11
Figure 18-1. Procedure of Program Memory Writing
Repeat × times
12
Reset
Write
Additional
writing
Verify
Address
increment
13
VDD+1
VDD
GND
RESET VDD+1
VDD
GND
VPP
VPP
VDD
GND
14
VDD
15
16
17
CLK
Hi-Z
D 0 - D7
Input data
Hi-Z
Hi-Z
Output data
Hi-Z
18
Input data
MD0
19
MD1
20
MD2
MD3
191
CHAPTER 18 ONE-TIME PROM WRITING/VERIFYING
18.4 READING PROCEDURE OF PROGRAM MEMORY
(1)
Connect VADC directly to VDD, and all the other pins to GND via pull-down resistor. Make the CLK pin low.
(2)
Apply 5 V to the VDD pin. Make VPP pin and RESET pin low.
(3)
Wait for 10 µs. Then, apply 5 V to RESET pin.
(4)
Set the program memory address 0 clear mode using mode selector pins.
(5)
Apply 6 V to VDD and RESET and 12.5 V to VPP.
(6)
Set mode selector pins to the program inhibit mode.
(7)
Set the verify mode. When clock pulses are input to the CLK pin, data for each address can be sequentially
output with four clocks as one cycle.
(8)
Set the program inhibit mode.
(9)
Set the program memory address 0 clear mode.
(10) Change the voltage of VDD and VPP pins to 5 V.
(11) Turn off the power.
Figure 18-2 shows the program reading procedure (2) through (9).
Figure 18-2. Procedure of Program Memory Reading
Reset
VDD+1
VDD
GND
RESET VDD+1
VDD
GND
VPP
VPP
VDD
GND
VDD
CLK
D0 - D7
Hi-Z
Output data
MD0
“L”
MD1
MD2
MD3
192
Output data
Hi-Z
CHAPTER 19 INSTRUCTION SET
19.1 OVERVIEW OF THE INSTRUCTION SET
b15
1
0
b14-b11
BIN
HEX
0000
0
ADD
r, m
ADD
m, #n4
0001
1
SUB
r, m
SUB
m, #n4
0010
2
ADDC
r, m
ADDC
m, #n4
0011
3
SUBC
r, m
SUBC
m, #n4
0100
4
AND
r, m
AND
m, #n4
0101
5
XOR
r, m
XOR
m, #n4
0110
6
OR
r, m
OR
m, #n4
INC
AR
INC
IX
MOVT
DBF, @AR
BR
@AR
CALL
@AR
RET
RETSK
EI
DI
0111
7
RETI
PUSH
AR
POP
AR
GET
DBF, p
PUT
p, DBF
PEEK
WR, rf
POKE
rf, WR
RORC
r
STOP
s
HALT
h
NOP
1000
8
LD
r, m
ST
m, r
1001
9
SKE
m, #n4
SKGE
m, #n4
1010
A
MOV
@r, m
MOV
m, @r
1011
B
SKNE
m, #n4
SKLT
m, #n4
1100
C
BR
addr
CALL
addr
1101
D
MOV
m, #n4
1110
E
SKT
m, #n
1111
F
SKF
m, #n
193
CHAPTER 19 INSTRUCTION SET
19.2 LEGEND
AR
: Address register
ASR
: Address stack register indicated by stack pointer
addr
: Program memory address (11 bits)
BANK
: Bank register
CMP
: Compare register
CY
: Carry flag
DBF
: Data buffer
h
: Halt release condition
INTEF
: Interrupt enable flag
INTR
: Register saved automatically to interrupt stack
INTSK
: Interrupt stack register
IX
: Index register
MP
: Data memory row address pointer
MPE
: Memory pointer enable flag
: Data memory address indicated by mR and mC
m
mR
: Data memory row address (high-order)
mC
: Data memory column address (low-order)
n
: Bit position (4 bits)
n4
: Immediate data (4 bits)
PC
p
:Program counter
: Peripheral address
pH
: Peripheral address (high-order 3 bits)
pL
: Peripheral address (low-order 4 bits)
r
: General register column address
rf
: Register file address
rfR
: Register file row address (high-order 3 bits)
rfC
: Register file column address (low-order 4 bits)
SP
s
:Stack pointer
: Stop release condition
WR
: Window register
(✕)
: Contents addressed by ×
194
CHAPTER 19 INSTRUCTION SET
19.3 LIST OF THE INSTRUCTION SET
1
Machine code
Group
Mnemonic
Operand
Operation
OP code
(r) ← (r) + (m)
00000
mR
mC
r
(m) ← (m) + n4
10000
mR
mC
n4
(r) ← (r) + (m) + CY
00010
mR
mC
r
(m) ← (m) + n4 + CY
10010
mR
mC
n4
AR
AR ← AR + 1
00111
000
1001
0000
IX
IX ← IX + 1
00111
000
1000
0000
(r) ← (r) – (m)
00001
mR
mC
r
(m) ← (m) – n4
10001
mR
mC
n4
(r) ← (r) – (m) – CY
00011
mR
mC
r
(m) ← (m) – n4 – CY
10011
mR
mC
n4
r, m
(r) ← (r) V (m)
00110
mR
mC
r
m, #n4
(m) ← (m) V n4
10110
mR
mC
n4
(r) ← (r)
(m)
00100
mR
mC
r
v
ADD
10100
mR
mC
n4
r, m
m, #n4
ADDC
r, m
m, #n4
INC
Subtract
SUB
r, m
m, #n4
SUBC
r, m
m, #n4
Logical
Operation
OR
AND
r, m
m, #n4
(r) ← (r) V (m)
00101
mR
mC
r
m, #n4
(m) ← (m) V n4
10101
mR
mC
n4
SKT
m, #n
CMP ← 0, if (m)
n = n, then skip
11110
mR
mC
n
SKF
m, #n
CMP ← 0, if (m)
v
Rotate
n4
v
Compare
(m) ← (m)
r, m
n = 0, then skip
11111
mR
mC
n
SKE
m, #n4
(m) –n4, skip if zero
01001
mR
mC
n4
SKNE
m, #n4
(m) –n4, skip if not zero
01011
mR
mC
n4
SKGE
m, #n4
(m) –n4, skip if not borrow
11001
mR
mC
n4
SKLT
m, #n4
(m) –n4, skip if borrow
11011
mR
mC
n4
RORC
r
00111
000
0111
r
LD
r, m
(r) ← (m)
01000
mR
mC
r
ST
m, r
(m) ← (r)
11000
mR
mC
r
MOV
@r, m
if MPE = 1: (MP, (r) ← (m)
if MPE = 0: (BANK, mR, (r)) ← (m)
01010
mR
mC
r
if MPE = 1: (m) ← (MP, (r))
if MPE = 0: (m) ← (BANK, mR, (r))
11010
(m) ← n4
11101
mR
mC
n4
SP ← SP –1, ASR ← PC, PC ← AR,
DBF ← (PC), PC ← ASR, SP ← SP +1
00111
000
0001
0000
XOR
Judge
v
Add
2
Operand
CY → (r)b3 → (r)b2 → (r)b1 → (r)b0
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Transfer
m, @r
m, #n4
MOVT
DBF, @AR
18
19
mR
mC
r
20
195
CHAPTER 19 INSTRUCTION SET
Machine code
Group
Mnemonic
Operand
Operation
OP code
Transfer
Branch
Subroutine
PUSH
AR
SP ← SP –1, ASR ← AR
00111
000
1101
0000
POP
AR
AR ← ASR, SP ← SP+1
00111
000
1100
0000
PEEK
WR, rf
WR ← (rf)
00111
rfR
0011
rfC
POKE
rf, WR
(rf) ← WR
00111
rfR
0010
rfC
GET
DBF, p
DBF ← (p)
00111
pH
1011
pL
PUT
p, DBF
(p) ← DBF
00111
pH
1010
pL
BR
addr
PC ← addr
01100
@AR
PC ← AR
00111
addr
SP ← SP –1, ASR ← PC, PC ← addr
11100
@AR
SP ← SP –1, ASR ← PC, PC ← AR
00111
000
0101
0000
PC ← ASR, SP ← SP +1
00111
000
1110
0000
PC ← ASR, SP ← SP +1 and skip
00111
001
1110
0000
PC ← ASR, INTR ← INTSK, SP ← SP +1
00111
100
1110
0000
EI
INTEF ← 1
00111
000
1111
0000
DI
INTEF ← 0
00111
001
1111
0000
CALL
RET
RETSK
RETI
Interrupt
Others
addr
000
0100
0000
addr
STOP
s
STOP
00111
010
1111
s
HALT
h
HALT
00111
011
1111
h
No operation
00111
100
1111
0000
NOP
196
Operand
CHAPTER 19 INSTRUCTION SET
19.4 ASSEMBLER (AS17K) EMBEDDED MACRO INSTRUCTIONS
1
Legend
2
flag n
: FLG type symbol
< >
: Can be omitted
Embedded
macro
3
Mnemonic
Operand
SKTn
flag 1, ...flag n
if (flag 1) to (flag n) = all “1” then skip
1≤n≤4
SKFn
flag 1, ...flag n
if (flag 1) to (flag n) = all “0”, then skip
1≤n≤4
SETn
flag 1, ...flag n
(flag 1) to (flag n) ← 1
1≤n≤4
CLRn
flag 1, ...flag n
(flag 1) to (flag n) ← 0
1≤n≤4
NOTn
flag 1, ...flag n
if (flag n) = “0”, then (flag n) ← 1
if (flag n) = “1”, then (flag n) ← 0
1≤n≤4
7
INITFLG
<NOT> flag 1,
...<<NOT> flag n>
if description = NOT flag n, then (flag n) ← 0
if description = flag n, then (flag n) ← 1
1≤n≤4
8
BANK ← n
n = 0, 1
9
BANKn
Operation
n
4
5
6
10
11
12
13
14
15
16
17
18
19
20
197
CHAPTER 19 INSTRUCTION SET
19.5 INSTRUCTIONS
19.5.1 Addition Instructions
(1) ADD r, m
Add data memory to general register
<1> OP code
10
00000
8
7
mR
4
3
mC
0
r
<2> Function
When CMP = 0, (r) ← (r) + (m)
Adds the data memory contents to the general register contents, and stores the result in general register.
When CMP = 1, (r) + (m)
The result is not stored in the register. Carry flag CY and zero flag Z are changed, according to the result.
Sets carry flag CY, if a carry occurs as a result of the addition. Resets the carry flag, if no carry occurs.
If the addition result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Addition can be executed in binary 4 bits or BCD. The BCD flag for the PSWORD specifies what kind of addition
is to be executed.
<3> Example 1
To add the address 0.2FH contents to the address 0.03H contents, when row address 0 (0.00H–0.0FH)
in bank 0 is specified as the general register (RPH = 0, RPL = 0), and to store the result in address 0.03H:
(0.03H) ← (0.03H) + (0.2FH)
198
MEM003
MEM
0.03H
MEM02F
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
ADD
MEM003, MEM02F
CHAPTER 19 INSTRUCTION SET
Example 2
1
To add the address 0.2FH contents to the address 0.23H contents, when row address 2 (0.20H–0.2FH)
in bank 0 is specified as the general register (RPH = 0, RPL = 4), and store the result in address 0.23H:
(0.23H) ← (0.23H) + (0.2FH)
MEM023
MEM
MEM02F
2
3
0.23H
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #04H
; General register row address 2
ADD
MEM023, MEM02F
4
Note
5
6
Note
RP
Register
RPH
Bit
b3
b2
b1
7
RPL
b0
b3
b2
b1
b0
8
B
Data
0
9
C
Bank
0
0
Row
Address
D
10
RP (general register pointer) is assigned in the system register, as shown above.
Therefore, to set bank 0 and row address 2 in a general register, 00H must be stored in RPH and 04H,
11
in RPL.
In this case, the subsequent arithmetic operation is executed in binary 4-bit operation, because the BCD
12
flag is reset.
13
Example 3
To add the address 0.6FH contents to the address 0.03H contents and store the result in address 0.3H.
14
At this time, data memory address 0.6FH can be specified, by selecting data memory address 2FH, if
15
IXE = 1, IXH = 0, IXM = 4, and IXL = 0, i.e., IX = 0.40H.
(0.03H) ← (0.03H) + (0.6FH)
Address obtained as result of ORing index register
16
contents, 0.40H, and data memory address 0.2FH
MEM003
MEM
0.03H
MEM02F
MEM
0.2FH
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00001000000B
MOV
IXM, #04H
;
17
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
ADD
MEM003, MEM02F ; IX
18
19
20
00001000000B (0.40H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00001101111B (0.6FH)
199
CHAPTER 19 INSTRUCTION SET
Example 4
To add the address 0.3FH contents to the address 0.03H contents and store the result in address 0.03H.
At this time, data memory address 2.3FH can be specified by specifying data memory address 2FH, if
IXE = 1, IXH = 0, IXM = 1, and IXL = 0, i.e., IX = 0.10H.
(0.03H) ← (0.03H) + (0.3FH)
Address obtained as result of ORing index register
contents, 0.10H, and data memory address 0.2FH
MEM003
MEM
MEM02F
0.03H
MEM
0.2FH
MOV
BANK, #00H
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00000010000B (0.10H) Note
MOV
IXM, #01H
MOV
IXL, #00H
SET1
IXE
ADD
MEM003, MEM02F ; IX
; IXE flag ← 1
00000010000B (0.10H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00100111111B (0.3FH)
Note
IX
Register
IXH
Bit
b3
IXM
b2
b1
b0
0
Bank
0
0
b3
b2
b1
IXL
b0
b3
b2
b1
b0
M
Data
P
E
Row
Address
Column
address
IX (index register) is assigned in the system register, as shown above,
Therefore, to specify IX = 0.10H, 00H must be stored in IXH. 01H in IXM, and 00H in IXL.
In this case, MP (memory pointer) for general register indirect transfer is invalid, because the MPE flag
(memory pointer enable) is reset.
200
CHAPTER 19 INSTRUCTION SET
<4> Caution
1
The first operand for the ADD r, m instruction is a column address. Therefore, if the instruction is
described as follows, the column address for the general register is 03H:
2
MEM013
MEM
0.13H
MEM02F
MEM
0.2FH
3
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
4
ADD
MEM013, MEM02F
Indicates the general register column address.
5
The low-order 4 bits (in this case, 03H) are valid
When CMP flag = 1, the addition result is not stored.
6
When BCD flag = 1, the decimal addition result is stored.
(2) ADD m, #n4
Add immediate data to data memory
8
<1> OP code
10
10000
7
8
7
mR
4
mC
3
0
9
n4
10
<2> Function
11
When CMP = 0, (m) ← (m) + n4
12
Adds immediate data to the data memory contents, and stores the result in data memory.
13
When CMP = 1, (m) + n4
The result is not stored in the data memory. Carry flag CY and zero flag Z are changed, according to
14
the result.
15
Sets carry flag CY, if a carry occurs as a result of the addition; resets the carry flag if no carry occurs.
If the addition result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
16
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Addition can be executed in binary 4 bits or BCD. The BCD flag for the PSWORD specifies which kind of
17
addition is to be executed.
18
19
20
201
CHAPTER 19 INSTRUCTION SET
<3> Example 1
To add 5 to the address 0.2FH contents, and store the result in address 0.2FH:
(0.2FH) ← (0.2FH) + 5
MEM02F
MEM 0.2FH
ADD
MEM02F, #05H
Example 2
To add 5 to the address 0.6FH contents and store the result in address 0.6FH. At this time, data memory
address 0.6FH can be specified by selecting data memory address 2FH, if IXE = 1, IXH = 0, IXM = 4,
and IXL = 0, i.e., IX = 0.40H.
(0.6FH) ← (0.6FH) + 05H
Address obtained as result of ORing index register contents, 0.40H,
and data memory address 0.2FH
MEM02F
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
MOV
IXL, #00H
SET1
IXE
ADD
MEM02F, #05H ; IX
; IXE flag ← 1
00001000000B (0.40H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00001101111B (0.6FH)
Example 3
To add 5 to the address 0.2FH contents and store the result in address 0.2FH. At this time, data memory
address 0.2FH can be specified by selecting data memory address 2FH, if IXE = 1, IXH = 0, IXM = 0,
and IXL = 0, i.e., IX = 0.00H.
(0.2FH) ← (0.2FH) + 05H
Address obtained as result of ORing index register contents, 0.00H,
and data memory address 0.2FH
MEM02F
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
IXH, #00H
; IX ← 00000000000B
MOV
IXM, #00H
MOV
IXL, #00H
SET1
IXE
ADD
MEM02F, #05H ; IX
; IXE flag ← 1
00000000000B (0.00H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00000101111B (0.2FH)
<4> Caution
When the CMP flag = 1, the addition result is not stored.
When the BCD flag = 1, the decimal addition result is stored.
202
CHAPTER 19 INSTRUCTION SET
(3) ADDC r, m
Add data memory to general register with carry flag
1
<1> OP code
10
00010
8
mR
7
4
mC
3
2
0
r
3
4
<2> Function
When CMP = 0, (r) ← (r) + (m) + CY
5
Adds the data memory contents to the general register contents with carry flag CY, and stores the result
6
in general register.
7
When CMP = 1, (r) + (m) + CY
The result is not stored in the register. Carry flag CY and zero flag Z are changed according to the result.
By using this ADDC instruction, one or more nibbles can be easily added.
8
9
Sets carry flag CY, if a carry occurs as a result of the addition; resets the carry flag if no carry occurs.
If the addition result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
10
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Addition can be executed in binary 4 bits or BCD. The BCD flag for PSWORD specifies which kind of addition
11
is to be executed.
12
<3> Example 1
To add the 12-bit contents for addresses 0.0DH through 0.0FH to the 12-bit contents for addresses 0.2DH
13
through 0.2FH, and store the result in the 12-bit contents for address 0.0DH to 0.0FH, when row address
0 (0.00H–0.0FH) of bank 0 is specified as a general register:
14
(0.0FH) ← (0.0FH) + (0.2FH)
(0.0EH) ← (0.0EH) + (0.2EH) + CY
15
(0.0DH) ← (0.0DH) + (0.2DH) + CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MEM02D
MEM
0.2DH
MEM02E
MEM
0.2EH
MEM02F
16
17
MEM
0.2FH
MOV
BANK,
MOV
RPH,
#00H
; General register bank 0
MOV
RPL,
#00H
; General register row address 0
ADD
MEM00F, MEM02F
ADDC
MEM00E, MEM02E
ADDC
MEM00D, MEM02D ; High-order nibble
#00H
18
; Data memory bank 0
19
; Low-order nibble
20
203
CHAPTER 19 INSTRUCTION SET
Example 2
To shift the 12-bit contents for addresses 0.2DH through 0.2FH 1 bit to the left, when row address 2 in
bank 0 (0.20H–0.2FH) is specified as a general register:
CY
(carry flag)
Bank 0
Address 0DH
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MEM02D
MEM
0.2DH
MEM02E
MEM
0.2EH
MEM02F
Bank 0
Address 0EH
Bank 0
Address 0FH
MEM
0.2FH
MOV
RPH, #00H
MOV
RPL, #04H
; General register row address 2
MOV
BANK, #00H
; Data memory bank 0
ADDC
MEM00F, MEM02F
ADDC
MEM00E, MEM02E
ADDC
MEM00D, MEM02D
CY
(carry flag)
; General register bank 0
Example 3
To add the address 0.0FH contents to the addresses 0.40H through 0.4FH contents, and store the result
in address 0.0FH:
(0.0FH) ← (0.0FH) + (0.40H) + (0.41H) + ... + (0.4FH)
MEM00F
MEM
0.0FH
MEM000
MEM
0.00H
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
MOV
IXL, #00H
SET1
IXE
ADD
MEM00F, MEM000
CLR1
IXE
; IXE flag ← 0
INC
IX
; IX ← IX + 1
LOOP1:
204
SKE
IXL, #0
JMP
LOOP1
; IXE flag ← 1
CHAPTER 19 INSTRUCTION SET
Example 4
1
To add the 12-bit contents for addresses 0.40H through 0.42H to the 12-bit contents for addresses 0.0DH
through 0.0FH, and store the result in 12-bit contents for addresses 0.0DH through 0.0FH:
2
(0.0DH) ← (0.0DH) + (0.40H)
(0.0EH) ← (0.0EH) + (0.41H) + CY
3
(0.0FH) ← (0.0FH) + (0.42H) + CY
MEM000
MEM
0.00H
MEM001
MEM
0.01H
MEM002
MEM
0.02H
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX 00001000000 (0.40H)
MOV
IXM, #04H
MOV
IXL, #00H
SET1
IXE
; IXE flag ← 1
ADD
MEM00D, MEM000
; (0.0DH) ← (0.0DH) + (0.40H) ; Low-order nibble
ADDC
MEM00E, MEM001
; (0.0EH) ← (0.0EH) + (0.41H)
ADDC
MEM00F, MEM002
; (0.0FH) ← (0.0FH) + (0.42H) ; High-order nibble
4
5
6
7
8
(4) ADDC m, #n4
9
10
Add immediate data to data memory with carry flag
11
12
<1> OP code
10
10010
8
mR
7
4
mC
3
0
13
n4
14
<2> Function
When CMP = 0, (m) ← (m) + n4 + CY
15
Adds immediate data to the data memory contents with carry flag (CY), and stores the result in data
16
memory.
17
When CMP = 1, (m) + n4 + CY
The result is not stored in the data memory, and carry flag CY and zero flag Z are changed, according
18
to the result.
19
Sets carry flag CY, if a carry occurs as a result of the addition. Resets the carry flag, if no carry occurs.
If the addition result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
20
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Addition can be executed in binary or BCD. The BCD flag for PSWORD specifies which kind of addition is
to be executed.
205
CHAPTER 19 INSTRUCTION SET
<3> Example 1
To add 5 to the 12-bit contents for addresses 0.0DH through 0.0FH, and store the result in addresses
0.0DH through 0.0FH;
(0.0FH) ← (0.0FH) + 05H
(0.0EH) ← (0.0EH) + CY
(0.0DH) ← (0.0DH) + CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MOV
BANK, #00H
ADD
MEM00F, #05H
ADDC
MEM00E, #00H
ADDC
MEM00D, #00H
; Data memory bank 0
Example 2
To add 5 to the 12-bit contents for addresses 0.4DH through 0.4FH and store the result in addresses
0.4DH through 0.4FH:
(0.4FH) ← (0.4FH) + 05H
(0.4EH) ← (0.4EH) + CY
(0.4DH) ← (0.4DH) + CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MOV
BANK, #00H
; Data memory bank 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
MOV
IXL, #00H
SET1
IXE
; IXE flag ← 1
ADD
MEM00F, #5
; (0.4FH) ← (0.4FH) + 5H
ADDC
MEM00E, #0
; (0.4EH) ← (0.4EH) + CY
ADDC
MEM00D, #0
; (0.4DH) ← (0.4DH) + CY
(5) INC AR
Increment address register
<1> OP code
10
00111
8
000
7
4
1001
3
0
0000
<2> Function
AR ← AR + 1
Increments the address register AR contents.
206
CHAPTER 19 INSTRUCTION SET
<3> Example 1
1
To add 1 to the 16-bit contents for AR3 through AR0 (address registers) in the system register and store
the result in AR3 through AR0:
2
AR0 ← AR0 + 1
AR1 ← AR1 + CY
3
AR2 ← AR2 + CY
AR3 ← AR3 + CY
4
INC AR
This program can be rewritten as follows, with addition instructions:
ADD
AR0,
#01H
ADDC
AR1,
#00H
ADDC
AR2,
#00H
ADDC
AR3,
#00H
5
6
7
Example 2
To transfer table data, 16 bits (1 address) at a time, to DBF (data buffer), using the table reference
8
instruction (for details, refer to 10.2.3 Table Reference):
9
; Address
Table data
ORG
10H
DW
0F3FFH
10
DW
0A123H
DW
0FFF1H
DW
0FFF5H
DW
..
..
..
..
0FF11H
MOV
AR3, #0H
; Table data address
MOV
AR2, #0H
; 0010H in address register
MOV
AR1, #1H
;
MOV
AR0, #0H
MOVT
DBF, @AR
11
12
13
14
15
LOOP:
; Reads table data to DBF
16
:
:
:
17
; Table data reference processing
:
INC
AR
BR
LOOP
18
; Increments address register by 1
19
<4> Caution
20
The numbers of bits, for address registers AR3 through AR0, differ, depending on the microcontroller
model to be used.
•
µPD17134A/17135A
•
µPD17136A/17137A/17P136A/17P137A : 11 bits
: 10 bits
207
CHAPTER 19 INSTRUCTION SET
(6) INC IX
Increment index register
<1> OP code
10
00111
8
7
000
4
3
1000
0
0000
<2> Function
IX ← IX + 1
Increments the index register IX contents.
<3> Example 1
To add 1 to the 12-bit contents for IXH, IXM, and IXL (index registers) in the system register and store
the result in IXH, IXM, and IXL;
IXL ← IXL + 1
IXM ← IXM + CY
IXH ← IXH + CY
INC IX
This program can be rewritten as follows, with addition instructions:
ADD
IXL, #01H
ADDC
IXM, #00H
ADDC
IXH, #00H
Example 2
To clear all the contents for data memory addresses 0.00H through 0.73H, using the index register:
MEM000
MEM0.00H
MOV
IXH, #00H
; Sets index register contents in 00H in bank 0
MOV
IXM, #00H
;
MOV
IXL, #00H
SET1
IXE
; IXE flag ← 1
MOV
MEM000, #00H
; Writes 0 to data memory indicated by index register
CLR1
IXE
; IXE flag ← 0
INC
IX
SET2
CMP, Z
RAM clear:
208
; CMP flag ← 1, Z flag ← 1
SUB
IXL, #03H
; Checks whether index register contents
SUBC
IXM, #07H
; are 73H in bank 0
SUBC
IXH, #00H
;
SKT1
Z
; Loops until contents of index register becomes
BR
RAM clear
; 73H of bank 0
CHAPTER 19 INSTRUCTION SET
19.5.2 Subtraction Instructions
1
(1) SUB r, m
Subtract data memory from general register
2
<1> OP code
10
00001
8
7
mR
4
3
mC
3
0
r
4
5
<2> Function
When CMP = 0, (r) ← (r) – (m)
6
Subtracts the data memory contents from the general register contents, and stores the result in general
register.
7
When CMP = 1, (r) – (m)
8
The result is not stored in the register. Carry flag CY and zero flag Z are changed, according to the result.
9
Sets carry flag CY, if a borrow occurs as a result of the subtraction. Resets the carry flag, if no borrow occurs.
If the subtraction result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
10
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
11
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Subtraction can be executed in binary 4 bits or BCD. The BCD flag for PSWORD specifies which kind of
subtraction is to be executed.
12
<3> Example 1
13
To subtract the address 0.2FH contents from the address 0.03H contents, store the result in address
0.03H, when row address 0 (0.00H–0.0FH) in bank 0 is specified as a general register (RPH = 0, RPL
= 0):
14
(0.03H) ← (0.03H) + (0.2FH)
MEM003
MEM
0.03H
MEM02F
MEM
0.2FH
SUB
MEM003, MEM02F
15
16
Example 2
17
To subtract the address 0.2FH contents from the address 0.23H contents, when row address 2 (0.20H–
0.2FH) in bank 0 is specified as the general register (RPH = 0, RPL = 4), and store the result in address
18
0.23H:
(0.23H) ← (0.23H) – (0.2FH)
19
MEM023
MEM
0.23H
MEM02F
MEM
0.2FH
MOV
BANK, #00H
;
Data memory bank 0
MOV
RPH, #00H
;
General register bank 0
MOV
RPL, #04H
;
General register row address 2
SUB
MEM023, MEM02F
20
209
CHAPTER 19 INSTRUCTION SET
Example 3
To subtract the address 0.6FH contents from the address 0.03H contents and store result in address
0.03H. At this time, data memory address 0.6FH can be specified by selecting data memory address
2FH, if IXE = 1, IXH = 0, IXM = 4, and IXL = 0, i.e., IX = 0.40H.
(0.03H) ← (0.03H) + (0.6FH)
MEM003
MEM02F
MEM
0.03H
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
;
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEM003, MEM02F
; IX 00001000000B (0.40H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00001101111B (0.6FH)
Example 4
To subtract the address 0.3FH contents from the address 0.03H contents and store result in address
0.03H. At this time, data memory address 0.3FH can be specified by selecting data memory address
2FH, if IXE = 1, IXH = 0, IXM = 1, and IXL = 0, i.e., IX = 0.10H.
(0.03H) ← (0.03H) + (0.3FH)
MEM003
MEM
0.03H
MEM02F
MEM
0.2FH
MOV
BANK #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00000010000B (0.10H)
MOV
IXM, #01H
;
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEM003, MEM02F
; IX 00000010000B (0.10H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
210
00000111111B (0.3FH)
CHAPTER 19 INSTRUCTION SET
<4> Caution
1
The first operand for the SUB r, m instruction is a general register address. Therefore, if the instruction
is described as follows, the general register address is 03H:
MEM013
MEM
MEM02F
2
0.13H
MEM
0.2FH
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
SUB
MEM013, MEM02F
3
4
Specify general register in 00H–0FH range
5
(set register pointer row address other than 1).
When the CMP flag = 1, the subtraction result is not stored.
When the BCD flag = 1, the decimal subtraction result is stored.
(2) SUB m, #n4
6
Subtract immediate data from data memory
7
<1> OP code
8
10
10001
8
7
mR
4
3
mC
0
9
n4
10
<2> Function
When CMP = 0, (m) ← (m) – n4
11
Subtracts immediate data from the data memory contents, and stores the result in data memory.
12
When CMP = 1, (m) – n4
13
The result is not stored in data memory. Carry flag CY and zero flag Z are changed, according to the
result.
Sets carry flag CY, if a borrow occurs as a result of the subtraction. Resets the carry flag, if no borrow occurs.
14
15
If the subtraction result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
16
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Subtraction can be executed in binary 4 bits or BCD. The BCD flag for PSWORD specifies which kind of
subtraction is to be executed.
17
18
<3> Example 1
19
To subtract 5 from the address 0.2FH contents, and store the result in address 0.2FH:
(0.2FH) ← (0.2FH) – 5
MEM02F
MEM
0.2FH
SUB
MEM02F, #05H
20
211
CHAPTER 19 INSTRUCTION SET
Example 2
To subtract 5 from the address 0.6FH contents and store the result in address 0.6FH. At this time, data
memory address 0.6FH can be specified by selecting data memory address 2FH, if IXE = 1, IXH = 0,
IXM = 4, and IXL = 0, i.e., IX = 0.40H.
(0.6FH) ← (0.6FH) – 5
Address obtained as a result of ORing index register contents,
0.40H, and data memory address 0.2FH
MEM02F
MEM
0.2FH
MOV
BANK, #00H
; Data memory bank 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
;
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEM02F, #05H ; IX
00001000000B (0.40H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
00001101111B (0.6FH)
Example 3
To subtract 5 from the address 0.2FH contents and store the result in address 0.2FH. At this time, data
memory address 0.2FH can be specified by selecting data memory address 2FH, if IXE = 1, IXH = 0,
IXM = 0, and IXL = 0, i.e., IX = 0.00H.
(0.2FH) ← (0.2FH) – 5
Address obtained as a result of ORing index register contents,
0.00H, and data memory address 0.2FH
MEM02F
MEM
0.2FH
MOV
BANK0, #00H
; Data memory bank 0
MOV
IXH, #00H
; IX ← 00000000000B (0.00H)
MOV
IXM, #00H
;
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEM02F, #05H ; IX
00000000000B (0.00H)
; Bank operand OR ) 00000101111B (0.2FH)
; Specified address
(3) SUBC r, m
Subtract data memory from general register with carry flag
<1> OP code
10
00011
212
00000101111B (0.2FH)
8
mR
7
4
mc
3
0
r
CHAPTER 19 INSTRUCTION SET
<2> Function
1
When CMP = 0, (r) ← (r) – (m) – CY
2
Subtracts the data memory contents from the general register contents with carry flag CY. Stores the
result in general register. By using this SUBC instruction, 2 or more words can be easily subtracted.
3
When CMP = 1, (r) – (m) – CY
4
The result is not stored in the register. Carry flag CY and zero flag Z are changed, according to the result.
5
Sets carry flag CY, if a borrow occurs as a result of the subtraction. Resets the carry flag, if no borrow occurs.
If the subtraction result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
6
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Subtraction can be executed in binary 4 bits or BCD. The BCD flag for PSWORD specifies which kind of
7
subtraction is to be executed.
8
<3> Example 1
9
To subtract the 12-bit contents for addresses 0.2DH through 0.2FH from the 12-bit contents for
addresses 0.0DH through 0.0FH and store the result in 12 bits for addresses 0.0DH through 0.0FH, when
row address 0 (0.00H–0.0FH) in bank 0 is specified as a general register:
(0.0FH) ← (0.0FH) – (0.2FH)
10
11
(0.0EH) ← (0.0EH) – (0.2EH) – CY
(0.0DH) ← (0.0DH) + (0.2DH) – CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MEM02D
MEM
0.2DH
MEM02E
MEM
0.2EH
MEM02F
MEM
0.2FH
SUB
MEM00F, MEM02F
SUBC
MEM00E, MEM02E
SUBC
MEM00D, MEM02D
12
13
14
; Low-order nibble
15
; High-order nibble
16
17
18
19
20
213
CHAPTER 19 INSTRUCTION SET
Example 2
To subtract the 12-bit contents for addresses 0.40H through 0.42H from the 12-bit contents for addresses
0.0DH through 0.0FH, and store the result in 12 bits for addresses 0.0DH through 0.0FH:
(0.0DH) ← (0.0DH) – (0.40H)
(0.0EH) ← (0.0EH) – (0.41H) – CY
(0.0FH) ← (0.0FH) + (0.42H) – CY
MEM000
MEM
0.00H
MEM001
MEM
0.01H
MEM002
MEM
0.02H
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MOV
BANK, #00H
; Data memory bank 0
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
;
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEMOOD, MEM000
; (0.0DH) ← (0.0DH) – (0.40H)
SUBC
MEM00E, MEM001
; (0.0EH) ← (0.0EH) – (0.41H)
SUBC
MEM00F, MEM002
; (0.0FH) ← (0.0FH) – (0.42H)
(4) SUBC m, #n4
Subtract immediate data from data memory with carry flag
<1> OP code
10
10011
8
mR
7
4
mc
3
0
n4
<2> Function
When CMP = 0, (m) ← (m) – n4 – CY
Subtracts immediate data from the data memory contents with carry flag CY, and stores the result in
data memory.
When CMP = 1, (m) – n4 – CY
The result is not stored in the register. Carry flag CY and zero flag Z are changed, according to the result.
Sets carry flag CY, if a borrow occurs as a result of the subtraction. Resets the carry flag, if no borrow occurs.
If the subtraction result is other than zero, zero flag Z is reset, regardless of compare flag CMP.
If the result is zero with the compare flag reset (CMP = 0), the zero flag Z is set.
If the result is zero with the compare flag set (CMP = 1), the zero flag Z is not changed.
Subtraction can be executed in binary or BCD. The BCD flag for PSWORD specifies which kind of subtraction
is to be executed.
214
CHAPTER 19 INSTRUCTION SET
<3> Example 1
1
To subtract 5 from the 12-bit contents for addresses 0.0DH through 0.0FH and store the result in 12 bits
2
for addresses 0.0DH through 0.0FH:
(0.0FH) ← (0.0FH) – 05H
(0.0EH) ← (0.0EH) – CY
3
(0.0DH) ← (0.0DH) – CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
SUB
MEM00F, #05H
SUBC
MEM00E, #00H
SUBC
MEM00D, #00H
4
5
6
Example 2
7
To subtract 5 from the 12-bit contents for addresses 0.4DH through 0.4FH and store the result in
8
addresses 0.4DH through 0.4FH:
(0.4FH) ← (0.4FH) – 05H
(0.4EH) ← (0.4EH) – CY
9
(0.4DH) ← (0.4DH) – CY
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
10
MEM
0.0FH
MOV
BANK, #00H
MOV
IXH, #00H
; IX ← 00001000000B (0.40H)
MOV
IXM, #04H
;
11
; Data memory bank 0
MOV
IXL, #00H
;
SET1
IXE
; IXE flag ← 1
SUB
MEM00F, #5
; (0.4FH) ← (0.4FH) – 5
SUBC
MEM00E, #0
; (0.4EH) ← (0.4EH) – CY
SUBC
MEM00D, #0
; (0.4DH) ← (0.4DH) – CY
12
13
14
15
16
17
18
19
20
215
CHAPTER 19 INSTRUCTION SET
19.5.3 Logical Operation Instructions
(1) OR r, m
OR between general register and data memory
<1> OP code
10
8
00110
7
mR
4
3
mc
0
r
<2> Function
(r) ← (r) v (m)
ORs the general register contents with data memory. Stores the result in general register.
<3> Example 1
To OR the address 0.03H contents (1010B) and the address 0.2FH contents (0111B) and store the result
(1111B) in address 0.03H:
(0.03H) ← (0.03H) v (0.2FH)
1
0
1
0
Address 03H
OR
0
1
1
1
Address 2FH
1
1
1
1
Address 03H
MEM003 MEM
0.03H
MEM02F MEM
0.2FH
MOV
MEM003, #1010B
MOV
MEM02F, #0111B
OR
MEM003, MEM02F
(2) OR m, #n4
OR between data memory and immediate data
<1> OP code
10
10110
216
8
mR
7
4
mc
3
0
n4
CHAPTER 19 INSTRUCTION SET
<2> Function
1
(m) ← (m) v n4
2
ORs the data memory contents and immediate data. Stores the result in data memory.
3
<3> Example 1
4
To set bit 3 (MSB) for address 0.03H:
(0.03H) ← (0.03H) v 1000B
5
Address 0.03H
1
×
×
MEM003
×
×: don't care
6
MEM
0.03H
OR
MEM003, #1000B
7
8
Example 2
To set all the bits for address 0.03H:
MEM003
9
MEM
0.03H
OR
MEM003, #1111B
MEM
0.03H
MOV
MEM003, #0FH
10
or,
MEM003
(3) AND r, m
11
AND between general register and data memory
<1> OP code
12
13
10
8
7
4
3
0
14
00100
mR
mc
r
15
<2> Function
16
v
(r) ← (r)
(m)
17
ANDs the general register contents with data memory and stores the result in general register.
18
19
20
217
CHAPTER 19 INSTRUCTION SET
<3> Example
To AND the address 0.03H (1010B) contents and the address 0.2FH (0110B) contents. To store the
result (0010B) in address 0.03H:
(0.03H) ← (0.03H) (0.2FH)
V
1
0
1
0
Address 03H
AND
0
1
1
0
Address 2FH
0
0
1
0
Address 03H
MEM003
MEM
0.03H
MEM02F
MEM
0.2FH
MOV
MEM003, #1010B
MOV
MEM02F, #0110B
AND
MEM003, MEM02F
(4) AND m, #n4
AND between data memory and immediate data
<1> OP code
10
11110
8
7
mR
4
3
mc
0
n
<2> Function
(m) ← (m) n4
v
ANDs the data memory contents and immediate data. Stores the result in data memory.
<3> Example 1
To reset bit 3 (MSB) for address 0.03H:
(0.03H) ← (0.03H) 0111B
v
Address 0.03H
0
×
MEM003
218
×
×
×: don't care
MEM
0.03H
AND
MEM003, #0111B
CHAPTER 19 INSTRUCTION SET
Example 2
1
To reset all the bits for address 0.03H:
MEM003
MEM
0.03H
AND
MEM003, #0000B
MEM
0.03H
MOV
MEM003, #00H
2
or,
MEM003
3
4
(5) XOR r, m
Exclusive OR between general register and data memory
5
<1> OP code
10
8
00101
7
mR
4
3
mc
6
0
r
7
<2> Function
8
(r) ← (r) v (m)
9
Exclusive-ORs the general register contents with data memory. Stores the result in general register.
10
<3> Example 1
11
To compare the address 0.03H contents and the address 0.0FH contents. If different bits are found, set
and store them in address 0.03H. If all the bits in address 0.03H are reset (i.e., the address 0.03H
12
contents are the same as those for address 0.0FH), jumps to LBL1; otherwise, jumps to LBL2.
This example is for processing to compare the status of an alternate switch (address 0.03H contents)
13
with the internal status (address 0.0FH contents) and to branch to another processing, if the switch status
changes.
1
14
0
1
0
Address 03H
15
XOR
0
1
1
16
0
Address 0FH
17
1
1
0
0
18
Address 03H
Bits changed
19
MEM003
MEM
0.03H
MEM00F
MEM
0.0FH
XOR
MEM003, MEM00F
SKNE
MEM003, #00H
BR
LBL1
BR
LBL2
20
219
CHAPTER 19 INSTRUCTION SET
Example 2
To clear the address 0.03H contents:
0
1
0
1
Address 03H
XOR
0
1
0
1
Address 03H
0
0
0
0
Address 03H
MEM003
MEM
0.03H
XOR
MEM003, MEM003
(6) XOR m, #n4
Exclusive OR between data memory and immediate data
<1> OP code
10
10101
8
mR
7
4
3
mc
0
n4
<2> Function
(m) ← (m) v n4
Exclusive-ORs the data memory contents and immediate data. Stores the result in data memory.
<3> Example
To invert bits 1 and 3 in address 0.03H and store the result in address 03H:
1
1
0
0
Address 03H
XOR
1
0
1
0
0
1
1
0
Address 03H
Inverted bits
MEM003
220
MEM
0.03H
XOR
MEM003, #1010B
CHAPTER 19 INSTRUCTION SET
19.5.4 Judgment Instructions
1
(1) SKT m, #n
Skip next instruction if data memory bits are true
2
<1> OP code
10
11110
8
7
mR
4
3
3
0
mc
n
4
5
<2> Function
CMP ← 0, if (m) n = n, then skip
v
6
Skips the next one instruction, if the result of ANDing the data memory contents and immediate data
is equal to n. (Executes as NOP instruction)
7
8
<3> Example 1
To jump to AAA, if bit 0 in address 03H is 1; if it is 0, jumps to BBB:
SKT
03H, #0001B
BR
BBB
BR
AAA
9
10
Example 2
11
To skip the next instruction, if both bits 0 and 1 in address 03H are 1.
12
SKT
03H, #0011B
Skip condition 03H
b3
b2
b1
b0
×
×
1
1
13
×: don't care
14
Example 3
15
The results of executing the following two instructions are the same:
16
SKT
13H, #1111B
SKE
13H, #0FH
17
(2) SKF m, #n
Skip next instruction if data memory bits are false
18
<1> OP code
19
10
11111
8
mR
7
4
mc
3
0
20
n
221
CHAPTER 19 INSTRUCTION SET
<2> Function
CMP ← 0, if (m) n = 0, then skip
v
Skips the next one instruction, if the result of ANDing the data memory contents and immediate data
is 0 (Executes as NOP instruction).
<3> Example 1
To store immediate data 00H to address 0FH in the data memory, if bit 2 in address 13H is 0; if it is 1,
jumps to ABC:
MEM013
MEM
0.13H
MEM00F
MEM
0.0FH
SKF
MEM013, #0100B
BR
ABC
MOV
MEM00F, #00H
Example 2
To skip the next instruction, if both bits 3 and 0 in address 29H are 0.
SKF
29H, #1001B
Skip condition 29H
b3
b2
b1
b0
0
×
×
0
×: don't care
Example 3
The results of executing the following two instructions are the same:
222
SKF
34H, #1111B
SKE
34H, #00H
CHAPTER 19 INSTRUCTION SET
19.5.5 Comparison Instructions
1
(1) SKE m, #n4
Skip if data memory equal to immediate data
2
<1> OP code
3
10
01001
8
7
mR
4
3
mc
0
4
n4
5
<2> Function
6
(m) –n4, skip if zero
Skips the next one instruction, if the data memory contents are equal to the immediate data value
7
(Executes as NOP instruction).
8
<3> Example
9
To transfer 0FH to address 24H, if the address 24H contents are 0; if not, jumps to OPE1:
MEM024
OPE1
MEM
0.24H
SKE
MEM024, #00H
BR
OPE1
MOV
MEM024, #0FH
10
11
:
12
(2) SKNE m, #n4
Skip if data memory not equal to immediate data
13
<1> OP code
10
01011
8
7
mR
4
mc
3
14
0
n4
15
<2> Function
16
(m) –n4, skip if not zero
17
Skips the next one instruction, if the data memory contents are not equal to the immediate data value
18
(Executes as NOP instruction).
19
20
223
CHAPTER 19 INSTRUCTION SET
<3> Example
To jump to XYZ, if the asddress 1FH contents are 1 and the address 1EH contents are 3; otherwise,
jump to ABC.
To compare 8-bit data, this instruction is used in the following combination:
3
1EH
0
0
MEM01E
1
1
1FH
1
MEM
MEM01F
0
0
0
1
0.1EH
MEM
0.1FH
SKNE
MEM01F, #01H
SKE
MEM01E, #03H
BR
ABC
BR
XYZ
The above program can be rewritten as follows, using compare and zero flags:
MEM01E
MEM
MEM01F
0.1EH
MEM
0.1FH
SET2
CMP, Z
; CMP flag ← 1, Z flag ← 1
SUB
MEM01F, #01H
SUBC
MEM01E, #03H
SKT1
Z
BR
ABC
BR
XYZ
(3) SKGE m, #n4
Skip if data memory greater than or equal to immediate data
<1> OP code
10
11001
8
mR
7
4
mc
3
0
n4
<2> Function
(m) –n4, skip if not borrow
Skips the next one instruction, if the data memory contents are greater than or equal to the immediate
data value (Executes as NOP instruction).
224
CHAPTER 19 INSTRUCTION SET
<3> Example
1
To execute RET, if 8-bit data stored in addresses 1FH (high-order) and 2FH (low-order) is greater than
immediate data ‘17H’; if not, execute RETSK:
MEM01F
MEM
MEM02F
2
0.1FH
MEM
0.2FH
SKGE
MEM01F, #1
3
RETSK
SKNE
MEM01F, #1
SKLT
MEM02F, #8
4
;7+1
5
RET
RETSK
6
(4) SKLT m, #n4
Skip if data memory less than immediate data
7
<1> OP code
10
11011
8
7
mR
4
3
mc
0
8
n4
9
<2> Function
10
(m) –n4, skip if borrow
11
Skips the next one instruction, if the data memory contents are less than the immediate data value
12
(Executes as NOP instruction).
<3> Example
13
To store 01H in address 0FH, if the address 10H contents are greater than immediate data ‘6’; if not,
store 02H in address 0FH:
MEM00F
MEM
0.0FH
MEM010
MEM
0.10H
MOV
MEM00F, #02H
SKLT
MEM010, #06H
MOV
MEM00F, #01H
14
15
16
17
18
19
20
225
CHAPTER 19 INSTRUCTION SET
19.5.6 Rotation Instructions
(1) RORC r
Rotate right general register with carry flag
<1> OP code
3
00111
000
0111
0
r
<2> Function
CY
(r)b3
(r)b2
(r)b1
(r)b0
Rotates the contents of general register indicated by r to right by 1 bit including carry flag.
<3> Example 1
When row address 0 of bank 0 (0.00H – 0.0FH) is specified as general register (RPH = 0, RPL = 0), rotate
the value of address 0.00H (1000B) to right by 1 bit to make it 0100B.
(0.00H) ← (0.00H) ÷ 2
MEM000
MEM
0.00H
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
CLR1
CY
; CY flag ← 0
RORC
MEM000
Example 2
When row address 0 of bank 0 (0.00H – 0.0FH) is specified as general register (RPH = 0, RPL = 0), rotate
the data buffer DBF contents 0FA52H to right by 1 bit to make DBF contents 7D29H.
CY
0
226
0CH
0DH
0EH
CY
0FH
1
1
1
1
1
0
1
0
0
1
0
1
0
0
1
0
0
1
1
1
1
1
0
1
0
0
1
0
1
0
0
1
MEM00C
MEM
0.0CH
MEM00D
MEM
0.0DH
MEM00E
MEM
0.0EH
MEM00F
MEM
0.0FH
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
CLR1
CY
; CY flag ← 0
RORC
MEM00C
RORC
MEM00D
RORC
MEM00E
RORC
MEM00F
0
CHAPTER 19 INSTRUCTION SET
19.5.7 Transfer Instructions
1
(1) LD r, m
Load data memory to general register
2
<1> OP code
10
01000
8
7
mR
4
3
mc
3
0
r
4
<2> Function
5
(r) ← (m)
6
Stores the data memory contents to general register.
7
<3> Example 1
8
To store the address 0.2FH contents to address 0.03H:
(0.03H) ← (0.2FH)
MEM003
MEM
MEM02F
9
0.03H
MEM
0.2FH
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
LD
MEM003, MEM02F
10
11
12
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
13
F
General register
0
14
Row address
1
2
3
15
4
5
16
6
7
System register
17
18
19
20
227
CHAPTER 19 INSTRUCTION SET
Example 2
To store the address 0.6FH contents to address 0.03H. At this time, data memory address 0.6FH can
be specified by selecting data memory address 2FH, if IXE = 1, IXH = 0, IXM = 4, and IXL = 0, i.e., IX
= 0.40H.
IXH ← 00H
IXM ← 04H
IXL ← 00H
IXE flag ← 1
(0.03H) ← (0.6FH)
Address obtained as result of ORing index register contents, 040H,
and data memory contents, 0.2FH
MEM003
MEM
MEM02F
0.03H
MEM
0.2FH
MOV
IXH, #00H
MOV
IXM, #04H
MOV
IXL, #00H
1
; IXE flag ← 1
SET1
IXE
LD
MEM003, MEM02F
Bank 0
0
; IX ← 00001000000B (0.40H)
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
General register
0
Row address
1
2
3
4
5
6
7
System register
(2) ST m, r
Store general register to data memory
<1> OP code
10
11000
8
mR
7
4
mc
3
0
r
<2> Function
(m) ← (r)
Stores the general register contents to data memory.
228
CHAPTER 19 INSTRUCTION SET
<3> Example 1
1
To store the address 0.03H contents to address 0.2FH:
(0.2FH) ← (0.03H)
MOV
RPH, #00H
2
; General register bank 0
MOV
RPL, #00H
; General register row address 0
ST
2FH, 03H
; Transfers general register contents to data memory
Bank 0
0
1
3
4
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
5
General register
0
Row address
1
6
2
3
7
4
5
8
6
7
System register
9
Example 2
To store the address 0.00H contents to addresses 0.18H through 0.1FH. The data memory addresses
10
(18H – 1FH) are specified by the index register.
11
(0.18H) ← (0.00H)
(0.19H) ← (0.00H)
..
..
..
..
..
.
(0.1FH) ← (0.00H)
12
13
MOV
IXH, #00H
MOV
IXM, #00H
MOV
IXL, #00H
MEM018
MEM
0.18H
MEM000
MEM
0.00H
SET1
IXE
; IX ← 00000000000B (0.00H)
14
; Specifies data memory address 0.00H
15
LOOP1:
16
; IXE flag ← 1
ST
MEM018, MEM000
; (0.1✕H) ← (0.00H)
CLR1
IXE
; IXE flag ← 0
INC
IX
; IX ← IX + 1
SKGE
IXL, #08H
BR
LOOP1
17
18
19
20
229
CHAPTER 19 INSTRUCTION SET
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
General register
0
Row address
1
2
3
4
5
6
7
System register
(3) MOV @r, m
Move data memory to destination indirect
<1> OP code
10
01010
8
7
4
mR
3
mc
0
r
<2> Function
When MPE = 1
((MP), (r)) ← (m)
When MPE = 0
(BANK, mR, (r)) ← (m)
Stores the data memory contents to the data memory addressed by the general register contents. When
MPE = 0, transfer is performed in the same row address in the same bank.
<3> Example 1
To store the address 0.20H contents to address 0.2FH with the MPE flag cleared to 0. The transfer
destination data memory address is at the same row address as the transfer source, and the column
address is specified by the general register contents at address 0.00H.
(0.2FH) ← (0.20H)
230
MEM000
MEM
0.00H
MEM020
MEM
0.20H
CLR1
MPE
; MPE flag ← 0
MOV
MEM000, #0FH
; Sets column address in general register
MOV
@MEM000, MEM020
; Store
CHAPTER 19 INSTRUCTION SET
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
General register
F
0
1
F
2
Row address
1
2
3
3
4
4
5
6
7
5
System register
6
Example 2
To store the address 0.20H contents to address 0.3FH, with the MPE flag set to 1. The row address
7
for the transfer destination data memory address is specified by the memory pointer MP contents. The
8
column address is specified by the general register contents at address 0.00H.
(0.3FH) ← (0.20H)
MEM000
MEM
0.00H
MEM020
MEM
0.20H
MOV
RPH, #00H
; General register bank 0
MOV
RPL, #00H
; General register row address 0
MOV
MEM000, #0FH
; Sets column address in general register
MOV
MPH, #00H
; Sets row address in memory pointer
9
MOV
MPL, #03H
;
SET1
MPE
; MPE flag ← 1
MOV
@MEM000, MEM020
; Store
10
11
12
13
Bank 0
0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
14
General register
F
Row address
1
15
2
3
16
4
5
17
6
7
System register
(4) MOV m, @r
18
Move data memory to destination indirect
<1> OP code
20
10
11010
19
8
mR
7
4
mc
3
0
r
231
CHAPTER 19 INSTRUCTION SET
<2> Function
When MPE = 1
(m) ← (MP, (r))
When MPE = 0
(m) ← (BANK, mR, (r))
Stores the data memory contents addressed by the general register contents to data memory. When
MPE = 0, transfer is performed in the same row address in the same bank.
<3> Example 1
To store the address 0.2FH contents to address 0.20H, with the MPE flag cleared to 0. The transfer
destination data memory address is at the same row address as the transfer source. The column address
is specified by the general register contents at address 0.00H.
(0.20H) ← (0.2FH)
MEM000
MEM
0.00H
MEM020
MEM
0.20H
CLR1
MPE
; MPE flag ← 0
MOV
MEM000, #0FH
; Sets column address in general register
MOV
MEM020, @MEM000
; Store
Bank 0
0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
General register
F
Row address
1
2
3
4
5
6
7
System register
Example 2
To store the address 0.3FH contents to address 0.20H, with the MPE flag set to 1. The row address
for the transfer source data memory address is specified by the memory pointer MP contents. The
column address is specified by the general register contents at address 0.00H.
(0.20H) ← (0.3FH)
232
MEM000
MEM
0.00H
MEM020
MEM
0.20H
MOV
MEM000, #0FH
; Sets column address in general register
MOV
MPH, #00H
; Sets row address in memory pointer
MOV
MPL, #03H
;
SET1
MPE
; MPE flag ← 1
MOV
MEM020, @MEM000
; Store
CHAPTER 19 INSTRUCTION SET
Bank 0
0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
1
F
General register
F
2
Row address
1
2
3
3
4
4
5
6
7
5
System register
6
(5) MOV m, #n4
Move immediate data to data memory
7
<1> OP code
10
8
7
4
3
0
8
11101
mR
mc
n4
9
<2> Function
10
(m) ← n4
11
Stores immediate data to data memory.
12
<3> Example 1
To store immediate data 0AH to data memory address 0.50H:
13
(0.5H) ← 0AH
MEM050
MEM
0.50H
MOV
MEM050, #0AH
14
Example 2
15
To store immediate data 07H to address 0.32H, when data memory address 0.00H is specified with IXH
16
= 0, IXM = 3, IXL = 2, and IXE flag = 1:
(0.32H) ← 07H
MEM000
MEM
0.00H
MOV
IXH, #00H
MOV
IXM, #03H
MOV
IXL, #02H
SET1
IXE
MOV
MEM000, #07H
17
; IX ← 00000110010B (0.32H)
18
; IXE flag ← 1
19
20
233
CHAPTER 19 INSTRUCTION SET
(6) MOVT DBF, @AR
Move program memory data specified by AR to DBF
<1> OP code
10
00111
8
7
000
4
0001
3
0
0000
<2> Function
SP ← SP – 1, ASR ← PC, PC ← AR,
DBF ← (PC), PC ← ASR, SP ← SP + 1
Stores the program memory contents, addressed by address register AR, to data buffer DBF.
Since this instruction temporarily uses one stack level, pay attention to nesting for subroutines and
interrupts.
<3> Example
To transfer 16 bits of table data, specified by the values for address registers AR3, AR2, AR1, and AR0
in the system register, to data buffers DBF3, DBF2, DBF1, and DBF0:
;*
; ** Table data
;*
ORG
0010H
DW
0000000000000000B
; (0000H)
DW
1010101111001101B
..
..
..
..
..
; (0ABCDH)
;*
; ** Table reference program
;*
MOV
AR3, #00H
; AR3 ← 00H Sets 0011H in address register
MOV
AR2, #00H
; AR2 ← 00H
MOV
AR1, #01H
; AR1 ← 01H
MOV
AR0, #01H
; AR0 ← 01H
MOVT
DBF, @AR
; Transfers address 0011H data to DBF
In this case, the data are stored in DBF, as follows:
DBF3 = 0AH
DBF2 = 0BH
DBF1 = 0CH
DBF0 = 0DH
234
CHAPTER 19 INSTRUCTION SET
(7) PUSH AR
Push address register
1
<1> OP code
2
00111
000
1101
0000
3
<2> Function
4
SP ← SP – 1,
ASR ← AR
5
Decrements stack pointer SP and stores the address register AR value to address stack register
6
specified by stack pointer.
7
<3> Example 1
8
To set 003FH in address register and store it in stack:
MOV
AR3, #00H
MOV
AR2, #00H
MOV
AR1, #03H
MOV
AR0, #0FH
PUSH
AR
9
10
11
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
12
S
0
T
A
C
K
Row address
1
13
2
3
14
4
5
0
0
3
F
6
7
0
0
3
15
F
16
System register
17
18
19
20
235
CHAPTER 19 INSTRUCTION SET
Example 2
To set the return address (next address of the data table) for a subroutine in the address register. Returns
execution, if a data table exists after a subroutine:
............
ORG
10H
DW
DW
DW
DW
1A1FH
002FH
010AH
0555H
..................
DW
ORG
SUB1:
............
SUB1
CALL
;*
;** DATA TABLE
;*
POP
AR
MOV
AR3, #00H
MOV
AR2, #00H
MOV
AR1, #03H
MOV
AR0, #00H
PUSH
AR
RET
0FFFH
30H
..................
If POP instruction is executed at
this time, the contents of address
register is “0011H” (the next address
of CALL instruction).
236
CHAPTER 19 INSTRUCTION SET
(8) POP AR
Pop address register
1
<1> OP code
2
00111
000
1100
0000
3
<2> Function
4
AR ← ASR,
SP ← SP + 1
5
Pops the contents of address stack register indicated by stack pointer to address register AR and then
6
increments stack pointer SP.
7
<3> Example
If the PSW contents are changed, while an interrupt processing routine is being executed, the PSW
8
contents are transferred to the address register through WR at the beginning of the interrupt processing
and saved to address stack register by the PUSH instruction. Before the execution returns from the
9
interrupt routine, the address register contents are restored through WR to PSW by the POP instruction.
10
....................
EI
11
WR, PSW
AR0, WR
AR
PEEK
POKE
PUSH
12
...........................................
................... ....................................................
Generates
interrupt source
Interrupt processing routine
13
14
15
POP
AR
PEEK
WR, AR0
POKE
PSW, WR
RET (or RETI)
16
17
18
19
20
237
CHAPTER 19 INSTRUCTION SET
(9) PEEK WR, rf
Peek register file to window register
<1> OP code
10
8
00111
7
rfR
4
3
0
0011
rfC
<2> Function
WR ← (rf)
Stores the register file contents to window register WR.
<3> Example 1
To store the stack pointer SP contents at address 01H in the register file to the window register:
PEEK WR, SP
Bank 0
0
Column address
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
Row address
1
2
3
4
5
6
7
WR
System register
Column address
Row address
0
0
1
2
3
4
SP
1
2
3
Register file
238
5
6
7
8
9
A
B
C
D
E
F
CHAPTER 19 INSTRUCTION SET
(10) POKE rf, WR
Poke window register to register file
1
<1> OP code
10
00111
8
7
rfR
4
3
0010
2
0
rfC
3
<2> Function
4
(rf) ← WR
5
Stores the window register WR contents to register file.
6
<3> Example
7
To store immediate data 0FH to P0DBIO for the register file through the window register:
MOV
WR, #0FH
POKE
P0DBIO, WR
8
; Sets all of P0D0, P0D1, P0D2, and P0D3 in output mode
9
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
0
11
2
3
12
4
5
13
6
7
WR
System register
14
15
Column address
0
Row address
Row address
1
1
2
3
4
5
6
7
8
9
16
A
B
C
D
E
F
17
0
1
18
2
3
Register file
19
P0DBIO
20
239
CHAPTER 19 INSTRUCTION SET
<4> Caution
It seems that the same addresses 40H through 7FH of the data memory exist at addresses 40H through
7FH of the register file as for as the program is concerned.
The PEEK and POKE instructions can access addresses 40H through 7FH in each data memory bank,
in addition to the register file. For example, these instructions can be used as follows:
MEM05F
MEM
0.5FH
PEEK
WR, PSW
; Stores PSW (7FH) contents in system register to WR
POKE
MEM05F, WR
; Stores WR contents to address 5FH in data memory
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
Row address
1
Register file
2
3
POKE
4
5FH, WR
5
Data memory
6
7
WR
PSW
PEEK
System register
WR, PSW
(11) GET DBF, p
Get peripheral data to data buffer
<1> OP code
10
00111
8
pH
7
4
1011
3
0
pL
<2> Function
DBF ← (p)
Stores the peripheral register contents to data buffer DBF.
DBF is a 16-bit area of addresses 0H through 0FH of BANK0 of the data memory regardless of the value
of the bank register.
<3> Example
To store the 8-bit contents for shift register SIOSFR in the serial interface to data buffers DBF0 and DBF1:
GET
240
DBF, SIOSFR
CHAPTER 19 INSTRUCTION SET
Bank 0
0
1
Column address
2
3
4
5
6
7
8
9
A
B
C
D
0
E
F
1
2
1
DBF
2
Row address
1
2
Peripheral
hardware
register
3
4
3
4
5
6
12H
SIOSFR
7
5
System register
6
<4> Caution
The data buffer is configured in 16 bits. However, the number of bits accessed differs depending on
7
the peripheral hardware. For example, if the GET instruction is executed to a peripheral hardware
register with a valid bit length of 8 bits, the contents of the peripheral hardware register are stored to
8
the low-order 8 bits (DBF1, DBF0) of the data buffer DBF.
9
DBF3
Retained
Data buffer
DBF2
Retained
DBF1
DBF0
10
b0
b7
GET
Peripheral
hardware
register
11
Actual bits
b7
12
b0
13
(12) PUT p, DBF
Put data buffer peripheral
14
<1> OP code
10
00111
8
pH
7
4
1010
3
15
0
pL
16
<2> Function
17
(p) ← DBF
18
Stores the data buffer DBF contents to peripheral hardware register.
DBF is a 16-bit area of addresses 0H through 0FH of BANK0 of the data memory regardless of the value
19
of the bank register.
20
241
CHAPTER 19 INSTRUCTION SET
<3> Example
To set 0AH and 05H to data buffers DBF1 and DBF0, respectively, and transfer them to a peripheral
register, shift register (SIOSFR) for serial interface:
MOV
BANK,
#00H
MOV
DBF0,
#05H
MOV
DBF1,
#0AH
PUT
SIOSFR,
DBF
Bank 0
0
1
; Data memory bank 0
Column address
2
3
4
5
6
7
8
9
A
B
C
D
0
E
F
A
5
DBF
Row address
1
2
Peripheral
hardware
register
3
4
5
6
0A5H
SIOSFR
7
System register
<4> Caution
The data buffer is configured in 16 bits. However, the number of bits accessed differs depending on
the peripheral hardware. For example, if the GET instruction is executed to a peripheral hardware
register with a valid bit length of 8 bits, the contents of the peripheral hardware register are stored to
the low-order 8 bits (DBF1, DBF0) of the data buffer DBF.
Data buffer
DBF3
Don’t care
DBF2
Don’t care
b7
DBF1
b 6 b5
b4
b3
DBF0
b2 b1
b0
PUT
Peripheral
hardware
register
242
Actual bits
b7
b0
CHAPTER 19 INSTRUCTION SET
19.5.8 Branch Instructions
1
(1) BR addr
Branch to the address
2
<1> OP code
0
10
01100
3
addr
4
<2> Function
5
PC ← addr
6
Branches to an address specified by addr.
7
<3> Example
FLY
LAB
0FH
; Defines FLY = 0FH
FLY
; Jumps to address 0FH
8
:
:
9
BR
:
10
:
BR
LOOP1
; Jumps to LOOP1
11
:
:
BR
$+2
; Jumps to an address 2 addresses lower than current address
$–3
; Jumps to an address 3 addresses higher than current address
12
:
:
13
BF
:
14
:
LOOP1:
15
(2) BR @AR
Branch to the address specified by address register
16
<1> OP code
17
00111
000
0100
0000
<2> Function
18
PC ← AR
19
Branches to the program address, specified by address register AR.
20
243
CHAPTER 19 INSTRUCTION SET
<3> Example 1
To set 003FH in address register AR (AR0 – AR3) and jump to address 003FH by using the BR @AR
instruction:
MOV
AR3,
; AR3 ← 00H
#00H
MOV
AR2,
#00H
; AR2 ← 00H
MOV
AR1,
#03H
; AR1 ← 03H
MOV
AR0,
#0FH
; AR0 ← 0FH
BR
@AR
; Jumps to address 003FH
Example 2
To change the branch destination according to the data memory address 0.10H contents, as follows:
0.10H contents
Branch destination label
00H
→
AAA
01H
→
BBB
02H
→
CCC
03H
→
DDD
04H
→
EEE
05H
→
FFF
06H
→
GGG
07H
→
HHH
08H – 0FH
→
ZZZ
;*
; ** Jump table
;*
ORG
10H
BR
AAA
BR
BBB
BR
CCC
BR
DDD
BR
EEE
BR
FFF
BR
GGG
BR
HHH
BR
ZZZ
:
:
:
MEM010
244
MEM
0.10H
MOV
AR3,
#00H
; AR3 ← 00H Sets AR to 001✕H
MOV
AR2,
#00H
; AR2 ← 00H
MOV
AR1,
#01H
; AR1 ← 01H
MOV
RPH,
#00H
; General register bank 0
MOV
RPL,
#02H
; General register row address 1
ST
AR0,
MEM010
; AR0 ← 0.10H
SKLT
AR0,
#08H
MOV
AR0,
#08H
BR
@AR
; Sets 08H in AR0, if AR0 contents are greater
; than 08H
CHAPTER 19 INSTRUCTION SET
<4> Caution
1
The number of bits, for address register AR3, AR2, AR1, and AR0, differs, depending on the
microcontroller model to be used.
• µPD17134A/17135A
2
: 10 bits
• µPD17136A/17137A/17P136A/17P137A : 11 bits
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
245
CHAPTER 19 INSTRUCTION SET
19.5.9 Subroutine Instructions
(1) CALL addr
Call subroutine
<1> OP code
0
10
11100
addr
<2> Function
SP ← SP – 1, ASR ← PC,
PC ← addr
Increments and stores the program counter PC value to stack, and branches to a subroutine specified
by addr.
<3> Example 1
MAIN
...................
....................
CALL
SUB1:
SUB1
RET
............
Example 2
MAIN
...........
CALL SUB2
CALL SUB3
RET
...........
...........
............
246
...........
SUB1
SUB2:
RET
SUB3:
..............................
...............
CALL
SUB1:
RET
CHAPTER 19 INSTRUCTION SET
(2) CALL @AR
Call subroutine specified by address register
1
<1> OP code
2
00111
000
0101
0000
3
<2> Function
4
SP ← SP – 1,
ASR ← PC,
5
PC ← AR
6
Saves the program counter PC value to the stack, and branches the execution to a subroutine that starts
from the address specified by address register AR.
7
<3> Example 1
8
To set 0020H in address register AR (AR0–AR3) and call the subroutine at address 0020H with the CALL
@AR instruction:
MOV
AR3,
9
#00H
; AR3 ← 00H
MOV
AR2,
#00H
; AR2 ← 00H
MOV
AR1,
#02H
; AR1 ← 02H
MOV
AR0,
#00H
; AR0 ← 00H
CALL
@AR
10
11
; Calls subroutine at address 0020H
12
Example 2
To call the following subroutine by the data memory address 0.10H contents:
Contents of 0.10H
13
Subroutine
00H
→
SUB1
01H
→
SUB2
02H
→
SUB3
03H
→
SUB4
04H
→
SUB5
05H
→
SUB6
06H
→
SUB7
07H
→
SUB8
08H–0FH
→
SUB9
14
15
16
17
18
19
20
247
CHAPTER 19 INSTRUCTION SET
...........
;*
;**Jump table for subroutine
;*
SUB1
BR
SUB2
BR
SUB3
BR
SUB4
BR
SUB5
BR
SUB6
BR
SUB7
BR
SUB8
BR
SUB9
SUB1:
SUB2:
...........
SUB4:
SUB5:
SUB6:
SUB3:
....................................
BR
....................................
10H
....................................
ORG
RET
RET
RET
SUB7:
SUB8:
SUB9:
....................................
....................................
....................................
....................................
....................................
....................................
RET
RET
RET
RET
RET
RET
...........
MOV
AR3,
#00H
; AR3
00H address register 001 · H
MOV
AR2,
#00H
; AR2
00H
MOV
AR1,
#01H
; AR1
01H
MOV
RPH,
#00H
; General register bank 0
MOV
RPL,
#02H
; General register row address 1
ST
AR0,
10H
; AR0
SKLT
AR0,
#08H
; If AR0 is larger than 08H,
MOV
AR0,
#08H
; set AR0 to 08H
CALL
@AR
To jump table
................
Returns here when executing
RET instruction in each subroutine
0.10H
<4> Caution
The number of bits, in address registers AR3, AR2, AR1, and AR0, differs, depending on the
microcontroller model to be used.
• µPD17134A/17135A
: 10 bits
• µPD17136A/17137A/17P136A/17P137A : 11 bits
248
CHAPTER 19 INSTRUCTION SET
(3) RET
Return to the main program from subroutine
1
<1> OP code
10
00111
8
000
7
4
3
1110
2
0
0000
3
<2> Function
4
PC ← ASR,
SP ← SP + 1,
5
Instruction to return to the main program from a subroutine.
6
Restores the return address, saved to the stack by the CALL instruction, to the program counter.
7
<3> Example
....................
8
SUB1
....................
..............................
CALL
9
SUB1:
10
11
RET
12
13
(4) RETSK
Return to the main program then skip next instruction
14
15
<1> OP code
16
00111
001
1110
0000
17
<2> Function
18
PC ← ASR, SP ← SP + 1 and skip
19
Instruction to return to the main program from a subroutine.
Skips the instruction next to the CALL instruction (i.e., treats that instructions as an NOP instruction).
Therefore, restores the return address, saved to the stack by the CALL instruction, to program counter
PC and then increments the program counter.
249
20
CHAPTER 19 INSTRUCTION SET
<3> Example
To execute the RET instruction, if the LSB (least significant bit) content for address 25H in the data
memory (RAM) is 0. The execution is returned to the instruction next to the CALL instruction. If the LSB
is 1, execute the RETSK instruction. The execution is returned to the instruction following the one next
to the CALL instruction (in this example, ADD 03H, 16H).
CALL
SUB1
BR
LOOP
ADD
03H, 16H
..............................
....................
SUB1:
SKF
....................
(5) RETI
25H, #0001B
RETSK
; LSB of 25H is "1"
RET
; LSB of 25H is "0"
Return to the main program from the interrupt service routine
<1> OP code
00111
100
1110
0000
<2> Function
PC ← ASR, INTR ← INTSK, SP ← SP + 1
Instruction to return to the main program, from an interrupt service routine.
Restores the return address, saved to the stack by a vector interrupt, to the program counter.
Part of the system register (BANK, PSWORD) is also returned to the status before the occurrence of
the vector interrupt.
250
CHAPTER 19 INSTRUCTION SET
19.5.10 Interrupt Instructions
1
(1) EI
Enable Interrupt
2
<1> OP code
3
00111
000
1111
0000
4
<2> Function
5
INTEF ← 1
6
Enables a vectored interrupt.
The interrupt is enabled after the instruction next to the EI instruction has been executed.
7
<3> Example 1
8
As shown in the following example, the interrupt is accepted after the instruction next to that, that has
accepted the interrupt, has been completely executed (excluding an instruction that manipulates
program counter). The flow then shifts to the vector address
9
Note1.
10
............
Note 2
................
routine (vector address)
MOV
0AH,
#00H
ADD
0BH,
#01H
ADD
0CH,
#01H
12
....................
Generating
interrupt request
11
Interrupt service
EI
13
EI
14
.......................
RET
15
DI
16
...........
Generating
interrupt request
17
EI
MOV
0AH,
#01H
SUB
0BH,
#01H
18
............
19
20
251
CHAPTER 19 INSTRUCTION SET
Notes 1. The vector address differs, depending on the interrupt to be accepted. Refer to Table
14-1.
2. The interrupt accepted in this example (an interrupt request is generated after the EI
instruction has been executed and the execution flow shifts to an interrupt service routine)
is the interrupt, whose interrupt enable flag (IP×××) is set. The program flow is not changed,
without the interrupt enable flag set, even if an interrupt request is generated, after the EI
instruction has been executed (therefore, the interrupt is not accepted). However, interrupt
request flag (IRQ×××) is set, and the interrupt is accepted, as soon as the interrupt enable
flag is set.
Example 2
An example of an interrupt, which occurs in response to an interrupt request being accepted counter
PC is being executed:
............
Interrupt service
EI
Generating
interrupt request
BR
....................
................
routine (vector address)
ABC
.................
ABC:
EI
RET
MOV
0AH,
#00H
ADD
0BH,
#01H
.............
(2) DI
Disable interrupt
<1> OP code
00111
001
1111
0000
<2> Function
INTEF ← 0
Instruction to disable a vectored interrupt.
<3> Example
Refer to Example 1 in (1) EI.
252
CHAPTER 19 INSTRUCTION SET
19.5.11 Other Instructions
1
(1) STOP s
Stop CPU and release by condition s
2
<1> OP code
3
00111
010
1111
0
3
s
4
<2> Function
5
Stops the system clock and places the device in the STOP mode.
In the STOP mode, the power consumption for the device is minimized.
6
The condition, under which the STOP mode is to be released, is specified by operand (s).
For the stop releasing condition (s), refer to 16.3 STOP MODE.
(2) HALT h
7
Halt CPU and release by condition h
8
<1> OP code
3
00111
011
1111
0
9
h
10
<2> Function
11
Places the device in the HALT mode.
12
In the HALT mode, the power consumption for the device is reduced.
The condition, under which the HALT mode is to be released, is specified by operand (h).
For HALT releasing condition (h), refer to 16.2 HALT MODE.
(3) NOP
13
No operation
14
<1> OP code
15
00111
100
1111
0000
16
<2> Function
17
Performs nothing and consumes one machine cycle.
18
19
20
253
[MEMO]
254
CHAPTER 20 ASSEMBLER RESERVED WORDS
20.1 MASK OPTION DIRECTIVE
The µPD173134A, 17135A, 17136A, and 17137A have the following mask options.
• Internal pull-up resistor of RESET pin
• Internal pull-up resistor of P0D3 through P0D0 pins
• Internal pull-up resistor of P1A3 through P1A0 pins
• Internal pull-up resistor of P1B0 pin
When developing a program, all the above mask options must be specified in the source program by using mask
option directives.
20.1.1 Specifying Mask Option
The mask options are described in the assembler source program by using the following directives.
• OPTION and ENDOP directives
• Mask option definition directive
(1) OPTION and ENDOP directives
These directives specify the range in which the mask option is to be described (mask option definition block).
Specify the mask option by describing the mask option directive in an area between the OPTION and ENDOP
directives.
Description format
Symbol field
Mnemonic field
[label: ]
OPTION
..
..
..
Operand field
Comment field
[;comment]
ENDOP
255
CHAPTER 20 ASSEMBLER RESERVED WORDS
(2) Mask option definition directive
Table 20-1. Mask Option Definition Directive
Option
Internal pull-up resistor
Definition directive and format
OPTRES <operand>
of RESET pin
Internal pull-up resistor of
OPTP0D <operand 1>, ..., <operand
4>Note 1
OPTP1A <operand 1>, ..., <operand
4>Note 2
P0D3 through P0D0 pins
Internal pull-up resistor of
P1A3 through P1A0 pins
Internal pull-up resistor of
OPTP1B <operand>
P1B0 pin
Notes 1.
Operand
Definition
OPEN
None
PULLUP
Provided
OPEN
None
PULLUP
Provided
OPEN
None
PULLUP
Provided
OPEN
Not used
PULLUP
Used
<operand 1>, <operand 2>, <operand 3>, and <operand 4> specify the mask options of the P0D3,
P0D2, P0D1, and P0D0 pins, respectively.
2.
<operand 1>, <operand 2>, <operand 3>, and <operand 4> specify the mask options of the P1A3,
P1A2, P1A1, and P1A0 pins, respectively.
(3) Example of describing mask option
; Example of describing mask option of µPD17134A subseries
MASK_OPTION:
OPTION
; Start of mask option definition block
OPTRES
PULLUP
OPTP0D
PULLUP, PULLUP, OPEN, OPEN ; Internal pull-up resistor is connected to P0D3 and P0D2 pins.
; Internal pull-up resistor is connected to RESET pin.
OPTP1A
PULLUP, OPEN, PULLUP, OPEN ; P1A3 and P1A1 pins are connected to internal pull-up resistor.
OPTP1A
PULLUP
; P0D1 and P0D0 are open (externally pulled up).
; P1A2 and P1A0 pins are open (externally pulled up).
ENDOP
256
; P1B0 pin is connected to internal pull-up resistor.
; End of mask option definition block
CHAPTER 20 ASSEMBLER RESERVED WORDS
20.2 RESERVED SYMBOLS
1
The reserved symbols defined in the µPD17134A, 17135A, 17136A, and 17137A device file (AS17134) are listed
below.
2
System register (SYSREG)
3
Symbolic
name
Attribute
Value
Read/
write
AR3
MEM
0.74H
R
Bits 15 to 12 of the address register
AR2
MEM
0.75H
R/W
Bits 11 to 8 of the address register
AR1
MEM
0.76H
R/W
Bits 7 to 4 of the address register
AR0
MEM
0.77H
R/W
Bits 3 to 0 of the address register
WR
MEM
0.78H
R/W
Window register
BANK
MEM
0.79H
R/W
Bank register
IXH
MEM
0.7AH
R/W
Index register high
MPH
MEM
0.7AH
R/W
Data memory row address pointer high
MPE
FLG
0.7AH.3
R/W
Memory pointer enable flag
IXM
MEM
0.7BH
R/W
Index register middle
MPL
MEM
0.7BH
R/W
Data memory row address pointer low
IXL
MEM
0.7CH
R/W
Index register low
RPH
MEM
0.7DH
R/W
General register pointer high
RPL
MEM
0.7EH
R/W
General register pointer low
PSW
MEM
0.7FH
R/W
Program status word
BCD
FLG
0.7EH.0
R/W
BCD flag
CMP
FLG
0.7FH.3
R/W
Compare flag
CY
FLG
0.7FH.2
R/W
Carry flag
Z
FLG
0.7FH.1
R/W
Zero flag
IXE
FLG
0.7FH.0
R/W
Index enable flag
4
Description
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
257
CHAPTER 20 ASSEMBLER RESERVED WORDS
Data buffer (DBF)
Symbolic
name
Attribute
Value
Read/
write
DBF3
MEM
0.0CH
R/W
DBF bits 15 to 12
DBF2
MEM
0.0DH
R/W
DBF bits 11 to 8
DBF1
MEM
0.0EH
R/W
DBF bits 7 to 4
DBF0
MEM
0.0FH
R/W
DBF bits 3 to 0
Symbolic
name
Attribute
Value
Read/
write
P0A3
FLG
0.70H.3
R/W
Description
Port register
Description
Port 0A bit 3
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0A2
FLG
0.70H.2
R/W
Port 0A bit 2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0A1
FLG
0.70H.1
R/W
Port 0A bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0A0
FLG
0.70H.0
R/W
Port 0A bit 0
P0B3
FLG
0.71H.3
R/W
Port 0B bit 3
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0B2
FLG
0.71H.2
R/W
Port 0B bit 2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0B1
FLG
0.71H.1
R/W
Port 0B bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0B0
FLG
0.71H.0
R/W
Port 0B bit 0
P0C3
FLG
0.72H.3
R/W
Port 0C bit 3
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C2
FLG
0.72H.2
R/W
Port 0C bit 2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C1
FLG
0.72H.1
R/W
Port 0C bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C0
FLG
0.72H.0
R/W
Port 0C bit 0
P0D3
FLG
0.73H.3
R/W
Port 0D bit 3
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0D2
FLG
0.73H.2
R/W
Port 0D bit 2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0D1
FLG
0.73H.1
R/W
Port 0D bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0D0
FLG
0.73H.0
R/W
Port 0D bit 0
P1A3
FLG
1.70H.3
R/W
Port 1A bit 3
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P1A2
FLG
1.70H.2
R/W
Port 1A bit 2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P1A1
FLG
1.70H.1
R/W
Port 1A bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
258
P1A0
FLG
1.70H.0
R/W
Port 1A bit 0
P1B0
FLG
1.71H.0
R
Port 1B bit 0
CHAPTER 20 ASSEMBLER RESERVED WORDS
Register file (control register)
1
Attribute
Value
Read/
write
SP
MEM
0.81H
R/W
Stack pointer
SIOTS
FLG
0.82H.3
R/W
SIO start flag
Symbolic
name
Description
2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
SIOHIZ
FLG
0.82H.2
R/W
3
SO pin state
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
SIOCK1
FLG
0.82H.1
R/W
SIO source clock selection flag bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
SIOCK0
FLG
0.82H.0
R/W
SIO source clock selection flag bit 0
WDTRES
FLG
0.83H.3
R/W
Watchdog timer reset flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
WDTEN
FLG
0.83H.0
R/W
Watchdog timer enable flag
TM0OSEL
FLG
0.8BH.3
R/W
Flag for switching timer 0 output and port
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
SIOEN
FLG
0.8BH.0
R/W
SIO enable flag
P0BGPU
FLG
0.8CH.1
R/W
P0B group pull-up selection flag (pull-up = 1)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
FLG
0.8CH.0
R/W
INT
FLG
0.8FH.0
R
PDRESEN
FLG
0.90H.0
R/W
Power-down reset enable flag
TM0EN
FLG
0.91H.3
R/W
Timer 0 enable flag
INT pin status flag
0.91H.2
R/W
6
7
8
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
FLG
5
P0A group pull-up selection flag (pull-up = 1)
P0AGPU
TM0RES
4
9
Timer 0 reset flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
TM0CK1
FLG
0.91H.1
R/W
Timer 0 source clock selection flag bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
TM0CK0
FLG
0.91H.0
R/W
Timer 0 source clock selection flag bit 0
TM1EN
FLG
0.92H.3
R/W
Timer 1 enable flag
TM1RES
FLG
0.92H.2
R/W
Timer 1 reset flag
TM1CK1
FLG
0.92H.1
R/W
Timer 1 source clock selection flag bit 1
TM1CK0
FLG
0.92H.0
R/W
Timer 1 source clock selection flag bit 0
BTMISEL
FLG
0.93H.3
R/W
BTM interrupt request clock selection flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
10
11
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
BTMRES
FLG
0.93H.2
R/W
12
13
BTM reset flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
BTMCK1
FLG
0.93H.1
R/W
BTM source clock selection flag bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
BTMCK0
FLG
0.93H.0
R/W
BTM source clock selection flag bit 0
P0C3IDI
FLG
0.9BH.3
R/W
P0C3 input port disable flag (ADC3/P0C3 selection)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C2IDI
FLG
0.9BH.2
R/W
14
15
P0C2 input port disable flag (ADC2/P0C2 selection)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C1IDI
FLG
0.9BH.1
R/W
P0C1 input port disable flag (ADC1/P0C1 selection)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0C0IDI
FLG
0.9BH.0
R/W
P0C0 input port disable flag (ADC0/P0C0 selection)
P0CBIO3
FLG
0.9CH.3
R/W
P0C3 input/output selection flag (1 = output port)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0CBIO2
FLG
0.9CH.2
R/W
16
17
P0C2 input/output selection flag (1 = output port)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0CBIO1
FLG
0.9CH.1
R/W
P0C1 input/output selection flag (1 = output port)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0CBIO0
FLG
0.9CH.0
R/W
P0C0 input/output selection flag (1 = output port)
ZCROSS
FLG
0.9DH.0
R/W
Zerocross detector enable flag
IEGMD1
FLG
0.9FH.1
R/W
INT pin edge detection selection flag bit 1
18
19
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
IEGMD0
FLG
0.9FH.0
R/W
INT pin edge detection selection flag bit 0
ADCSTRT
FLG
0.0A0H.0
R/W
A/D converter start flag (always 0 when read)
ADCSOFT
FLG
0.0A1H.3
R/W
A/D converter software control flag (1 = single mode)
20
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
ADCCMP
FLG
0.0A1H.1
R/W
A/D converter comparison result flag (valid only in single mode)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
ADCEND
FLG
0.0A1H.0
R/W
A/D converter conversion end flag
259
CHAPTER 20 ASSEMBLER RESERVED WORDS
Symbolic
name
Attribute
Value
Read/
write
ADCCH3
FLG
0.0A2H.3
R/W
Description
Dummy flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
ADCCH2
FLG
0.0A2H.2
R/W
Dummy flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
ADCCH1
FLG
0.0A2H.1
R/W
A/D converter channel selection flag bit 1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
ADCCH0
FLG
0.0A2H.0
R/W
A/D converter channel selection flag bit 0
P0DBIO3
FLG
0.0ABH.3
R/W
P0D3 input/output selection flag (1 = output port)
R/W
P0D2 input/output selection flag (1 = output port)
R/W
P0D1 input/output selection flag (1 = output port)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0DBIO2
FLG
0.0ABH.2
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0DBIO1
FLG
0.0ABH.1
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0DBIO0
FLG
0.0ABH.0
R/W
P0D0 input/output selection flag (1 = output port)
P1AGIO
FLG
0.0ACH.2
R/W
P1A group input/output selection flag (1 = all P1As are output ports.)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0BGIO
FLG
0.0ACH.1
R/W
P0B group input/output selection flag (1 = all P0Bs are output ports.)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
P0AGIO
FLG
0.0ACH.0
R/W
P0A group input/output selection flag (1 = all P0As are output ports.)
IPSIO
FLG
0.0AEH.0
R/W
SIO interrupt enable flag
IPBTM
FLG
0.0AFH.3
R/W
BTM interrupt enable flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
IPTM1
FLG
0.0AFH.2
R/W
TM1 interrupt enable flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
IPTM0
FLG
0.0AFH.1
R/W
TM0 interrupt enable flag
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
IP
FLG
0.0AFH.0
R/W
INT pin interrupt enable flag
IRQSIO
FLG
0.0BBH.0
R/W
SIO interrupt request flag
IRQBTM
FLG
0.0BCH.0
R/W
BTM interrupt request flag
IRQTM1
FLG
0.0BDH.0
R/W
TM1 interrupt request flag
IRQTM0
FLG
0.0BEH.0
R/W
TM0 interrupt request flag
IRQ
FLG
0.0BFH.0
R/W
INT pin interrupt request flag
Peripheral register
Symbolic
name
Attribute
Value
Read/
write
SIOSFR
DAT
01H
R/W
TM0M
DAT
02H
W
Peripheral address of the timer 0 modulo register
TM1M
DAT
03H
W
Peripheral address of the timer 1 modulo register
ADCR
DAT
04H
R/W
Peripheral address of A/D converter data register
TM0TM1C
DAT
45H
R
AR
DAT
40H
R/W
Attribute
Value
DBF
DAT
0FH
Fixed operand value of PUT, GET, or MOVT instruction
IX
DAT
01H
Fixed operand value of INC instruction
Description
Peripheral address of the shift register
Peripheral address of timer 0 timer 1 count register
Peripheral address of the address register for GET, PUT, PUSH, CALL,
BR, MOVT, and INC instructions
Others
Symbolic
name
260
Description
Small general-purpose controllers
(One-time PROM model is available for all models.)
Performance
Medium-voltage port
AC zerocross
A/D
: 4ch
Timer
: 3ch
Serial interface : 1ch
Comparator
: 4ch
Timer
: 1ch
Serial interface : 1ch
µ PD17133
µ PD17132
ROM: 2 KB, ceramic
ROM: 2 KB, RC
Timer
: 1ch
Serial interface : 1ch
µ PD17121
µ PD17120
ROM: 1.5 KB, ceramic
ROM: 1.5 KB, RC
µ PD17137A
µ PD17136A
µ PD17135A
µ PD17134A
µ PD17149
µ PD17147
µ PD17145
ROM: 4 KB, ceramic
ROM: 4KB, RC
ROM: 2 KB, ceramic
ROM: 2 KB, RC
ROM: 8 KB, ceramic
ROM: 4 KB, ceramic
ROM: 2 KB, ceramic
Tiny controller
ROM 1 KB
ROM 1 KB
µ PD17103L
µ PD17103
µPD17107L
µ PD17107
16
Ceramic, low-voltage: 1.8 V MIN.
Ceramic
RC, low-voltage: 1.5 V MIN.
RC
µ PD17104L
µ PD17104
µ PD17108L
µ PD17108
22
Ceramic, low-voltage: 1.8 V MIN.
Ceramic
RC: low-voltage: 1.5 V MIN.
RC
24
28
Number of pins
APPENDIX A DEVELOPMENT OF µPD171×× SUBSERIES
A/D
: 4ch
Timer
: 3ch
Serial interface : 1ch
261
[MEMO]
262
APPENDIX B COMPARISON OF FUNCTIONS BETWEEN µPD17135A, 17137A,
AND µPD17145 SUBSERIES
1
2
(1/2)
ROM
µPD17145
µPD17147
µPD17149
µPD17135A
µPD17137A
2K bytes
4K bytes
8K bytes
2K bytes
4K bytes
110 × 4 bits
RAM
Instruction execution time
(clock, supply voltage)
2 µs (fX = 8 MHz, VDD = 4.5 to 5.5 V)
4 µs (fX = 4 MHz, VDD = 3.6 to 5.5 V)
8 µs (fX = 2 MHz, VDD = 2.7 to 5.5 V)
CMOS I/O
Input
Sense input
N-ch open-drain I/O
Internal pull-up resistor
A/D converter (supply voltage)
2 (P0F0, P0F1)
1 (P1B0)
1 (INT)
Can be pulled up by mask option
1 (INT)
Interrupt
8 (P0D, P0E, voltage: VDD)
9
100 kΩ TYP. (except P0D)
10 kΩ TYP. (P0D)
100 kΩ TYP.
8 bits × 4 channels (VDD = 4.0 to 5.5 V)
8 bits × 4 channels (VDD = 4.5 to 5.5 V)
None (VREF = VADC = VDD)
8 bits (TM0, TM1)
2 (timer output: TM1OUT)
TM0 clock : fX/512
fX/64
fX/16
INT
TM1 clock : fX/8192
fX/128
fX/16
TM0 count up
2 (timer output: TM0OUT)
TM0 clock : fX/256
fX/64
fX/16
INT
TM1 clock : fX/1024
fX/512
fX/256
TM0 count up
1 (multiplexed with watchdog timer)
Count pulse : fX/16384
fX/4096
fX/512
fX/16
1 (multiplexed with watchdog timer)
Count pulse : fX/8192
fX/4096
TM0 count up
INT
Internal
7
8 (P0D, P1A, voltage: 9 V)
P0D pull up: mask option
P1A pull up: mask option
VREF (VREF = 2.5 to VDD)
External
6
8
Reference voltage pin
Basic interval timer
(BTM)
5
2 µs (fX = 8 MHz, VDD = 4.5 to 5.5 V)
4 µs (fX = 4 MHz, VDD = 2.7 to 5.5 V)
12 (P0A, P0B, P0C)
P0D pull up: software
P0E pull up: software
Timer
4
Address stack × 5 levels
Interrupt stack × 3 levels
Stack
I/O
112 × 4 bits
3
1
10
11
12
13
14
15
16
1
(with AC zero cross detection function)
18
4 (TM0, TM1, BTM, SIO)
SIO
17
1 (clocked 3-wire)
Output latch
Independent of P0D1 latch
19
Multiplexed with P0D1 latch
20
263
APPENDIX B COMPARISON OF FUNCTIONS BETWEEN µPD17135A, 17137A, AND µPD17145 SUBSERIES
(2/2)
µPD17145
Standby function
Oscillation stabilization wait time
POC function
µPD17147
µPD17149
µPD17135A
µPD17137A
HALT, STOP
(with input pin RLS for releasing)
HALT, STOP
128 × 256 counts
512 × 256 counts
Mask option
Internal
Package
28-pin plastic SDIP (400 mil)
28-pin plastic SOP (375 mil)
One-time PROM
µPD17P149
µPD17P137A
Caution The µPD17145 subseries is not pin-compatible with the µPD17135A and 17137A. The µPD17145
subseries has no model equivalent to the µPD17134A and 17136A (RC oscillation type).
For the electrical characteristics, refer to the Data Sheet of each model.
Remark fX: system clock oscillation frequency
264
APPENDIX C DEVELOPMENT TOOLS
1
The following support tools are available for developing programs for the µPD17134A subseries.
2
Hardware
3
Name
Outline
In-circuit emulator
IE-17K
IE-17K-ETNote1
EMU-17KNote2
These are in-circuit emulators that can be commonly used with microcontrollers in 17K series.
IE-17K and IE-17K-ET are connected to a host machine, NEC PC-9800 series or IBM PC/ATTM,
through RS-232-C. EMU-17K is mounted in expansion slot of NEC PC-9800 series that serves as
host machine.
When these in-circuit emulators are used in combination with the evaluation board (SE board)
dedicated to each model of microcontroller, they operate as emulators corresponding to microcontroller.
When these in-circuit emulators are used with man-machine interface software SIMPLEHOSTTM, a
more sophisticated debugging environment can be created.
EMU-17K also has a function that allows you to monitor data memory contents real-time.
SE board (SE-17134)
SE-17134 is an SE board for µPD17134A subseries series. It can be used alone for system evaluation
or in combination with an in-circuit emulator for debugging.
Emulation probe
(EP-17K28CT)
EP-17K28CT is an emulation probe for 17K series 28-pin shrink DIP (400 mil) and connects SE board
and target system.
Emulation probe
(EP-17K28GT)
EP-17K28GT is an emulation probe for 17K series 28-pin SOP (375 mil) and connects SE board and
target system by being used with EV-9500GT-28Note3.
Conversion adapter
(EV-9500GT-28Note3)
EV-9500GT-28 is an adapter for 28-pin SOP (375 mil) and is used to connect EP-17K28GT to target
system.
4
5
6
7
8
9
10
11
PROM programmer
AF-9703Note4
AF-9704Note4
AF-9705Note4
AF-9706Note4
AF-9703, AF-9704, AF-9705, and AF-9706 are PROM programmers corresponding to µPD17P136A
and 17P137A. When connected with program adapter AF-9808F, these programmers can be used
to program µPD17P136A and 17P137A.
Programmer adapter
(AF-9808FNote4)
AF-9808F is an adapter for programming µPD17P136A and 17P137A, and is used in combination with
AF-9703, AF-9704 or AF-9706.
12
13
14
Notes 1.
Low-price model: external power supply type
2.
This is a program of IC Corp. For details, consult IC.
3.
Two EV-9500GT-28 are supplied as accessories with the EP-17K28GT. Five EV-9500GT-28's are
15
optionally available as a set.
4.
16
Manufactured by Ando Electric. For details, consult Ando Electric.
17
18
19
20
265
APPENDIX C DEVELOPMENT TOOLS
Software
Name
17K series
assembler (AS17K)
Device file
(AS17134)
Support software
(SIMPLEHOST)
Description
Host machine
AS17K is an assembler
applicable to the 17K series.
In developing µPD17134A,
17135A, 17136A, and 17137A
programs, AS17K is used in
combination with a device file
(AS17134).
AS17134 is a device file for
the µPD17134A, 17135A,
17136A, and 17137A.
It is used together with the
assembler (AS17K) which is
applicable to the 17K series.
OS
PC-9800
series
MS-DOS
PC-9800
series
PC-9800
series
PC DOS
3.5-inch, 2HD
µS5A13AS17K
5-inch, 2HC
µS7B10AS17K
5-inch, 2HD
µS5A10AS17134
3.5-inch, 2HD
µS5A13AS17134
5-inch, 2HC
µS7B10AS17134
5-inch, 2HD
µS5A10IE17K
Windows 3.5-inch, 2HD
IBM PC/AT
PC DOS
Version
MS-DOS
Ver. 3.30 to Ver. 5.00ANote
PC DOS
Ver. 3.1 to Ver. 5.0Note
Windows
Ver. 3.0 to Ver. 3.1
Note Although MS-DOS Ver. 5.00/5.00A and PC DOS
Ver. 5.0 have a task swap function, this function
cannot be used with this software.
266
µS5A10AS17K
MS-DOS
Remark The supported OS versions are as follows:
OS
5-inch, 2HD
MS-DOS
IBM PC/AT
SIMPLEHOST, running on the
WindowsTM, provides manmachine-interface in developing programs by using a
personal computer and the incircuit emulator.
Part number
TM
PC DOSTM
IBM PC/AT
Distribution
media
5-inch, 2HC
µS5A13IE17K
µS7B10IE17K
APPENDIX D NOTES ON CONFIGURATION OF SYSTEM CLOCK OSCILLATION CIRCUIT
1
2
The system clock oscillation circuit oscillates by using a ceramic resonator connected across the X1 and X2 pins
or an oscillation resistor connected across the OSC1 and OSC0 pins.
3
Figure D-2 shows the external circuits of the system clock oscillation circuit.
4
Figure D-1. External Circuit of System Clock Oscillation Circuit
5
XOUT
µ PD17135A
µ PD17134A
µ PD17137A
µ PD17136A
µ PD17P137A
µ PD17P136A
XIN
GND
OSC0
6
7
OSC1
Ceramic resonator
8
Oscillation resistor
9
10
Caution Wire the system clock oscillation circuit so that the resistance component and inductance
component of the ground wiring can be minimized. Wire the portion enclosed in the dotted line
11
in Figure D-1 as follows to prevent influence of wiring capacitance.
12
• Keep the wiring length as short as possible.
• Do not cross the wiring with the other signal lines. Keep a distance between the wiring and
13
a line through which a high alternating current flows.
• Always keep the ground point of the capacitor of the oscillation circuit at the same potential
as VSS. Do not ground the wiring to a ground pattern through which a high current flows.
14
• Do not extract signals from the oscillation circuit.
15
Figure D-2 shows an examples of incorrect oscillation circuits.
16
17
18
19
20
267
APPENDIX D NOTES ON CONFIGURATION OF SYSTEM CLOCK OSCILLATION CIRCUIT
Figure D-2. Example of Incorrect Oscillation Circuits
(a) Wiring length of circuit is too long.
XIN
XOUT
(b) Crossed signal lines
PORT
GND
XOUT
XIN
GND
Too long
(c) Signal line close to high alternating current
(d) Current flowing through ground line of
oscillation circuit (potential at points A and B
changes in respect to point C)
XOUT
XIN
GND
High
current
PORT
XOUT
XIN
A
B
High current
(e) Signal is extracted
XOUT
268
XIN
GND
GND
C
APPENDIX E INSTRUCTION LIST
1
E.1 INSTRUCTION LIST (by function)
[Addition Instructions]
2
r, m ... 198
LD
r, m ... 227
ADD
m, #n4 ... 201
ST
m, r ... 228
ADDC
r, m ... 203
MOV
@r, m ... 231
ADDC
m, #n4 ... 205
MOV
m, @r ... 231
INC
AR ... 206
MOV
m, #n4 ... 233
INC
IX ... 208
MOVT
DBF, @AR ... 234
PUSH
AR ... 235
[Subtraction Instructions]
POP
AR ... 237
SUB
r, m ... 209
PEEK
WR, rf ... 238
SUB
m, #n4 ... 211
POKE
rf, WR ... 239
SUBC
r, m ... 212
GET
DBF, p ... 240
SUBC
m, #n4 ... 214
PUT
p, DBF ... 241
[Logical Operation Instructions]
OR
3
[Transfer Instructions]
ADD
4
5
6
7
8
9
[Branch Instructions]
r, m ... 216
BR
addr ... 243
OR
m, #n4 ... 216
BR
@AR ... 243
10
AND
r, m ... 217
AND
m, #n4 ... 218
[Subroutine Instructions]
11
XOR
r, m ... 219
CALL
addr ... 246
XOR
m, #n4 ... 220
CALL
@AR ... 247
12
RET ... 249
[Judgment Instructions]
SKT
m, #n ... 221
SKF
m, #n ... 223
RETSK ... 249
13
RETI ... 250
[Interrupt Instructions]
[Comparison Instructions]
SKE
m, #n4 ... 223
SKNE
m, #n4 ... 223
SKGE
m, #n4 ... 224
SKLT
m, #n4 ... 224
[Rotation Instructions]
RORC
14
EI ... 251
DI ... 252
15
[Other Instructions]
STOP
s ... 253
HALT
h ... 253
16
17
NOP ... 253
r ... 226
18
19
20
269
APPENDIX E INSTRUCTION LIST
E.2 IINSTRUCTION LIST (alphabetical order)
[A]
[O]
ADD
m, #n4 ... 201
OR
m, #n4 ... 216
ADD
r, m ... 198
OR
r, m ... 216
ADDC
m, #n4 ... 205
ADDC
r, m ... 203
AND
m, #n4 ... 218
PEEK
WR, rf ... 238
AND
r, m ... 217
POKE
rf, WR ... 239
[P]
[B]
BR
addr ... 243
BR
@AR ... 243
POP
AR ... 237
PUSH
AR ... 235
PUT
p, DBF ... 241
[R]
[C]
RET ... 249
CALL
addr ... 246
RETI ... 250
CALL
@AR ... 247
RETSK ... 249
RORC
r ... 226
[D]
DI ... 252
[S]
SKE
[E]
EI ... 251
[G]
GET
DBF, p ... 240
[H]
HALT
h ... 253
[I]
INC
AR ... 206
INC
IX ... 208
m, #n4 ... 223
SKF
m, #n ... 221
SKGE
m, #n4 ... 224
SKLT
m, #n4 ... 224
SKNE
m, #n4 ... 223
SKT
m, #n ... 221
ST
m, r ... 228
STOP
s ... 253
SUB
m, #n4 ... 211
SUB
r, m ... 209
SUBC
m, #n4 ... 214
SUBC
r, m ... 212
XOR
m, #n4 ... 220
XOR
r, m ... 219
[x]
[L]
LD
r, m ... 227
[M]
MOV
m, #n4 ... 233
MOV
m, @r ... 231
MOV
@r, m ... 231
MOVT
DBF, @AR ... 234
[N]
NOP ... 253
270
APPENDIX F ORDERING MASK ROM
1
2
After developing the program, place an order for the mask ROM version, according to the following procedure:
3
(1) Make reservation when ordering mask ROM.
Advise NEC of the schedule for placing an order for the mask ROM. If NEC is not informed in advance, on-
4
time delivery may not be possible.
5
(2) Create ordering medium.
6
Use UV-EPROM to place an order for the mask ROM.
Add /PROM as an assemble option of the Assembler (AS17K), and create a mask ROM ordering HEX file (with
extender for .PRO).
7
Next, write the mask ROM ordering HEX file into the UV-EPROM.
8
Create three UV-EPROMs with the same contents.
(3) Prepare necessary documents.
9
Fill out the following forms to place an order for the mask ROM:
10
• Mask ROM ordering sheet
• Mask ROM ordering check sheet
11
(4) Ordering
12
Submit the media created in (2) and documents prepared in (3) to NEC by the specified date.
13
Caution For details, refer to information document ROM Code Ordering Procedure (IEM-1366).
14
15
16
17
18
19
20
271
[MEMO]
272
Facsimile Message
From:
Name
Company
Tel.
Although NEC has taken all possible steps
to ensure that the documentation supplied
to our customers is complete, bug free
and up-to-date, we readily accept that
errors may occur. Despite all the care and
precautions we've taken, you may
encounter problems in the documentation.
Please complete this form whenever
you'd like to report errors or suggest
improvements to us.
FAX
Address
Thank you for your kind support.
North America
Hong Kong, Philippines, Oceania
NEC Electronics Inc.
NEC Electronics Hong Kong Ltd.
Corporate Communications Dept. Fax: +852-2886-9022/9044
Fax: 1-800-729-9288
1-408-588-6130
Korea
Europe
NEC Electronics Hong Kong Ltd.
NEC Electronics (Europe) GmbH
Seoul Branch
Technical Documentation Dept.
Fax: 02-528-4411
Fax: +49-211-6503-274
South America
NEC do Brasil S.A.
Fax: +55-11-889-1689
Asian Nations except Philippines
NEC Electronics Singapore Pte. Ltd.
Fax: +65-250-3583
Japan
NEC Corporation
Semiconductor Solution Engineering Division
Technical Information Support Dept.
Fax: 044-548-7900
Taiwan
NEC Electronics Taiwan Ltd.
Fax: 02-719-5951
I would like to report the following error/make the following suggestion:
Document title:
Document number:
Page number:
If possible, please fax the referenced page or drawing.
Document Rating
Excellent
Good
Acceptable
Poor
Clarity
Technical Accuracy
Organization
CS 96.8