Data Sheet
Data Sheet
78K/0 Series
8-bit Single-chip Microcontroller
Basic (III)
© 1995
Printed in Japan
[MEMO]
NOTES FOR CMOS DEVICES
Purchase of NEC I2C components conveys a license under the Philips I2C Patent Rights to use these
components in an I2C system, provided that the system conforms to the I2C Standard Specification as defined
by Philips.
The export of these products from Japan is regulated by the Japanese government. The export of some or all of these
products may be prohibited without governmental license. To export or re-export some or all of these products from a
country other than Japan may also be prohibited without a license from that country. Please call an NEC sales
representative.
The application circuits and their parameters are for reference only and are not intended for use in actual design-ins.
M7 96.5
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
• 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 Benelux Office Hong Kong
Tel: 800-366-9782 Eindhoven, The Netherlands Tel: 2886-9318
Fax: 800-729-9288 Tel: 040-2445845 Fax: 2886-9022/9044
Fax: 040-2444580
NEC Electronics (Germany) GmbH NEC Electronics Hong Kong Ltd.
Duesseldorf, Germany NEC Electronics (France) S.A. Seoul Branch
Tel: 0211-65 03 02 Velizy-Villacoublay, France Seoul, Korea
Fax: 0211-65 03 490 Tel: 01-30-67 58 00 Tel: 02-528-0303
Fax: 01-30-67 58 99 Fax: 02-528-4411
NEC Electronics (UK) Ltd.
Milton Keynes, UK NEC Electronics (France) S.A. NEC Electronics Singapore Pte. Ltd.
Tel: 01908-691-133 Spain Office United Square, Singapore 1130
Fax: 01908-670-290 Madrid, Spain Tel: 253-8311
Tel: 01-504-2787 Fax: 250-3583
NEC Electronics Italiana s.r.1. Fax: 01-504-2860
Milano, Italy NEC Electronics Taiwan Ltd.
Tel: 02-66 75 41 NEC Electronics (Germany) GmbH Taipei, Taiwan
Fax: 02-66 75 42 99 Scandinavia Office Tel: 02-719-2377
Taeby, Sweden Fax: 02-719-5951
Tel: 08-63 80 820
Fax: 08-63 80 388 NEC do Brasil S.A.
Sao Paulo-SP, Brasil
Tel: 011-889-1680
Fax: 011-889-1689
J96. 8
Major Revisions in This Edition
Page Description
Throughout Addition of following products as target products:
µPD780018, 780018Y, 780058, 780058Y, 780308, 780308Y, 78058F, 78058FY, 78064B, 78075B, 78075BY,
78098B subseries, µPD78070A, 78070AY
µPD78052(A), 78053(A), 78054(A)
µPD78062(A), 78063(A), 78064(A)
µPD78081(A), 78082(A), 78P083(A), 78081(A2)
µPD78058F(A), 78058FY(A)
µPD78064B(A)
Deletion of following products as target products:
µPD78P054Y, 78P064Y, 78074, 78075, 78075, 78074Y, 78075Y
p.100 Addition of Note 2 and Caution 2 to Figure 4-5 Format of Watchdog Timer Mode Register
p.113 Addition of Caution to Figure 5-8 Format of External Interrupt Mode Register 0
p.196 Addition of Table 8-2 Items Supported by Each Subseries
p.197 Addition of Table 8-3 Registers of Serial Interface
p.204, p206 Addition of note on using wake-up function and note on changing operation mode to Figures 8-7 and 8-8
Format of Serial Operating Mode Register 0
p.218, p.224 Addition of Caution to Figures 8-16 and 8-17 Format of Automatic Data Transfer/Reception Interval
Specification Register
p.239 Addition of Figures 8-23 and 8-24 Format of Serial Interface Pin Select Register
p.240 µPD6252 as maintenance product in 8.1 Interface with EEPROMTM (µPD6252)
p.250 Addition of (5) Limitations when using I2C bus mode to 8.1.2 Communication in I2C bus mode
p.286 Addition of (f) Limitations when using UART mode to 8.5 Interface in Asynchronous Serial Interface
(UART) Mode
p.347 Addition of Figure 11-3 Format of Port Mode Register 12
p.216, p.217 Description of following register formats and tables for each subseries:
p.229-p.232 Figures 8-14 and 8-15 Format of Automatic Data Transmission/Reception Control Register
p.352, p.353 Tables 8-4, 8-5, and 8-6 Setting of Operation Modes of Serial Interface Channel 2
Figures 12-1 and 12-2 Format of LCD Display Mode Register
Readers This Application Note is intended for use by engineers who understand the functions
of the 78K/0 series and wish to design application programs with the following
subseries products:
• Subseries
µPD78054 subseries : µPD78052, 78053, 78054, 78P054, 78055, 78056,
78058, 78P058, 78052(A), 78053(A), 78054(A)
µPD78054Y subseries : µPD78052Y, 78053Y, 78054Y, 78055Y, 78056Y,
78058Y, 78P058Y
µPD78064 subseries : µPD78062, 78063, 78064, 78P064, 78062(A), 78063(A),
78064(A)
µPD78064Y subseries : µPD78062Y, 78063Y, 78064Y
µPD78078 subseries : µPD78076, 78078, 78P078
µPD78078Y subseries : µPD78076Y, 78078Y, 78P078Y
µPD78083 subseries : µPD78081, 78082, 78P083, 78081(A), 78082(A),
78P83(A), 78081(A2)
µPD78098 subseries : µPD78094, 78095, 78096, 78098ANote 1, 78P098ANote 1
µPD780018 subseries : µPD780016Note 2, 780018Note 2, 78P0018Note 2
µPD780018Y subseries : µPD780016YNote 2, 780018YNote 2, 78P0018YNote 2
µPD780058 subseries : µPD780053Note 1, 780054Note 1, 780055Note 1,
780056Note 1, 780058Note 1, 78F0058Note 1
µPD780058Y subseries : µPD780053YNote 2, 780054YNote 2,
780055YNote 2, 780056YNote 2, 780058YNote 2,
78F0058YNote 2
µPD780308 subseries : µPD780306Note 1, 780308Note 1, 78P0308Note 1
µPD780308Y subseries : µPD780306YNote 1, 780308YNote 1, 78P0308YNote 1
µPD78058F subseries : µPD78056F, 78058F, 78P058F, 78058F(A)
µPD78058FY subseries : µPD78056FY, 78058FY, 78P058FY, 78P058FY(A)
µPD78064B subseries : µPD78064B, 78P064B, 78064B(A)
µPD78070A, 78070AY
µPD78075B subseries : µPD78074B, 78075B
µPD78075BY subseries: µPD78074BYNote 1, 78075BYNote 1
µPD78098B subseries : µPD78095BNote 2, 78096BNote 2, 78098BNote 2,
78P098BNote 2
In addition to this Application Note, the following Application Notes are also available:
Document Number
Document Name Targeted Subseries Contents
Japanese English
Caution The application examples and program lists shown in this Application Note assume that the main
system clock operates at 4.19 MHz, not at 5.0 MHz.
How to Read This Manual Although this Application Note explains the functions of the 78K/0 series products,
the functions of some products in each subseries differ from those of the others.
(1/2)
(2/2)
Please refer to "Quality Grades on NEC Semiconductor Devices" (Document No. C11531E) published by
NEC Corporation to know the specification of quality grade on the devices and its recommended applications.
Related documents
Some of the related documents listed below are preliminary versions but not so specified here.
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
µPD78052, 78053, 78054, 78055, 78056, 78058 Data Sheet U12327J IC-3403
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
µPD78070A U10133J –
µPD78070AY U10134J –
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
Document Number
Document Name
Japanese English
The contents of the above related documents are subject to change without notice. Be sure to use the
latest edition when you design your system.
CONTENTS
–i–
8.2 Interface with OSD LSI (µPD6451A) ............................................................................ 260
8.3 Interface in SBI Mode .................................................................................................... 265
8.3.1 Application as master CPU ............................................................................................. 267
8.3.2 Application as slave CPU ................................................................................................ 276
8.4 Interface in 3-Wire Serial I/O Mode ............................................................................. 279
8.4.1 Application as master CPU ............................................................................................. 280
8.4.2 Application as slave CPU ................................................................................................ 283
8.5 Interface in Asynchronous Serial Interface (UART) Mode ...................................... 286
– ii –
LIST OF FIGURES (1/6)
– iii –
LIST OF FIGURES (2/6)
– iv –
LIST OF FIGURES (3/6)
6-3. Format of Timer Clock Select Register 1 (µPD780018, 780018Y subseries) .............................. 167
6-4. Format of 8-Bit Timer Mode Control Register .............................................................................. 168
6-5. Format of 8-Bit Timer Output Control Register ............................................................................ 169
6-6. Format of Port Mode Register 3 ................................................................................................... 170
6-7. Count timing of 8-Bit Timers ........................................................................................................ 171
6-8. Musical Scale Generation Circuit ................................................................................................. 174
6-9. Timer Output and Interval ............................................................................................................ 174
–v–
LIST OF FIGURES (4/6)
– vi –
LIST OF FIGURES (5/6)
– vii –
LIST OF FIGURES (6/6)
12-1. Format of LCD Display Mode Register (µPD78064, 78064Y, 78064B subseries) ....................... 352
12-2. Format of LCD Display Mode Register (µPD780308, 780308Y subseries) ................................. 353
12-3. Format of LCD Display Control Register ...................................................................................... 354
12-4. Relations between Contents of LCD Display Data Memory and Segment/Common Output ....... 356
12-5. Common Signal Waveform .......................................................................................................... 358
12-6. Phase Difference in Voltage between Command Signal and Segment Signal ............................ 359
12-7. Display Pattern and Electrode Wiring of Static LCD .................................................................... 360
12-8. Connection of Static LCD ............................................................................................................. 361
12-9. Example of Connecting LCD Driving Power in Static Display Mode
(with external divider resistor, VDD = 5 V, and VLCD = 5 V) ........................................................... 361
12-10. Example of Static LCD Driving Waveform ................................................................................... 362
12-11. Display Pattern of 4-Time Division LCD and Electrode Wiring .................................................... 366
12-12. Connections of 4-Time Division LCD Panel ................................................................................. 367
12-13. Example of Connecting LCD Drive Power in 4-Time Division Mode
(with external divider resistor, VDD = 5 V, VLCD = 5 V) .................................................................. 367
12-14. Example of 4-Time Division LCD Driving Waveform .................................................................... 368
– viii –
LIST OF TABLES (1/2)
– ix –
LIST OF TABLES (2/2)
10-1. Voltage of SIN Wave Output and Preset Value ........................................................................... 339
11-1. Operation Mode and Output Trigger of Real-Time Output Port ................................................... 346
A-1. Comparison between SPD Symbols and Flowchart Symbol ....................................................... 379
–x–
CHAPTER 1 GENERAL
The following shows the products organized according to usage. The names in the parallelograms are subseries
names.
Inverter control
64-pin µPD780964 A/D converter of the µ PD780924 was enhanced
64-pin µPD780924 On-chip inverter control circuit and UART. EMI-noise was reduced.
FIPTM drive
100-pin µ PD780208 The I/O and FIP C/D of the µ PD78044F were enhanced, Display output total: 53
100-pin µ PD780228 The I/O and FIP C/D of the µ PD78044H were enhanced, Display output total: 48
78K/0 80-pin µ PD78044H An N-ch open drain I/O was added to the µ PD78044F, Display output total: 34
Series
80-pin µPD78044F Basic subseries for driving FIP, Display output total: 34
LCD drive
100-pin µ PD780308 µPD780308Y The SIO of the µPD78064 was enhanced, and ROM, RAM capacity increased
100-pin µPD78064B EMI-noise reduced version of the µ PD78064
100-pin µPD78064 µ PD78064Y Basic subseries for driving LCDs, On-chip UART
IEBusTM supported
80-pin µ PD78098B EMI-noise reduced version of the µPD78098
80-pin µ PD78098 An IEBus controller was added to the µPD78054
Meter control
80-pin µ PD780973 On-chip automobile meter driving controller/driver
LV
64-pin µ PD78P0914 On-chip PWM output, LV digital code decoder, and Hsync counter
1
CHAPTER 1 GENERAL
The following lists the main functional differences between subseries products.
Control µPD78075B 32K-40K 4ch 1ch 1ch 1ch 8ch – 2ch 3ch (UART: 1ch) 88 1.8 V
µPD78078 48K-60K
µPD78070A – 61 2.7 V
µPD780058 24K-60K 2ch 2ch 3ch (time division UART: 1ch) 68 1.8 V
FIP µPD780208 32K-60K 2ch 1ch 1ch 1ch 8ch – – 2ch 74 2.7 V –
drive µPD780228 48K-60K 3ch – – 1ch 72 4.5 V
µPD78044H 32K-48K 2ch 1ch 1ch 68 2.7 V
µPD78064 16K-32K
IEBus µPD78098 40K-60K 2ch 1ch 1ch 1ch 8ch – 2ch 3ch (UART: 1ch) 69 2.7 V
supported µPD78098B 32K-60K
Meter µPD780973 24K-32K 3ch 1ch 1ch 1ch 5ch – – 2ch (UART: 1ch) 56 4.5 V –
control
2
CHAPTER 1 GENERAL
The 78K/0 series is a collection of 8-bit single-chip microcontrollers ideal for commercial systems.
The µPD78054 and 78054Y subseries are provided with peripheral hardware functions such as an A/D converter,
D/A converter, timer, serial interface, real-time output port, and interrupt function.
The µPD78064 and 78064Y subseries are provided with peripheral hardware functions such as an LCD controller/
driver, A/D converter, timer, serial interface, and interrupt function.
The µPD78078 and 78078Y subseries are based on the µPD78054 and 78054Y subseries with a timer added and
the external interface function reinforced.
The µPD78083 subseries is provided with peripheral hardware functions such as an A/D converter, timer, serial
interface, and interrupt function.
The µPD78098 subseries is based on the µPD78054 subseries with an IEBus controller added.
The µPD780018 and 780018Y subseries are versions of the µPD78078 and 78078Y subseries (serial interface
with time division transfer function) with an improved serial interface and a limited number of functions.
The µPD780058 and 780058Y subseries are low-EMI noise versions of the µPD78054 and 78054Y subseries
(serial interface with time division transfer function), with an improved serial interface.
The µPD780308 and 780308Y subseries are versions of the µPD78064 and 78064Y subseries with increased ROM
and RAM with an improved serial interface.
The µPD78058F, 78058FY, 78064B, 78075B, 78075BY, and 78098B subseries are low-EMI noise versions of the
µPD78054, 78054Y, 78064, 78078, 78078Y, and 78098 subseries.
The µPD78070A and 78070AY subseries are the ROM-less versions of the µPD78078 and 78078Y subseries.
The µPD78054Y, 78064Y, 78078Y, 780058Y, 780308Y, 78058FY, 78075BY subseries and µPD78070AY are
provided with I2C bus control function instead of the SBI function of the µPD78054, 78064, 78078, 780058, 780308,
78058F, 78075B subseries and µPD78070A.
In addition, one-time PROM, EPROM, or flash-memory models that can operate at the same operating voltage
as the mask ROM models and that are ideal for early and small-scale production of the application system are also
available.
The block diagram and function outline of each series is shown on the following pages.
3
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
SI0/SB0/P25 PORT5
SERIAL P50-P57
SO0/SB1/P26
INTERFACE 0
SCK0/P27 78K/0
ROM
CPU CORE
PORT6 P60-P67
SI1/P20
SO1/P21
SERIAL
SCK1/P22
INTERFACE 1 PORT7 P70-P72
STB/P23
BUSY/P24
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P054, 78P058
4
CHAPTER 1 GENERAL
High-speed RAM 512 bytes 1024 bytes 1024 bytesNote 3 1024 bytes 1024 bytesNote 3
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Notes 1. The µPD78P054 is a PROM model of the µPD78052, 78053, and 78054.
2. The µPD78P058 is a PROM model of the µPD78055, 78056, and 78058.
3. The capacities of the internal PROM and internal high-speed RAM can be changed by using a memory
size select register (IMS).
4. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
5
CHAPTER 1 GENERAL
Notes 1. The µPD78P054 is a PROM model of the µPD78052, 78053, and 78054.
2. The µPD78P058 is a PROM model of the µPD78055, 78056, and 78058.
3. Under planning
6
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
SI0/SB0/SDA0/P25 PORT5
SERIAL P50-P57
SO0/SB1/SDA1/P26
INTERFACE 0
SCK0/SCL/P27 78K/0
ROM
CPU CORE
PORT6 P60-P67
SI1/P20
SO1/P21
SERIAL
SCK1/P22
INTERFACE 1 PORT7 P70-P72
STB/P23
BUSY/P24
Remarks 1. The capacities of the internal ROM and RAM differ depending on the model.
2. ( ): µPD78P058Y
7
CHAPTER 1 GENERAL
Item
µPD78052Y µPD78053Y µPD78054Y µPD78055Y µPD78056Y µPD78058Y µPD78P058Y
Part Number
Internal ROM Mask ROM PROM
memory
16K bytes 24K bytes 32K bytes 40K bytes 48K bytes 60K bytes 60K bytesNote 1
Notes 1. The capacities of the internal PROM and internal high-speed RAM can be changed by using a memory
size select register (IMS).
2. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
8
CHAPTER 1 GENERAL
Item
µPD78052Y µPD78053Y µPD78054Y µPD78055Y µPD78056Y µPD78058Y µPD78P058Y
Part Number
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Package • 80-pin plastic QFP (14 × 14 mm, resin thickness 2.7 mm)
• 80-pin plastic QFP (14 × 14 mm, resin thickness 1.4 mm)Note
• 80-pin ceramic WQFN (14 × 14 mm)(µPD78P058Y only)
9
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT1 P10-P17
TO1/P31 8-bit TIMER/EVENT
TI1/P33 COUNTER 1
PORT2 P25-P27
PORT7 P70-P72
WATCHDOG TIMER
PORT8 P80-P87
WATCH TIMER 78K/0
ROM
CPU CORE
PORT9 P90-P97
SI0/SB0/P25
SERIAL
SO0/SB1/P26
INTERFACE 0
SCK0/P27 PORT10 P100-P103
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P064
10
CHAPTER 1 GENERAL
Item
µPD78062 µPD78063 µPD78064 µPD78P064
Part Number
Internal ROM Mask ROM PROM
memory 16K bytes 24K bytes 32K bytes 32K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Package • 100-pin plastic QFP (fine pitch) (14 × 14 mm, resin thickness 1.45 mm)
• 100-pin plastic LQFP (fine pitch) (14 × 14 mm, resin thickness 1.4 mm)
• 100-pin plastic QFP (14 × 20 mm)
• 100-pin ceramic WQFN (14 × 20 mm)Note 2 (µPD78P064 only)
Notes 1. The capacities of the internal PROM and internal high-speed RAM can be changed by using a memory
size select register (IMS).
2. Under development
11
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT1 P10-P17
TO1/P31 8-bit TIMER/EVENT
TI1/P33 COUNTER 1
PORT2 P25-P27
PORT7 P70-P72
WATCHDOG TIMER
PORT8 P80-P87
WATCH TIMER 78K/0
ROM
CPU CORE
PORT9 P90-P97
SI0/SB0/SDA0/P25
SERIAL
SO0/SB1/SDA1/P26
INTERFACE 0
SCK0/SDL/P27 PORT10 P100-P103
Remark The internal ROM and RAM capacities differ depending on the model.
12
CHAPTER 1 GENERAL
Item
µPD78062Y µPD78063Y µPD78064Y
Part Number
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Timer • 16-bit timer/event counter : 1 channel
• 8-bit timer/event counter : 2 channels
• Watch timer : 1 channel
• Watchdog timer : 1 channel
Timer output 3 (14-bit PWM output: 1)
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
Vectored Maskable Internal: 12, external: 6
interrupt Non-maskable Internal: 1
source Software 1
Test input Internal: 1, external: 1
Supply voltage VDD = 2.0 to 6.0 V
Package • 100-pin plastic QFP (fine pitch) (14 × 14 mm, resin thickness 1.45 mm)
• 100-pin plastic LQFP (fine pitch) (14 × 14 mm, resin thickness 1.4 mm)
• 100-pin plastic QFP (14 × 20 mm)
13
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
8-bit TIMER/EVENT
TI5/TO5/P100
COUNTER 5 PORT4 P40-P47
PORT7 P70-P72
WATCH TIMER
14
CHAPTER 1 GENERAL
Item
µPD78076 µPD78078 µPD78P078
Part Number
Internal ROM Mask ROM PROM
memory
48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
timon clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
source Software 1
Package • 100-pin plastic QFP (fine pitch) (14 × 14 mm, resin thickness 1.45 mm)
• 100-pin plastic LQFP (fine pitch) (14 × 14 mm, resin thickness 1.4 mm)Note 2
• 100-pin plastic QFP (14 × 20 mm, resin thickness 2.7 mm)
• 100-pin ceramic WQFN (14 × 20 mm) (µPD78P078 only)
Notes 1. The internal ROM capacity can be changed by using a memory size select register (IMS).
2. Under planning
15
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
8-bit TIMER/EVENT
TI5/TO5/P100
COUNTER 5 PORT4 P40-P47
PORT7 P70-P72
WATCH TIMER
16
CHAPTER 1 GENERAL
Item
µPD78076Y µPD78078Y µPD78P078Y
Part Number
Internal ROM Mask ROM PROM
memory 48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Timer • 16-bit timer/event counter : 1 channel
• 8-bit timer/event counter : 4 channels
• Watch timer : 1 channel
• Watchdog timer : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
Vectored Maskable Internal: 15, external: 7
interrupt Non-maskable Internal: 1
source Software 1
Test input Internal: 1, external: 1
Supply voltage VDD = 1.8 to 5.5 V
Package • 100-pin plastic QFP (14 × 20 mm, resin thickness 2.7 mm)
• 100-pin plastic LQFP (fine pitch) (14 × 14 mm, resin thickness 1.4 mm)Note 2
• 100-pin ceramic WQFN (14 × 20 mm) (µPD78P078Y only)
Notes 1. The internal ROM capacity can be changed by using a memory size select register (IMS).
2. Under development
17
CHAPTER 1 GENERAL
P00
8-bit TIMER/
TI5/TO5/P100 PORT0 P01-P03
EVENT COUNTER 5
5-bit TIMER/
TI6/TO6/P101
EVENT COUNTER 6 PORT1 P10-P17
78K/0
WATCHDOG TIMER ROM
CPU CORE
PORT3 P30-P37
SI2/RxD/P70
SERIAL
SO2/TxD/P71
INTERFACE 2
SCK2/ASCK/P72
ANI0/P10- PORT5 P50-P57
ANI7/P17
AVDD A/D CONVERTER
AVSS
AVREF1
RAM PORT7 P70-P72
INTP1/P01- INTERRUPT
INTP3/P03 CONTROL
RESET
CLOCK OUTPUT SYSTEM
PCL/P35 VDD VSS IC X1
CONTROL CONTROL
(VPP) X2
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P083
18
CHAPTER 1 GENERAL
Item
µPD78081 µPD78082 µPD78P083
Part Number
Internal ROM Mask ROM PROM
memory 8K bytes 16K bytes 24K bytesNote 1
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz
(with main system clock of 5.0 MHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Notes 1. The capacities of the internal PROM and internal-high-speed RAM can be changed by using a memory
size select register. (IMS)
2. The supply voltage (VDD) of the µPD78081(A2) is 4.5 to 5.5 V.
19
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
PORT5 P50-P57
SI0/SB0/P25
SERIAL
SO0/SB1/P26
INTERFACE 0 PORT6 P60-P67
SCK0/P27 78K/0
ROM
CPU CORE
SI1/P20
PORT7 P70-P72
SO1/P21
SERIAL
SCK1/P22
INTERFACE 1
STB/P23 PORT12 P120-P127
BUSY/P24
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P098A
20
CHAPTER 1 GENERAL
Item
µPD78094 µPD78095 µPD78096 µPD78098ANote 1 µPD78P098ANote 1, 2
Part Number
Internal ROM Mask ROM PROM
memory 32K bytes 40K bytes 48K bytes 60K bytes 60K bytesNote 3
Minimum With main 0.5 µs/1.0 µs/2.0 µs/4.0 µs/8.0 µs/16.0 (at 6.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
21
CHAPTER 1 GENERAL
Item
µPD78094 µPD78095 µPD78096 µPD78098ANote 1 µPD78P098ANote 1, 2
Part Number
Buzzer output 977 Hz, 1.95 kHz, 3.9 kHz, 7.8 kHz (with main system clock of 6.0 MHz)
Vectored Maskable Internal: 14, external: 7
interrupt Non-maskable Internal: 1
source Software 1
Test input Internal: 1, external: 1
Supply voltage VDD = 2.7 to 6.0 V
Package • 80-pin plastic QFP (14 × 14 mm)
• 80-pin ceramic WQFN (14 × 14 mm)Note 1 (µPD78P098A only)
22
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01
PORT3 P30-P37
8-bit TIMER/EVENT
TI5/TO5/P100
COUNTER 5
PORT4 P40-P47
8-bit TIMER/EVENT
TI6/TO6/P101
COUNTER 6
78K/0 PORT5 P50-P57
ROM
WATCHDOG TIMER CPU CORE
PORT6 P60-P67
WATCH TIMER
23
CHAPTER 1 GENERAL
Item
µPD780016 µPD780018 µPD78P0018
Part Number
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O mode (with automatical transfer/reception function) : 1 channel
• 3-wire serial I/O mode selectable (with time-division transfer function) : 1 channel
Clock output 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with main
system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Note The internal ROM capacity can be changed by using a memory size select register. (IMS)
24
CHAPTER 1 GENERAL
Item
µPD780016 µPD780018 µPD78P0018
Part Number
Buzzer output 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
25
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01
WATCH TIMER
PORT6 P60-P67
SI1/P20
SO1/P21
SERIAL PORT8 P80-P87
SCK1/P22
INTERFACE 1
STB/P23
BUSY/P24
RAM
PORT9 P90-P96
SI4A/P90
SO4A/P91
SCK4A/P92
PORT10 P100-P103
SI4B/P93
SO4B/P94 SERIAL
SCK4B/P95 INTERFACE 4
PORT11 P110-P117
SI4C/P110
SO4C/P111
SCK4C/P112
PORT15 P150-P156
SDA/P116 SERIAL
SCL/P117 INTERFACE 5 AD0/P40-
AD7/P47
ANI0/P10- A0/P80-
ANI7/P17 A7/P87
A/D CONVERTER EXTERNAL A8/P50-
AVSS ACCESS A15/P57
AVREF RD/P64
WR/P65
INTP0/P00- INTERRUPT WAIT/P66
INTP6/P06 CONTROL ASTB/P67
26
CHAPTER 1 GENERAL
Item
µPD780016Y µPD780018Y µPD78P018Y
Part Number
Serial interface • 3-wire serial I/O mode (with automatical transfer/reception function) : 1 channel
• 3-wire serial I/O mode selectable (with time-division transfer function) : 1 channel
• I2C bus mode (multi-master compatible) : 1 channel
Note The internal PROM capacity can be changed by using a memory size select register. (IMS)
27
CHAPTER 1 GENERAL
Item
µPD780016Y µPD780018Y µPD78P018Y
Part Number
Buzzer output 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
28
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT3 P30-P37
WATCHDOG TIMER
SI0/SB0/P25
SERIAL
SO0/SB1/P26
INTERFACE 0 ROM PORT5 P50-P57
SCK0/P27 78K/0
FLASH
CPU CORE
MEMORY
SI1/P20
SO1/P21 PORT6 P60-P67
SERIAL
SCK1/P22
INTERFACE 1
STB/TxD1/P23
BUSY/RxD1/P24 PORT7 P70-P72
BUSY/RxD1/P24
STB/TxD1/P23 PORT12 P120-P127
SERIAL
SI2/RxD0/P70 RAM
INTERFACE 2
SO2/TxD0/P71
SCK2/ASCK/P72
PORT13 P130, P131
ANI0/P10-
ANI7/P17
A/D CONVERTER REAL-TIME RTP0/P120-
AVSS
OUTPUT PORT RTP7/P127
AVREF0
ANO0/P130, AD0/P40-
ANO1/P131 AD7/P47
AVSS D/A CONVERTER
A8/P50-
AVREF1 EXTERNAL A15/P57
ACCESS RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP5/P05 CONTROL WAIT/P66
ASTB/P67
Remarks 1. The capacities of the internal ROM and RAM differ depending on the model.
2. ( ): µPD78F0058
29
CHAPTER 1 GENERAL
Item
µPD780053 µPD780054 µPD780055 µPD780056 µPD780058 µPD78F0058
Part Number
Internal ROM Mask ROM Flash memory
memory
24K bytes 32K bytes 40K bytes 48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable (with time-division transfer function) : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Notes 1. The capacities of the flash memory can be changed by using a memory size select register (IMS).
2. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
30
CHAPTER 1 GENERAL
Item
µPD780053 µPD780054 µPD780055 µPD780056 µPD780058 µPD78F0058
Part Number
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Package • 80-pin plastic QFP (14 × 14 mm, resin thickness 2.7 mm)
• 80-pin plastic QFP (14 × 14 mm, resin thickness 1.4 mm)Note
• 80-pin plastic TQFP (fine pitch) (12 × 12 mm)
31
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT3 P30-P37
WATCHDOG TIMER
SI0/SB0/SDA0/P25
SERIAL
SO0/SB1/SDA1/P26
INTERFACE 0 ROM PORT5 P50-P57
SCK0/SCL/P27 78K/0
FLASH
CPU CORE
MEMORY
SI1/P20
SO1/P21 PORT6 P60-P67
SERIAL
SCK1/P22
INTERFACE 1
STB/TxD1/P23
BUSY/RxD1/P24 PORT7 P70-P72
BUSY/RxD1/P24
STB/TxD1/P23 PORT12 P120-P127
SERIAL
SI2/RxD0/P70 RAM
INTERFACE 2
SO2/TxD0/P71
SCK2/ASCK/P72
PORT13 P130, P131
ANI0/P10-
ANI7/P17
A/D CONVERTER REAL-TIME RTP0/P120-
AVSS
OUTPUT PORT RTP7/P127
AVREF0
ANO0/P130, AD0/P40-
ANO1/P131 AD7/P47
AVSS D/A CONVERTER
A8/P50-
AVREF1 EXTERNAL A15/P57
ACCESS RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP5/P05 CONTROL WAIT/P66
ASTB/P67
Remarks 1. The capacities of the internal ROM and RAM differ depending on the model.
2. ( ): µPD78F0058Y
32
CHAPTER 1 GENERAL
Item
µPD780053Y µPD780054Y µPD780055Y µPD780056Y µPD780058Y µPD78F0058Y
Part Number
Internal ROM Mask ROM Flash memory
memory
24K bytes 32K bytes 40K bytes 48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable (with time-division transfer function) : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Notes 1. The capacities of the flash memory can be changed by using a memory size select register (IMS).
2. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
33
CHAPTER 1 GENERAL
Item
µPD780053Y µPD780054Y µPD780055Y µPD780056Y µPD780058Y µPD78F0058Y
Part Number
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
Software 1
Package • 80-pin plastic QFP (14 × 14 mm, resin thickness 2.7 mm)
• 80-pin plastic QFP (14 × 14 mm, resin thickness 1.4 mm)
• 80-pin plastic TQFP (fine pitch) (12 × 12 mm)
34
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P25-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT7 P70-P72
WATCH TIMER
PORT8 P80-P87
SI0/SB0/P25 78K/0
SERIAL ROM
SO0/SB1/P26 CPU CORE
INTERFACE 0 PORT9 P90-P97
SCK0/P27
SI2/RXD/P70
SO2/TXD/P71 PORT10 P100-P103
SERIAL
RXD/P114
INTERFACE 2
TXD/P113
SCK2/ASCK/P72 PORT11 P110-P117
SI3/P110
SERIAL RAM
SO3/P111 S0-S23
INTERFACE 3
SCK3/P112
S24/P97-
ANI0/P10- S31/P90
ANI7/P17 S32/P87-
AVDD A/D CONVERTER LCD
S39/P80
AVSS CONTROLLER/
AVREF DRIVER COM0-COM3
VLC0-VLC2
INTP0/P00- INTERRUPT
INTP5/P05 CONTROL BIAS
fLCD
35
CHAPTER 1 GENERAL
Item
µPD780306 µPD780308 µPD78P0308
Part Number
Internal ROM Mask ROM PROM
memory 48K bytes 60K bytes 60K bytesNote
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
• 3-wire serial I/O mode : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
Software 1
Note The capacity of the internal PROM can be changed by using a memory size select register (IMS).
36
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT1 P10-P17
TO1/P31 8-bit TIMER/EVENT
TI1/P33 COUNTER 1
PORT2 P25-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT7 P70-P72
WATCH TIMER
PORT8 P80-P87
SI0/SB0/SDA0/P25 78K/0
ROM
CPU CORE
SO0/SB1/SDA1/P26
SERIAL PORT9 P90-P97
RxD/P114 INTERFACE 0
TxD/P113
SCK0/SDL/P27
PORT10 P100-P103
SI2/RXD/P70
SERIAL
SO2/TXD/P71
INTERFACE 2 PORT11 P110-P117
SCK2/ASCK/P72
SI3/P110 RAM
SERIAL S0-S23
SO3/P111
INTERFACE 3
SCK3/P112 S24/P97-
S31/P90
ANI0/P10-
ANI7/P17 S32/P87-
AVDD LCD S39/P80
A/D CONVERTER
AVSS CONTROLLER/
DRIVER COM0-COM3
AVREF
VLC0-VLC2
INTP0/P00- INTERRUPT
BIAS
INTP5/P05 CONTROL
fLCD
37
CHAPTER 1 GENERAL
Item
µPD780306Y µPD780308Y µPD78P0308Y
Part Number
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
Instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
cycle clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
• 3-wire serial I/O mode : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Note The capacity of the internal PROM can be changed by using a memory size select register (IMS).
38
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
PORT5 P50-P57
SI0/SB0/P25
SERIAL
SO0/SB1/P26 78K/0
INTERFACE 0 ROM
SCK0/P27 CPU CORE
PORT6 P60-P67
SI1/P20
SO1/P21
SERIAL PORT7 P70-P72
SCK1/P22
INTERFACE 1
STB/P23
BUSY/P24
PORT12 P120-P127
SI2/RXD/P70
SERIAL
SO2/TXD/P71
INTERFACE 2 RAM PORT13 P130, P131
SCK2/ASCK/P72
ANI0/P10-
ANI7/P17 REAL-TIME RTP0/P120-
A/D CONVERTER OUTPUT PORT RTP7/P127
AVREF0
ANO0/P130, AD0/P40-
ANO1/P131 D/A CONVERTER AD7/P47
AVREF1 A8/P50-
EXTERNAL A15/P57
ACCESS RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP6/P06 CONTROL
WAIT/P66
ASTB/P67
BUZ/P36 BUZZER OUTPUT RESET
X1
SYSTEM
CONTROL X2
CLOCK OUTPUT
PCL/P35 VDD VSS AVDD AVSS IC XT1/P07
CONTROL
(VPP) XT2
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P058F
39
CHAPTER 1 GENERAL
Item
µPD78056F µPD78058F µPD78P058F
Part Number
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Notes 1. The capacity of the internal PROM can be changed by using a memory size select register (IMS).
2. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
40
CHAPTER 1 GENERAL
Item
µPD78056F µPD78058F µPD78P058F
Part Number
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
Package • 80-pin plastic QFP (14 × 14 mm, resin thickness 2.7 mm)
• 80-pin plastic QFP (14 × 14 mm, resin thickness 1.4 mm)Note
• 80-pin plastic TQFP (fine pitch) (12 × 12 mm) (µPD78058F only)
41
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
PORT5 P50-P57
SI0/SB0/SDA0/P25
SERIAL
SO0/SB1/SDA1/P26 78K/0
INTERFACE 0 ROM
SCK0/SCL/P27 CPU CORE
PORT6 P60-P67
SI1/P20
SO1/P21
SERIAL PORT7 P70-P72
SCK1/P22
INTERFACE 1
STB/P23
BUSY/P24
PORT12 P120-P127
SI2/RXD/P70
SERIAL
SO2/TXD/P71
INTERFACE 2 RAM PORT13 P130, P131
SCK2/ASCK/P72
ANI0/P10-
ANI7/P17 REAL-TIME RTP0/P120-
A/D CONVERTER OUTPUT PORT RTP7/P127
AVREF0
ANO0/P130, AD0/P40-
ANO1/P131 D/A CONVERTER AD7/P47
AVREF1 A8/P50-
EXTERNAL A15/P57
ACCESS RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP6/P06 CONTROL
WAIT/P66
ASTB/P67
BUZ/P36 BUZZER OUTPUT RESET
X1
SYSTEM
CONTROL X2
CLOCK OUTPUT
PCL/P35 VDD VSS AVDD AVSS IC XT1/P07
CONTROL
(VPP) XT2
Remarks 1. The capacities of the internal ROM and RAM differ depending on the model.
2. ( ): µPD78P058FY
42
CHAPTER 1 GENERAL
Item
µPD78056FY µPD78058FY µPD78P058FY
Part Number
Internal ROM Mask ROM PROM
memory
48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Notes 1. The capacity of the internal PROM can be changed by using a memory size select register (IMS).
2. The internal expansion RAM capacity can be changed by using an internal expansion RAM size select
register (IXS).
43
CHAPTER 1 GENERAL
Item
Part Number µPD78056FY µPD78058FY µPD78P058FY
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
Package • 80-pin plastic QFP (14 × 14 mm, resin thickness 2.7 mm)
• 80-pin plastic QFP (14 × 14 mm, resin thickness 1.4 mm)Note
• 80-pin plastic TQFP (fine pitch)(12 × 12 mm) (µPD78058FY only)
44
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P05
EVENT COUNTER
TI01/INTP1/P01 P07
PORT1 P10-P17
TO1/P31 8-bit TIMER/EVENT
TI1/P33 COUNTER 1
PORT2 P25-P27
PORT7 P70-P72
WATCHDOG TIMER
PORT8 P80-P87
78K/0
WATCH TIMER ROM
CPU CORE
PORT9 P90-P97
SI0/SB0/P25
SERIAL
SO0/SB1/P26 PORT10 P100-P103
INTERFACE 0
SCK0/P27
PORT11 P110-P117
SI2/RXD/P70
SERIAL
SO2/TXD/P71
INTERFACE 2
SCK2/ASCK/P72 RAM
S0-S23
S24/P97-
ANI0/P10- S31/P90
ANI7/P17 A/D CONVERTER S32/P87-
AVREF LCD
S39/P80
CONTROLLER/
DRIVER COM0-COM3
INTP0/P00- INTERRUPT
VLC0-VLC2
INTP5/P05 CONTROL
BIAS
fLCD
Remark ( ): µPD78P064B
45
CHAPTER 1 GENERAL
Item
µPD78064B µPD78P064B
Part Number
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
46
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
8-bit TIMER/EVENT
TI5/TO5/P100 PORT3
COUNTER 5 P30-P37
8-bit TIMER/EVENT
TI6/TO6/P101
COUNTER 6 PORT6 P60-P63,P66
78K/0
RAM
WATCHDOG TIMER CPU CORE
PORT7 P70-P72
WATCH TIMER
SI2/RXD/P70
SERIAL
SO2/TXD/P71 PORT13 P130, P131
INTERFACE 2
SCK2/ASCK/P72
ANI0/P10-
ANI7/P17 REAL-TIME RTP0/P120-
AVDD A/D CONVERTER OUTPUT PORT RTP7/P127
AVSS
AVREF0
ANO0/P130, AD0-AD7
ANO1/P131
AVSS D/A CONVERTER
EXTERNAL A0-A15
AVREF1 ACCESS
RD
INTP0/P00- INTERRUPT WR
INTP6/P06 CONTROL WAIT/P66
47
CHAPTER 1 GENERAL
48
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
8-bit TIMER/EVENT
TI5/TO5/P100 PORT3
COUNTER 5 P30-P37
8-bit TIMER/EVENT
TI6/TO6/P101
COUNTER 6 PORT6 P60-P63, P66
78K/0
RAM
WATCHDOG TIMER CPU CORE
PORT7 P70-P72
WATCH TIMER
SI2/RXD/P70
SERIAL
SO2/TXD/P71 PORT13 P130, P131
INTERFACE 2
SCK2/ASCK/P72
ANI0/P10-
ANI7/P17 REAL-TIME RTP0/P120-
AVDD A/D CONVERTER OUTPUT PORT RTP7/P127
AVSS
AVREF0
ANO0/P130, AD0-AD7
ANO1/P131
AVSS D/A CONVERTER
EXTERNAL A0-A15
AVREF1 ACCESS
RD
INTP0/P00- INTERRUPT WR
INTP6/P06 CONTROL WAIT/P66
49
CHAPTER 1 GENERAL
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
50
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
8-bit TIMER/EVENT
TI5/TO5/P100 PORT4 P40-P47
COUNTER 5
PORT7 P70-P72
WATCH TIMER
SI2/RXD/P70
SERIAL PORT13 P130, P131
SO2/TXD/P71
INTERFACE 2
SCK2/ASCK/P72
REAL-TIME RTP0/P120-
ANI0/P10-
OUTPUT PORT RTP7/P127
ANI7/P17
AVSS A/D CONVERTER
AD0/P40-
AVREF0
AD7/P47
ANO0/P130, A0/P80-
ANO1/P131 A7/P87
AVSS D/A CONVERTER A8/P50-
EXTERNAL
AVREF1 ACCESS A15/P57
RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP6/P06 CONTROL WAIT/P66
ASTB/P67
51
CHAPTER 1 GENERAL
Item
µPD78074B µPD78075B
Part Number
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
source Software 1
Package • 100-pin plastic QFP (fine pitch) (14 × 14 mm, resin thickness 1.45 mm)
• 100-pin plastic QFP (14 × 20 mm, resin thickness 2.7 mm)
52
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
8-bit TIMER/EVENT
TI5/TO5/P100 PORT4 P40-P47
COUNTER 5
PORT7 P70-P72
WATCH TIMER
SI2/RXD/P70
SERIAL PORT13 P130, P131
SO2/TXD/P71
INTERFACE 2
SCK2/ASCK/P72
REAL-TIME RTP0/P120-
ANI0/P10-
OUTPUT PORT RTP7/P127
ANI7/P17
AVSS A/D CONVERTER
AD0/P40-
AVREF0 AD7/P47
ANO0/P130, A0/P80-
ANO1/P131 A7/P87
AVSS D/A CONVERTER A8/P50-
EXTERNAL
AVREF1 ACCESS A15/P57
RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP6/P06 CONTROL WAIT/P66
ASTB/P67
53
CHAPTER 1 GENERAL
Item
µPD78074BY µPD78075BY
Part Number
Internal ROM Mask ROM
memory 32K bytes 40K bytes
Minimum With main 0.4 µs/0.8 µs/1.6 µs/3.2 µs/6.4 µs/12.8 µs (at 5.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/2-wire serial I/O/I2C bus mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz, 1.25 MHz, 2.5 MHz, 5.0 MHz (with
main system clock of 5.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 1.2 kHz, 2.4 kHz, 4.9 kHz, 9.8 kHz (with main system clock of 5.0 MHz)
source Software 1
54
CHAPTER 1 GENERAL
TO0/P30 P00
16-bit TIMER/
TI00/INTP0/P00 PORT0 P01-P06
EVENT COUNTER
TI01/INTP1/P01 P07
PORT1 P10-P17
TO1/P31 8-bit TIMER/EVENT
TI1/P33 COUNTER 1
PORT2 P20-P27
TO2/P32 8-bit TIMER/EVENT
TI2/P34 COUNTER 2
PORT3 P30-P37
WATCHDOG TIMER
PORT4 P40-P47
WATCH TIMER
PORT5 P50-P57
SI0/SB0/P25
SERIAL
SO0/SB1/P26 78K/0 PORT6 P60-P67
INTERFACE 0 ROM
SCK0/P27 CPU CORE
ANO0/P130, AD0/P40-
ANO1/P131 D/A CONVERTER AD7/P47
AVREF0 A8/P50-
EXTERNAL A15/P57
ACCESS RD/P64
INTP0/P00- INTERRUPT WR/P65
INTP6/P06 CONTROL
WAIT/P66
ASTB/P67
BUZ/P36 BUZZER OUTPUT RESET
X1
SYSTEM
CONTROL X2
CLOCK OUTPUT
PCL/P35 VDD VSS AVDD AVSS IC XT1/P07
CONTROL
(VPP) XT2
Remarks 1. The internal ROM and RAM capacities differ depending on the model.
2. ( ): µPD78P098B
55
CHAPTER 1 GENERAL
Item
µPD78095B µPD78096B µPD78098B µPD78P098B
Part Number
Internal ROM Mask ROM PROM
memory 40K bytes 48K bytes 60K bytes 60K bytesNote 1
Minimum With main 0.5 µs/1.0 µs/2.0 µs/4.0 µs/8.0 µs/16.0 (at 6.0 MHz)
instruction system clock
execution With subsystem 122 µs (at 32.768 kHz)
time clock
Instruction set • 16-bit operation
• Multiplication/division (8 bits × 8 bits, 16 bits ÷ 8 bits)
• Bit manipulation (set, reset, test, Boolean operation)
• BCD adjustment, etc.
Serial interface • 3-wire serial I/O/SBI/2-wire serial I/O mode selectable : 1 channel
• 3-wire serial I/O mode (with function to automatically transfer/receive up to 32 bytes) : 1 channel
• 3-wire serial I/O/UART mode selectable : 1 channel
Clock output 15.6 kHz, 31.3 kHz, 62.5 kHz, 125 kHz, 250 kHz, 500 kHz, 1.0 MHz, 2.0 MHz, 4.0 MHz (with
main system clock of 6.0 MHz), 32.768 kHz (with subsystem clock of 32.768 kHz)
Buzzer output 977 Hz, 1.95 kHz, 3.9 kHz, 7.8 kHz (with main system clock of 6.0 MHz)
source Software 1
Notes 1. The internal PROM capacity can be changed by using a memory size select register (IMS).
2. The internal expansion RAM can be changed by using an internal expansion RAM size select register
(IXS).
56
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
Data is exchanged by using an address specified by the DE and HL registers as the first address. The number
of bytes of the data to be exchanged is specified by the B register.
Address Address
DE + B – 1 HL + B – 1
Data exchange
DE HL
EXCH:
MOV A,[DE]
XCH A,[HL]
XCH A,[DE]
INCW DE
INCW HL
DBNZ B,$EXCH
RET
57
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
Data is compared by using an address specified by the DE and HL registers as the first address. The number
of bytes of the data to be compared is specified by the B register. If the result of comparison is equal, CY is cleared
to 0; if not, CY is set to 1.
Address Address
DE + B – 1 HL + B – 1
Data comparison
DE HL
COMP:
MOV A,[DE]
CMP A,[HL]
BNZ $ERROR
INCW DE
INCW HL
DBNZ B,$COMP
CLR1 CY
BR RTN
ERROR:
SET1 CY
RTN:
RET
58
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
The lowest address for decimal addition is specified by the DE and HL registers, and the number of digits specified
by BYTNUM is added. The result of the addition is stored to an area specified by the HL register. If an overflow or
underflow occurs as a result of the addition, execution branches to error processing. Define the branch address as
‘ERROR’ in the main routine. Also declare it as PUBLIC.
+ =
DE HL HL
(1) Flowchart
BCDADD
B←C–1 BCDAD2
Number of bytes for decimal
addition without sign
Signs of No
augend and addend
same?
Yes
RET
59
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
DADDS
CY ← 0
Sign flag SFLAG ← 0
DADDS1
A ← [DE] + [HL] + CY
Adds augend and addend with CY
DE ← DE + 1, HL ← HL + 1
Increments addend
and augend addresses
B←B–1
No
B=0
Yes
A ← [DE] + [HL] + CY
Adds addend and augend with CY
No
CY = 1
Yes
DADDS3
Yes
CY = 1
No
Yes
A7 = 1
No
ERROR
No
Sign flag SFLAG = 1
Yes
A7 ← 1
DADDS6
Stores A to memory
RET
60
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
DSUBS
No
Minuend < 0
Yes
DSUBS1
B ← C, CY ← 0
DSUBS2
A ← [DE] – [HL] – CY
Subtracts subtrahend from
minuend with CY
DE ← DE + 1, HL ← HL + 1
Increments subtrahend
and minuend addresses
C←C–1
No
C=0
Yes
No
CY = 1
Yes
DSUBS5
Yes
Result = 0
No
No
Sign flag = 1
Yes
RET
61
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
;******************************************************************
; *
; Input parameter *
; HL register: addend first address *
; DE register: augend first address *
; Output parameter *
; HL register: Operation result first address *
; *
;******************************************************************
PUBLIC BCDADD,BCDAD1,BCDAD2
PUBLIC DADDS
PUBLIC DSUBS
EXTRN ERROR ; Error processing branch address
EXTBIT SFLAG ; Sign flag
;
BYTNUM EQU 4 ; Sets number of digits for operation
;
CSEG
BCDADD:
MOV C,#BYTNUM ; Sets number of digits for operation to C register
BCDAD1:
MOV A,C
MOV B,A
DEC B
BCDAD2:
MOV A,[HL+BYTNUM–1] ; Loads MSB (sign data) of augend
XCHW AX,DE
XCHW AX,HL
XCHW AX,DE
XOR A,[HL+BYTNUM–1] ; Loads MSB (sign data) of augend
XCHW AX,HL
XCHW AX,DE
XCHW AX,HL
62
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
;=============================================================
; ***** 10 Decimal addition *****
;=============================================================
DADDS:
CLR1 CY
CLR1 SFLAG
DADDS1:
MOV A,[DE] ; Starts addition from lowest digit
ADDC A,[HL]
ADJBA
MOV [HL],A
INCW HL
INCW DE
DBNZ B,$DADDS1 ; End of addition (number of digits for operation – 1)
MOV A,[DE]
ADDC A,[HL]
DADDS2:
BNC $DADDS3 ; Negative addition
SET1 SFLAG ; THEN sets negative status
CLR1 CY
DADDS3:
ADJBA
BNC $DADDS4
BR ERROR
DADDS4:
BF A.7,$DADDS5
BR ERROR
DADDS5:
BF SFLAG,$DADDS6 ; Sets sign
SET1 A.7
DADDS6:
MOV [HL],A
RET
63
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
;================================================================
; ***** 10 Decimal subtraction *****
;================================================================
DSUBS:
PUSH HL
CLR1 SFLAG
MOV A,[HL+BYTNUM–1] ; Sets subtrahend as positive value
CLR1 A.7
MOV [HL+BYTNUM–1],A
XCHW AX,DE
XCHW AX,HL
XCHW AX,DE
MOV A,[HL+BYTNUM–1]
BF A.7,$DSUBS1 ; Minuend is negative
CLR1 A.7 ; THEN sets minuend as positive value
MOV [HL+BYTNUM–1],A
SET1 SFLAG ; Sets sign as negative
DSUBS1:
XCHW AX,HL
XCHW AX,DE
XCHW AX,HL
MOV A,C
MOV B,A
CLR1 CY
DSUBS2:
MOV A,[DE]
SUBC A,[HL]
ADJBS
MOV [HL],A
INCW HL
INCW DE
DBNZ C,$DSUBS2 ; End of subtraction of number of digits for operation
POP HL
PUSH HL
SET1 CY
MOV A,B
MOV C,A
DSUBS4:
MOV A,#0 ; Adds 1 to result of complement operation
ADDC A,[HL]
ADJBA
64
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
MOV [HL],A
INCW HL
DBNZ C,$DSUBS4
MOV1 CY,SFLAG
NOT1 CY
MOV1 SFLAG,CY
;======================================================
; ***** 0 check of operation result *****
;======================================================
DSUBS5:
MOV A,B
MOV C,A
POP HL
PUSH HL
MOV A,#0
DSUBS6:
CMP A,[HL] ; 0 check from lowest digit
INCW HL
BNZ $DSUBS7
DBNZ C,$DSUBS6 ; 0 check of all digits completed
POP HL ; THEN result of subtraction = 0
RET
DSUBS7:
BF SFLAG,$DSUBS8 ; Result of subtraction is negative
POP HL ; THEN sets sign
PUSH HL
MOV A,[HL+BYTNUM–1]
SET1 A.7
MOV [HL+BYTNUM–1],A
DSUBS8:
POP HL
RET
65
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
The lowest address for decimal subtraction is specified by the DE and HL registers, and the number of digits
specified by BYTNUM is subtracted. The result of the subtraction is stored to an area specified by the HL register.
If an overflow or underflow occurs as a result of the subtraction, execution branches to error processing. Define the
branch address as ‘ERROR’ in the main routine. Also declare it as PUBLIC.
This program replaces minuend and subtrahend with augend and addend, and calls a program of decimal addition.
– =
DE HL HL
(1) Flowchart
BCDSUB
RET
66
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
;******************************************************************
; *
; Input parameter *
; HL register: subtrahend first address *
; DE register: minuend first address *
; Output parameter *
; HL register: Operation result first address *
; *
;******************************************************************
PUBLIC BYTNUM
PUBLIC BCDSUB
EXTRN BCDADD,BCDAD2
;
BYTNUM EQU 4 ; Sets number of digits for operation
;
CSEG
BCDSUB:
MOV C,#BYTNUM ; Sets number of digits for operation to C register
BCDSU1:
MOV A,C
MOV B,A
DEC B
67
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
Binary data of 16 bits in data memory is converted into 5-digit decimal data and stored in data memory. Binary
data of 16 bits is divided by decimal 10 by the number of times equal to the number of digits (4 times), and conversion
is carried out with the result of the operation and the value of the remainder at that time.
× × × × 0 × 0 × 0 × 0 × 0 ×
F F 0 0 0 5 0 5 0 2 0 0 0 0
68
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
PUBLIC B_DCONV
DATDEC EQU 10
DSEG SADDRP
REGA: DS 2 ; Stores binary 16-bit data
REGB: DS 5 ; Stores decimal 5-digit data
COLNUM EQU 4
B_DCONV:
MOVW AX,REGA
MOV B,#COLNUM
MOVW HL,#REGB
B_D1:
MOV C,#DATDEC
DIVUW C
XCH A,C
MOV [HL],A
INCW HL
XCH A,C
DBNZ B,$B_D1
MOV A,X
MOV [HL],A
RET
69
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
A 1 bit of a flag in the data memory is ANDed with the bit 4 of port 6, and the result is ANDed with the bit 5 of
port 6 and is output to the bit 6 of port 6.
FLG
PORT6.4
PORT6.6
PORT6.5
PUBLIC BIT_OP,FLG
BSEG
FLG DBIT
BIT_OP:
MOV1 CY,FLG
AND1 CY,P6.4
OR1 CY,P6.5
MOV1 P6.6,CY
RET
70
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
Data in a multiplicand area (HIKAKE; 16 bits) and multiplier area (KAKE; 16 bits) are multiplied, and the result
is stored in an operation result storage area (KOTAE).
HIKAKE + 1 HIKAKE
×
KAKE + 1 KAKE
=
KOTAE + 3 KOTAE
<Processing contents>
Multiplication is performed by adding the multiplicand by the number of bits of the multiplier that are “1”.
71
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
<Contents used>
Set the data in the multiplicand (HIKAKE) and multiplier (KAKE) areas, and call subroutine S_KAKERU.
EXTRN S_KAKERU
EXTRN HIKAKE,KAKE,KOTAE
MAIN: ; Multiplier
·
·
HIKAKE=WORKA (A) ; Stores multiplicand data to multiplicand area
HIKAKE+1=WORKA+1 (A) ;
KAKE=WORKB (A) ; Stores multiplier data to multiplier area
KAKE+1=WORKB+1 (A) ;
CALL !S_KAKERU ; Calls multiplication routine
HL=#KOTAE ; HL ← RAM address of operation result storage area
· ; Stores result by indirect address transfer
·
·
72
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
[Multiplication subroutine]
73
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
$PC(054)
;
PUBLIC HIKAKE,S_KAKERU,KAKE,KOTAE
;
;************************************************
; RAM definition
;************************************************
DSEG SADDR
HIKAKE: DS 2 ; Multiplicand area
KAKE: DS 2 ; Multiplier area
WORK1: DS 1 ; Work area
KOTAE: DS 4 ; Operation result storage area
;
;************************************************
; Multiplication
;************************************************
CSEG ;
S_KAKERU: ;
WORK1=KAKE+1 (A) ; Stores multiplier (low) in work area
KOTAE=#0 ; Initializes operation result storage area
KOTAE+1=#0 ;
KOTAE+2=#0 ;
KOTAE+3=#0 ;
for(B=#0;B<#16;B++)(A) ; Stores higher multiplier in work area
if(B == #8)(A) ; if low multiplication is completed
WORK1=KAKE (A) ;
endif ;
A=WORK1 ; Shifts multiplier 1 bit to left
CLR1 CY ;
ROLC A,1 ;
WORK1=A ;
if_bit(CY) ; Adds multiplicand to operation
KOTAE+=HIKAKE (A) ; result storage area if carry occurs
(KOTAE+1)+=HIKAKE+1,CY (A) ;
(KOTAE+2)+=#0,CY (A) ;
(KOTAE+3)+=#0,CY (A) ;
endif ;
if(B != #15) (A) ;
KOTAE+=KOTAE (A) ; Shifts operation result storage area 1 bit to left
KOTAE+1+=KOTAE+1,CY (A) ;
KOTAE+2+=KOTAE+2,CY (A) ;
KOTAE+3+=KOTAE+3,CY (A) ;
endif ;
next ;
RET ;
END
74
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
Data in a dividend area (HIWARU; 32 bits) is divided by data in a divisor area (WARUM; 16 bits), and the result
is stored in an operation result storage area (KOTAE). If a remainder is generated, it is stored in a calculation result
reminder area (AMARI).
If division is executed with the divisor being 0, an error occurs.
HIWARU + 3 HIWARU
÷
WARUM + 1 WARUM
=
KOTAE + 3 KOTAE
AMARI + 1 AMARI
<Processing contents>
The dividend is shifted to the left to the work area starting from the highest digit. If the contents of the work
area are greater than the divisor, the divisor is subtracted from the work area, and the least significant bit of
the dividend is set to 1. In this way, division is carried out by executing the program by the number of bits of
the dividend.
If the divisor is 0, an error flag (F_ERR) is set.
75
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
<Usage>
Set data in the dividend area (HIWARU) and divisor area (WARUM), and call subroutine S_WARU.
EXTRN S_WARU
EXTRN HIWARU,WARUM,KOTAE
EXBIT F_ERR
MAIN:
· ;
· ;
HIWARU=WORKA (A) ; Stores dividend data to dividend area
HIWARU+1=WORKA+1 (A) ;
WARUM=WORKB (A) ; Stores divisor data to divisor area
WARUM+1=WORKB+1 (A) ;
CALL !S_WARU ; Calls division calculation routine
HL=#KOTAE ; HL ← stores RAM address of operation result storage area
· ;
· ;
if_bit(F_ERR) ;
Calculation error processing ;
endif ;
·
·
·
76
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
[Division subroutine]
77
CHAPTER 2 FUNDAMENTALS OF SOFTWARE
$PC(054)
;
PUBLIC S_WARU,HIWARU,WARUM,F_ERR
EXTRN KOTAE
;
;************************************************
; RAM definition
;************************************************
DSEG SADDR
HIWARU: DS 4 ; Dividend area
WARUM: DS 2 ; Divisor area
AMARI: DS 2 ; Calculation result remainder storage area
BSEG
F_ERR DBIT ; Operation error flag
;************************************************
; Division
;************************************************
CSEG ;
S_WARU: ;
CLR1 F_ERR ; Clears operation error flag
AMARI=#0 ; Clears calculation result storage area to 0
AMARI+1=#0 ;
KOTAE=#0 ; Clears operation result storage area to 0
KOTAE+1=#0 ;
KOTAE+2=#0 ;
KOTAE+3=#0 ;
if(WARUM == #0) ; Divisor = 0?
if(WARUM+1 == #0) ;
SET1 F_ERR ; Sets operation error flag if divisor is 0
endif ;
endif ;
if_bit(!F_ERR) ; Operation error?
for(B=#0;B < #32;B++) (A) ; Starts 32-bit division
HIWARU+=HIWARU (A) ; Shifts dividend and remainder 1 bit to left
HIWARU+1+=HIWARU+1,CY (A) ;
HIWARU+2+=HIWARU+2,CY (A) ;
HIWARU+3+=HIWARU+3,CY (A) ;
AMARI+=AMARI,CY (A) ;
AMARI+1+=AMARI+1,CY (A) ;
;
if(AMARI+1 > WARUM+1) (A) ; Remainder ≥ divisor?
AMARI–=WARUM (A) ; Remainder = remainder – divisor
AMARI+1–=WARUM+1,CY (A) ;
HIWARU |= #1 ; Stores 1 to first bit of dividend area
elseif_bit(Z) ;
if(AMARI >= WARUM) (A) ;
AMARI–=WARUM(A) ;
AMARI+1–=WARUM+1,CY (A) ;
HIWARU |= #1 ;
endif ;
endif ;
next ;
KOTAE=HIWARU (A) ; Stores operation result
KOTAE+1=HIWARU+1 (A) ;
KOTAE+2=HIWARU+2 (A) ;
KOTAE+3=HIWARU+3 (A) ;
endif ;
RET ;
END
78
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
The 78K/0 series allows you to select a CPU clock and controls the operation of the oscillator by rewriting the
contents of the processor clock control register (PCC), oscillation mode select register (OSMS), and clock select
registers 1 and 2 (IECL1 and IECL2).
When the CPU clock is changed, the time shown in Table 3-1 is required since the contents of the PCC have been
rewritten until the CPU clock is actually changed. It is therefore not apparent for a while after the contents of the
PCC have been rewritten, whether the processor operates on the new or old clock. To stop the main system clock
or execute the STOP instruction, therefore, the wait time shown in Table 3-1 is necessary.
Caution IECL1 and IECL2 are provided to the µPD78098, 78098B subseries only.
79
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 × × ×
1 1 × × × fX/2fXT instructions fX/4fXT instructions fX/8fXT instructions fX/16fXT instructions fX/32fXT instructions
(77 instructions) (39 instructions) (20 instructions) (10 instructions) (5 instructions)
0 1 × × × fX/4XT instructions fX/8fXT instructions fX/16fXT instructions fX/32fXT instructions fX/64fXT instructions
(39 instructions) (20 instructions) (10 instructions) (5 instructions) (3 instructions)
Caution Do not select dividing the CPU clock (PCC0-PCC2) and changing from the main system clock to
subsystem clock (by setting CSS to 0 → 1) at the same time.
However, dividing the CPU clock (PCC0-PCC2) can be selected at the same time as changing from
the subsystem clock to the main system clock.
Remarks 1. One instruction is the minimum instruction execution time of the CPU clock before change.
2. ( ): fX = 5.0 MHz, fXT = 32.768 kHz
80
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
0 0 0 0 fXX fX fX/2
0 0 1 fXX/2 fX/2 fX/22
0 1 0 fXX/22 fX/22 fX/23
0 0 1
0 1 0
0 1 1
1 0 0
Others Setting prohibited
0 Enables oscillation
1 Stops oscillation
81
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
0 0 0 fXX fX fX/2
0 0 1 fXX/2 fX/2 fX/22
0 1 0 fXX/22 fX/22 fX/23
0 1 1 fXX/23 fX/23 fX/24
82
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
Figure 3-3. Format of Processor Clock Control Register (µPD78098, 78098B subseries)
0 0 1 fXX/2
0 1 0 fXX/22
0 1 1 fXX/23
1 0 0 fXX/24
1 0 0 0 fXT/2
0 0 1
0 1 0
0 1 1
1 0 0
1 Subsystem clock
1 Stops oscillation
83
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
Figure 3-4. Format of Processor Clock Control Register (µPD780018, 780018Y subseries)
0 0 1 fXX/2 fX/2
0 1 0 fXX/22 fX/22
0 1 1 fXX/23 fX/23
1 0 0 fXX/24 fX/24
1 0 0 0 fXT/2
0 0 1
0 1 0
0 1 1
1 0 0
1 Subsystem clock
1 Stops oscillation
84
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
Cautions 1. When an instruction that writes a value to the OSMS is executed (including when the
instruction is executed to write the same value), the main system clock cycle is extended up
to 2/fX only during the execution of the write instruction.
Consequently, a temporary error of the count clock cycle of the peripheral hardware units that
operate on the main system clock, such as timers, occurs.
When the oscillation mode is changed, the clock supplied to the peripheral hardware, as well
as the clock supplied to the CPU, is changed.
It is therefore recommended that you execute the instruction to write the OSMS only once after
the reset signal has been deasserted, and before the peripheral hardware operates.
2. Set 1 to MCS after VDD has risen to 2.7 V or more.
Figure 3-6. Format of Oscillation Mode Select Register (µPD78098, 78098B subseries)
Caution When an instruction that writes a value to the OSMS is executed (including when the instruction
is executed to write the same value), the main system clock cycle is extended up to 2/fX only during
the execution of the write instruction.
Consequently, `rary error of the count clock cycle of the peripheral hardware units that operate
on the main system clock, such as timers, occurs.
When the oscillation mode is changed, the clock supplied to the peripheral hardware, as well as
the clock supplied to the CPU, is changed.
It is therefore recommended that you execute the instruction to write the OSMS only once after
the reset signal has been deasserted, and before the peripheral hardware operates.
85
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
Figure 3-7. Format of Oscillation Mode Select Register (µPD780018, 780018Y subseries)
Cautions 1. When an instruction that writes a value to the OSMS is executed (including when the
instruction is executed to write the same value), the main system clock cycle is extended up
to 2/fX only during the execution of the write instruction.
Consequently, a temporary error of the count clock cycle of the peripheral hardware units that
operate on the main system clock, such as timers, occurs.
2. Setting MCS to 0 is prohibited. On RESET input, however, OSMS is reset to 00H. Therefore,
be sure to set MCS to 1 at the start of a program or after clearing reset.
86
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
The fastest instruction is executed in two CPU clocks. Therefore, the relation between the CPU clock (fCPU) and
minimum instruction execution time is as shown in Tables 3-2 and 3-3.
Table 3-2. Relation between CPU Clock and Minimum Instruction Execution Time
(other than µPD78098 and 78098B subseries)
87
Table 3-3. CPU Clock (fCPU) List (µPD78098 and 78098B Subseries)
88
CHAPTER 3
(0.67 µs) (1.00 µs) (2.00 µs) (3.00 µs) (Setting prohibited) (0.50 µs) (1.00 µs) (1.50 µs)
1 0 0 0 fXT/2(122 µs)
0 0 1
0 1 0
0 1 1
1 0 0
Others Setting prohibited
When the RESET signal is asserted, the slowest mode (processor clock control register: PCC = 04H, oscillation
mode select register: OSMS = 00H) of the main system clock is selected for the CPU clock. To set the highest speed
of the CPU clock, therefore, the contents of the PCC must be rewritten (PCC = 00H, OSMS = 01H). To use the fasted
mode, however, the voltage on the VDD pin has to have risen to a sufficient level and be stable.
In the following example, the CPU waits until the VDD pin voltage has risen to the sufficient level by using the watch
timer (the interval time is set to 3.91 ms). After that, the CPU operates on the fastest clock.
Figure 3-10. Example of Selecting CPU Clock after RESET (with µPD78054 subseries)
ON
Commercial
power source
OFF
4.5 V
VDD pin voltage 2.0 V
RESET signal
L
89
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
;**************************************
;* Sets wait time
;**************************************
TCL2=#00010000B
TMC2=#00110110B ; Sets watch timer to 3.91 ms
while_bit(!TMIF3) ; 3.91 ms?
endw
CLR1 WTIF
OSMS=#00000001B ; Does not use divider circuit
PCC=#00000000B ; Sets CPU clock in fastest mode
90
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
The 78K/0 series can operate in an ultra low current consumption mode by using the processor clock control register
(PCC) and selecting the subsystem clock. By providing a backup power supply such as a Ni-Cd battery or super
capacitor to the system, therefore, the system can continue operating even if a power failure occurs.
In this example, a power failure is detected by using INTP1 (both the rising and falling edges are selected as the
edge to be detected), and the contents of the PCC are changed depending on the port level at that time. Figure 3-
11 shows a circuit example, and Figure 3-12 shows the system clock changing timing.
+ 5.6V
+
VDD VSS
INTP1/TI01/P01
µ PD78054
91
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
Figure 3-12. Example of Changing System Clock on Power Failure (µPD78054 subseries)
6.0 (V)
VDD pin voltage 4.5 (V)
2.0 (V)
ON
Commercial
power source
OFF
H
P01/INTP1 pin
L
92
CHAPTER 3 APPLICATION OF SYSTEM CLOCK SELECTION
;*****************************************
;* Sets low-/high-speed mode
;*****************************************
INTP1:
if_bit(!P0.1)
; Setting of internal hardware (low speed)
; User processing
else
; Sets internal hardware (high speed)
; User processing
endif
RETI
93
[MEMO]
94
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
The watchdog timer of the 78K/0 series has two modes: watchdog timer mode in which a hang-up of the
microcontroller is detected, and interval timer mode.
The watchdog timer is set by using timer clock select register 2 (TCL2) and watchdog timer mode register (WDTM).
95
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
Caution To change the data of TCL2 except when writing the same data, once stop the timer operation.
96
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
TCL2 TCL27 TCL26 TCL25 0 0 TCL22 TCL21 TCL20 FF42H 00H R/W
MCS = 1 MCS = 0
0 × × Disables buzzer output
1 0 0 fXX/29 fX/29 (9.8 kHz) fX/210 (4.9 kHz)
Cautions 1. To change the data of TCL2 except when writing the same data, once stop the timer operation.
2. Be sure to clear bits 3 and 4 to 0.
97
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
Figure 4-3. Format of Timer Clock Select Register 2 (µPD78098, 78098B subseries)
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
1 1 1 Setting prohibited
Caution To change the data of TCL2 except when writing the same data, once stop the timer operation.
98
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
Figure 4-4. Format of Timer Clock Select Register 2 (µPD780018, 780018Y subseries)
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
1 1 1 Setting prohibited
Caution To change the data of TCL2 except when writing the same data, once stop the timer operation.
99
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
Note 1
WDTM4 WDTM3 Selects operation mode of watchdog time
×
Note 2
0 Interval timer mode (maskable interrupt
request occurs when overflow occurs)
1 0 Watchdog timer mode (non-maskable
interrupt request occurs when overflow occurs)
1 1 Watchdog timer mode 2 (reset operation
starts when overflow occurs)
Notes 1. Once WDTM3 and WDTM4 have been set to 1, they cannot be cleared to 0 by software.
2. When RUN is set to 1, the WDTM starts interval timer operation.
3. Once RUN has been set to 1, it cannot be cleared to 0 by software. Therefore, when counting has been
started, it cannot be stopped by any means other than the RESET signal.
Caution 1. When RUN is set to 1 and the watchdog timer is cleared, the actual overflow time is up to 0.5%
shorter than the time set by the timer clock select register 2.
2. When using the watchdog timer modes 1 and 2, confirm that the interrupt request flag (TMIF4)
is 0 and then set WDTM4 to 1. If WDTM4 is set to 1 while TMIF4 is 1, the non-maskable interrupt
occurs regardless of the contents of WDTM3.
100
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
Reset processing or non-maskable interrupt processing is performed after the watchdog timer has detected a hang-
up. You can select which processing is to be performed by the watchdog timer mode register (WDTM). When the
watchdog timer mode is used, the timer must be cleared at intervals shorter than the set hang-up detection time. If
the timer is not cleared, an overflow occurs, and reset or interrupt processing is executed.
The hang-up detection time of the watchdog timer is set by the timer clock select register 2 (TCL2).
In the following example, the hang-up detection time is set to 7.81 ms and the reset processing is performed when
an overflow occurs.
101
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
;*************************************
;* Sets watchdog timer
;*************************************
;
User processing 1
--
;
User processing 2
--
;
User processing 3
--
102
CHAPTER 4 APPLICATIONS OF WATCHDOG TIMER
When the interval timer mode is used, the interval time is set by the timer clock select register 2 (TCL2) (interval
time = 0.488 ms to 125 ms, at fX = 4.19 MHz). In this mode, an interrupt request flag (TMIF4) is set when an overflow
occurs in the timer.
In the following example, three types of times, 0.977 ms, 7.82 ms, and 125 ms, are set.
Timer count FC FD FE FF 00 01 02 03 FD FE FF 00
INTWDT
Remark The above interval time is the value when OSMS = 01H.
103
[MEMO]
104
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
The 16-bit timer/event counter of the 78K/0 series has the following six functions:
• Interval timer
• PWM output
• Pulse width measurement
• External event counter
• Square wave output
• One-shot pulse output
105
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
TCL0 CLOE TCL06 TCL05 TCL04 TCL03 TCL02 TCL01 TCL00 FF40H 00H R/W
1 Enables output
Cautions 1. The valid edge of the TI00/INTP0 pin is specified by the external interrupt mode register 0
(INTM0). The frequency of the sampling clock is selected by the sampling clock select register
(SCS).
2. To enable PCL output, set TCL00 through TCL03, and then set CLOE to 1 by using a 1-bit
memory manipulation instruction.
3. Read the count value from TM0, not from the capture/compare register 01(CR01), when TI00
is specified as the count clock of TM0.
4. Before writing new data to TCL0, stop the timer operation once.
106
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
107
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Figure 5-2. Format of Timer Clock Select Register 0 (µPD78098, 78098B subseries)
TCL0 CLOE TCL06 TCL05 TCL04 TCL03 TCL02 TCL01 TCL00 FF40H 00H R/W
0 Disables output
1 Enables output
Cautions 1. The valid edge of the TI00/INTP0 pin is specified by the external interrupt mode register 0
(INTM0). The frequency of the sampling clock is selected by the sampling clock select register
(SCS).
2. To enable PCL output, set TCL00 through TCL03, and then set CLOE to 1 by using a 1-bit
memory manipulation instruction.
3. Read the count value from TM0, not from the capture/compare register 01(CR01), when TI00
is specified as the count clock of TM0.
4. Before writing new data to TCL0, stop the timer operation once.
108
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Figure 5-3. Format of Timer Clock Select Register 0 (µPD780018, 780018Y subseries)
TCL0 CLOE TCL06 TCL05 TCL04 TCL03 TCL02 TCL01 TCL00 FF40H 00H R/W
1 Enables output
Cautions 1. The valid edge of the TI00/INTP0 pin is specified by the external interrupt mode register 0
(INTM0). The frequency of the sampling clock is selected by the sampling clock select register
(SCS).
2. To enable PCL output, set TCL00 through TCL03, and then set CLOE to 1 by using a 1-bit
memory manipulation instruction.
3. Read the count value from TM0, not from the capture/compare register 01(CR01), when TI00
is specified as the count clock of TM0.
4. Before writing new data to TCL0, stop the timer operation once.
109
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
1 Overflow occurs
TMC03 TMC02 TMC01 Selects operation mode Selects output timing of TO0 Occurrence of
and clear mode interrupt request
0 0 1 PWM mode (free running) PWM pulse output Occurs if TM0 and CR00
Free running mode Coincidence between TM0 coincide and if TM0 and
0 1 0
and CR00 or between TM0 CR01 coincide
and CR01
Cautions 1. Before setting the clear mode or changing the output timing of TO0, stop the timer operation
(by clearing TMC01 through TMC03 to 0, 0, 0).
2. The valid edge of the TI00/INTP0 pin is selected by the external interrupt mode register 0
(INTM0). The frequency of the sampling clock is selected by the sampling clock select register
(SCS).
3. When using the PWM mode, set data to CR00 after setting the PWM mode.
4. When a mode in which the timer is cleared and started on coincidence between TM0 and CR00,
the OVF0 flag is set to 1 when the set value of CR00 is FFFFH and the value of TM0 changes
from FFFFH to 0000H.
5. The 16-bit timer register starts operating as soon as a value other than 0, 0, 0 (operation stop
mode) is set to TMC01 through TMC03. To stop the operation, clear TMC01 through TMC03
to 0, 0, 0.
110
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
111
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
TOC0 0 OSPT OSPE TOC04 LVS0 LVR0 TOC01 TOE0 FF4EH 00H R/W
Cautions 1. Be sure to stop the timer operation before setting TOC0 (except OSPT).
2. LVS0 and LVR0 are always 0 when they are read immediately after data has been set.
3. OSPT is automatically cleared after data has been set. It is therefore always 0 when read.
112
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PM3 PM37 PM36 PM35 PM34 PM33 PM32 PM31 PM30 FF23H FFH R/W
INTM0 ES31 ES30 ES21 ES20 ES11 ES10 0 0 FFECH 00H R/W
Caution Before setting the valid edge of the INTP0/TI00/P00 pin, clear bits 1 through 3 (TMC01 through
TMC03) of the 16-bit timer mode control register (TMC0) to 0, 0, 0, and stop the timer.
113
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Caution fXX/2N is the clock supplied to the CPU, and fXX/25, fXX/26, and fXX/27 are the clocks supplied to the
peripheral hardware. fXX/2N is stopped in the HALT mode.
Remarks 1. N : Value (N = 0 to 4) set to the bits 0 through 2 (PCC0 through PCC2) of the processor clock
control register (PCC)
2. fXX : main system clock frequency (fX or fX/2)
3. fX : main system clock oscillation frequency
4. MCS: bit 0 of oscillation mode select register (OSMS)
5. ( ) : at fX = 5.0 MHz
114
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Figure 5-10. Format of Sampling Clock Select Register (µPD78098, 78098B subseries)
Caution fXX/2N is the clock supplied to the CPU, and fXX/25, fXX/26, and fXX/27 are the clocks supplied to the
peripheral hardware. fXX/2N is stopped in the HALT mode.
Remarks 1. N : Value (N = 0 to 4) set to the bits 0 through 2 (PCC0 through PCC2) of the processor clock control
register (PCC)
2. fXX : main system clock frequency
3. ( ) : at fXX = 4.0 MHz
Figure 5-11. Format of Sampling Clock Select Register (µPD780018, 780018Y subseries)
Caution fXX/2N is the clock supplied to the CPU, and fXX/25, fXX/26, and fXX/27 are the clocks supplied to the
peripheral hardware. fXX/2N is stopped in the HALT mode.
Remarks 1. N : Value (N = 0 to 4) set to the bits 0 through 2 (PCC0 through PCC2) of the processor clock control
register (PCC)
2. fXX : main system clock frequency (fX)
3. fX : main system clock oscillation frequency
4. ( ) : at fX = 5.0 MHz
115
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
To set the 16-bit timer/event counter as an interval timer, first set the timer clock select register 0 (TCL0) and the
16-bit timer mode control register (TMC0). The clear mode of the 16-bit timer is set by TMC0 and the interval time
is set by TCL0.
After that, set the value of the compare register (CR00) from the setup time and count clock. Determine the setup
time by using the following expression:
This section shows two examples of setup times of the interval timer: 10 ms and 50 ms.
(a) Interval of 10 ms
116
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
(b) Interval of 50 ms
117
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
When using the 16-bit timer/event counter in the PWM output mode, set the PWM mode by the 16-bit timer mode
control register (TMC0) and enables the output of the 16-bit timer/event counter by the 16-bit timer output control
register (TOC0).
The pulse width (active level) of PWM is determined by the value set to the capture/compare register 00 (CR00).
Because the PWM of the 78K/0 series has a resolution of 14 bits, however, bits 2 through 15 of CR00 are valid (clear
bits 0 and 1 of CR00 to ‘0, 0’).
1
In the example below, the basic cycle of the PWM mode is set to 61.0 µs ( × 28) and the low level is selected
fXX
as the active level. The high-order 4 bits of the pulse width are rewritten depending on the value of the parameter
(00H to FFH). Therefore, in the following application example, PWM output can be performed in 16 steps (CR00 =
0FFCH to FFFCH).
<Registers used>
AX
<RAM used>
<Nesting>
1 level 2 bytes
118
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• Setting of 16-bit timer/event counter
CRC0 = #00000000B ; Selects CR00 as compare register
TMC0 = #00000010B ; PWM output mode
TCL0 = #00100000B ; PWM basic cycle: 61.0 µs
TOC0 = #00000011B ; Low-active output
• PM30 = 0 ; P30 output mode
• P30 = 0 ; P30 output latch
<Starting>
After setting data to PWMOUT in RAM, call subroutine PWM.
119
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC PWM,PWMOUT
PWM_DAT DSEG SADDR
PWMOUT: DS 1 ; PWM output data area (0-15)
;************************************
;* PWM output (16 steps)
;************************************
P0_SEG CSEG
PWM:
A=PWMOUT ; Loads high-order data of PWMOUT
A<<=1
A<<=1
A<<=1
A<<=1
A|=#0FH ; Sets low-order 12 bits to 0FFCH
X=#0FCH
CR00=AX
RET
120
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
This section introduces two examples of programs that receives signals from a remote controller by using the 16-
bit timer/event counter.
• The counter is cleared each time the valid edge of the remote controller signal has been detected, and measures
a pulse width from the timer count value (capture register CR01) when the next valid edge has been detected.
• The timer operates in the free running mode to measure a pulse width from the difference of the counter between
valid edges. PWM output is also performed at the same time.
The remote controller signal is received by a PIN receiver diode and is input to the P00/TI00/INTP0 pin via receive
amplifier µPC1490. Figure 5-12 shows an example of a remote controller signal receiver circuit, and Figure 5-13 shows
the format of the remote controller signal.
+5 V
+
100 µ F
160 kΩ
VDD
PH310 100 kΩ
f0 VCC
µ PD78054
IN– CD GND C1
4.7 Ω
+
10 µ F 1000 pF
+ GND
1 µF
Shield case
121
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
67.5 ms
108 ms 108 ms
9 ms 4.5 ms
Custom Code Custom Code Data Code Data Code
13.5 ms 8 bits 8 bits 8 bits 8 bits
Leader Code 27 ms 27 ms
67.5 ms
First
time
9 ms 4.5 ms 0.56 ms
9 ms 2.25 ms
11.25 ms
0.56 ms
Because the receiver preamplifier µPC1490 used in the circuit example on the previous page is low-active, the
level input to the µPD78054 subseries is the inverted data of the remote controller transmit data.
H
µ PC1490 output
L
9 ms 4.5 ms
Leader code
122
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
123
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Registers used>
Bank 0: AX, BC, HL
124
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<RAM used>
<Flags used>
Name Usage
<Nesting>
5 levels 12 bytes
<Hardware used>
• 16-bit timer/event counter
• P00/TI00/INTP0
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• Setting of 16-bit timer/event counter
CRC0 = #00000100B ; Selects operation mode of CR00, CR01
TMC0 = #00001100B ; Clears timer on coincidence between TM0 and CR00
TCL0 = #00100000B ; Count clock fXX
CR00 = #6290 ; Compare register 00
• SCS = #00000011B ; INTP0 sampling clock fXX/26
• PPR0 = 0 ; INTP0 high-priority interrupt
• TMMK0 = 0 ; Enables 16-bit timer/event counter interrupt
• Defines custom code to be CSTM and declares PUBLIC
• RAM clear
<Starting>
Started by INTP0 and INTTM00 interrupt requests
125
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC CSTM
EXTRN RMDATA,RPTCT
EXTBIT RPT,RMDTSET,IPDTFG
DT_TEST:
if_bit(RMDTSET)
CLR1 RMDTSET
if_bit(RPT)
;
; Repeat processing
;
else
;
; Processing when there is input
;
endif
else
if_bit(!RPT)
;
; Processing when there is no input
;
endif
endif
126
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
127
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
128
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
129
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
130
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC RPT,IPDTFG,RMDTOK,RMDTSET
PUBLIC RMENDCT,RPTCT,SELMOD,LD_CT,RMDATA
EXTRN CSTM
RM_DAT DSEG SADDR
RPTCT: DS 1 ; Repeat code valid time counter
RMENDCT: DS ; No-input1 time counter after data input
SELMOD: DS 1 ; Selects mode
LD_CT: DS 1 ; Leader signal detection counter
RMDATA: DS 1 ; Valid data storage area
BSEG
IPDTFG DBIT ; Valid data exists
RMDTOK DBIT ; Input signal is valid
RMDTSET DBIT ; Input signal exists
RPT DBIT ; Repeat code valid period
;******************************************************
; Remote controller signal timer processing
;******************************************************
TM0_SEG CSEG
INTTM00:
SEL RB1
EI ; Enables interrupt (INTP0)
if_bit(IPDTFG) ; Input signal exists?
if_bit(RMDTOK) ; Valid data exists?
RPTCT––
if(RPTCT==#0) ; Repeat invalid time
CLR1 RPT ; Repeat code invalid status
CLR1 IPDTFG
CLR1 RMDTOK
endif
CALL !S_LOWCT
else
RMENDCT––
if(RMENDCT==#0)
SET1 RMDTOK ; Sets that valid data exists
SET1 RMDTSET
CALL !S_M0SET ; Sets leader (low) detection mode
endif
LD_CT=#5
endif
else
CALL !s_LOWCT
endif
RETI
131
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
S_LOWCT:
if(SELMOD==#0) ; Leader (low) detection mode?
if_bit(!P0.0)
LD_CT––
if(LD_CT==#0)
SELMOD=#1 ; Leader (low) measuring mode
TMC0=#00000000B
CR00=#32767 ; Timer: 7.81 ms
TMC0=#00001100B
INTM0=#00000100B
CLR1 PIF0
CLR1 PMK0 ; Enables INTP0 interrupt
LD_CT=#5
endif
else
LD_CT=#5
endif
else
CALL !S_MOSET ; Sets leader (low) detection mode
LD_CT=#5
endif
RET
$EJECT
;***********************************************************
;* Remote controller signal edge detection processing
;***********************************************************
P0_SEG CSEG
INTP0:
SEL RB0
CALL !WAIT ; Waits for 100 µs
switch(SELMOD)
case 1:
CALL !LEAD_L ; Leader low detection processing
break
case 2:
CALL !LEAD_H ; Leader high detection processing
break
case 3:
CALL !CDCODE ; Custom/data code loading processing
break
case 4:
CALL !REPCD ; Repeat code detection processing
break
case 5:
CALL !ENDCHK ; Abnormal data detection processing
ends
RET1
132
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;****************************************
;* Leader low detection
;****************************************
LEAD_L:
133
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;******************************
;* Custom/data code loading
;******************************
CDCODE:
if_bit(!P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CALL !CR_READ ; Reads timer value
if(AX>=#1257–190/2) ; 0.5 ms – 100 µs * 2 – 190 clocks (edge detection → timer starts)
if(AX<#9646–190/2) ; 2.5 ms – 100 µs * 2 –190 clocks (edge detection → timer starts)
if(AX>=#6710–190/2) ; 1.8 ms – 100 µs * 2 – 190 clocks (edge detection → timer starts)
SET1 CY
else
CLR1 CY
endif
HL=#WORKP+3 ; Sets work area address
C=#4 ; Sets number of digits of work area
WKSHFT:
A=[HL] ; Stores 1-bit data
RORC A,1 ; Shifts 1 bit
[HL]=A
HL––
DBNZ C,$WKSHFT ; End of shifting all bits
if_bit(CY) ; End of 32-bit input?
if(WORKP+0==#CSTM) (A)
; Custom code check
A^WORKP+1
if(A==#0FFH) ; Custom code inverted data check
A=WORKP+2
A^=WORKP+3 ; Data code inverted data check
if(A==#0FFH)
; Stores input data
RMDATA=WORKP+2 (A)
; Sets status in which input data exists
SET1 IPDTFG
CLR1 RMDTSET
CLR1 RPT
CLR1 RMDTOK
CALL !S_M5SET
else
; Sets leader (low) detection mode
CALL !S_M0SET
endif
else
; Sets leader (low) detection mode
CALL !S_M0SET
endif
else
CALL !S_M0SET
134
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
endif
endif
else
CALL !S_M0SET ; Sets leader (low) detection mode
endif
else
CALL !S_M0SET ; Sets leader (low) detection mode
endif
endif
endif
RET
$EJECT
;************************************
;* Repeat code detection
;************************************
REPCD:
if_bit(P0.0) ; Level check P0.0 = 0: noise
CALL !WAIT ; Waits for 100 µs
if_bit(P0.0)
if_bit(RMDTOK) ; Valid data exists?
CALL !CR_READ ; Reads timer value
if(AX<=#3354–190/2) ; 1 ms – 100 µs * 2 – 190 clocks (edge detection → timer starts)
SET1 RPT
CLR1 RMDTOK ; Input signal check after end of data
CLR1 RMDTSET
CALL !S_M5SET
else
CALL !S_M0SET ; Sets leader (low) detection mode
endif
else
CALL !S_M0SET ; Sets leader (low) detection mode
endif
endif
endif
RET
$EJECT
135
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;****************************************
;* Abnormal data detection
;****************************************
ENDCHK:
if_bit(!P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CLR1 IPDTFG ; Abnormal data input
CLR1 RPT ; Input signal invalid
CALL !S_M0SET ; Sets leader (low) detection mode
endif
endif
RET
;****************************************
;* Waits for 100 µs
;****************************************
WAIT:
B=#(838–14–12–8)/12 ; CALL(14), RET(12), MOV(8)
WAITCT: ; Sets 100 µs
DBNZ B,$WAITCT ; 1 instruction 12 clocks
RET
;*****************************************
;* Sets leader (low) detection mode
;*****************************************
S_M0SET:
TMC0=#00000000B
CR00=#6290
TCL0=#00100000B ; Sets timer to 1.5 ms
TMC0=#00001100B
SELMOD=#0 ; Leader (low) detection mode
SET1 PMK0
RET
;*****************************************
;* Sets abnormal data detection mode
;*****************************************
S_M5SET:
RPTCT=#173 ; 250 ms measuring counter
SELMOD=#5 ; Data input end mode
RMENDCT=#3 ; No-input checking counter
TMC0=#00000000B ; Stops operation
CR00=#6290 ; Sets 1.5 ms
TMC0=#00001100B
RET
;****************************************
;* Reads timer count value
;****************************************
CR_READ:
AX=CR01
TMC0=#00000000B ; Stops operation
TMC0=#00001100B ; Starts timer
RET
136
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
5.3.2 Remote controller signal reception by PWM output and free running mode
Table 5-2 shows the valid pulse width when a remote controller signal is received by this program. <1> through
<6> below describes how each signal is processed.
137
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Registers used>
Bank 0: AX, BC, HL
<RAM used>
138
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Flag used>
Name Usage
<Nesting>
5 levels 11 bytes
<Hardware used>
• 16-bit timer/event counter
• P00/TI00/INTP0
• P30/TO0
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• Setting of 16-bit timer/event counter
CRC0 = #00000100B ; Selects operation mode of CR00, CR01
TMC0 = #00000010B ; PWM output mode
TCL0 = #00100000B ; PWM basic cycle: 61.0 µs
TOC0 = #00000011B ; Low-active output
• PM30 = 0 ; P30 output mode
• SCS = #00000011B ; INTP0 sampling clock fXX/26
• PPR0 = 0 ; INTP0 high-priority interrupt
• PMK0 = 0 ; Enables INTP0 interrupt
• Defines custom code to CSTM and declares PUBLIC
• RAM clear
<Starting>
• Test the OVF0 of the 16-bit timer/event counter. When OVF0 is set, call subroutine TIM_PRO.
• Start by an interrupt request when the valid edge of the remote controller signal is detected.
139
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC CSTM
EXTRN RMDATA,RPTCT,PWM,PWMOUT,TIM_PRO
EXTBIT RPT,RMDTSET,IPDTFG,TO_FLG,OVSENS
CSTM EQU 9DH ; Custom code
140
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
141
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
142
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
143
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
144
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC TIM_PRO,RPT,IPDTFG,RMDTOK,RMDTSET
PUBLIC RMENDCT,RPTCT,SELMOD,LD_CT,RMDATA
PUBLIC TO_FLG,OVSENS
EXTRN CSTM
BSEG
IPDTFG DBIT ; Valid data exists
RMDTOK DBIT ; Input signal valid
RMDTSET DBIT ; Input signal exists
RPT DBIT ; Repeat code valid period
TO_FLG DBIT ; Timer overflow occurs
OVSENS DBIT ; Detects timer overflow by INTP0 processing
$EJECT
;******************************************************
; Remote controller signal timer processing
;******************************************************
TM0_SEG CSEG
TIM_PRO:
if_bit(IPDTFG) ; Input signal exists?
if_bit(RMDTOK) ; Valid data exists?
RPTCT––
if(RPTCT==#0) ; Repeat invalid time
CLR1 RPT ; Repeat code valid status
CLR1 IPDTFG
CLR1 RMDTOK
endif
else
RMENDCT––
if(RMENDCT==#0)
SET1 RMDTOK ; Valid data exists
SET1 RMDTSET
CALL !S_M0SET ; Sets leader (low) detection mode
endif
endif
else
CALL !TO_CHK ; Checks timer overflow
endif
RET
145
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
TO_CHK:
if(SELMOD==#0)
CLR1 TO_FLG
else
TO_CNT++
if(TO_CNT==#2)
CALL !S_M0SET ; Sets start edge detection mode
endif
endif
RET
$EJECT
;***********************************************************
;* Remote controller signal edge detection processing
;***********************************************************
P0_SEG CSEG
INTP0:
SEL RB0
switch(SELMOD)
case 0:
CALL !RM_STA ; Start edge detection processing
break
case 1:
CALL !LEAD_L ; Leader low detection processing
break
case 2:
CALL !LEAD_H ; Leader high detection processing
break
case 3:
CALL !CDCODE ; Custom/data code loading processing
break
case 4:
CALL !REPCD ; Repeat code detection processing
break
case 5:
CALL !ENDCHK ; Abnormal data detection processing
ends
RET1
;***********************************************************
;* Start edge detection
;***********************************************************
RM_STA:
CLR1 TO_FLG ; Starts timer count
if_bit(!P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CR01_OP=CR01 (AX) ; Stores capture register
SELMOD=#1 ; Leader low detection mode
INTM0=#00000100B ; INTP0 rising edge
TO_CNT=#0
endif
endif
RET
146
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;****************************************
;* Leader low detection
;****************************************
LEAD_L:
if_bit(P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(P0.0)
CALL !PW_CT ; Reads timer value
if_bit(!CY)
TO_CNT=#0
if(AX>=#12582) ; 3 ms
if(AX<#41942) ; 10 ms
SELMOD=#2 ; Leader high detection mode
INTM0=#00000000B ; INTP0 falling edge
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
endif
endif
RET
$EJECT
;****************************************
;* Leader high detection
;****************************************
LEAD_H:
if_bit(!P0.0) ; Level check P0.0 = 0: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CALL !PW_CT ; Reads timer value
if_bit(!CY)
TO_CNT=#0
if(AX>=#7549) ; 1.8 ms
if(AX<#20971) ; 5 ms
if(AX>#12582) ; Custom/data code (3 ms)?
SELMOD=#3 ; Data loading mode
WORKP=#0000H ; Initializes work area
(WORKP)+2=#8000H ; Sets most significant bit to 1 (to confirm end of data)
else
SELMOD=#4 ; Repeat detection mode
INTM0=#00000100B ; INTP0 rises
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
endif
endif
RET
$EJECT
147
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;******************************
;* Custom/data code loading
;******************************
CDCODE:
if_bit(!P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CALL !PW_CT ; Reads timer value
if_bit(!CY)
TO_CNT=#0
if(AX>=#2096) ; 0.5 ms
if(AX<#10485) ; 2.5 ms
if(AX>=#7549) ; 1.8 ms
SET1 CY
else
CLR1 CY
endif
148
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;************************************
;* Repeat code detection
;************************************
REPCD:
if_bit(P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(P0.0)
if_bit(RMDTOK) ; Valid data?
CALL !PW_CT ; Reads timer value
if_bit(!CY)
TO_CNT=#0
if(AX<=#4193) ; 1 ms
SET1 RPT
CLR1 RMDTOK ; Checks input signal after end of data
CLR1 RMDTSET
CALL !S_M5SET
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
else
CALL !S_M0SET ; Sets start edge detection mode
endif
endif
endif
RET
$EJECT
149
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;*********************************************
;* Abnormal data detection
;*********************************************
ENDCHK:
if_bit(!P0.0) ; Level check P0.0 = 1: noise
CALL !WAIT ; Waits for 100 µs
if_bit(!P0.0)
CLR1 IPDTFG ; Abnormal data input
CLR1 RPT ; Input signal invalid
CALL !S_M0SET ; Sets start edge detection mode
endif
endif
RET
;*********************************************
;* Calculation of capture register value
;*********************************************
PW_CT:
if_bit(OVF0) ; OVF0 after edge detection?
if(CR01<#10000–33) (AX) ; Interrupt acknowledgment processing time = 65 clocks (MAX)
CLR1 OVF0
SET1 OVSENS
SET1 TO_FLG
endif
endif
CR01_OP=CR01_NP (AX)
AX=BC ; Restores operation result
CLR1 TO_FLG
RET
150
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
;**********************************************
;* Waits for 100 µs
;**********************************************
WAIT:
B=#(838–14–12–8)/12 ; CALL (14), RET (12), MOV (8)
WAITCT: ; Sets 100 µs
DBNZ B,$WAITCT ; 1 instruction 12 clocks
RET
;**********************************************
;* Sets start edge detection mode
;**********************************************
S_M0SET:
TO_CNT=#0
SELMOD=#0 ; Start edge detection mode
INTM0=#00000000B ; INTP0 falling edge
RET
;**********************************************
;* Setting of abnormal data detection mode
;**********************************************
S_M5SET:
RPTCT=#16 ; 250 ms measuring counter
SELMOD=#5 ; Data input end mode
RMENDCT=#2 ; No-input checking counter
RET
151
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
The 16-bit timer/event counter has a function which outputs a one-shot pulse in synchronization with a software
trigger and external trigger (INTP0/TI00/P00 pin input).
When using the one-shot pulse output function, the 16-bit timer mode control register (TMC0), capture/compare
control register 0 (CRC0), and 16-bit timer output control register (TOC0) must be set.
In this section, an example for setting the one-shot pulse by using the software trigger is introduced.
The OSPT flag (bit 6 of the TOC0 register) is set at arbitrary timing (such as key input).
After the software trigger has occurred, TM0 is cleared and started. When the value of TM0 coincides with the
value set in advance to CR01, the TO0/P30 pin output is inverted (and becomes active). When the value of TM0
later coincides with the value set in advance to CR00, the TO0/P30 pin output is inverted again (and becomes inactive).
The TM0 counter is cleared and counting up is started again after the value of TM0 has coincided with the value of
CR00. The output of the TO0/P30 pin, however, is not inverted even if coincidence occurs next time. TM0 is cleared
and started and the output of the TO0/P30 pin is inverted only when the software trigger is set. The active level of
the TO0/P30 pin is determined by selecting the initial value of the TO0/P30 pin output of the TOC0 register.
Note that, when using the one-shot pulse output function with the software trigger, the OSPT flag must not be set
to 1 while the one-shot pulse is output. To output the one-shot pulse again, do so after INTTM00, which is an interrupt
request that occurs when TM0 coincides with CR00, has occurred.
In the example presented in this section, the software trigger is designed by using key input, and “H” active output
is produced 10 ms after for 1 ms.
152
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Count clock
OSPT
INTTM01
INTTM00
F_TRG
10 ms 1 ms
Remark F_TRG: flag indicating that output of the one-shot pulse is in progress. For details, refer to (2) Example
of use.
153
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Register used>
None
<RAM used>
None
<Nesting level>
1 level 2 bytes
<Hardware used>
• 16-bit timer/event counter
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• CLR1 P3.0 ; Clears output latch of bit 0 of port 3 to 0
• CLR1 PM3.0 ; Sets bit 0 of port mode register 3 in output mode
• CALL !SOP_INIT ; Sets by subroutine SOP_INIT
<Starting>
Set bit 6 (OSPT) of the 16-bit timer output control register (TOC0).
154
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
EXTRN SOP_INT
M1PR0 CSEG
RES_STA:
OSMS=#00000001B ; Does not use divider circuit
CLR1 P3.0 ; Sets 0 to output latch if multiplexed pin is used
CLR1 PM3.0 ; Sets output mode if multiplexed pin is used
CALL !SOP_INIT ; One-shot pulse output initial setting routine
·
·
if(key request issued)
if_bit(!F_TRG) ; Previous output ends?
SET1 OSPT ; Clears and starts 16-bit counter
SET1 F_TRG ; Sets one-shot pulse trigger flag
endif ;
endif ;
if_bit(TMIF00) ; End of one-shot pulse output?
CLR1 F_TRG ; Clears one-shot trigger flag
CLR1 TMIF00 ; Clears TMIF00 request flag
endif ;
·
·
155
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC SOP_INIT
OPINIT CSEG
SOP_INIT:
TMC0=#00000000B ; Stops timer operation
TCL0=#01000000B ; Count clock of 16-bit timer register: 1.05 MHz
CRC0=#00000000B ; Uses CR00 and CR01 as compare registers
CR00=#11550–1 ; Sets compare register to 11 ms
CR01=#10500–1 ; Sets compare register to 10 ms
TOC0=#00110111B ; Selects one-shot pulse mode
TMC0=#00001100B ; Starts on coincidence between TM0 and CR00 (enables timer operation)
RET ;
END
When using the 16-bit timer/event counter in the PPG (Programmable Pulse Generator) mode, the 16-bit timer
mode control register (TMC0), capture/compare control register 0 (CRC0), and 16-bit timer output control register
(TOC0) must be set.
As the PPG output pulse, a square wave with a cycle specified by the count value set in advance to the 16-bit
capture/compare register 00 (CR00) and a pulse width specified by the count value set in advance to the 16-bit capture/
compare register 01 (CR01) is output from the TO0/P30 pin.
In the application example shown in this section, the output waveform is changed by using the PPG output. Data
indicating the one cycle and pulse width of the output waveform is stored in ROM. This data is stored in the compare
register.
The cycle and pulse width of the PPG output in this program can be changed in units of 1 ms to 10 ms. Therefore,
the cycle can be set in a range of 2 to 10 ms, and the pulse width can be set in a range of 1 to 9 ms. If the cycle
is equal to or less than the pulse width when the output waveform is changed, the data is not changed.
The output waveform is changed after the end of one output cycle. Figure 5-17 shows the PPG output waveform
changing timing.
Pulse
width
1 cycle
156
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Registers used>
SPG_INIT : Bank 0 AX, HL
INTTM00 : Bank 2 AX
<RAM used>
<Flag used>
None
157
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
<Nesting level>
1 level 3 bytes
<Hardware used>
• 16-bit timer/event counter
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• CLR1 P3.0 ; Clears output latch of bit 0 of port 3 to 0
• CLR1 PM3.0 ; Sets bit 0 of port mode register 3 in output mode
• CALL !PPG_INIT ; Sets by subroutine PPG_INIT
<Starting>
After the 16-bit timer/event counter has been reset and started, set pulse width time in the specified range
to PARUSU in RAM and cycle time in the specified range to SAIKURU, and call subroutine PPG_INIT.
When changing the PPG output waveform, clear the INTTM00 interrupt request flag to enable the interrupt
after setting a compare data value corresponding to the pulse width in the specified range to PARUSUP,
and a compare data value corresponding to the cycle time in the specified range to SAIKURUP.
158
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
EXTRN SPG_INIT
EXTRN SAIKURUP.PARUSUP
EXTRN SAIKURU,PARUSU
EXTRN PDAT,SDAT
;
SMIN EQU 02H ; Minimum cycle time
PMIN EQU 01H ; Minimum pulse width time
·
·
OSMS=#00000001B ; Does not use divider circuit
SAIKURU=#SMIN ; Sets initial cycle value
PARUSU=#PMIN ; Sets initial pulse width value
CLR1 P3.0 ; Clears output latch to 0 if multiplexed pin is used
CLR1 PM3.0 ; Sets output mode if multiplexed pin is used
CALL !SPG_INIT ;
EI ;
·
·
if(request for changing square wave)
if(SAIKURU > PARUSU) (A) ; If SAIKURUP > PARUSU
A=PARUSU ; Data 1 → address XXX0
A–– ; Data 2 → address XXX2
A <<= 1 ; Data 3 → address XXX4
X=A ; ·
A=#0 ; Table reference of low-order 8 bits of value stored to
AX+=#PDAT ; compare register
HL=AX ; X register ← low-order 8 bits
X=[HL] (A) ;
HL++ ; Table reference of high-order 8 bits of value stored to compare register
A=[HL] ; A register ← high-order 8 bits
PARUSUP=AX ;
; ;
A=SAIKURU ; Cycle time storage processing
A–– ;
A–– ;
A <<= 1 ;
X=A ;
A=#0 ;
AX+=#SDAT ;
HL=AX ;
X=[HL] (A) ;
HL++ ;
A=[HL] ;
SAIKURUP=AX ;
CLR1 TMIF00 ; Clears request flag
CLR1 TMMK00 ; Enables compare register 00 interrupt
endif ; No data change
endif ;
·
·
159
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
Sets successive pulse output and sets initial value "H" of TO0 pin output
160
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PUBLIC SPG_INIT,PDAT,SDAT
PUBLIC SAIKURU,PARUSU
EXTRN SAIKURUP,PARUSUP
;
;************************************************
; RAM definition
;************************************************
PPGRAM DSEG SADDR ;
SAIKURU: DS 1 ; 1 cycle time storage area
PARUSU: DS 1 ; Pulse width storage area
;
;************************************************
; PPG output initial setting
;************************************************
PPGINIT CSEG
SPG_INIT:
TMC0=#00000000B ; Stops timer operation
TCL0=#00100000B ; Count clock of 16-bit timer register: 4.19 MHz
CRC0=#00000000B ; Uses CR00 and CR01 as compare register
A=PARUSU ; Data 1 → address XXX0
A–– ; Data 2 → address XXX2
A <<= 1 ; Data 3 → address XXX4
X=A ; ·
A=#0 ; Table reference of low-order 8 bits of value stored to
AX+=#PDAT ; compare register
HL=AX ; X register ← low-order 8 bits
X=[HL] (A) ;
HL++ ; Table reference of high-order 8 bits of value stored to compare register
A=[HL] ; A register ← high-order 8 bits
PARUSUP=AX ;
; ;
A=SAIKURU ; Cycle time storage processing
A–– ;
A–– ;
A <<= 1 ;
X=A ;
A=#0 ;
AX+=#SDAT ;
HL=AX ;
X=[HL] (A) ;
HL++ ;
A=[HL] ;
SAIKURUP=AX ;
CR00=SAIKURUP (AX) ; Sets compare register to 2 ms
CR01=PARUSUP (AX) ; Sets compare register to 1 ms
TOC0=#00011011B ; Sets successive pulse output and initial value ‘H’
TMC0=#00001100B ; Starts on coincidence between TM0 and CR00 (enables timer opera-
RET tion)
;
161
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
PDAT: ;
DW 4201 ; Address XXX0
DW 8403 ; Address XXX2
DW 12605 ; Address XXX4
DW 16807 ;
DW 21009 ;
DW 25211 ;
DW 29413 ;
DW 33615 ;
DW 37817 ;
SDAT: ;
DW 8403 ; Address XXX0
DW 12605 ; Address XXX2
DW 16807 ; Address XXX4
DW 21009 ;
DW 25211 ;
DW 29413 ;
DW 33615 ;
DW 37817 ;
DW 42019 ;
END
PUBLIC PARUSUP,SAIKURUP
;
VETM00 CSEG AT 20H
DW INTTM00
;
P2RAM DSEG SADDRP
PARUSUP: DS 2 ; Pulse width time changing data storage area
SAIKURUP: DS 2 ; 1 cycle time changing data storage area
;****************************************************************
; PPG output (cycle pulse width time changing interrupt)
;****************************************************************
TM00 CSEG ;
INTTM00: ;
SEL RB2 ; Selects bank 2
CR01=PARUSUP (AX) ; CR00, CR01 ← stores pulse width and cycle time changing data
CR00=SAIKURUP (AX) ;
SET1 TMMK00 ; Disables compare register 00 interrupt
RETI ;
END
162
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
The 8-bit timer/event counter of the 78K/0 series has three functions: interval timer, external event counter, and
square wave output. Two channels of 8-bit timers/event counters are provided and these timers/event counters can
be used as a 16-bit timer/event counter when connected in cascade.
The 8-bit timers/event counters are set by the following registers:
163
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
TCL1 TCL17 TCL16 TCL15 TCL14 TCL13 TCL12 TCL11 TCL10 FF41H 00H R/W
TCL13 TCL12 TCL11 TCL10 Selects count clock of 8-bit timer register 1
MCS = 1 MCS = 0
TCL17 TCL16 TCL15 TCL14 Selects count clock of 8-bit timer register 2
MCS = 1 MCS = 0
Caution Before writing new data to TCL1, stop the timer operation once.
164
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
165
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
Figure 6-2. Format of Timer Clock Select Register 1 (µPD78098, 78098B subseries)
TCL1 TCL17 TCL16 TCL15 TCL14 TCL13 TCL12 TCL11 TCL10 FF41H 00H R/W
TCL13 TCL12 TCL11 TCL10 Selects count clock of 8-bit timer register 1
0 0 0 0 Falling edge of TI1
TCL17 TCL16 TCL15 TCL14 Selects count clock of 8-bit timer register 2
0 0 0 0 Falling edge of TI2
0 0 0 1 Rising edge of TI2
Caution Before writing new data to TCL1, stop the timer operation once.
166
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
Figure 6-3. Format of Timer Clock Select Register 1 (µPD780018, 780018Y subseries)
TCL1 TCL17 TCL16 TCL15 TCL14 TCL13 TCL12 TCL11 TCL10 FF41H 00H R/W
TCL13 TCL12 TCL11 TCL10 Selects count clock of 8-bit timer register 1
0 0 0 0 Falling edge of TI1
TCL17 TCL16 TCL15 TCL14 Selects count clock of 8-bit timer register 2
0 0 0 0 Falling edge of TI2
0 0 0 1 Rising edge of TI2
Caution Before writing new data to TCL1, stop the timer operation once.
167
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
Cautions 1. Before changing the operation mode, stop the timer operation.
2. When using the two 8-bit timer registers as a one 16-bit timer register, enable or stop the
operation by using TCE1.
168
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
TOC1 LVS2 LVR2 TOC15 TOE2 LVS1 LVR1 TOC11 TOE1 FF4FH 00H R/W
169
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
PM3 PM37 PM36 PM35 PM34 PM33 PM32 PM31 PM30 FF23H FFH R/W
170
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
When using an 8-bit timer/event counter as an interval timer, set an operation mode by the 8-bit timer mode control
register (TMC1) and interval time by the timer clock select register 1 (TCL1).
After that, set the values of the compare registers (CR10 and CR20) from the setup time and count clock. The
setup time is determined by using the following expression:
The setup time can be calculated in the same manner regardless of whether each 8-bit timer/event counter is used
or two 8-bit timers/event counters are used as a 16-bit timer/event counter. The count clock when two 8-bit timers/
event counters are used as a 16-bit timer/event counter, however, is selected by the bits 0 through 3 (TCL10 through
TCL13) of TCL1.
Examples of the modes of the 8-bit timers and 16-bit timer are described next.
Count clock
INTTM1, INTTM2
TO1
171
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
1
500 µs = (N + 1) ×
4.19 MHz/24
1
100 ms = (N + 1) ×
4.19 MHz/211
172
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
N+1
500 ms =
4.19 MHz/25
10 s = N+1
4.19 MHz/211
173
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
This section shows an example of a program that uses the square wave output (P31/TO1) of an 8-bit timer/event
counter and generates a musical scale by supplying pulses to an external buzzer.
VDD
µ PD78054
P31/TO1
The output frequency of the P31/TO1 pin is set by the count clock and a compare register. In this example, the
central frequency of the musical scale is set to a range of 523 to 1046 Hz. Therefore, fXX/25 is selected as the count
clock (oscillation mode select register: OSMS = 01H). Table 6-1 shows the musical scale, the set value of the compare
register, and frequency of the output pulse. Because one cycle of the timer output is created when the value of the
timer coincides with the value of the compare register two times, the interval time is set as half a cycle time.
CR10 coincidence
Interval interval
174
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
As for the time length of a sound, the output time is determined by setting an interval time with 8-bit timer/event
counter 2 and by counting the number of times the interrupt generated by the timer/event counter. In this example,
8-bit timer/event counter 2 is set to 20 ms.
Musical Scale Musical Scale Frequency Hz Compare Register Value Output Frequency Hz
Mi 659.25 98 662.0
Fa 698.46 93 697.2
So 783.98 83 780.2
La 880.00 73 885.6
The format of the data table for this program is shown below.
TABLE:
DB musical scale data 1, sound length data 1
DB musical scale data 2, sound length data 2
.. ..
. .
DB musical scale data n, sound length data n
DB 0, 0
The musical scale data is set to 0 for rest, and the sound length data is set to 0 for the end of data.
Example Number of counts of 8-bit timer/event counter to output sound for 1 second
Number of counts = 1 s/20 ms = 50 (50 is set as number of counts)
This program sequentially outputs do, re, mi, and so on, for 1 second each.
175
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
<Registers used>
Bank 0: A, B, HL
<RAM used>
<Nesting>
1 level 3 bytes
<Hardware used>
• 8-bit timer/event counters 1 and 2
• P31/TO1
<Initial setting>
• Sets by subroutine MLDY
• Enables interrupt
<Starting>
• Call subroutine MLDY
EXTRN MLDY
..
.
CALL !MLDY
EI
176
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
177
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
PUBLIC MLDY
;*************************************************
;* Musical scale generation initialize
;*************************************************
ML_SEG CSEG
MLDY:
CLR PM3.1 ; Sets P3.1 in output mode
POINT=#0 ; Initial setting of pointer
LGN=#1
OSMS=#00000001B ; Does not use divider circuit
TOC1=#00000011B ; Sets TO1 output mode
TCL1=#11101010B
CR20=#163 ; Sets timer 2 to 20 ms
TMC1=#00000010B ; Enables timer 2 operation
CLR1 TMMK2 ; Enables timer 2 interrupt
RET
$EJECT
178
CHAPTER 6 APPLICATIONS OF 8-BIT TIMER/EVENT COUNTER
;***********************************************
; Sets musical scale generation data
;***********************************************
TM2_SEG CSEG
INTTM2:
SEL RB0
LNG––
if(LNG==#0)
B=POINT (A)
HL=#TABLE ; Sets table first address
A=[HL+B]
if(A!=#0)
CLR1 TCE1 ; Sets sound data
CR10=A
SET1 TOE1
SET1 TCE1
else
CLR1 TOE1
endif
179
[MEMO]
180
CHAPTER 7 APPLICATIONS OF WATCH TIMER
The watch timer of the 78K/0 series has a watch timer function that causes the timer to overflow every 0.5 second
by using the main system clock or subsystem clock as the clock source, and an interval timer function that allows
you to set six types of reference times. These two functions can be simultaneously used.
The watch timer is set by using timer clock select register 2 (TCL2) and watch timer mode control register (TMC2).
181
CHAPTER 7 APPLICATIONS OF WATCH TIMER
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
Caution Before writing new data to TCL2, stop the timer operation once.
182
CHAPTER 7 APPLICATIONS OF WATCH TIMER
Figure 7-2. Format of Timer Clock Select Register 2 (µPD78098, 78098B subseries)
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
1 1 1 Setting prohibited
Caution Before writing new data to TCL2, stop the timer operation once.
183
CHAPTER 7 APPLICATIONS OF WATCH TIMER
Figure 7-3. Format of Timer Clock Select Register 2 (µPD780018, 780018Y subseries)
TCL2 TCL27 TCL26 TCL25 TCL24 0 TCL22 TCL21 TCL20 FF42H 00H R/W
1 fXT
1 1 1 Setting prohibited
Caution Before writing new data to TCL2, stop the timer operation once.
184
CHAPTER 7 APPLICATIONS OF WATCH TIMER
TMC2 0 TMC26 TMC25 TMC24 TMC23 TMC22 TMC21 TMC20 FF4AH 00H R/W
1 Enables operation
1 Enables operation
Caution Do not often clear the prescaler when the watch timer is used.
185
CHAPTER 7 APPLICATIONS OF WATCH TIMER
Figure 7-5. Format of Watch Timer Mode Control Register (µPD78098, 78098B subseries)
TMC2 0 TMC26 TMC25 TMC24 TMC23 TMC22 TMC21 TMC20 FF4AH 00H R/W
Caution Do not often clear the prescaler when the watch timer is used.
186
CHAPTER 7 APPLICATIONS OF WATCH TIMER
As an example of using the watch timer, this section introduces a program that counts time by using an 0.5 second
overflow and dynamically displays LED at intervals of 1.95 ms.
To count time, an overflow flag is tested each time a subroutine is called. When the flag is set, time is counted
up in seconds. Because an overflow occurs every 0.5 second, it takes 1 minute to count 120 times. The overflow
flag is tested at intervals of 1.95 ms so that the flag is tested without fail. The watch of this program is 24-hour watch.
The high-order and low-order digits of minute and hour data are stored in separate areas of memory.
187
CHAPTER 7 APPLICATIONS OF WATCH TIMER
As LED dynamic display, four digits are displayed with the display digit changed at intervals of 1.95 ms. In this
example, the high-order 4 bits of P3 are used as a digit signal, and P5 that can directly drive an LED is selected as
a segment signal.
The digit of an LED specified by a display digit area (DIGCT) in an LED display area is displayed. To change the
digit signal, the segment signal is turned off so that the adjacent digits are not displayed.
P34
P35
P36
P37
Port 5
DIGIT 0 1 2 3 0 1 2 3 0 1 2 3
Segment signal OFF
µ PD78054
7-segment LED × 4
P50
P57
P37
P36
P35
P34
188
CHAPTER 7 APPLICATIONS OF WATCH TIMER
<Register used>
Bank 0: AX, B, HL
<RAM used>
<Hardware used>
• Watch timer
• P34-37
• P5
<Initial setting>
• TMC2 = #00100110B ; 0.5-second watch operation at 1.95 ms interval
• TMMK3 = 0 ; enables watch timer interrupt
<Starting>
Started by the interval timer interrupt request of the watch timer.
189
CHAPTER 7 APPLICATIONS OF WATCH TIMER
190
CHAPTER 7 APPLICATIONS OF WATCH TIMER
PUBLIC HOURDP,MINDP,SECD,LEDDP
;***************************************
;* Interval interrupt processing
;***************************************
TM3_SEG CSEG
INTTM3:
SEL RB0
CALL !TIME
CALL !LEDDPSP
RETI
191
CHAPTER 7 APPLICATIONS OF WATCH TIMER
;************************************
; LED display
;************************************
LEDDPSP:
P5=#0FFH ; Turns OFF segment output
DIGCT&=#00000011B ; Adjusts digit counter (0-3)
if(DIGCT==#0)
A=P3
A&=#00001111B ; Initial setting of digit signal (high-order 4 bits)
A|=#00010000B
P3=A
else
A=P3
A&=#11110000B ; Shifts high-order 4 bits
X=A
A=P3
A+=X
P3=A
endif
DIGCT++
RET
SEGDT:
DB 11000000B ; 0
DB 11111001B ; 1
DB 10100100B ; 2
DB 10110000B ; 3
DB 10011001B ; 4
DB 10010010B ; 5
DB 10000010B ; 6
DB 11111000B ; 7
DB 10000000B ; 8
DB 10010000B ; 9
DB 10001000B ; A
DB 10000011B ; B
DB 11000110B ; C
DB 10100001B ; D
DB 10000110B ; E
DB 10001110B ; F
$EJECT
192
CHAPTER 7 APPLICATIONS OF WATCH TIMER
;********************************
;* Watch count up
;********************************
TIME: ; 0.5 second test
if_bit(WTIF)
CLR1 WTIF ; 120 = 60 seconds/0.5
SECD++
if(SECD==#120)
SECD=#0 ; Increments minute (low)
(MINDP+0)++ ; Carry occurs
if((MINDP+0)==#10)
(MINDP+0)=#0 ; Increments minute (high)
(MINDP+1)++ ; Carry occurs
if(MINDP+1==#6)
(MINDP+1)=#0
(HOURDP+0)++ ; Hour data 24?
if(HOURDP!=#0204H) (AX) ; Carry occurs
if((HOURDP+0)==#10)
(HOURDP+0)=#0
(HOURDP+1)++
endif
else
HOURDP=#0000H
endif
endif
endif
endif
endif
RET
193
[MEMO]
194
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The 78K/0 series is provided with the serial interface shown in Table 8-1.
µPD78054 × × × ×
µPD78054Y × × × ×
µPD78064 × × × × × ×
µPD78064Y × × × × × ×
µPD78078 × × × ×
µPD78078Y × × × ×
µPD78083 × × × × × × × × ×
µPD78098 × × × ×
µPD780018 × × × × × × × ×
µPD780018Y × × × × × × ×
µPD780058 × Note × × ×
µPD780058Y × Note × × ×
µPD780308 × × × Note
× ×
µPD780308Y × × × Note × ×
µPD78058F × × × ×
µPD78058FY × × × ×
µPD78064B × × × × × ×
µPD78070A × × × ×
µPD78070AY × × × ×
µPD78075B × × × ×
µPD78075BY × × × ×
µPD78098B × × × ×
195
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The serial interface of the 78K/0 series has a different function depending on the subseries, as shown in Table
8-1. This chapter explains each function and application example of the serial interface. The function supported by
each subseries are listed in Table 8-2. For details of application examples of using the serial interface function of
a specific subseries, refer to the section or paragraph marked in this table.
µPD78054 –
µPD78054Y –
µPD78064 – –
µPD78064Y – –
µPD78078 –
µPD78078Y –
µPD78083 – – – – –
µPD78098 –
µPD780018 – – – – –
µPD780018Y – – – – –
µPD780058 –
µPD780058Y –
µPD780308 – –
µPD780308Y – –
µPD78058F –
µPD78058FY –
µPD78064B – –
µPD78070A –
µPD78070AY –
µPD78075B –
µPD78075BY –
µPD78098B –
196
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The functions and operations of the serial interface are specified by using the following registers:
Note This register is provided only on the µPD780058, 780058Y, 780308, and 780308Y subseries.
Remark This chapter describes the register formats and application examples of serial interface channels 0, 1,
and 2. For details of the register formats of channels 3, 4, and 5, refer to the User’s Manual of each
subseries.
197
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
TCL3 TCL37 TCL36 TCL35 TCL34 TCL33 TCL32 TCL31 TCL30 FF43H 88H R/W
TCL33 TCL32 TCL31 TCL30 Selects serial clock of serial interface channel 0
MCS = 1 MCS = 0
0 1 1 0 fXX/2 Setting prohibited fX/22 (1.25 MHz)
0 1 1 1 fXX/22 fX/22 (1.25 MHz) fX/23 (625 kHz)
TCL37 TCL36 TCL35 TCL34 Selects serial clock of serial interface channel 1
MCS = 1 MCS = 0
0 1 1 0 fXX/2 Setting prohibited fX/22 (1.25 MHz)
0 1 1 1 fXX/22 fX/22 (1.25 MHz) fX/23 (625 kHz)
Caution Before writing new data to TCL3, stop serial transfer once.
198
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
TCL3 TCL37 TCL36 TCL35 TCL34 TCL33 TCL32 TCL31 TCL30 FF43H 88H R/W
TCL33 TCL32 TCL31 TCL30 Selects serial clock of serial interface channel 0
0 1 1 0 fXX/25 Setting prohibited fX/26 (78.1 kHz) fXX/2 Setting prohibited fX/22 (1.25 MHz)
0 1 1 1 fXX/26 fX/26 (78.1 kHz) fX/27 (39.1 kHz) fXX/22 fX/22 (1.25 MHz) fX/23 (625 kHz)
1 0 0 0 fXX/27 fX/27 (39.1 kHz) fX/28 (19.5 kHz) fXX/23 fX/23 (625 kHz) fX/24 (313 kHz)
1 0 0 1 fXX/28 fX/28 (19.5 kHz) fX/29 (9.77 kHz) fXX/24 fX/24 (313 kHz) fX/25 (156 kHz)
1 0 1 0 fXX/29 fX/29 (9.77 kHz) fX/210 (4.88 kHz) fXX/25 fX/25 (156 kHz) fX/26 (78.1 kHz)
1 0 1 1 fXX/210 fX/210 (4.88 kHz) fX/211 (2.44 kHz) fXX/26 fX/26 (78.1 kHz) fX/27 (39.1 kHz)
1 1 0 0 fXX/211 fX/211 (2.44 kHz) fX/212 (1.22 kHz) fXX/27 fX/27 (39.1 kHz) fX/28 (19.5 kHz)
1 1 0 1 fXX/212 fX/212 (1.22 kHz) fX/213 (0.61 kHz) fXX/28 fX/28 (19.5 kHz) fX/29 (9.8 kHz)
TCL37 TCL36 TCL35 TCL34 Selects serial clock of serial interface channel 1
MCS = 1 MCS = 0
0 1 1 0 fXX/2 Setting prohibited fX/22 (1.25 MHz)
0 1 1 1 fXX/22 fX/22 (1.25 MHz) fX/23 (625 kHz)
Caution Before writing new data to TCL3, stop serial transfer once.
199
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-3. Format of Timer Clock Select Register 3 (µPD78064, 780308, 78064B subseries)
TCL33 TCL32 TCL31 TCL30 Selects serial clock of serial interface channel 0
MCS = 1 MCS = 0
200
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-4. Format of Timer Clock Select Register 3 (µPD78064Y, 780308Y subseries)
TCL33 TCL32 TCL31 TCL30 Selects serial clock of serial interface channel 0
Serial clock in 3-wire serial I/O or
Serial clock in I2C bus mode 2-wire serial I/O mode
0 1 1 0 fXX/25 Setting prohibited fX/26 (78.1 kHz) fXX/2 Setting prohibited fX/22 (1.25 MHz)
0 1 1 1 fXX/26 fX/26 (78.1 kHz) fX/27 (39.1 kHz) fXX/22 fX/22 (1.25 MHz) fX/23 (625 kHz)
1 0 0 0 fXX/27 fX/27 (39.1 kHz) fX/28 (19.5 kHz) fXX/23 fX/23 (625 kHz) fX/24 (313 kHz)
1 0 0 1 fXX/28 fX/28 (19.5 kHz) fX/29 (9.77 kHz) fXX/24 fX/24 (313 kHz) fX/25 (156 kHz)
1 0 1 0 fXX/29 fX/29 (9.77 kHz) fX/210 (4.88 kHz) fXX/25 fX/25 (156 kHz) fX/26 (78.1 kHz)
1 0 1 1 fXX/210 fX/210 (4.88 kHz) fX/211 (2.44 kHz) fXX/26 fX/26 (78.1 kHz) fX/27 (39.1 kHz)
1 1 0 0 fXX/211 fX/211 (2.44 kHz) fX/212 (1.22 kHz) fXX/27 fX/27 (39.1 kHz) fX/28 (19.5 kHz)
1 1 0 1 fXX/212 fX/212 (1.22 kHz) fX/213 (0.61 kHz) fXX/28 fX/28 (19.5 kHz) fX/29 (9.8 kHz)
201
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-5. Format of Timer Clock Select Register 3 (µPD78098, 78098B subseries)
TCL3 TCL37 TCL36 TCL35 TCL34 TCL33 TCL32 TCL31 TCL30 FF43H 88H R/W
TCL33 TCL32 TCL31 TCL30 Selects serial clock of serial interface channel 0
0 1 1 0 fXX/2Note
TCL37 TCL36 TCL35 TCL34 Selects serial clock of serial interface channel 1
0 1 1 0 fXX/2Note
0 1 1 1 fXX/22 (1.0 MHz)
1 0 0 0 fXX/23 (500 kHz)
Note Can be set only when the main system clock frequency is 5.0 MHz or less.
Caution Before writing new data to TCL3, stop serial transfer once.
202
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-6. Format of Timer Clock Select Register 3 (µPD780018, 780018Y subseries)
TCL37 TCL36 TCL35 TCL34 Selects serial clock of serial interface channel 1
0 1 1 1 fXX/22 fX/22 (1.25 MHz)
Caution Before writing new data to TCL3, stop serial transfer once.
203
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
CSIM0
CSIE
COI WUP
CSIM CSIM CSIM CSIM CSIM FF60H 00H R/WNote 1
0 04 03 02 01 00
R/W CSIM CSIM CSIM PM25 P25 PM26 P26 PM27 P27 Operation mode First bit Function of Function of Function of
04 03 02 SI0/SB0/P25 pin SO0/SB1/P26 pin SCK0/P27 pin
0 × 0 Note 2 Note 2 0 0 0 1 3-wire serial MSB SI0Note 2 SO0 SCK0
1 ×
1 I/O mode LSB (input) (CMOS output) (CMOS I/O)
Caution Do not change the operation mode (3-wire serial I/O/2-wire serial I/O/SBI) while the operation of
the serial interface channel 0 is enabled. To change the operation mode, stop the serial operation.
204
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
1 Enables operation
Caution Do not change the operation mode (3-wire serial I/O/2-wire serial I/O/SBI) while the operation of
the serial interface channel 0 is enabled. To change the operation mode, stop the serial operation.
205
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
CSIM0
CSIE
COI WUP
CSIM CSIM CSIM CSIM CSIM FF60H 00H R/WNote 1
0 04 03 02 01 00
R/W CSIM CSIM CSIM PM25 P25 PM26 P26 PM27 P27 Operation mode First bit Function of Function of Function of
04 03 02 SI0/SB0/SDA0/P25 pin SO0/SB1/SDA1/P26 pin SCK0/SCL/P27 pin
Caution Do not change the operation mode (3-wire serial I/O/2-wire serial I/O/I2C bus) while the operation
of the serial interface channel 0 is enabled. To change the operation mode, stop the serial
operation.
206
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
1 Enables operation
Caution Do not change the operation mode (3-wire serial I/O/2-wire serial I/O/I2C bus) while the operation
of the serial interface channel 0 is enabled. To change the operation mode, stop the serial
operation.
207
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
• On execution of transfer start instruction • When bus release signal (REL) is detected
• If values of SIO0 and SVA do not coincide when
address is received
• When CSIE0 = 0
• At RESET input
R/W ACKT Outputs acknowledge signal in synchronization with falling edge of SCK0 clock immediately after
instruction that sets this bit to 1 has been executed. After acknowledge signal has been output, this
bit is automatically cleared to 0. ACKE is cleared to 0.
This bit is also cleared to 0 when transfer of serial interface is started and when CSIE0 = 0.
Note Bits 2, 3, and 6 (RELD, CMDD, and ACKD) are read-only bits.
Remarks 1. Bits 0, 1, and 4 (RELD, CMDT, and ACKT) are cleared to 0 when they are read after data has been
set.
2. CSIE0: Bit 7 of the serial operating mode register 0 (CSIM0)
208
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
• Falling edge of SCK0 clock immediately after • When acknowledge signal (ACK) is detected at
busy mode has been released after execution rising edge of SCK0 clock after completion of
of transfer start instruction transfer
• When CSIE0 = 0
• At RESET input
Note The busy mode can be released by starting serial interface transfer and receiving of an address signal.
However, the BSYE flag is not cleared to 0.
209
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
• At RESET input
R/W ACKT Makes SDA0 (SDA1) low immediately after instruction that sets this bit to 1 (ACKT = 1) until next
SCL falls. Used to generate ACK signal by software when 8-clock wait is selected.
Cleared to 0 when transfer by serial interface is started and CSIE0 = 0
Note Bits 2, 3, and 6 (RELD, CMDD, and ACKD) are read-only bits.
210
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
R/W BSYENote 3 Controls transmission N-ch open drain output in I2C bus modeNote 4
0 Enables output (transmission)
1 Disables output (reception)
211
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
R/W
SVAM Bits of SVA used as slave address
0 Bits 0 through 7
1 Bits 1 through 7
R/W
SIC Selects INTCSI0 interrupt sourceNote 2
0 Sets CSIIF0 at end of transfer of serial interface
channel 0
1 Sets CSIIF0 at end of transfer of serial interface
channel 0 or on detection of bus release
R
CLD Level of SCK0 pinNote 3
0 Low level
1 High level
212
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
213
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Notes 1. Sets SIC to 1 when using the wake-up function in the I2C mode.
2. CLD is 0 when CSIE0 = 0.
214
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
CSIE CSIM PM20 P20 PM21 P21 PM22 P22 Operation of Controls operation Function of Function of Function of
of counter of
1 11 shift register 1 SI1/P20 pin SO1/P21 pin SCK1/P22
serial clock
0 × Note 2 Note 2 Note 2 Note 2 Note 2 Note 2 Stops Clear P20 P21 P22
× × × × × × operation (CMOS I/O) (CMOS I/O) (CMOS I/O)
1 0 Note 3 Note 3 0 0 1 × Enables Count operation SI1Note 3 SO1 SCK1
1 × operation (input) (CMOS output) (input)
1 0 1 SCK1
(CMOS output)
Notes 1. Clear bit 2 (STRB) and bit 1 (BUSY1) of the automatic data transfer/reception control register (ADTC)
to 0, 0 when the external clock input is selected by clearing CSIM11 to 0.
2. These pins can be used as port pins.
3. When only transmit is executed, this pin can be used as P20 (CMOS I/O). (Set bit 7 (RE) of the automatic
data transfer/reception control register (ADTC) to 0.)
215
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
R/W
BUSY1 BUSY0 Controls busy input
0 × Does not use busy input
1 0 Enables busy input (active high)
1 1 Enables busy input (low active)
R/W
STRB Controls strobe output
0 Disables strobe output
1 Enables strobe output
R Note 2
TRF Status of automatic transfer/reception function
0 Detects end of automatic transfer/reception (0 when
automatic transfer/reception is stopped or when ARLD
= 0)
1 Automatic transfer/reception in progress (1 when SIO1
is written)
R
ERR Detects error of automatic transfer/reception function
0 No error on automatic reception (0 when 1 is written to
SIO1)
1 Error on automatic transfer/reception
R/W
ERCE Controls error check of automatic transfer/reception
function
0 Disables error check on automatic transfer/reception
1 Enables error check on automatic transfer/reception
(only when BUSY1 = 1)
R/W
ARLD Selects operation mode of automatic transfer/
reception function
0 Single mode
1 Repetitive mode
R/W
RE Controls reception of automatic transfer/reception
function
0 Disables reception
1 Enables reception
Caution When external clock input is selected by clearing bit 1 (CSIM11) of the serial operating mode
register 1 (CSIM1) to 0, clear STRB and BUSY1 of ADTC to 0, 0.
216
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
R/W
BUSY1 BUSY0 Controls busy input
0 × Does not use busy input
1 0 Enables busy input (active high)
1 1 Enables busy input (low active)
R/W
STRB Controls strobe output
0 Disables strobe output
1 Enables strobe output
R Note 2
TRF Status of automatic transfer/reception function
0 Detects end of automatic transfer/reception (0 when
automatic transfer/reception is stopped or when ARLD
= 0)
1 Automatic transfer/reception in progress (1 when SIO1
is written)
R
ERR Detects error of automatic transfer/reception function
0 No error on automatic reception (0 when 1 is written to
SIO1)
1 Error on automatic transfer/reception
R/W
ERCE Controls error check of automatic transfer/reception
function
0 Disables error check on automatic transfer/reception
1 Enables error check on automatic transfer/reception
(only when BUSY1 = 1)
R/W
ARLD Selects operation mode of automatic transfer/
reception function
0 Single mode
1 Repetitive mode
R/W
RE Controls reception of automatic transfer/reception
function
0 Disables reception
1 Enables reception
217
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 5.0 MHz)
Minimum valueNote 2 Maximum valueNote 2
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
218
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
219
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 5.0 MHz)
Note The interval time of data transfer includes an error margin. The minimum and maximum values of the interval
time for data transfer can be calculated by the following expressions (where n is the value set to ADTI0
through ADTI4). However, if the minimum value calculated by the expression below is less than 2/fSCK,
the minimum interval time is 2/fSCK.
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
220
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 2.5 MHz)
Minimum valueNote 2 Maximum valueNote 2
0 0 0 0 0 36.8 µs + 0.5/fSCK 40.0 µs + 1.5/fSCK
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
221
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
222
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 2.5 MHz)
Note The interval time of data transfer includes an error margin. The minimum and maximum values of the interval
time for data transfer can be calculated by the following expressions (where n is the value set to ADTI0
through ADTI4). However, if the minimum value calculated by the expression below is less than 2/fSCK,
the minimum interval time is 2/fSCK.
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
223
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 4.0 MHz)
Minimum valueNote 2 Maximum valueNote 2
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
224
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
225
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ADTI ADTI7 0 0 ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 FF6BH 00H R/W
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 Specifies interval time of data transfer (fXX = 4.0 MHz)
Minimum valueNote Maximum valueNote
1 0 0 0 0 279.0 µs + 0.5/fSCK 281.0 µs + 1.5/fSCK
Note The interval time of data transfer includes an error margin. The minimum and maximum values of the interval
time for data transfer can be calculated by the following expressions (where n is the value set to ADTI0
through ADTI4). However, if the minimum value calculated by the expression below is less than 2/fSCK,
the minimum interval time is 2/fSCK.
26 28 0.5
Minimum value = (n+1) × + +
fXX fXX fSCK
26 36 1.5
Maximum value = (n+1) × + +
fXX fXX fSCK
226
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
227
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
ASIM TXE RXE PS1 PS0 CL SL ISRM SCK FF70H 00H R/W
Note When the baud rate generator output is selected by setting SCK to 1, the ASCK pin can be used as an
I/O port pin.
Cautions 1. Set ASIM to 00H when the 3-wire serial I/O mode is selected.
2. Before changing the operation mode, stop the serial transfer/reception operation.
228
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
229
Table 8-5. Setting of Operation Modes of Serial Interface Channel 2 (µPD780058 and 780058Y Subseries) (1/2)
230
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM23 P23 PM24 P24 PM72 P72 First Shift Function of Function of Function of Function of Function of
TXE RXE SCK CSIE2 CSIM22 CSCK SIPS21 SIPS20 bit clock P70/SI2/RxD0 pin P71/SO2/TxD0 pin P23/STB/TxD1 pin P24/BUSY/RxD1 pin P72/SCK2/ASCK pin
0 0 × 0 × × × × ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 – – P70 P71 P23/STB P24/BUSY P72
Others Setting prohibited
CHAPTER 8
(2) 3-wire serial I/O mode
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM23 P23 PM24 P24 PM72 P72 First Shift Function of Function of Function of Function of Function of
bit clock
0 0 0 1 0 0 × × 1Note 2 ×Note 2 0 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 1 × MSB External SI2Note 2 SO2 P23/STB P24/BUSY SCK2 input
clock
1 0 1 Internal (CMOS output) SCK2 output
clock
1 1 0 1 × LSB External SI2Note 2 SO2 SCK2 input
clock
Internal
1 0 1 (CMOS output) SCK2 output
clock
Others Setting prohibited
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM23 P23 PM24 P24 PM72 P72 First Shift Function of Function of Function of Function of Function of
TXE RXE SCK CSIE2 CSIM22 CSCK SIPS21 SIPS20 bit clock P70/SI2/RxD0 pin P71/SO2/TxD0 pin P23/STB/TxD1 pin P24/BUSY/RxD1 pin P72/SCK2/ASCK pin
1 0 0 0 0 0 0 0 ×Note ×Note 0 1 ×Note ×Note ×Note ×Note 1 × LSB External P70 TxD0 P23/STB P24/BUSY ASCK input
clock
1 ×Note ×Note Internal (CMOS output) P72
clock
CHAPTER 8
0 1 0 0 0 0 0 0 1 1 P71 ASCK input
clock
Internal
1 ×Note ×Note P72
clock
External
1 1 0 0 0 0 0 0 1 × 0 1 ×Note ×Note ×Note ×Note 1 × TxD0 ASCK input
clock
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM113 P113 PM114 P114 PM72 P72 First Shift Function of Function of Function of Function of Function of
TXE RXE SCK CSIE2 CSIM22 CSCK SIPS21 SIPS20 bit clock P70/SI2/RxD0 pin P71/SO2/TxD0 pin P113/TxD pin P114/RxD pin P72/SCK2/ASCK pin
0 0 × 0 × × × × ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 – – P70 P71 P113 P114 P72
Others Setting prohibited
CHAPTER 8
(2) 3-wire serial I/O mode
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM113 P113 PM114 P114 PM72 P72 First Shift Function of Function of Function of Function of Function of
0 0 0 1 0 0 × × 1Note 2 ×Note 2 0 1 ×Note 1 ×Note 1 ×Note 1 ×Note 1 1 × MSB External SI2Note 2 SO2 P113 P114 SCK2 input
clock
1 0 1 Internal (CMOS output) SCK2 output
clock
1 1 0 1 × LSB External SI2Note 2 SO2 SCK2 input
clock
Internal
1 0 1 (CMOS output) SCK2 output
clock
Others Setting prohibited
ASIM CSIM2 SIPS PM70 P70 PM71 P71 PM113 P113 PM114 P114 PM72 P72 First Shift Function of Function of Function of Function of Function of
TXE RXE SCK CSIE2 CSIM22 CSCK SIPS21 SIPS20 bit clock P70/SI2/RxD0 pin P71/SO2/TxD0 pin P113/TxD pin P114/RxD pin P72/SCK2/ASCK pin
1 0 0 0 0 0 0 0 ×Note ×Note 0 1 ×Note ×Note ×Note ×Note 1 × LSB External P70 TxD P113 P114 ASCK input
clock
1 ×Note ×Note Internal (CMOS output) P72
clock
CHAPTER 8
0 1 0 0 0 0 0 0 1 × ×Note ×Note ×Note ×Note ×Note ×Note 1 × External RxD P71 ASCK input
clock
Internal
1 ×Note ×Note P72
clock
External
1 1 0 0 0 0 0 0 1 × 0 1 ×Note ×Note ×Note ×Note 1 × TxD ASCK input
clock
Notes 1. If an overrun error occurs, be sure to read the receive buffer register (RXB). The overrun error persists
each time data is received until RXB is read.
2. Even if the stop bit length is set to 2 bits by the bit 2 (SL) of the asynchronous serial interface mode
register (ASIM), only 1 stop bit is detected during reception.
234
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
BRGC TPS3 TPS2 TPS1 TPS0 MDL3 MDL2 MDL1 MDL0 FF73H 00H R/W
MDL3 MDL2 MDL1 MDL0 Selects input clock of baud rate generator k
0 0 0 0 fSCK/16 0
0 0 0 1 fSCK/17 1
0 0 1 0 fSCK/18 2
0 0 1 1 fSCK/19 3
0 1 0 0 fSCK/20 4
0 1 0 1 fSCK/21 5
0 1 1 0 fSCK/22 6
0 1 1 1 fSCK/23 7
1 0 0 0 fSCK/24 8
1 0 0 1 fSCK/25 9
1 0 1 0 fSCK/26 10
1 0 1 1 fSCK/27 11
1 1 0 0 fSCK/28 12
1 1 0 1 fSCK/29 13
1 1 1 0 fSCK/30 14
1 1 1 1 fSCKNote –
235
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
MCS = 1 MCS = 0
0 0 0 0 fXX/210 fX/210 (4.9 kHz) fX/211 (2.4 kHz) 11
0 1 0 1 fXX fX (5.0 MHz) fX/2 (2.5 MHz) 1
Caution If data is written to BRGC during communication, the output of the baud rate generator is
disturbed and communication cannot be executed normally.
Therefore, do not write data to BRGC during communication.
236
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-22. Format of Baud Rate Generator Control Register (µPD78098, 78098B subseries) (1/2)
BRGC TPS3 TPS2 TPS1 TPS0 MDL3 MDL2 MDL1 MDL0 FF73H 00H R/W
MDL3 MDL2 MDL1 MDL0 Selects input clock of baud rate generator k
0 0 0 0 fSCK/16 0
0 0 0 1 fSCK/17 1
0 0 1 0 fSCK/18 2
0 0 1 1 fSCK/19 3
0 1 0 0 fSCK/20 4
0 1 0 1 fSCK/21 5
0 1 1 0 fSCK/22 6
0 1 1 1 fSCK/23 7
1 0 0 0 fSCK/24 8
1 0 0 1 fSCK/25 9
1 0 1 0 fSCK/26 10
1 0 1 1 fSCK/27 11
1 1 0 0 fSCK/28 12
1 1 0 1 fSCK/29 13
1 1 1 0 fSCK/30 14
1 1 1 1 fSCKNote –
237
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-22. Format of Baud Rate Generator Control Register (µPD78098, 78098B subseries) (2/2)
Caution If data is written to BRGC during communication, the output of the baud rate generator is
disturbed and communication cannot be executed normally.
Therefore, do not write data to BRGC during communication.
238
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Cautions 1. Change the mode of an I/O Pin after stopping the serial transfer/reception operation.
2. When using the busy control option or busy & strobe control option in the 3-wire serial I/O
mode with automatic transfer/reception function of the serial interface channel 1, the RxD1/
BUSY/P24 and TxD1/STB/P23 pins cannot be used as data I/O pins.
Cautions 1. Change the mode of an I/O Pin after stopping the serial transfer/reception operation.
2. Port 11 has a falling edge detection function. Do not input a falling edge to the pin used as
a multiplexed pin of this port.
239
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The µPD6252Note is a 2048-bit EEPROM which can be electrically written or erased. To write or read data to or
from the µPD6252, the 3-wire serial interface is used.
CE 1 8 VDD
IC 2 7 CS
IC 3 6 SCL
GND 4 5 SDA
240
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Caution Do not change the level of this pin from high to low during data
transfer.
To change the level of this pin from high to low, make sure that the CS pin (pin 7)
is low. By making both the CE and CS pins low, you can set the standby status in
which the power consumption is reduced.
SDA
241
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
SCK0 SCL CE
SB1 SDA
P32 CS
Table 8-8 and Figure 8-27 shows the commands to write and read data to/from the µPD6252 and communication
format.
RANDOM READ 11000000B [C0H] Executes data read starting from a set word address (WA) after the word address has
MSB been set.
C7-C0 The difference from CURRENT READ is that this command sets a word address (WA)
after it has been executed.
After the word address has been set, this command performs the same operation as
CURRENT READ.
242
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
WA input
CS
Command input Write data input (WA) (WA + 1) (WA + 2)
SDA C7 C6 C5 C4 C3 C2 C1 C0 WB flag output WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 D7 D6 D5 D4 D3 D2 D1 D0 2nd byte 3rd byte
0 0 0 0 0 0 0 0 1st byte
SCL
Internal WA CURRENT ADDRESS WA WA + 1 to WA + 3
SDA mode IN
OUT IN
WA retains input value until STP is
Starts by making CS pin high detected, and is incremented each time
when SCL pin is high 1 byte is written in the internal write
(issuance of STA). cycle after STP has been detected.
Data of 1st byte is written to
WB flag is retained while eight
memory addressed by WA.
clocks are input to SCL pin.
Write is executed by making CS in low with SCL pin high.
(2) CURRENT READ WA is last written address + 1 and is retained
(current address) (issuance of STP).
Current address
CS
Command input Read data (WA) (WA + 1) (WA + 2) (WA + n)
SDA C7 C6 C5 C4 C3 C2 C1 C0 WB flag output D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D0 D7 D6 D2 D1 D0
1 0 0 0 0 0 0 0
SCL
Internal WA CURRENT ADDRESS = WA WA+1 WA+2 WA+n WA + n + 1
SDA mode IN OUT OUT
Operation ends by making CS pin high with
SCL pin high. WA is last read address + 1 and
retained (current address) (issuance of STP)
CS
WA input (WA) (WA+1) ··· (WA+n)
SDA C7 C6 C5 C4 C3 C2 C1 C0 WB flag output WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D1 D0
1 1 0 0 0 0 0 0
SCL
Internal WA CURRENT ADDRESS WA WA+1 WA+n WA + n + 1
SDA mode IN OUT IN OUT
WB flag is retained while 8 clocks are input to SCL pin.
Starts by making CS pin high Contents of WA are read as
with SCL pin high (issuance of STA). data of first byte.
Contents of WA+1, ··· WA+n are
sequentially read each time 1 byte
has been read.
Operation ends if CS pin is made low with
SCL pin high (issuance of STP).
WA is last read address + 1 and retained.
243
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Steps <1> through <5> below are the operating procedure of the µPD6252. In this example, the number of data
to be written or read per interface operation is fixed to 1 byte. If the µPD6252 is in the write busy (WB) status when
interfaced, the busy flag is set.
<Register used>
A
<RAM used>
Name Usage Attribute Bytes
WAADR Stores word address (before start of transfer) SADDR 1
244
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Flag used>
Name Usage
<Nesting>
1 level 3 bytes
<Hardware used>
• Serial interface channel 0
• P32
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• Setting of serial interface channel 0
CSIM0 = #10011011B ; Selects 2-wire serial I/O mode and SB1 pin
• TCL3 = #××××1001B ; Serial clock fXX/24
• RELT = 1 ; Makes SB1 latch high
<Starting>
Set the necessary data corresponding to the commands and call T3_6252. After execution returns from the
subroutine, the busy flag (BUSYFG) is tested. If the busy flag is set, transfer is not executed. It is therefore
necessary to execute transfer again. In the receive mode, the receive data is stored RCVDAT after execution
has returned from the subroutine.
245
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
EXTRN RWRITE,RREAD,CREAD
EXTRN WADAT,TRNDAT,RCVDAT,CMDDAT,T3_6252
EXTBIT BUSYFG,CS6252
CMDDAT=A
.
.
.
.
WADAT=A
.
.
.
.
TRNDAT=A
.
.
.
.
repeat
CLR1 BUSYFG
CALL !T3_6252
until_bit(!BUSYFG)
.
.
.
.
A=RCVDAT
246
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
247
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC RWRITE,RREAD,CREAD
PUBLIC WADAT,TRNDAT,RCVDAT,CMDDAT,T3_6252
PUBLIC BUSYFG,CS6252
CSI_DAT DSEG SADDR
WADAT: DS 1 ; Word address storage area
TRNDAT: DS 1 ; Transmit data storage area
RCVDAT: DS 1 ; Receive data storage area
CMDDAT: DS 1 ; Command data storage area
CSI_FLG BSEG
BUSYFG DBIT ; Sets busy status
CSI_SEG CSEG
;*************************************
;* µPD6252 (3-wire) communication
;*************************************
T3_6252:
CLR1 BUSYFG
SET1 CS6252 ; Issues start bit
SI00=CMDDAT (A) ; Transfers command
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
SIO0=#0FFH ; Starts reception of busy signal
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
if(SIO0==#00H) ; Busy check
switch (CMDDAT)
case RWRITE:
SIO0=WADAT (A) ; Transfers word address
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
SIO0=TRNDAT (A) ; Starts data transfer
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
break
case RREAD:
SIO0=WADAT (A) ; Transfers word address
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
case CREAD:
SIO0=#0FFH ; Starts data reception
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
RCVDAT=SIO0 (A) ; Stores receive data
ends
248
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
else
SET1 BUSYFG ; Sets busy status
endif
CLR1 CS6252
RET
249
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Figure 8-28. Example of Connection between µPD6252 and I2C Bus Mode
µ PD78054Y µ PD6252
SCL SCL A2 = 0
SDA0 (SDA1) SDA A1 = 0
SCL A2 = 0
SDA A1 = 1
SCL A2 = 1
SDA A1 = 0
SCL A2 = 1
SDA A1 = 1
Figure 8-29 shows the communication format in which data is written to or read from the µPD6252.
250
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
SDA 1 0 1 0 A2 A1 0 0 ACK WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 ACK D7 D6 D5 D4 D3 D2 D1 D0 ACK D7 D6 D5 D4 D3 D2 D1 D0 ACK
SCL
SCL
SDA 1 0 1 0 A2 A1 0 0 ACK WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 ACK 1 0 1 0 A2 A1 0 1 ACK D7 D6 D5 D4 D3 D2 D1 D0
SCL
251
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Steps <1> through <5> below are the communication procedure of the µPD6252. In this example, the number
of data to be written or read is fixed to 1 byte. If the master receives data in the I2C bus format, and if it has received
the last data, the ACK signal is not output. Because the master does not output the ACK signal in this example, ACKE
is always 0.
<2> Transmit the slave address value (bits 1 through 7) of the µPD6252 and write (bit 0 = 0)/read (bit 0 = 1) select
bit.
1 0 1 0 A2 A1 0 R/W
• In reception mode
Receive the read data.
<5> Because a word address is specified only in the write mode, to read data by specifying an address, the address
must be specified by once setting the write mode.
If the µPD6252 does not return the ACK signal during data transfer, communication is stopped.
The start and end conditions are set by CLC when the serial clock is manipulated, and by RELT and CMDT when
data is manipulated.
252
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
A
<RAM used>
Name Usage Attribute Bytes
WAADR Stores word address (before start of transfer) SADDR 1
<Flag used>
Name Usage
<Nesting>
1 level 2 bytes
<Hardware used>
Serial interface 0
253
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• Setting of serial interface channel 0
CSIM0 = #10011011B ; Selects 2-wire serial I/O mode and SB0 pin
• TCL3 = #××××1000B ; Selects serial clock fXX/23 and 16
• SINT = #00001011B ; Generates interrupts at rising edge of 9th serial clock and sets clock line to high
level
<Starting>
• Set the necessary data corresponding to the commands and call T2_6252. In the reception mode, the
receive data is stored to RCVDAT after execution has returned from the subroutine.
• If the serial clock is low (busy status) when communication is started or if ACK cannot be received during
data transfer, the BUSYFG and ERRFG are set. Test and clear these flags with the main processing.
Sets data
Calls T2_6252
(IF: sets BUSYFG)
Clears BUSYFG
To busy processing
(IF: sets ERRFG)
Clears ERRFG
To error processing
EXTRN WAADR,TRNDAT,RCVDAT,SLVADR,T2_6252
EXTBIT BUSYFG,WRCHG,ERRFG
SET1 SB0
OSMS=#00000001B ; Does not use divider circuit
CSIM0=#10011011B ; Serial interface 2-wire, SB0
SINT=#00001011B ; Sets I2C mode
TCL3=#10001000B ; SCK = 32.7 kHz
SET1 RELT
SET1 SCK0
CLR1
. SB0
.
.
.
WAADR=A
.
.
.
.
TRNDAT=A
SLVADR=A
CALL !T2_6252
if_bit(BUSYFG)
CLR1 BUSYFG
.
.
.
.
endif
.
.
.
.
if|bit(ERRFG)
CLR1 ERRFG
.
.
.
.
ENDIF
254
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
255
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC WAADR,TRNDAT,RCVDAT,SLVADR,T2_6252
PUBLIC BUSYFG,WRCHG,ERRFG
CSI_FLG BSEG
BUSYFG DBIT ; Sets busy status
WRCHG DBIT ; Changes mode
ERRFG DBIT ; Sets error status
CSI_SEG CSEG
;*************************************
;* µPD6252 (2-wire) communication
;*************************************
T2_6252:
if_bit(!CLD)
SET1 BUSYFG ; Busy status
else
STABIT:
SET1 CMDT ; Issues start bit
NOP ; Waits for start bit valid width
NOP
NOP
NOP
NOP
CLR1 CLC ; Changes clock to low level
SIO0=SLVADR (A) ; Starts transmitting slave address
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
if_bit(!ACKD) ; ACK signal not detected
SET1 ERRFG
elseif_bit(!SLVADR.0) ; Transmission mode
SI00=WAADR (A) ; Starts transmitting word address
while_bit(!CSIIF0) ; Waits for end of transfer
endw
CLR1 CSIIF0
if_bit(!ACKD) ; ACK signal not detected
SET1 ERRFG
elseif_bit(WRCHG)
while_bit(CLD)
endw
SET1 RELT
SET1 CLC
while_bit(!CLD) ; Checks high level of clock
endw
NOP ; Waits for high level valid width of clock
NOP
NOP
NOP
NOP
NOP
NOP
NOP
SET1 SLVADR.0 ; Changes to read mode address
goto STABIT
else
256
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
while_bit(CLD)
endw
SET1 CMDT
SET1 CLC
while_bit(!CLD) ; Checks high level of clock
endw
NOP ; Waits for high level valid width of clock
NOP
NOP
NOP
NOP
NOP
NOP
NOP
SET1 RELT ; Issues stop bit
endif
RET
257
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
• Limitation when the device is used as a slave device in the I2C bus mode
Description: If the wake-up function is executed (by setting the WUP flag (bit 5 of serial operation mode
register 0 (CSIM0) to 1) in the serial transfer statusNote, the data between other slave device
and the master devices is checked as an address. If that data coincides with the slave address
of the µPD78054Y, therefore, the µPD78054Y takes part in communication, destroying the
communication data.
Note The serial transfer status is the status from when the serial I/O shift register 0 (SIO0)
has been written until the interrupt request flag (CSIIF0) is set to 1 by completion of
serial transfer.
Preventive measures: The above problem can be prevented by modifying the program.
Before executing the wake-up function, execute the following program that clears
the serial transfer status. When executing the wake-up function, do not execute
an instruction that writes data to SIO0. Even if such an instruction is executed,
data can be received when the wake-up function is executed.
This program is to clear the serial transfer status. To clear the serial transfer status,
serial interface channel 0 must be stopped (by clearing the CSIE0 flag (bit 7 of the
serial operation mode register (CSIM0) to 0). If the serial interface channel 0 is
stopped in the I2C bus mode, however, the SCL pin outputs a high level and the
SDA0 (SDA1) pin outputs a low level, affecting communication on the I2C bus.
Therefore, this program allows the SCL and SDA0 (SDA1) pin to go into a high-
impedance state to prevent the I2C bus from being affected.
Note that, in this example, the serial data input/output pin is SDA0 (/P25). If SDA1
(/P26) is used as the serial data input/output pin, take P2.5 and PM2.5 in the
program as P2.6 and PM2.6.
258
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<1> When the I2C bus mode is restored by instruction <5>, the SDA0 pin does not output a low level. The
output of the SDA0 pin goes into a high-impedance state.
<2> The P25(/SDA0) pin is set in the input mode to prevent the SDA0 line from being affected when the
port mode is set by instruction <4>. The P25 pin is set in the input mode when instruction <2> is
executed.
<3> The P27 (/SCL) pin is set in the input mode to prevent the SCL line from being affected when the port
mode is set by instruction <4>. The P27 pin is set in the input mode when instruction <3> is executed.
<4> The I2C bus mode is changed to the port mode.
<5> The port mode is changed to the I2C bus mode.
<6> Instruction <8> prevents the SDA0 pin from outputting a low level.
<7> The P27 pin is set in the output mode because it must be in the output mode in the I2C bus mode.
<8> The output latch of the P25 pin is cleared to 0 because it must be cleared to 0 in the I2C bus mode.
<9> The P25 pin is set in the output mode because it must be in the output mode in the I2C bus mode.
259
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The OSD (On Screen Display) LSI µPD6451A displays the program information of a VCR and TV channels on
a display when used in combination with a microcontroller. The µPD6451A is interface with four lines: DATA, CLK,
STB, and BUSY. In the example shown in this section, the µPD78054 subseries is used to interface the µPD6451A.
SCK1 CLK
STB STB
BUSY BUSY
SCK1
STB
BUSY
The strobe signal (STB) is output and busy signal (BUSY) is tested automatically by the serial interface channel
1 of the 78K/0 series to establish handshaking with and to interface the µPD6451A. To match the communication
format of the µPD6451A, the µPD78054 subseries is set in a mode in which output of the strobe signal and input of
the busy signal (high active) are enabled. By setting the transmit data (32 bytes MAX) in a buffer area (FAC0H through
FADFH) and the number of transmit data to the automatic data transmit/receive address pointer (ADTP), you can
automatically transmit plural data successively.
260
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
A
<RAM used>
Name Usage Attribute Bytes
DTVAL Stores number of transmit data SADDR 1
<Nesting>
1 level 2 bytes
<Hardware used>
• Serial interface channel 1
<Initial setting>
• Setting of serial interface channel 1
CSIM1 = #10100011B ; Enables automatic transmission/reception with MSB first
ADTC = #00000110B ; Enables busy input (high active) and strobe output in single mode
• ADTI = #00000000B ; Interval time of data transfer
• OSMS = #00000001B ; Oscillation mode select register; does not use divider circuit
• TCL3 = #1001××××B ; Serial clock fXX/24
• Makes P22 output latch high
• PM2 = #×××1000×B ; Sets P21, P22, and P23 in output mode and P24 in input mode
<Starting>
Set the data to be transmitted to the buffer RAM (starting from the highest address), and the number of data
to be transmitted to DTVAL, and call TR6451. You can check the end of data transfer by testing the bit 3
(TRF) of the automatic data transfer/reception control register (ADTC).
261
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
EXTRN TR6451,DTVAL
262
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
TABLE1:
DB 11111111B ; Power-ON reset, command 1
DB 01000000B ; Vertical address 0
DB 11000000B ; Horizontal address 0
DB 10000000B ; Character size
DB 11111100B ; Command 0
DB 11101001B ; Turns LC transmission ON, blinking OFF, display ON
DB 07H ; 7
DB 08H ; 8
DB 1BH ; K
DB 6DH ; /
DB 00H ; 0
DB 10H
DB 11H ; A
DB 20H ; P
DB 20H ; P
DB 1CH ; L
DB 19H ; I
DB 13H ; C
DB 11H ; A
DB 24H ; T
DB 19H ; I
DB 00H ; O
DB 1EH ; N
DB 10H
DB 1EH ; N
DB 00H ; O
DB 24H ; T
DB 15H ; E
Remark For the command and data of the output table data, refer to µPD6451A Data Sheet (Document No. IC-
2337).
263
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC TR6451,DTVAL
CSI_SEG CSEG
;*************************************
;* µPD6451A communication
;*************************************
TR6451:
A=DTVAL ; Sets number of data
A––
ADTP=A
SIO1=#0FFH ; Starts transfer
RET
264
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
The 78K/0 series has an SBI mode conforming to NEC serial bus format. In this mode, one master CPU can
communicate with two or more slave CPUs by using two lines: clock and data. In the example shown in this section,
the µPD78054 subseries is used.
Figure 8-32 shows an example of connection to use the SBI mode, and Figure 8-33 shows the communication
format.
VDD
SB0 SB0
SCK0 SCK0
Slave CPU
SB
SCK
Slave CPU
SB
SCK
265
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
SCK0
SB0 A7 A6 A5 A4 A3 A2 A1 A0
Sets Sets
RELD CMDD
SCK0
SB0 C7 C6 C5 C4 C3 C2 C1 C0
Sets
CMDD
SCK0
SB0 D7 D6 D5 D4 D3 D2 D1 D0 ACK
Sets
ACKD
Note This signal is output by the receiver side during normal operation. However, it is output
by the master CPU in case of an error such as time out.
266
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
While the above processing is performed, errors <1> and <2> below are checked.
SB0 ACK
(time out)
INTTM3 (ACKD test)
SIO0 = 0FH 0 0 0 0 1 1 1 1
SB0 = 07H 0 0 0 0 0 1 1 1
In Figure 8-35, the values of SIO0 and SVA do not coincide (SIO0 = 07H and SVA = 0FH). Consequently, COI
= 0, and an error has occurred on the bus line.
267
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
Subroutine A
<RAM used>
Name Usage Attribute Bytes
TR_MODE Stores transfer mode select value SADDR 1
ACKCT Time out counter
<Flag used>
Name Usage
RCVFLG Sets reception mode
<Nesting>
2 levels 5 bytes
268
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Hardware used>
• Serial interface channel 0
• Watch timer
<Initial setting>
• OSMS=#00000001B ; Oscillation mode select register: does not use divider circuit
• Sets serial interface channel 0
CSIM0=#10010011B ; Selects SBI mode and SB1 pin
• TCL3=#××××1001B ; Serial clock: fXX/24
• RELT=1 ; Makes SO0 latch high
• P27=1 ; Makes P27 output latch high
• TMC2=#00100110B ; Watch timer interval: 1.95 ms
• Enables watch timer interrupt
<Starting>
Set the transfer mode and necessary data, and call M_TRANS. When execution has returned from the
subroutine, occurrence of a transfer error can be checked by testing the error flag (ERRORF). In the reception
mode, the receive data is stored to RCVDAT after execution has returned from the subroutine.
269
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
EXTRN M_TRANS,TR_MODE,TRADR,TRCMD,TRDAT,RCDAT
EXTRN TRNDAT,RCVDAT
EXTBIT ERRORF
270
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
271
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
272
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC M_TRANS,TR_MODE,TRADR,TRCMD,TRDAT,RCDAT
PUBLIC TRNDAT,RCVDAT,ERRORF
SBI_FLG BSEG
RCVFLG DBIT ; Sets reception mode
BUSYFG DBIT ; Transfer status
ERRORF DBIT ; Error display
ACKWFG DBIT ; ACK wait status
273
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
;*******************************************
;* SBI data transfer processing
;*******************************************
SBI_SEG CSEG
M_TRANS:
switch(TR_MODE)
case TRADR:
SET1 PM2.5
while_bit(!SB0) ; SB0 = high?
CLR1 PM2.5
endw
while_bit(!SCK0) ; SCK = high?
endw
SET1 CMDT ; Outputs command signal
NOP ; Wait
SET1 RELT ; Outputs bus release signal
A=#TRCMD
case TRCMD:
SET1 PM2.5
while_bit(!SB0) ; SB0 = high?
CLR1 PM2.5
endw
while_bit(!SCK0) ; SCK = high?
endw
SET1 CMDT ; Outputs command signal
A=#TRDAT
case TRDAT:
CLR1 RCVFLG ; Sets transmission mode
A=TRNDAT ; Sets transmit data
break
case RCDAT:
SET1 RCVFLG ; Sets reception mode
MOV A,#0FFH ; Turns off receive buffer
break
ends
274
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
;***************************************
;* INTCSI0 interrupt processing
;***************************************
CSI_SEG CSEG
INTCSI0:
SEL RB0
if_bit(!RCVFLG) ; Transmission mode
if_bit(!ACKD) ; Acknowledge signal not received
ACKCT=#5 ; Sets acknowledge signal wait status
SET1 ACKWFG
else
CLR1 BUSYFG ; Clears busy status
CLR1 ERRORF ; Clears error status
endif
else
SET1 ACKT ; Outputs acknowledge signal
CLR1 BUSYFG ; Clears busy status
CLR1 ERRORF ; Clears error status
endif
RET
;***************************************
;* Time out processing
;***************************************
TM3_SEG CSEG
INTTM3:
SEL RB0
if_bit(ACKWFG) ; Acknowledge signal wait status?
if_bit(ACKD) ; Acknowledge signal received?
CLR1 ACKWFG ; Clears acknowledge signal wait status
CLR1 BUSYFG ; Clears busy status
else
ACKCT--
if(ACKCT==#0) ; Time out?
SET1 ACKT ; Time out error processing
SET1 ERRORF
CLR1 ACKWFG ; Clears acknowledge signal wait status
CLR1 BUSYFG ; Clears busy status
endif
endif
endif
275
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
Bank 0: A
<RAM used>
Name Usage Attribute Bytes
RCVDAT Stores receive data SADDR 1
<Flag used>
Name Usage
<Nesting>
1 level 3 bytes
<Hardware used>
• Serial interface channel 0
<Initial setting>
• Setting of serial interface channel 0
CSIM0=#10010011B; Sets SBI mode, SBI pin, and wake-up mode, and inputs
serial clock from external source
• BYSE=1 Outputs synchronous busy signal
• RELT=1 Makes SO0 latch high
• SVA=#SLVADR; Slave address
• Enables serial interface channel 0 interrupt
276
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Starting>
The interrupt processing is started by generation of INTCSI0. The interrupt processing performs the following
processing:
• Identifies address/command/data
• Outputs ACK signal
• Stores receive data to RCVDAT
EXTRN RCVDAT
EXTBIT RCVFLG
277
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
CSI_FLG BSEG
RCVFLG DBIT ; Sets reception mode
CSI_SEG CSEG
;***************************************
;* INTCSI0 interrupt processing
;***************************************
INTCSI0:
SEL RB0
if_bit(RELD) ; To address reception
CLR1 WUP ; Clears wake-up mode
SET1 ACKT ; Outputs acknowledge signal
; User processing (address reception)
;***************************************
if_bit(RCVFLG)
; User processing (data reception processing)
SET1 ACKT ; Outputs acknowledge signal
else
; User processing (data transmission processing)
endif
;***************************************
endif
RCVDAT=SIO0 (A)
RETI
278
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
In this section, examples of communication between the master and a slave by using the 3-wire serial I/O mode
(serial clock, data input, data output) of the serial channel 0 of the 78K/0 series are shown. In these examples, one
extra busy signal is used as a handshake signal for simultaneous transmission/reception between the master and
slave. This busy signal is active-low and is output by the slave. The data is 8 bits long and transmitted with the MSB
first. In the examples in this section, the µPD78054 subseries is used.
Master Slave
SCK0 SCK0
SI0 SO0
SO0 SI0
BUSY BUSY
BUSY
SCK0
279
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
Interrupt : Bank 0, A
Subroutine : A
<RAM used>
Name Usage Attribute Bytes
<Flag used>
Name Usage
TREND Sets transfer end status
<Nesting>
2 levels 5 bytes
<Hardware used>
• Serial interface channel 0
• P33
<Initial setting>
• OSMS=#00000001B ; Oscillation mode select register: does not used divider
circuit
• Setting of serial interface channel 0
CSIM0=#10000011B ; 3-wire serial I/O mode, MSB first
• TCL3=#××××1001B ; Serial clock fXX/24
• P27=1 ; Makes P27 output latch high
• P33 input mode
• Enables serial interface channel 0 interrupt
280
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Starting>
Set the transmit data to TDATA and call TRANS. After execution has returned from the subroutine, test the
busy flag (BUSYFG). If the busy flag is set, transfer has not been executed and therefore, you must execute
it again. If the busy flag is cleared, transfer has ended and the receive data has been stored to RDATA.
EXTRN TDATA,RDATA,TRANS
EXTBIT TREND,BUSYFG,BUSY
281
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC TRANS,RDATA,TDATA,BUSY,TREND,BUSYFG
VECSI0 CSEG AT 14H
DW INTCSI0 ; Sets vector address of serial interface channel 0
CSI_FLG BSEG
TREND DBIT ; Sets transfer end status
BUSYFG DBIT ; Sets busy status
CSI_SEG CSEG
;**************************************
;:* INTCSI0 interrupt processing
;**************************************
INTCSI0:
SEL RB0
RDATA=SIO0 (A) ; Stores receive data
SET1 TREND ; Sets transfer end status
RETI
;**************************************
;* 3-wire (master)
;**************************************
TRANS:
if_bit(BUSY)
SIO0=TDATA (A) ; Enables transfer
else ; Sets transmit data
SET1 BUSYFG
endif ; Sets busy status
RET
282
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
BUSY
<Register used>
Interrupt : Bank 0, A
Subroutine : A
<RAM used>
Name Usage Attribute Bytes
TDATA Stores transmit data SADDR 1
RDATA Stores receive data
<Flag used>
Name Usage
<Nesting>
2 level 5 bytes
<Hardware used>
• Serial interface channel 0
• P33
283
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Initial setting>
• Setting of serial interface channel 0
CSIM0=#10000000B ; Sets 3-wire serial I/O mode with MSB first, and inputs external
clock
• P33=0 ; P33 output mode
• Setting of busy status
• Enables serial interface channel 0
<Starting>
Set the transmit data to TDATA and call TRANS. Because the busy signal is cleared by the processing of
TRANS, the slave waits for communication with the master. After the communication has ended, INTCSI0
occurs and interrupt processing is started. You can check the end of transfer by testing TREND. After TREND
has been set, the receive data has been stored to RDTA.
EXTRN TDATA,RDATA,TRANS
EXTBIT TREND,BUSY
.
.
.
.
CSIM0=#10000000B ; Sets 3-wire I/O mode with MSB first
CLR1 BUSY ; Busy status
CLR1 PM3.3 ; P3.3 output mode
CLR1 CSIMK0 ; Enables serial interface channel 0
EI
.
.
.
.
TDATA=A ; Sets transmit data
CALL !TRANS
while_bit(!TREND) ; Ends transfer
endw
A=RDATA ; Loads receive data
284
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC RDATA,TDATA,BUSY,TREND,BUSYFG
PUBLIC TRANS
VECSI0 CSEG AT 14H
DW INTCSI0 ; Sets vector address of serial interface channel 0
CSI_FLG BSEG
TREND DBIT ; Sets transfer end status
BUSYFG DBIT ; Sets busy status
CSI_SEG CSE
;**************************************
;* INTCSI0 interrupt processing
;**************************************
INTCSI0:
SEL RB0
CLR1 BUSY ; Sets busy status
RDATA=SI00 (A) ; Stores receive data
SET1 TREND ; Sets transfer end status
RETI
;**************************************
;* 3-wire (slave)
;**************************************
TRANS:
SIO0=TDATA (A) ; Sets transmit data
SET1 BUSY ; Clears busy status
RET
285
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Serial interface channel 2 has two modes: asynchronous serial interface (hereafter referred to as “UART”) and
3-wire serial I/O modes.
Serial interface channel 2 is set by the following registgers:
• Serial operating mode register 2 (CSIM2)
• Asynchronous serial interface mode register (ASIM)
• Asynchronous serial interface status register (ASIS)
• Baud rate generator control register (BRGC)
• Oscillation mode select register (OSMS)
UART using serial interface channel 2 is briefly described below.
The UART mode of serial interface channel 2 is to transmit or receive 1-byte data following a start bit and can
perform full-duplex operation.
The operations of UART communication are described below.
fXX
[Baud rate] = [Hz]
2n × (k + 16)
286
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
Table 8-10. Relations between Main System Clock and Baud Rate (at fX = 4.19 MHz)
MCS = 1 MCS = 0
Baud rate (bps)
Set value of BRGC Error (%) Set value of BRGC Error (%)
(c) Transmission
Transmission is started when transmit data has been written to the transmit shift register (TXS). The start
bit and parity bit are automatically appended.
(d) Reception
Reception is enabled when bit 6 (RXE) of the asynchronous serial interface mode register (ASIM) is set to
1, and the data input to the RxD pin is sampled. When reception of one frame of data has been completed,
the receive data in the shift register is transferred to the receive buffer register (RXB) and a receive end interrupt
request (INTSR) occurs.
Cautions 1. The contents of the asynchronous serial interface status register (ASIS) are reset to 0
when the receive buffer register (RXB) is read or the next data is received. To determine
the nature of the error, be sure to read ASIS before reading RXB.
2. Be sure to read the receive buffer register (RXB) when a reception error has occurred.
Otherwise, an overrun error will occur when the next data is received, and the reception
error status will persist.
287
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
During communication, transmission and reception with a terminal is performed and RTS and CTS are
controlled for handshaking. The communication protocol is shown below.
When transmission is started, the end of the previous transmission (in which case the transmission end
interrupt request flag (STIF) is set to 1) is checked, and transmission is executed if the CTS input status is
ready (“L”).
During reception, the busy signal (“H”) is output to the RTS output pin when a reception end interrupt request
(INTSR) occurs. “L” is output to the RTS output pin when reception is enabled.
A receive error interrupt request (INTSER) occurs if a receive error (parity error, framing error, or overrun error)
occurs, and the error flag is set. Figure 8-39 shows a communication block diagram, and Figures 8-40 and
8-41 show the transmission/reception format.
µ PD78054 Terminal
TXD TXD
RXD RXD
288
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
289
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Register used>
S_SOSHIN : Bank 0, A
INTSR : Bank 3, A
INTSER : Bank 3, A
<RAM used>
Name Usage Attribute Bytes
SOSHIN Transmit data storage area SADDR 1
JUSHIN Receive data storage area SADDR 1
<Flag used>
Name Usage
<Nesting level>
2 levels 5 bytes
290
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
<Hardware used>
• Serial interface channel 2 (UART mode)
<Initial setting>
• OSMS=#00000001B ; Oscillation mode select register: does not use divider circuit
• CLR1 P3.2 ; P31 = CTS input, P32 = RTS output
PM3=#××××10×B
• BRGC=#10001011B ; Sets baud rate to 9600 bps (error: 1.14%)
• CSIM2=#00000000B ; Sets 0 to serial operation mode register 2 when UART is used
• ASIM=#11001101B ; Sets asynchronous serial interface mode register
• CLR1 SRIF ; Clears reception end receive error interrupt request flags
CLR1 SERIF
• SET1 STIF ; Sets transmission end interrupt request flag (to end transmission)
• CLR1 SRMK ; Enables reception end and receive error interrupts
CLR1 SERMK
Caution Before starting transmission, check the transmission end interrupt request flag (STIF) so
that transmission is not executed during transmission. Therefore, set the transmission
end interrupt request flag (STIF) after reset and start.
Remark To use the transmission end interrupt (to generate the interrupt request), use an additional flag.
Set the additional flag as the initial setting. Clear the flag at the start of transmission, and set
it in the interrupt processing.
<Starting>
Store the transmit data to the SOSHIN area at the start of transmission and call the S_SOSHIN routine.
291
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
EXTRN S_SOSHIN
EXTRN SOSHIN,JUSHIN
EXTBIT F_TUSHIN,F_ERR,F_BUSY
;
RTS_0 EQU P3.2 ; RTS output port
;
OSMS=#00000001B ; Does not use divider circuit
CLR1 RTS_0 ;
PM3=#11111011B ; P31 = CTS input, P32 = RTS output
BRGC=#10001011B ; 9600 bps (error: 1.41%)
CSIM2=#00000000B ; Initial setting when UART is used
ASIM=#11001101B ; Enables receive error interrupt. Stop bit: 2 bits
; Transmit data: 8 bits. No parity. Enables reception and transmission.
CLR1 SERIF ; Clears receive error interrupt request flag
CLR1 SRIF ; Clears reception end interrupt request flag
SET1 STIF ; Sets transmit end interrupt request flag
; ; →Ends transmission
CLR1 SERMK ; Enables receive error interrupt
CLR1 SRMK ; Enables reception end interrupt
EI ;
.
.
.
.
if_bit(transmission request) ; Sets transmission request flag?
SOSHIN=A ; Stores transmit data
CALL !S_SOSHIN ; Calls transmit routine
endif
if_bit(F_BUSY) ; End of transmission?
.
Communication busy processing ;
.
endif ;
.
.
if_bit(F_TUSHIN) ; Sets reception end flag?
CLR1 F_TUSHIN ; Clears reception end flag
A=JUSHIN ; Reads receive data
.
Reception processing ;
.
CLR1 RTS_0 ; RTS output pin ← “L” (ready status)
endif ;
.
.
292
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
293
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
PUBLIC S_SOSHIN
PUBLIC SOSHIN,JUSHIN
PUBLIC F_TUSHIN,F_ERR,F_BUSY
;
VESR CSEG AT 1AH
DW INTSR
VESER CSEG AT 18H
DW INTSER
;
RTS_0 EQU P3.2 ; RTS output port
CTS_I EQU P3.1 ; CTS input port
;
UARTRAM DSEG SADDR
SOSHIN: DS 1 ; Transmit data storage area
JUSHIN: DS 1 ; Receive data storage area
;
UARTFLG BSEG
F_TUSHIN DBIT ; Reception end flag
F_BUSY DBIT ; Communication busy flag
F_ERR DBIT ; Reception error flag
;
;************************************
; Transmission routine
;************************************
UARTPR0 CSEG
S_SOSHIN:
if_bit(STIF) ; Previous transmission end?
if_bit(!CTS_I) ; Enables transmission?
CLR1 STIF ; Clears transmit end interrupt request flag
TXS=SOSHIN (A) ; Stores transmit data
CLR1 F_BUSY ; Clears transmit busy flag
else ;
SET1 F_BUSY ; Disables transmission → sets transmission busy flag
endif ;
else ;
SET1 F_BUSY ;
endif ;
RET
;************************************
; Reception end routine
;************************************
INTSR: ;
SEL RB3 ; RTS ← H
SET1 RTS_0 ; Loads receive data
JUSHIN=RXB (A) ; Sets reception end flag
SET1 F_TUSHIN ;
RETI
;************************************
; Reception error routine
;************************************
INTSER: ; Selects bank 3
SEL RB3 ; Reads error data
A=RXB ; Sets receive error flag
SET1 F_ERR ;
RETI
END
294
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
• Description
If bit 1 (ISRM) of the asynchronous serial interface mode register (ASIM) is set to 1, the reception
completion interrupt (INTSR) does not occur when a reception error occurs. If the receive buffer register
(RXB) is read at certain timing (a in Figure 8-42) during reception error interrupt (INTSER) processing,
the internal error flag is cleared to 0. Therefore, it is judged that a reception error has not occurred,
and INTSR, which should not occur, occurs. Figure 8-42 illustrates this operation.
fSCK
a
Error flag
(internal flag)
Interrupt routine
of CPU
• Preventive measures
• In case of framing error or overrun error
Disable the receive buffer register (RXB) from being read for a certain period (T2 in Figure 8-43)
after the receive error interrupt (INTSER) has occurred.
295
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
STOP
RxD (input) D0 D1 D2 D6 D7 Parity
START
INTSR
T1 T2
T1: Time of one data of baud rate selected by baud rate generator control register (BRGC) (1/baud rate)
T2: Time of two source clocks (fSCK) of 5-bit counter selected by BRGC
[Condition]
fX = 5.0 MHz
Processor clock control register (PCC) = 00H
Oscillation mode select register (OSMS) = 01H
Baud rate generator control register (BRGC) = 80H (2400 bps is selected as baud rate)
tCY = 0.4 µs (tCY = 0.2 µs)
1
T1 = = 833.4 µs
2400
T2 = 12.8 × 2 = 25.6 µs
T1 + T2
= 4295 (clocks)
tCY
296
CHAPTER 8 APPLICATIONS OF SERIAL INTERFACE
[Example]
EI
INTSER occurs
MOV A, RXB
RETI
297
[MEMO]
298
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
The A/D converter of the 78K/0 series is a successive approximation type with an 8-bit resolution and eight
channels. Although only a select mode is supported as the operation mode, conversion can be started by an external
trigger. If the external trigger is not used, the analog data of a selected channel is repeatedly converted into a digital
signal.
The A/D converter is set by the A/D converter mode register (ADM), A/D converter input select register (ADIS),
external interrupt mode register 1 (INTM1), and A/D current cut select register (IEAD).
299
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
ADM CS TRG FR1 FR0 ADM3 ADM2 ADM1 HSC FF80H 01H R/W
0 0 0 ANI0
0 0 1 ANI1
0 1 0 ANI2
0 1 1 ANI3
1 0 0 ANI4
1 0 1 ANI5
1 1 0 ANI6
1 1 1 ANI7
1 Starts operation
Cautions 1. To reduce the power consumption of the A/D converter when the standby function is used,
stop the A/D conversion operation by clearing bit 7 (CS) to 0, and then execute the HALT or
STOP instruction.
2. To resume the A/D conversion operation which has been once stopped, clear the interrupt
request flag (ADIF) to 0 and then start the A/D conversion operation.
300
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
Figure 9-2. Format of A/D Converter Mode Register (µPD78098, 78098B subseries)
ADM CS TRG FR1 FR0 ADM3 ADM2 ADM1 HSC FF80H 01H R/W
0 1 0 ANI2
0 1 1 ANI3
1 0 0 ANI4
1 0 1 ANI5
1 1 0 ANI6
1 1 1 ANI7
0 Stops operation
1 Starts operation
Cautions 1. To reduce the power consumption of the A/D converter when the standby function is used,
stop the A/D conversion operation by clearing bit 7 (CS) to 0, and then execute the HALT or
STOP instruction.
2. To resume the A/D conversion operation which has been once stopped, clear the interrupt
request flag (ADIF) to 0 and then start the A/D conversion operation.
301
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
Figure 9-3. Format of A/D Converter Mode Register (µPD780018, 780018Y subseries)
ADM CS TRG FR1 FR0 ADM3 ADM2 ADM1 HSC FF80H 01H R/W
0 1 0 ANI2
0 1 1 ANI3
1 0 0 ANI4
1 0 1 ANI5
1 1 0 ANI6
1 1 1 ANI7
0 Stops operation
1 Starts operation
Cautions 1. To reduce the power consumption of the A/D converter when the standby function is used,
stop the A/D conversion operation by clearing bit 7 (CS) to 0, and then execute the HALT or
STOP instruction.
2. To resume the A/D conversion operation which has been once stopped, clear the interrupt
request flag (ADIF) to 0 and then start the A/D conversion operation.
302
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
303
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
INTM1 ES71 ES70 ES61 ES60 ES51 ES50 ES41 ES40 FFEDH 00H R/W
304
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
INTM1 0 0 ES61 ES60 ES51 ES50 ES41 ES40 FFEDH 00H R/W
305
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
Figure 9-8. Format of A/D Current Cut Select Register (µPD78098, 78098B subseries)
306
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
In this application example, the analog voltage input to the A/D converter is displayed on an LED matrix consisting
of 4 × 4, i.e., 16 LEDs.
Because a level meter has been included in this example, the LED display is given in decibel units. Figure 9-9
shows the circuit of the level meter, and Figure 9-10 shows the relations between the result of the A/D conversion
and the number of display digits.
µ PD78054
P60
P61
P62
P63
ANIn P64
P65
P66
P67 =
LED(Units)
16
15
14
13
12
Display level
11
10
9
8
7
6
5
4
3
2
1
0 0AH 12H 20H 2EH 39H 40H 48H 51H 5BH 66H 72H 80H 90H A2H B5H FFH
–22 –17 –12 –9 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 6 [dB]
Display value
307
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
The level meter in this example operates with specifications <1> through <3> below.
Hold level 6 6 6 6 7 8 9 9 9 9 9 9 4 4 4 5 6 6
Display level 6 5 4 5 7 8 9 8 7 6 5 5 4 3 3 5 6 2
<Register used>
AX, HL, BC (subroutine processing)
Bank 0: A, HL, B (interrupt processing)
308
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<RAM used>
Name Usage Attribute Bytes
<Flag used>
Name Usage
T20MSF Set every 20 ms
T1SF Set every 1 s
<Nesting>
2 levels 5 bytes
<Hardware used>
• A/D converter
• 8-bit timer/event counter 1
• P6
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• ADM = #1000×××1B ; Selects channel of A/D converter and starts operation
• TCL1 = #10111011B ; Interval time of 2 ms of 8-bit timer/event counter 1
TMC1 = #00000001B
CR10 = 130
• P6 output mode
• Makes P6 output latch low
• Enables INTTM1 interrupt
309
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<Starting>
This program performs two types of processing: A/D conversion (subroutine) and LED display (interrupt).
EXTRN LEVEL,CT20MS,CT1S
MOV CT20MS,#10
MOV CT1S,#50
MOV TMC2,#00100110B
CLR1 TMMK3
; Turns OFF LED display
P6=#00H
PM6=#00000000B ; Does not use divider circuit
OSMS=#00000001B ; ANI0 pin starts operation
ADM=#10000001B ; Sets 8-bit timer/event counter 1 to 2 ms
TCL1=#10111011B
CR10=#130
TMC1=#00000001B ; Enables 8-bit timer/event counter 1 interrupt
CLR1 TMMK1
EI
310
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
311
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
PUBLIC LEVEL,HLDLEV,DSPLEV,CT20MS,CT1S
AD_FLG BSEG
T20MSF DBIT ; Measures 20 ms
T1SF DBIT ; Measures 1 s
AD_SEG CSEG
;*********************************
* Sets level meter data
;*********************************
LEVEL:
IF_BIT(T20MSF) ; Checks 20 ms
CLR1 T20MSF
A=ADCR ; Inputs A/D conversion value
A<->ADDAT ; Stores A/D conversion value
A<->ADDAT+1
A<->ADDAT+2
A<->ADDAT+3
; Averages four A/D conversion values
AX=#0H
HL=#ADDAT ; Data storage address
for(WORKCT=#0;WORKCT<#4;WORKCT++)
A+=[HL]
HL++
if_bit(CY) ; Carry
X++ ; Higher digit
endif
next
A<->X
C=#4 ; Averages four values
AX/=C ; AX/C = AX (quotient) ... C (remainder)
if(C>=#2) (A) ; Remainder processing (2 or higher is carried)
X++ ; Carry processing
endif
HL=#LEVTBL
B=#0 ; Conversion result storage register
for(WORKCT=#0;WORKCT<#16;WORKCT++)
if(X>=[HL+B]) (A) ; Compares data
B++
else
break
endif
next
312
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
HL=#DSPTBL
A=DSPLEV ; Creates display level
A+=A
B=A
A=HLDLEV
A+=A
C=A
X=[HL+B] (A)
B++
A=[HL+B]
HL=#HLDTBL ; Creates hold level
A<->X
A|=[HL+C]
A<->X
C++
A|=[HL+C]
BC=AX
313
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
RET
LEVTBL:
DB 0AH
DB 12H
DB 20H
DB 2EH
DB 39H
DB 40H
DB 48H
DB 51H
DB 5BH
DB 66H
DB 72H
DB 80H
DB 90H
DB 0A2H
DB 0B5H
DB 0FFH
DSPTBL:
DW 0000000000000000B
DW 0000000000000001B
DW 0000000000000011B
DW 0000000000000111B
DW 0000000000001111B
DW 0000000000011111B
DW 0000000000111111B
DW 0000000001111111B
DW 0000000011111111B
DW 0000000111111111B
DW 0000001111111111B
DW 0000011111111111B
DW 0000111111111111B
DW 0001111111111111B
DW 0011111111111111B
DW 0111111111111111B
DW 1111111111111111B
HLDTBL:
DW 0000000000000000B
DW 0000000000000001B
DW 0000000000000010B
DW 0000000000000100B
DW 0000000000001000B
DW 0000000000010000B
DW 0000000000100000B
DW 0000000001000000B
DW 0000000010000000B
DW 0000000100000000B
DW 0000001000000000B
DW 0000010000000000B
DW 0000100000000000B
DW 0001000000000000B
DW 0010000000000000B
DW 0100000000000000B
DW 1000000000000000B
$EJECT
314
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
;*********************************
* Level meter data
;*********************************
TM1_SEG CSEG
INTTM1:
SEL RB0 ; Turns OFF digit and segment signals
P6=#00000000B
HL=#DSPDAT
B=DIGCNT (A)
P6=[HL+B] (A)
DIGCNT++
DIGCNT&=#00000011B ; 20 ms?
CT20MS--
if(CT20MS==#0) ; Sets initial counter value
CT20MS=#10
SET1 T20MSF ; 1s?
CT1S--
if(CT1S==#0) ; Sets initial counter value
CT1S=#50
SET1 T1SF
endif
endif
RETI
315
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
9.2 Thermometer
In this application example, a temperature in a range of –20°C to +50°C is measured by using a thermistor (6 kΩ/
0°C) as a temperature sensor. Changes in the resistance of the thermistor with respect to temperature are given
by the following expression:
where,
R : resistance at given temperature T [°K]
T : given temperature [°K]
R0 : resistance at reference temperature T0 [°K]
T0 : reference temperature [°K]
B : constant obtained by reference temperature T0 [°K] and T0 [°K]
Constant B changes with the temperature. This constant can be calculated by changing the above expression
as follows:
1 R
B= In
(1/T–1/T0) R0
Figure 9-12 shows a circuit example. This circuit is designed to input 0 V at –20°C, and 5 V at + 50°C.
Th µ PD78054
+
ANIn
–
316
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
Because the characteristic of the thermistor is non linear in this example, the input analog voltage is not converted
to a temperature in a range of –20 °C to +50 °C through calculation but by comparison with table data. This conversion
result is stored to RAM (DSPDAT) as 2-digit BCD. Figure 9-13 shows the characteristics of the thermistor, and Table
9-1 shows the relations between temperature and A/D conversion value.
To measure the temperature, four conversion values are averaged and converted to a temperature. The result
of the conversion is stored in a display area. Therefore, the data is updated once every four times. For example,
if measurement processing is executed every 250 ms, the display updating cycle is 1 second.
(%)
100
90
Percentage of output characteristic
80
70
60
50
40
30
20
10
0
–20 –10 0 10 20 30 40 50 (°C)
Temperature
317
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<Register used>
AX, BC, HL
318
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<RAM used>
Name Usage Attribute Bytes
ADDAT Stores A/D conversion value SADDR 4
<Flag used>
Name Usage
<Nesting>
1 level 2 bytes
<Hardware used>
A/D converter
<Initial setting>
ADM = #1000×××1B; Selects A/D converter channel and starts operation
<Starting>
Set the T250MSF flag in each measurement cycle by using timer processing. After that, call THMETER at
least once in measurement cycle.
319
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
EXTRN THMETER,DSPDAT,CNTPRO
EXTBIT MINUSF,T250MSF
;**********************************************
; Watch timer interrupt processing
; Interval time: 1.95 ms
;**********************************************
INTTM3: ; 1.95 ms interrupt processing
.
.
.
.
DBNZ CT250MS,$RTNTM3
MOV CT250MS,#128 ; 250 ms elapses
SET1 T250MSF
RTNTM3:
.
.
.
.
RETI
320
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
321
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
PUBLIC THMETER,DSPDAT,CNTPR0,T250MSF,MINUSF
AD_FLG BSEG
T250MSF DBIT ; Sets 250 ms
MINUSF DBIT ; Sets minus data
TH_SEG CSEG
;*********************************
* Sets temperature data
;*********************************
THMETER:
if_bit(T250MSF) ; 250 ms
CLR1 T250MSF
A=ADCR
A<->ADDAT
A<->ADDAT+1
A<->ADDAT+2
A<->ADDAT+3
CNTPR0--
if(CNTPR0==#0)
CNTPR0=#4
AX=#0H
HL=#ADDAT ; Data storage address
for(WORKCT=#0;WORKCT<#4;WORKCT++)
A+=[HL]
HL++
if_bit(CY) ; Carry occurs
X++ ; Carry
endif
next
A<->X
C=#4
AX/=C ; AX/C = AX (quotient) ... C (remainder)
if(C>=#2) (A) ; Remainder processing (2 digits or more carried)
X++ ; Carry processing
endif
322
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
endif
CLR1 MINUSF
A=#20 ; Temperature data 20
B–=A
if_bit(CY) ; To decimal conversion
SET1 MINUSF
A=#0
A–=B ; Absolute value of data
A<->B
endif
X=#0 ; Decimal conversion
A=B
A<->X
C=#10
AX/=C ; Temperature data/10
DSPDAT=C (A) ; Updates display data
(DSPDAT+1)=X (A)
endif
endif
RET
323
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
THRTBL;
;
DB 1 ; –19.5
DB 4 ; –18.5
DB 7 ; –17.5
DB 0AH ; –16.5
DB 0CH ; –15.5
DB 0FH ; –14.5
DB 12H ; –13.5
DB 16H ; –12.5
DB 19H ; –11.5
DB 1CH ; –10.5
DB 1FH ; –9.5
DB 23H ; –8.5
DB 26H ; –7.5
DB 2AH ; –6.5
DB 2DH ; –5.5
DB 31H ; –4.5
DB 35H ; –3.5
DB 38H ; –2.5
DB 3CH ; –1.5
DB 40H ; –0.5
DB 44H ; +0.5
DB 48H ; 1.5
DB 4CH ; 2.5
DB 50H ; 3.5
DB 54H ; 4.5
DB 58H ; 5.5
DB 5CH ; 6.5
DB 60H ; 7.5
DB 64H ; 8.5
DB 69H ; 9.5
DB 6DH ; 10.5
DB 71H ; 11.5
DB 75H ; 12.5
DB 7AH ; 13.5
DB 7EH ; 14.5
DB 82H ; 15.5
DB 86H ; 16.5
DB 8BH ; 17.5
DB 8FH ; 18.5
DB 93H ; 19.5
DB 97H ; 20.5
DB 9BH ; 21.5
DB 9FH ; 22.5
DB 0A3H ; 23.5
DB 0A8H ; 24.5
DB 0ACH ; 25.5
DB 0B0H ; 26.5
DB 0B4H ; 27.5
DB 0B7H ; 28.5
DB 0BBH ; 29.5
DB 0BFH ; 30.5
DB 0C3H ; 31.5
DB 0C7H ; 32.5
DB 0CBH ; 33.5
DB 0CEH ; 34.5
DB 0D2H ; 35.5
DB 0D6H ; 36.5
324
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
DB 0D9H ; 37.5
DB 0DCH ; 38.5
DB 0E0H ; 39.5
DB 0E3H ; 40.5
DB 0E7H ; 41.5
DB 0EAH ; 42.5
DB 0EDH ; 43.5
DB 0F0H ; 44.5
DB 0F3H ; 45.5
DB 0F6H ; 46.5
DB 0F9H ; 47.5
DB 0FCH ; 48.5
DB 0FFH ; 49.5
325
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
In this example, sixteen keys are input by using the A/D converter. To input keys, a circuit must be designed so
that a voltage peculiar to a key is input to the A/D converter when the key is pressed.
Because sixteen keys are input in this example, VDD is divided by 16 and the voltage of each key is converted into
a key code. Table 9-2 shows the relations between the input voltages and key codes (00H through 0FH). When
no key input is made, the key code is 10H.
Figure 9-14 shows an example of the circuit that satisfies the above relations between the input voltages and key
codes. Note, however, that this circuit gives a priority to the key with the lower number if two or more keys are pressed
at the same time.
326
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
VDD
R0
K0
ANIn
R1
K1
µ PD78054
K2 R2
R14
K14
R15
K15
Resistances R0 through R15 used in the circuit in Figure 9-14 can be calculated by the following expression:
n n × R0
Σ RK =
K=1 16–n
Table 9-3 shows the resistances of R1 through R15 where R0 is 1 kΩ in the above expression (the calculation
result of a resistance may slightly different from the resistance of commercial resistors indicated by a color code).
This program converts an input analog voltage into the corresponding key code shown in Table 9-2, absorbs
chattering, and then stores the input voltage to RAM. To absorb chattering, a key code is assumed to be valid when
it coincides with a given value five times in succession. For example, if an analog voltage is sampled every 5 ms,
chattering of 20 to 25 ms is absorbed. If a key input is changed, a key change flag (KEYCHG) is set.
327
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<Register used>
A
<RAM used>
Name Usage Attribute Bytes
<Flag used>
Name Usage
<Nesting>
1 level 2 bytes
<Hardware used>
A/D converter
<Initial setting>
ADM = #1000×××1B; Selects A/D converter channel and starts operation
<Starting>
• Call AKEYIN at fixed interval.
• Input a key code after testing the key change flag. Note that this flag is not cleared by the subroutine and
must be cleared after the flag has been tested.
328
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
EXTRN AKEYIN,KEYDAT,PASTDT,CHATCT
EXTRN KEYOFF
EXTBIT KEYCHG,CHTENDF
TMC2=#00100110B
CLR1 TMMK3
CT5MS=#3
329
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
330
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
PUBLIC AKEYIN,KEYDAT,PASTDT
PUBLIC CHATCT,KEYOFF
PUBLIC KEYCHG,CHTENDF
; Key data storage area
AK_DAT DSEG SADDR
; Chattering key data
KEYDAT: DS 1
; Chattering counter
PASTDT: DS 1
CHATCT: DS 1
; Key changed
AK_FLG BSEG
; Chattering absorption end status
KEYCHG DBIT
CHTENDF DBIT
; OFF key data
; Number of times of chattering absorption
KEYOFF EQU 10H
CHAVAL EQU 5
AK_SEG CSEG
;******************************
* Analog key input
;******************************
; Inputs A/D conversion value
AKEYIN:
; Corrects data
A=ADCR
A+=#8
; Sets no key input status
if_bit(CY)
A=#KEYOFF
; Decodes key
else
A>>=1
A>>=1
A>>=1
A>>=1
A&=0FH
; No key change
endif
; Chattering being absorbed
if(A==PASTDT)
; End of chattering absorption
if_bit(!CHTENDF)
CHATCT--
; Sets chattering absorption status
if(CHATCT==#0)
SET1 CHTENDF
; Valid key changed
A=PASTDT
; Updates key data
if(A!=KEYDAT)
; Sets key change status
KEYDAT=A
SET1 KEYCHG
endif
endif
endif
; Updates previous key data
endif
; Starts chattering absorption
PASTDT=A
CHATCT=#CHAVAL-1
CLR1 CHTENDF
endif
RET
331
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
This section describes the method to scan four channels for A/D conversion. The A/D conversion operation is
started by the software.
The analog voltages input to the selected four channels are converted into digital signals. The result of the
A/D conversion of each channel is stored in RAM.
An interrupt request is generated by using 8-bit timer/event counter 1. The result of the conversion is loaded and
channel is converted in the processing of this interrupt request. Because 8-bit timer/event counter 1 is set to 10 ms,
it is not necessary to measure the wait time of the A/D conversion.
• Set timer longer than A/D conversion end time + Interrupt entry
return time + Interrupt processing time.
• Test flags that indicate the end of the conversion.
INTTM2
10 ms
ADCR ANI0 ANI1 ANI2 ANI3 ANI0 ANI1 ANI2 ANI3 ANI0
ADIn 0 1 2 3 0 1 2 3 0 1
332
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
<Register used>
A
<RAM used>
Name Usage Attribute Bytes
M_CH0 Channel 0 conversion result storage area SADDR 1
<Nesting>
1 level 3 bytes
<Hardware used>
• A/D converter
• 8-bit timer/event counter 1
• Port 1 (P10-P13)
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• ADM = #1000××××B ; Selects A/D converter channel and starts operation
• ADIS = #00000100B ; Selects number of A/D converter channels
• TCL1 = #00001110B ; Interval time of 8-bit timer/event counter 1: 10 ms
TMC1 = #00000001B
CR10 = #81
• Enables TMMK1 interrupt
333
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
EXTRN M_CH0,M_CH1,M_CH2,M_CH3,M_MODE
;******************************************
; Initialize
;******************************************
M4 CSEG ;
RES_STA:
SEL RB0 ;
DI ;
.
.
.
.
OSMS=#00000001B ; Does not use divider circuit
ADM=#10000001B ; Starts A/D operation and selects external trigger channel 0
ADIS=#00000100B ; Selects analog input channel 4
CR10=#81 ; Sets modulo register 81
TCL1=#00001110B ; Count clock: 8.2 kHz
TMC1=#00000001B ; Enables 8-bit timer/register 1 operation
CLR1 TMIF1 ; Clears timer 1 interrupt request flag
CLR1 TMMK1 ; Enables timer 1 interrupt
EI ;
M_MODE=#0 ; Sets initial value (0 channel) to mode area
.
.
while(forever) ;
.
.
A=M_CH0 ; A ← data of channel 0
.
.
A=M_CH1 ; A ← data of channel 1
.
.
A=M_CH2 ; A ← data of channel 2
.
.
A=M_CH3 ; A ← data of channel 3
.
.
334
CHAPTER 9 APPLICATIONS OF A/D CONVERTER
;********************************************
; A/D conversion
;********************************************
;
$PC(054) ;
;
PUBLIC M_CH0,M_CH1,M_CH2,M_CH3,M_MODE ;
;
VEINTM1 CSEG AT 24H
DW KASAN
;********************************************
; RAM definition
;********************************************
DSEG SADDR
M_CH0: DS 1 ; Area for channel 0 addition
M_CH1: DS 1 ; Area for channel 1 addition
M_CH2: DS 1 ; Area for channel 2 addition
M_CH3: DS 1 ; Area for channel 3 addition
M_MODE: DS 1 ; Mode storage area
;
CSEG ;
KASAN:
SEL RB2 ; Selects bank 2
switch(M_MODE) ; Channel currently selected?
case 0: ; Channel 0:
M_CH0=ADCR (A) ; Transfers conversion result to RAM
M_MODE++ ;
ADM=#10000011B ; Select channel 1:
break ;
case 1: ; Channel 1:
M_CH1=ADCR (A) ; Transfers conversion result to RAM
M_MODE++ ;
ADM=#10000101B ; Selects channel 2
break ;
case 2: ; Channel 2:
M_CH2=ADCR (A) ; Transfers conversion result to RAM
M_MODE++ ;
ADM=#10000111B ; Selects channel 3
break ;
case 3: ; Channel 3:
M_CH3=ADCR (A) ; Transfers conversion result to RAM
M_MODE=#0 ;
ADM=#10000001B ; Selects channel 0
break ;
ends ;
RETI ;
END
335
[MEMO]
336
CHAPTER 10 APPLICATIONS OF D/A CONVERTER
The D/A converter of the 78K/0 series consists of two voltage output type D/A converter channels with an 8-bit
resolution. This D/A can be used in two modes: normal mode and real-time output mode. In the normal mode, the
output trigger is writing data to the D/A conversion value setting registers 0 and 1 (DACS0 and 1). In the real-time
output mode, the output is triggered by the interrupt requests (INTTM1 and 2) of 8-bit timer/event counters 1 and 2.
In this mode, set data to DACS0 and DACS1 after an output trigger has been generated until the next output trigger
is generated.
The D/A converter is set by the D/A converter mode register.
Cautions 1. To use the D/A converter, set the multiplexed port pins in the input mode and disconnect the
pull-up resistor.
2. Be sure to clear bits 2, 3, 6, and 7 to 0.
3. The output goes into a high-impedance state when D/A conversion operation is stopped.
4. The output trigger in the real-time output mode is INTTM1 for channel 0 and INTTM2 for
channel 1.
337
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
This section introduces an example that outputs a SIN wave with a frequency of 50 Hz by using the real-time output
mode of D/A converter channel 0.
After the output operation has been started, an analog value resulting from the D/A conversion specified by the
D/A conversion value setting register 0 (DACS0) is output, and the next output data is set to DACS0 by interrupt
processing. The value set by the interrupt processing is output at the next timing of 8-bit timer/event counter 1.
Figure 10-2 shows the output data writing timing and analog output timing.
8-bit timer
interrupt request
Writing
D1 D2 D3 D4 D5 D6 D7 D8
output data
Analog
D0 D1 D2 D3 D4 D5 D6 D7
output
The interval time of 8-bit timer/event counter 1 is set to about 668 µs and a 50-Hz D/A output wave is generated
as shown in Figure 10-3.
The SIN wave output data is stored in ROM. Data are sequentially referenced by the interrupt processing of 8-
bit timer/event counter 1 and written to DACS0.
Table 10-1 shows the voltages for SIN wave output and set values.
[V]
5
3
Voltage
0 24 48 72 96 120 144 168 192 216 240 264 288 312 336 360
Degree [degree]
338
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
Remark The analog voltage output to the ANO0 pin is determined by the following expression:
AVREF1 × DACS0
ANO0 pin output voltage =
256
Caution The voltage values shown in Table 10-1 is rounded off at the fifth position after the decimal point.
However, the preset value is calculated with the data before rounding off. The resultant data is
rounded off at the first position after the decimal point.
339
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
The output analog value is processed by the SIN wave conversion circuit shown in Figure 10-4 to create a SIN
wave without step.
ANO0 10 kW 0.012 µ F
Amplifier
1 µF
270 kΩ
SlN wave
<Register used>
Bank 3; AX, HL, B
<RAM used>
Name Usage Attribute Bytes
C_DATA Counter indicating pointer that extracts SIN wave SADDR 1
output data
<Flag used>
None
<Nesting level>
1 level 3 bytes
340
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
<Hardware used>
• D/A converter
• 8-bit timer/event counter 1
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• PM13 = #×××××××1B ; Sets port 13 in input mode
• TCL1 = #××××1001B ; Interval of 8-bit timer/event counter: 668 µs
TMC1 = #000000×0B
CR10 = #174
• DACS0 = #80H ; Sets D/A converter
DAM = #00000001B
• SET1 DAM.4 ; Sets D/A converter in real-time output mode
• SET1 TCE1 ; Enables operation of 8-bit timer/event counter 1 and enables interrupt
CLR1 TMIF1
CLR1 TMMK1
Caution To prevent output of a value on resetting and starting, once set the normal mode and write
the initial value to the D/A conversion value setting register 0 (DACS0), and then output
the initial value. After that, set the real-time output mode, and enable the operation of
8-bit timer/event counter 1 and interrupt.
If D/A conversion is started in the real-time output mode after reset and start with the initial
value set to the DACS0 register, 0 V (data D0 in Figure 10-2. Analog Output and Output
Data Storage Timing) is output.
<Starting>
When starting output, enable the operation of the D/A converter (by setting bit 4 (DAM4) of the D/A converter
mode register(DAM)), the operation of 8-bit timer/event counter 1 (by setting bit 0 (TCE) of the 8-bit timer
mode control register (TMC1)), and interrupts (by clearing TMIF1 and TMMK1).
341
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
EXTRN C_DATA,SDATA,ENDDAT
;
F_RIARU EQU DAM.4 ; Real-time output port setting flag
;
.
.
OSMS=#00000001B ; Does not use divider circuit
TCL1=#00001001B ; SIN_DAT; 8-bit timer 1. Count clock: 262 kHz
CR10=#175-1 ; 8-bit timer 1. Interval: 668 µs
TMC1=#00000000B ; Disables 8-bit timer 1 operation
; ;
HL=#SDATA ;
B=C_DATA (A) ;
DACS0=[HL+B] (A) ;
DAM=#00000001B ; Enables D/A conversion operation of channel 0 in normal mode
PM13=#11111111B ; Sets P130 in input port mode
EI
.
.
.
.
if_bit(SIN wave output data start) ;
SET1 F_RIARU ; Sets channel 0 in real-time output mode
C_DATA=#0 ; Sets initial value to conversion value setting register
HL=#SDATA ;
B=C_DATA (A) ;
DACS0=[HL+B] (A) ;
SET1 TCE1 ; Enables 8-bit timer 1 operation
CLR1 TMIF1 ; Clears 8-bit timer 1 request flag
CLR1 TMMK1 ; Enables 8-bit timer 1 interrupt
SET1 DACE0 ; Enables D/A operation
endif ;
.
.
.
.
342
CHAPTER 10 APPLICATIONS OF A/D CONVERTER
PUBLIC C_DATA,SDATA,ENDDAT
;
VETIM1 CSEG AT 24H
DW INTTM1
343
[MEMO]
344
CHAPTER 11 APPLICATION OF REAL-TIME OUTPUT PORT
This chapter describes the real-time output function of the 78K/0 series.
The real-time output function is used to output data set in advance in the real-time output buffer registers (RTBL
and RTBH) to an external device by transferring the data to an output latch by hardware as soon as a timer interrupt
request or external interrupt request occurs.
By using the real-time output port function, a jitter free signal can be output. Therefore, this function is ideal for
controlling a stepping motor. The real-time output port can be set in the port mode or real-time output mode in 1-
bit units.
The real-time output data is written to the real-time output buffer registers (RTBL and RTBH). RTBL and RTBH
are mapped to independent addresses in the SFR area.
When an operation mode of 4 bits × 2 channels is selected, RTBL and RTBH can independently set data.
When an operation mode of 8 bits × 1 channel is specified, data can be set to RTBL or RTBH by writing 8-bit data
to either of RTBL or RTBH.
The real-time output port is set by using the real-time output port mode register (RTPM), real-time output control
register (RTPC), and port mode register 12 (PM12).
345
CHAPTER 11 APPLICATION OF REAL-TIME OUTPUT PORT
RTPM RTPM7 RTPM6 RTPM5 RTPM4 RTPM3 RTPM2 RTPM1 RTPM0 FF34H 00H R/W
Cautions 1. When the real-time output port mode is used, the port that performs real-time output must
be set in the output mode (by clearing the corresponding bits of the port mode register 12
(PM12) to 0).
2. Data cannot be set to the output latch of the port set in the real-time output port mode. To
set an initial value, therefore, set data to the output latch before setting the real-time output
port mode.
The relationship between operation mode and output trigger of the real-time output port is shown in Table 11-1.
Table 11-1. Operation Mode and Output Trigger of Real-Time Output Port
BYTE EXTR Output Mode RTBH → Port Output RTBL → Port Output
0 0 4 bits × 2 channels INTTM2 INTTM1
1 INTTM1 INTP2
1 0 8 bits × 1 channel INTTM1
1 INTP2
346
CHAPTER 11 APPLICATIONS OF REAL-TIME OUTPUT PORT
PM12 PM127 PM126 PM125 PM124 PM123 PM122 PM121 PM120 FF2CH FFH R/W
347
CHAPTER 11 APPLICATION OF REAL-TIME OUTPUT PORT
A 4-phase stepping motor is connected to the real-time output port (P120 through P123) and is controlled with
1-phase excitation pattern. A motor that rotates 1.8 degree per step is used for 1-phase excitation and is driven 200
revolutions per minute.
The time required for 1 step is calculated by the following expression:
60 seconds
1 step = = 1.5 ms
360 degrees
200 revolutions × Step
1.8 degree
The compare register (CR01) of 8-bit timer/event counter 1 is set to 1.5 ms and the real-time output buffer register
(RTBL) is set.
By using the real-time output port control register (RTPC), set the 4 bit × 2 channel real-time output mode, and
the coincidence interrupt (INTTM1) of the 8-bit timer/event counter 1 as the output trigger (refer to Table 11-1).
Figure 11-4 shows the phase excitation output pattern and output timing.
1.5 ms
P120
0 0 0 1
P121
0 0 1 0
0 1 0 0
P122
1 0 0 0
P123
348
CHAPTER 11 APPLICATIONS OF REAL-TIME OUTPUT PORT
<Register used>
Bank 3, A
<RAM used>
None
<Flag used>
None
<Nesting level>
1 level 3 bytes
<Hardware used>
• Real-time output port
• 8-bit timer/event counter 1
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register: does not use divider circuit
• P12 = #××××0000B ; Sets P120-P123 in output port mode
PM12 = #××××0000B
• TCL1 = #××××1010B ; Timer clock select register 1 (count clock: 131 kHz)
• CR10 = #195 ; Compare register (set to 1.5 ms)
• TMC1 = #000000×1B ; 8-bit timer mode control register 1 (enables operation of 8-bit timer/event counter
1)
• RTPM = ××××1111B ; Real-time output port mode register (lower 4 bits are used as real-time output
port)
• RTPC = #00000000B ; Real-time output port control register (selects 4 bit × 2 channel mode and
INTTM1 as output trigger)
• RTBL = #00000001B ; Initial setting of real-time output buffer register
• CLR1 TMIF1 ; Clears 8-bit timer/event counter 1 interrupt request flag
• CLR1 TMMK1 ; Enables 8-bit timer/event counter 1
<Starting>
Clear the interrupt request flag of 8-bit timer/event counter 1 and enable the interrupt when the operation
is started.
349
CHAPTER 11 APPLICATION OF REAL-TIME OUTPUT PORT
RTBL ← A
350
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
The LCD controller/driver of the µPD78064, 78064Y, 780308, 780308Y, and 78064B subseries is set by using the
LCD display mode register (LCDM) and LCD display control register (LCDC).
351
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
LCDM LCDON LCDM6 LCDM5 LCDM4 0 LCDM2 LCDM1 LCDM0 FFB0H 00H R/W
0 1 0 2 1/2
0 1 1 3 1/2
1 0 0 Static
1 Display on
Note The LCD clock is supplied by the watch timer. To perform LCD display, set the bit 1 (TMC21) of watch
timer mode control register (TMC2) to 1.
If TMC21 is reset to 0 during LCD display, supply of the LCD clock is stopped and the display is disturbed.
352
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
LCDM LCDON LCDM6 LCDM5 LCDM4 LCDM3 LCDM2 LCDM1 LCDM0 FFB0H 00H R/W
0 0 1 3 1/3
0 1 0 2 1/2
0 1 1 3 1/2
1 0 0 Static
Others Setting prohibited
1 Display on
Notes 1. To lower the power consumption, clear LCDM3 to 0 when LCD display is not used. To manipulate
LCDM3, be sure to turn off the LCD display.
If TMC21 is cleared to 0 during LCD display, the supply of the LCD clock is stopped and the display
is disturbed.
2. The LCD clock is supplied by the watch timer. To perform LCD display, set the bit 1 (TMC21) of watch
timer mode control register (TMC2) to 1.
If TMC21 is reset to 0 during LCD display, supply of the LCD clock is stopped and the display is disturbed.
353
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
LCDC LCDC7 LCDC6 LCDC5 LCDC4 0 0 LEPS LIPS FFB2H 00H R/W
Cautions 1. Pins that output segments cannot be used as output port pins even if 0 is set to the
corresponding port mode register.
2. When pins that output segments are read as port pins, 0 is returned.
3. Pins set by LCDC to output segments are not used with the internal pull-up resistor,
regardless of the values of the bits 0 and 1 (PUO8 and PUO9) of the pull-up resistor option
register H (PUOH).
354
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
The LCD controller/driver of the µPD78064, 78064Y, 780308, and 780308Y subseries is described next.
<1> Automatically outputs segment and common signals by automatically reading the display data memory.
<2> Five types of display modes are available:
• Static mode
• 1/2 duty mode (1/2 bias)
• 1/3 duty mode (1/2 bias)
• 1/3 duty mode (1/3 bias)
• 1/4 duty mode (1/3 bias)
<3> Four types of frame frequencies can be selected in each display mode.
<4> Up to 40 segment signal outputs (S0 through S39) and four common signal outputs (COM0 through
COM3) are available. Sixteen segment outputs can be set in the input/output port mode in 2-bit units
(P80/S39 through P87/S32, and P90/S31 through P97/S24).
<5> Divider resistors for generating the LCD drive voltage can be provided to the mask ROM model by mask
option.
<6> Can operate on the subsystem clock.
Table 12-1 shows the maximum number of pixels that can be displayed in each display mode.
Notes 1. Can display 5 digits with eight segments for each digit on an 8-segment LCD panel.
2. Can display 10 digits with four segments for each digit on an 8-segment LCD panel.
3. Can display 13 digits with three segments for each digit on an 8-segment LCD panel.
4. Can display 20 digits with two segments for each digit on an 8-segment LCD panel.
355
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
<1> Enables the watch operation by using the timer clock select register 2 (TCL2) and watch timer mode
control register (TMC2).
<2> Set the initial value to the display data memory (FA58H through FA7FH).
<3> Specify the pins used for segment output by using the LCD display control register (LCDC).
<4> Set the display mode and LCD clock by using the LCD display mode register.
After that, set data to the display data memory according to the contents to be displayed.
Figure 12-4. Relations between Contents of LCD Display Data Memory and Segment/Common Output
FA7EH S1
FA7DH S2
FA7CH S3
FA5AH S37/P82
FA59H S38/P81
FA58H S39/P80
Caution The high-order 4 bits of the LCD display data memory are not used as memory bits. Be sure to
clear these bits to 0.
356
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
COM Signal
COM0 COM1 COM2 COM3
Number of Time
Divisions
Static
4 time divisions
357
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
VLC0
COMn
(static) VLCD
VSS
TF = T
VLC0
COMn VLC2 VLCD
(2-time division)
VSS
TF = 2T
VLC0
COMn VLC2 VLCD
(3-time division)
VSS
TF = 3T
VLC0
COMn VLC1
(3-time division) VLC2 VLCD
VSS
TF = 3T
VLC0
COMn VLC1
(4-time division) VLC2 VLCD
VSS
TF = 4T
358
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
Figure 12-6. Phase Difference in Voltage between Command Signal and Segment Signal
Select Unselect
VLC0
Common signal VLCD
VSS
VLC0
Segment signal VLCD
VSS
T T
Select Unselect
VLC0
VLCD
Common signal VLC2
VSS
VLC0
Select Unselect
VLC0
VLC1
Common signal VLC2 VLCD
VSS
VLC0
VLC1
VLC2 VLCD
Segment signal VSS
T T
359
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
This section explains an example using the µPD78064 subseries. A 4-digit static LCD is driven by using the 32
segment signals (S0 through S31) and a common signal (COM0). Figure 12-7 shows the display pattern and electrode
wiring of the static LCD. Figure 12-8 shows the connections among the segment signals and common signal. Figure
12-9 shows an example of connecting an LCD driving power supply in the static display mode (with an external divider
resistor, VDD = 5 V, and VLCD = 5 V). The display example in Figure 12-8 is “1234”, and the contents of the display
data memory (addresses FA60H through FA7FH) correspond to this.
In this section, how to display the second digit, “3”, is described. According to the display pattern in Figure 12-
8, the select and unselect voltages must be output to the S8 through S15 pins in the timing of the common signal
COM0, as shown in Table 12-3.
Segment
S8 S9 S10 S11 S12 S13 S14 S15
Common
COM0 Unselect Select Select Select Unselect Select Unselect Select
From Table 12-3, it is clear that 10101110 must be set to bit 0 of the display data memory (addresses FA70H through
FA77H) corresponding to S8 through S15.
Figure 12-10 shows the LCD driving waveforms of S11, S12, and COM0.
Because the same waveform as COM0 is output to COM1, 2, and 3, the driving capability can be increased by
connecting COM0, 1, 2, and 3.
S8n + 3
S8n + 4 S8n + 2
COM0
S8n + 5
S8n + 6 S8n + 1
S8n
S8n + 7
Remark n = 0-3
360
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
FA6FH
FA7FH
C
D
C
D
A
B
A
B
E
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
TIMING STROBE
0 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 BIT0
× × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × BIT1
× × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × BIT2
× × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × × BIT3
S31
S30
S29
S28
S27
S26
S25
S24
S23
S22
S21
S20
S19
S18
S17
S16
S15
S14
S13
S12
S11
S10
S9
S8
S7
S6
S5
S4
S3
S2
S1
S0
COM0
COM1
COM2
COM3
LCD PANEL
Figure 12-9. Example of Connecting LCD Driving Power in Static Display Mode
(with external divider resistor, VDD = 5 V, and VLCD = 5 V)
VDD
LIPS
BIAS pin
LEPS
(= 0)
VLC0
VLC1
VLCD
VLC2
VSS
VLCD = VDD
361
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
TF
VLC0
COM0 Common signal
VSS
VLC0
S11 Segment signal
VSS
VLC0
S12 Segment signal
VSS
+ VLCD
– VLCD
+ VLCD
– VLCD
To display the LCD, segment signals are output based on the waveform of the common signal.
The static LCD is lit by a segment signal (S11) output at a frame frequency half a cycle shifted from that of the
common signal (COM0) as shown in Figure 12-10. This means that a potential difference is generated between the
common signal and segment signal, and this potential difference is responsible for lighting the LCD. As can be seen
from COM0 and S11 in Figure 12-10, a potential difference ±VLCD (LCD drive voltage) is generated between these
signals.
To extinguish the LCD, the segment signal (S12) is output in a waveform synchronous to that of the common signal
(COM0). In this way, the potential difference between COM0 and S12 is eliminated and the LCD remains dark.
362
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
<Register used>
Bank 0 : AX, DE, HL
<RAM used>
Name Usage Attribute Bytes
B_LCD LCD display data storage buffer area SADDR 1
i Display digit loop counter SADDR 1
<Flag used>
None
<Nesting level>
1 level 2 bytes
<Hardware used>
• LCD controller/driver
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register
• TCL2 = #×××00×××B ; Count clock of watch timer = selects system clock
• TMC2 = #0×××××1×B ; Supplies LCD clock (enables prescaler operation)
• LCDC = #01000010B ; LCD display control register (supplies LCD drive power from BIAS pin with
segment pins S24 through S31 used)
• LCDM = #10100100B ; LCD display mode register (sets static display, selects LCD clock, and turns on
display)
Caution Set the initial value to the LCD display data memory (FA58H through FA7FH) before
turning on the LCD display.
<Starting>
Set the display contents in the B_LCD area and call the S_LCD routine.
363
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
EXTRN SLCD,B_LCD,S0
.
.
.
HL=#S0 ; Clears LCDRAM
BC=#0FA80H-0FA58H ; (from FA58H to FA7FH)
while(BC!=#0) (AX) ;
A=#0 ;
[HL]=A ;
HL-- ;
BC-- ;
endw ;
;
B_LCD=#0 ;
B_LCD+1=#0 ;
B_LCD+2=#0 ;
B_LCD+3=#0 ;
;
TCL2=#00000000B ; Count clock of watch timer = selects main system clock
TMC2=#00000010B ; Enables operation of prescaler
LCDC=#01000010B ; Supplies LCD drive power from BIAS pin with segments S24 through 31 used
LCDM=#10100100B ; Turns ON static display with 256-Hz clock selected
;
.
.
B_LCD+3=A ;
.
.
B_LCD+2=A ;
.
.
B_LCD+1=A ;
.
.
B_LCD=A ;
CALL !S_LCD ;
.
.
364
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
PUBLIC S_LCD,B_LCD,S0
;
S0 EQU 0FA7FH ; 1st digit of LCD
;
LCDRAM1 DSEG SADDR
B_LCD: DS 4 ; Display BUF area
i: DS 1 ; Work counter
j: DS 1 ; Work counter
LCDRAM2 DSEG SADDRP
WORKP: DS 2 ; Work area
;******************************************************
; LCD display (static display) processing
;******************************************************
LSDS CSEG
S_LCD:
HL=#S0 ; HL ← address S0
WORKP=#B_LCD-1 ; Work area ← address of B_LCD - 1
for(i=#0;i<#4;i++) ;
DE=WORKP (AX) ;
DE++ ; References display data of contents of next digit
WORKP=DE (AX) ;
X=[DE] (A) ;
A=#0 ;
AX+=#LCDDAT ;
DE=AX ;
A=[DE] ;
for(j=#0;j<#8;j++) ;
RORC A,1 ; Stores display data to bit 0 from address S0
[HL].0=CY ;
HL-- ;
next ;
next ;
RET ;
LCDDAT:
DB 11011110B ; 0
DB 00000110B ; 1
DB 11101100B ; 2
DB 10101110B ; 3
DB 00110110B ; 4
DB 10111010B ; 5
DB 11111010B ; 6
DB 00011110B ; 7
DB 11111110B ; 8
DB 10111110B ; 9
DB 01111110B ; A
DB 11110010B ; B
DB 11011000B ; C
DB 11100110B ; D
DB 11111000B ; E
DB 01111000B ; F
DB 00000000B ; Extinguishes
END
365
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
This section explains an example using the µPD78064 subseries. Four LCD digits are driven by means of 1/3
bias and 4-time division by using the 16 segment signals (S0 through S15) and four common signals (COM0 through
COM3). Figure 12-12 shows the connection of a 4-time division 4-digit LCD panel with 10 display patterns shown
in Figure 12-11 and the segment (S0 through S15) and common (COM0 through COM4) signals of the µPD78064
subseries. Figure 12-13 shows an example of connecting an LCD drive power supply in the 4-time division display
mode (with external divider resistor, VDD = 5 V, and VLCD = 5 V). The display example in Figure 12-12 is “12345678”,
and the contents of the display data memory (addresses FA70H through FA7FH) correspond to this.
In this case, “6” at the third digit has been taken as an example. According to the display pattern in Figure 12-
12, the select and unselect voltages shown in Table 12-4 must be output to the S4 and S5 pins in the timing of the
common signals COM0 through COM3.
Remark (a) through (h) in the table corresponds to the segments a through h in Figure 12-12.
Table 12-4 indicates that 0101 should be stored to the display data memory address (FA7BH) corresponding to
S4.
Figure 12-14 shows the LCD drive waveforms between S4 and COM0 and COM1 signals.
Figure 12-11. Display Pattern of 4-Time Division LCD and Electrode Wiring
COM2
COM3
S2n + 1
Remark n = 0-7
366
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
FA7FH
TIMING STROBE
D
A
E
0
9
0 0 0 1 0 1 1 0 1 1 1 1 1 1 1 1 BIT0
0 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 BIT1
BIT2
0 1 1 0 0 1 0 1 0 1 1 1 0 1 1 1
BIT3
0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0
S15
S14
S13
S12
S11
S10
S9
S8
S7
S6
S5
S4
S3
S2
S1
S0
COM0
COM1
COM2
COM3
a
b
e f
c
g
h d
LCD PANEL
Figure 12-13. Example of Connecting LCD Drive Power in 4-Time Division Mode
(with external divider resistor, VDD = 5 V, VLCD = 5 V)
VDD
LIPS
BIAS pin
LEPS
(= 0)
VLC0
R
VLC1
VLCD R
VLC2
VSS
VLCD = VDD
367
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
TF
VLC0
VLC1
COM0
VLC2
VSS
VLC0
VLC1
COM1
VLC2
VSS
VLC0
VLC1
COM2
VLC2
VSS
VLC0
VLC1
COM3
VLC2
VSS
VLC0
VLC1
S4
VLC2
VSS
Select Unselect Select Unselect
+ VLC0
+ 1/3VLCD
COM0–S4 0
– 1/3VLCD
– VLCD
+ VLC0
+ 1/3VLCD
COM1–S4 0
– 1/3VLCD
+ VLCD
368
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
For 4-time division LCD display, the valid timing (enclosed in dotted line in Figure 12-14) of each common signal
is output in a cycle 1/4 of the frame frequency (TF) as shown in Figure 12-14. In this timing,each segment signal is
output to light or extinguish the LCD.
For example, segment signal S4 outputs a waveform that lights the LCD in the timing of COM0 and COM2, in respect
to each common signal (COM0 through COM3) in Figure 12-14.
When the relations between each common signal and S4 is examined, it can be seen that a potential difference
of ±VLCD (LCD drive voltage) is generated at the COM0 select timing between COM0 and S4, as can be seen from
the waveform of COM0-S4. In the case of COM2 and S4, a voltage difference of ±VLCD (LCD drive voltage) is also
generated between COM2 and S4 at the COM2 select timing. Therefore, the segment indicated by COM0, COM2
and S4 lights.
Because a voltage difference between COM1 and S4 is always ±1/3 VLCD (COM1-S4 in Figure 12-14) at the select
timing of COM1 (COM1 in Figure 12-14), the LCD remains dark.
369
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
<Register used>
Bank 0; AX, DE, HL
<RAM used>
Name Usage Attribute Bytes
B_LCD LCD display data storage buffer area SADDR 1
<Flag used>
None
<Nesting level>
1 level 2 bytes
<Hardware used>
• LCD controller/driver
<Initial setting>
• OSMS = #00000001B ; Oscillation mode select register
• TCL2 = #×××00×××B ; Count clock of watch timer = selects system clock
• TMC2 = #0×××××1×B ; Supplies LCD clock (enables operation of prescaler)
• LCDC = #00000001B ; LCD display control register (LCD driving power is supplied from VDD with
segment signal pins S24 through S31 not used)
• LCDM = #10100000B ; LCD display mode register (sets 4-time division display, selects LCD clock, turns
ON display)
Caution Set the initial value to the LCD display data memory (FA58H through FA7FH) before
turning ON the LCD.
<Starting>
Set the display contents to the B_LCD area and call the S_4LCD routine.
370
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
EXTRN S_4LCD,B_LCD,S0
.
.
.
HL=#S0 ; Clears LCDRAM
BC=#0FA80H-0FA58H ; (from FA58H to FA7FH)
while(BC!=#0) (AX) ;
A=#0 ;
[HL]=A ;
HL-- ;
BC-- ;
endw ;
;
B_LCD=#0 ;
B_LCD+1=#0 ;
B_LCD+2=#0 ;
B_LCD+3=#0 ;
;
TCL2=#00000000B ; Count clock of watch timer = selects main system clock
TMC2=#00000010B ; Enables prescaler operation
LCDC=#00000001B ; Supplies driving power from VDD with segments S24 through S31 not used
LCDM=#10100000B ; Turns on 4-time division display with 256-Hz clock selected, turns ON display
;
.
.
B_LCD+3=A ;
.
.
B_LCD+2=A ;
.
.
B_LCD+1=A ;
.
.
B_LCD=A ;
CALL !S_4LCD ;
.
.
371
CHAPTER 12 APPLICATIONS OF LCD CONTROLLER/DRIVER
PUBLIC S_4LCD,B_LCD,S0
372
CHAPTER 13 APPLICATIONS OF KEY INPUT
This chapter introduces an example of a program that inputs signals from a key matrix of 4 × 8 keys. The key
scan be pressed successively, and two or more keys can be pressed simultaneously. In the circuit shown in this
section, the high-order 4 bits of port 3 (P34 through P37) are used as key scan signals, and port 4Note is used as
key return signals. As the pull-up resistor of port 4 for key return, the internal pull-up resistor set by software is used
(refer to Figure 13-1).
Port 4 of the 78K/0 series has a function to detect the falling edges of the eight port pins in parallel. If port 4 is
used for key return signals, therefore, the standby mode can be released through detection of a falling edge, i.e.,
by key input.
In this example, the µPD78054 subseries is used.
Note With the µPD78064, 78064Y, 780308, 780308Y, and 78064B subseries, port 11 is used instead of port 4.
µ PD78054
P34
P35
P36
P37
P40
P41
Pull-up P42
resistors P43
connected P44
P45
P46
P47 =
The input keys are stored to RAM on a one key-to-1 bit basis. The RAM bit corresponding to a pressed key is
set and the bit corresponding to a released key is cleared. By testing the RAM data on a 1-bit-by-1-bit basis starting
from the first bit, the key status can be checked. To absorb chattering, the key is assumed to be valid when four
successive key codes coincide with a given code. For example, if a key code is sampled every 5 ms, chattering of
15 ms to 20 ms can be absorbed. If the key input is changed, a key change flag (KEYCHG) is set.
373
CHAPTER 13 APPLICATIONS OF KEY INPUT
<Register used>
AX, DE, HL
<RAM used>
Name Usage Attribute Bytes
KEYDATA Stores valid key data SADDR 4
WORK Stores key data during chattering
<Flag used>
Name Usage
CHGFG Set if key input changes
<Nesting>
1 level 2 bytes
<Hardware used>
• P4
• P3 (P34-P37)
<Initial setting>
• PUO4 = 1 ; Connects pull-up resistor to P4
• PM3 = #0000××××B ; Sets high-order 4 bits of P3 in output mode
<Starting>
• Call KEYIN at specific intervals.
• Before inputting the key data, test the key change flag. The key change flag is not cleared by the subroutine.
Clear the flag after it has been tested.
374
CHAPTER 13 APPLICATIONS OF KEY INPUT
EXTRN KEYDATA,CHATCT,KEYIN
EXTBIT KEYCHG
375
CHAPTER 13 APPLICATIONS OF KEY INPUT
376
CHAPTER 13 APPLICATIONS OF KEY INPUT
PUBLIC KEYDATA,KEYCHG,KEYIN,CHATCT
KEY_FLG BSEG
CHGFG DBIT ; Key change status
KEYCHG DBIT ; Key changed
CHTEND DBIT ; Chattering absorption end status
KEY_SEG CSEG
;*******************************
* Matrix key input
;*******************************
KEYIN:
CLR1 CHGFG
P3&=#00001111B
P3|=#00010000B
HL=#WORK ; Sets address of key work area
repeat
A=P4
A^=#11111111B ; Data inverted
if(A!=[HL]) ; Key changed?
SET1 CHGFG
[HL]=A
endif
HL++
A=P3 ; Shifts key scan 1 bit
A&=#11110000B
X=A
A=P3
A+=X
P3=A
until_bit(CY)
377
[MEMO]
378
APPENDIX A DESCRIPTION OF SPD CHART
Table A-1. Comparison between SPD Symbols and Flowchart Symbol (1/2)
Processing Name SPD Symbol Flowchart Symbol
Sequential processing
Processing 1
Processing 1
Processing 2
Processing 2
Conditional branch
(IF)
(IF: condition) ELSE
Condition
[THEN]
Processing 1 THEN
[ELSE] Processing 1 Processing 2
Processing 2
Conditional branch
(SWITCH)
(SWITCH: condition)
[CASE: 1]
Processing 1 Condition
[CASE: 2]
Processing 2
..
. Processing 1 Processing 2 Processing n
[CASE: n]
Processing n
379
APPENDIX A DESCRIPTION OF SPD CHART
Table A-1. Comparison between SPD Symbols and Flowchart Symbol (2/2)
Processing
Conditional loop
(UNTIL)
THEN
Conditional loop
(FOR)
Initial value
Increment/
decrement
Infinite loop
(WHILE: forever)
Processing Processing
Connector
(IF: condition)
[THEN] ELSE
Condition A
GOTO A
THEN
A
Processing
A
Processing
380
APPENDIX A DESCRIPTION OF SPD CHART
1. Sequential processing
Sequential processing executes processing from top to bottom in the sequence in which processing appears.
• SPD chart
Processing 1
Processing 2
• SPD chart
(IF: condition)
[THEN]
Processing 1
[ELSE]
Processing 2
(IF: X > 0)
[THEN]
X is positive number
[ELSE]
X is 0 or negative number
381
APPENDIX A DESCRIPTION OF SPD CHART
• SPD chart
(execution)
(SWITCH: condition)
[CASE: status 1]
Processing 1 When status 1: processing 1
break
[CASE: status 2]
Processing 2 When status 2: processing 2
break .. ..
.. ..
. . .. ..
. .
[CASE: status n]
Processing n When status n: processing n
[default]
Processing 0 If status does not coincide: processing 0
382
APPENDIX A DESCRIPTION OF SPD CHART
• SPD chart
(execution)
(SWITCH: condition)
[CASE: Status 1]
Processing 1 When status 1: processing 1 → processing 2 → ... → processing n
[CASE: Status 2]
Processing 2 When status 2: processing 2 → ... → processing n
. .
. . .. ..
. .
. .
[CASE: Status n] . .
. .
Processing n When status n: processing n
[default]
Processing 0 If status does not coincide: processing 0
(execution)
(SWITCH: transfer mode)
[CASE: 1]
Address transmission When status 1: address transmission → data transmission
[CASE: 2]
Data transmission When status 2: data transmission
break
[CASE: 3]
Data reception When status 3: data reception
• SPD chart
(WHILE: condition)
Processing
383
APPENDIX A DESCRIPTION OF SPD CHART
• SPD chart
(UNTIL: condition)
Processing
Initializes A register
Sets value to B register
Stores 10 to counter
(UNTIL: counter = 0)
A=A+B
Decrements counter
• SPD chart
384
APPENDIX A DESCRIPTION OF SPD CHART
7. Infinite Loop
If ‘forever’ is set as the condition of WHILE, processing is infinitely executed.
• SPD chart
(WHILE: forever)
Processing
(WHILE: forever)
Decodes key
Main processing
Stores key code to display area
8. Connector (GOTO)
Unconditionally branches to a specified address.
• SPD chart
(IF: condition)
[THEN]
GOTO ERR
..
.
ERR
Processing
385
APPENDIX A DESCRIPTION OF SPD CHART
(IF: condition)
[THEN]
GOTO ERR
(SUB_ER) ; Module name
SUB_ER Processing
..
.
ERR
Processing
Example To select a parameter at the start address of a subroutine and set wait state
WAIT
(UNTIL: A = 0)
Decrements A
9. Connector (continuation)
Used when the SPD of one module requires two or more pages to indicate the flow of processing.
• SPD chart
Processing 1
1
Processing 2
Processing 3
1
Processing 4
386
APPENDIX B REVISION HISTORY
The revision history of this document is as follows. “Chapter” indicates the chapter number in the preceding edition.
(1/2)
Edition Major Revision from Preceding Edition Chapter
387
APPENDIX B REVISION HISTORY
(2/2)
Edition Major Revision from Preceding Edition Chapter
2nd edition Description of following register formats and tables for each CHAPTER 8 APPLICATION OF
subseries: SERIAL INTERFACE
Figures 8-14 and 8-15 Format of Automatic Data Transfer/
Reception Control Register
Tables 8-4, 8-5, and 8-6 Setting of Operating Modes of Serial
Interface Channel 2
Figures 12-1 and 12-2 Format of LCD Display Mode Register
388
Facsimile Message 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
From:
errors may occur. Despite all the care and
precautions we've taken, you may
Name encounter problems in the documentation.
Please complete this form whenever
Company you'd like to report errors or suggest
improvements to us.
Tel. FAX
Address
North America Hong Kong, Philippines, Oceania Asian Nations except Philippines
NEC Electronics Inc. NEC Electronics Hong Kong Ltd. NEC Electronics Singapore Pte. Ltd.
Corporate Communications Dept. Fax: +852-2886-9022/9044 Fax: +65-250-3583
Fax: 1-800-729-9288
1-408-588-6130
Korea Japan
Europe
NEC Electronics Hong Kong Ltd. NEC Corporation
NEC Electronics (Europe) GmbH
Seoul Branch Semiconductor Solution Engineering Division
Technical Documentation Dept.
Fax: 02-528-4411 Technical Information Support Dept.
Fax: +49-211-6503-274
Fax: 044-548-7900
South America Taiwan
NEC do Brasil S.A. NEC Electronics Taiwan Ltd.
Fax: +55-11-889-1689 Fax: 02-719-5951
Document title: