Request for your special attention and precautions in using the technical information and
semiconductors described in this book
(1) If any of the products or technical information described in this book is to be exported or provided to non-residents, the
laws and regulations of the exporting country, especially, those with regard to security export control, must be observ ed.
(2) The technical information described in this book is intended only to show the main characteristics and application circuit
examples of the products, and no license is granted under any intellectual property right or other right owned by our
company or any other company. Therefore, no responsibility is assumed by our company as to the infringement upon any
such right owned by any other company which may arise as a result of the use of technical information described in this
book.
(3) The products described in this book are intended to be used for standard applications or general electronic equipment
(such as office equipment, communications equipment, measuring ins truments and household appliances).
Consult our sales staff in advance for information on the following applications:
x Special applications (such as for airplanes, aerospace, automobiles, traffic control equipment, combustion equipment,
life support systems and safety devices) in which exceptional quality and reliability are required, or if the failure or
malfunction of the products may directly jeopardize life or harm the human body.
x Any applications other than the standard applications intended.
(4) The products and product specifications described in this book are subject to change without notice for modification and/
or improvement. At the final stage of your de sign, pur chasing, o r use of the p roducts, therefore , ask for the mo st up-todate Product Standards in advance to make sure that the latest specifications satisfy your requirements.
(5) When designing your equipment, comply with the range of absolute maximum rating and the guaranteed operating condi-
tions (operating power supply voltage and operating environment etc.). Especially, please be careful not to exceed the
range of absolute maximum rating on the transient state, such as power-on, power-off and mode-switching. Otherwise,
we will not be liable for any defect which may arise later in your equipment.
Even when the products are used within the guaranteed values, take into the consideration of incidence of break down
and failure mode, possible to occur to semiconductor products. Measures on the systems such as redundant design,
arresting the spread of fire or preventing glitch are recommended in order to prevent physical injury, fire, social damages, for example, by using the products.
(6) Comply with the instructions for use in order to prevent breakdown and characteristics change due to external factors
(ESD, EOS, thermal stress and mechanical stress) at the time of handling, mounting or at customer's process. When
using products for which damp-proof packing is required, satisfy the conditions, such as shelf life and the elapsed time
since first opening the packages.
(7) This book may be not reprinted or reproduced whether wholly or partially, without the prior written permission of Mat-
sushita Electric Industrial Co., Ltd.
PanaXSeries is a trademark of Matsushita Electric Industrial Co., Ltd.
The other corporation names, logotype and product names written in this book are trademarks or registered trademarks
of their corresponding corporations.
Page 3
About This Manual
■ Configuration of This Manual
This LSI application note is consists of the following sections.
Chapter 1 Overview
This chapter describes the overview of this application note.
Chapter 2 Startup Program
This chapter describes a startup process necessary for executing a program.
Chapter 3 Register Setup of Each Function
This chapter describes the setting method and setting examples of registers having
MN101C49LSI function.
Chapter 4 Sample Program 1
This chapter describes sample programs for using each peripheral device referring to sample
circuits.
Chapter 5 Sample Program 2
This chapter provides an explanation of a startup process necessary before executing a sample
program in "5.1 Startup", and an explanation of sample programs utilizing basic functions of
this LSI in "5.2 Sample Program Using Timer Function" and "5.3 Sample Program Using
Serial Function". Each sample program is described following the sections below.
(1) Program operation and display
(2) Function used
(3) State transition diagram
(4) Software
Chapter 6 Appendix 1
This chapter provides a circuit diagram operated in "Chapter 3 Register Setup of Each
Function" and "Chapter 4 Sample Program 1" and supplementary explanations.
Chapter 7 Appendix 2
This chapter describes a sample program file organization and directory block diagram of
"Chapter 5 Sampler Program 2", and Makefile.
Page 4
■ Related Manuals
Note that the following related documents are available.
"MN101C49G/49H/49K/F49K/P49K LSI User's Manual"
"MN101C Series C Compiler User's Manual: Language Description"
<Describes the syntax of the C Compiler.>
"MN101C Series C Compiler User's Manual: Library Reference"
<Describes the standard library of the C Compiler.>
"MN101C/MN101E Series C Compiler User's Manual: Usage Guide"
<Describes the installation, the commands, and options of the C Compiler.>
"MN101C/MN101E Series Cross-assembler User's Manual"
1.3 Register Setup of Each Function.......................................................................................................................14
1.4 Sample Program 1.............................................................................................................................................14
1.5 Sample Program 2.............................................................................................................................................14
2.2.1. Memory area (Section) ......................................................................................................................... 18
2.2.2 Declaration for section............................................................................................................................... 19
2.2.4 Clear area to be used to 0 ...........................................................................................................................19
2.2.5 Initializing static variables with initial values............................................................................................19
Chapter 3
Register Setup of Each Function
3.1 Description of C and Assembly Languages....................................................................................................... 22
3.2.1 Memory control register.............................................................................................................................24
3.2.2 Expansion address control register.............................................................................................................25
3.2.3 Oscillation frequency register....................................................................................................................26
3.2.4 CPU mode control register.........................................................................................................................27
3.3.1 Address bank register.................................................................................................................................30
3.3.2 ROM correction register............................................................................................................................ 31
3.4 Operation State Transition, Initializing Peripherals........................................................................................... 34
3.5.1 Interrupt control register............................................................................................... ............................. 36
3.5.2 Noise filter control register........................................................................................................................ 42
3.5.3 Both edges interrupt control register.......................................................................................................... 43
3.5.4 Key interrupt control register..................................................................................................................... 44
Page 7
3.6 How to Interrupt................................................................................................................................................ 45
3.7.1 Port 0..........................................................................................................................................................49
3.7.2 Port 1..........................................................................................................................................................50
3.7.3 Port 2..........................................................................................................................................................51
3.7.4 Port 3..........................................................................................................................................................51
3.7.5 Port 4..........................................................................................................................................................52
3.7.6 Port 5..........................................................................................................................................................53
3.7.7 Port 6..........................................................................................................................................................54
3.7.8 Port 7..........................................................................................................................................................55
3.7.9 Port 8..........................................................................................................................................................56
3.7.10 Port A....................................................................................................................................................... 56
3.7.11 Port C.......................................................................................................................................................57
3.7.12 Port D....................................................................................................................................................... 58
3.8.1 Prescaler control register............................................................................................................................59
3.9.1 Types of setting for 8-bit timer .................................................................................................................. 64
3.9.2 Setting for cascade connection...................................................................................................................70
3.9.3 Setting remote control carrier output operation..........................................................................................72
3.10.1 Types of setting for 16-bit timer..............................................................................................................76
3.11 Initializing Free Run Time Base Timer, Initializing Peripherals.....................................................................82
3.11.1 Time base timer .......................................................................................................................................82
3.11.2 Free run timer...........................................................................................................................................83
3.14.3 Handling on communication errors........................................................................................................ 105
...............................................98
Page 8
3.14.4 Setting communication speed for UART...............................................................................................106
3.14.5 Notes and applications related to communication channel.....................................................................106
3.15 Data Transfer Function, Initializing Peripherals............................................................................................108
3.15.1 Setting in individual modes....................................................................................................................110
Chapter 4 Sample Program 1.....................................................................................................................................119
4.1 Overview of Sample Circuit ................................................................................................. ........................... 120
4.2 Sample Program Features................................................................................................................................ 129
4.2.1 Sample program features.........................................................................................................................129
4.2.2 Basic operation of sample program..........................................................................................................129
4.2.3 Structure of sample program.................................................................................................................... 131
4.2.4 Descriptions of individual functions........................................................................................................ 131
4.3 Switching States between Operation Mode and Sleep Mode...........................................................................147
4.3.1 Processing during initialization................................................................................................................147
4.4.6 Processing for data transfer...................................................................................................................... 156
4.4.7 Processing for input/output ports............................................................................................................. 157
Chapter 5 Sample Program 2.....................................................................................................................................159
5.2.3 Time matching program........................................................................................................................... 179
5.2.4 Roulette program .....................................................................................................................................191
5.2.5 Slot program ............................................................................................................................................ 205
Page 9
5.3 Sample Program Using Serial Function...........................................................................................................219
5.3.1 Serial program..........................................................................................................................................219
5.3.2 Serial program 1.......................................................................................................................................222
5.3.3 Serial program 2.......................................................................................................................................235
6.1 Description on Functions Not Used in This Sample........................................................................................ 252
6.2 Initializing Based on Applications...................................................................................................................254
6.4 Notes on Designing Circuit.............................................................................................................................258
6.4.1 Selecting high speed clock crystal oscillator............................................................................................ 258
6.4.3 Analog input pins..................................................................................................................................... 258
6.4.4 Analog output .......................................................................................................................................... 258
6.5 Notes on Designing Program........................................................................................................................... 259
6.6 How to Use C Language Compiler..................................................................................................................259
6.7 Using MAKE...................................................................................................................................................261
6.8 CD Directory Tree........................................................................................................................................... 262
7.1 Program File Composition...............................................................................................................................270
There are five 8-bit timers comprising timer 0 to 4.
The timer comprises a binary counter, a compare register and a mode register. You can combine two 8-bit timers,
timer 0 and 1 or 2 and 3, to use as a 16-bit timer.
Binary counter
This counter counts a clock selected by the prescaler or the mode register.
Compare register
This register determines the time base of a timer by specifying clock number counted by the binary counter.
Mode register
This register enables/disables the timer operation, and selects the clock source. The setting content of the
mode register depends on the timer.
Timer 0:
BIT7: Unused
BIT6: Unused
BIT5: "0" Normal operation
"1" P22(IRQ2), pulse width measurement
BIT4: "0" Normal operation
"1" PWM operation
BIT3: "0" Stop count
"1" Count operation
BIT2, 1, 0: Clock source selection
000: High speed crystal clock oscillation frequency
001: Timer 0, prescaler output signal
010: Low speed crystal clock oscillation frequency
011: Synchronous low speed crystal clock oscillation frequency
110: Timer 0, pin input external signal
111: Synchronous timer 0, pin input external signal
62
Timer 1:
BIT7: Not used
BIT6: Not used
BIT5: Not used
BIT4: "0" Normal operation
"1" Cascade connection
Page 11
Chapter 3 Register Setup of Each Function
BIT3: "0" Stop count
"1" Count operation
BIT2, 1, 0: Clock source selection
000:
High speed crystal clock oscillation frequency
001: Timer 1, prescaler output signal
010: Low speed crystal clock oscillation frequency
011: Synchronous low speed crystal clock oscillation frequency
110: Timer 1, pin input external signal
111: Synchronous timer 1, pin input external signal
Timer 2:
BIT7: Unused
BIT6: Unused
BIT5: "0" Normal operation
"1" P23(IRQ3), pulse width measurement
BIT4: "0" Normal operation
000: High speed crystal clock oscillation frequency
001: Timer 4, prescaler output signal
010: Low speed crystal clock oscillation frequency
011: Synchronous low speed crystal clock oscillation frequency
110: Timer 4, pin input external signal
111: Synchronous timer 4, pin input external signal
The synchronization synchronizes with the timing of the system clock. See the "LSI User’s Manual".
3.9.1 Types of setting for 8-bit timer
Interval timer
You can apply interval timer setting to all 8-bit timers ranging from the timer 0 to 4. Your source clock
selection and compare register setting determines the generation cycle of the timer interrupt. The timer
generates the interrupt on the next count after it matches the set value on the compare register, then clears
the count. You write a count which is equivalent to a period setting minus 1 to the compare register.
64
The following is the example for setting the interval timer with 10 milli seconds.
To set to the interval timer with 10 milli seconds, convert the time base to the frequency first.
Formula: 1 / 10 milli seconds = 100 Hz
Setting by using
high speed oscillation clock:
The prescaler can set the high speed oscillation clock to 4, 16, 32 or 64 divisions.
Page 13
Chapter 3 Register Setup of Each Function
20 MHz / 64 = 312500 312500 / 100 = 3125
This setting is not available with the 8-bit timer.
Setting by using
The following section describes a sample program.
/* Control data declaration */
#define TM0MOD 0x00
#define TM0PWM 0x00
#define TM0EN 0x08
#define TM0CK 0x01
/* Determine time for interval timer */
#define TM0PSC 0x00
#define TIME
The event count uses a binary counter to count an external signal supplied from the timer pin.
You can set a measurement count value to the compare register for generating an interrupt as for the interval
timer.
The following section describes a sample program.
/* Control data declaration */
#define TM0CAS 0x00 /* 0b00000000 Normal timer operation */
#define TM0EN 0x08 /* 0b00001000 Count operation */
#define TM0CK 0x06 /* 0b00000110 External input signal */
/* Set value to interrupt, interrupt on 5th signal */
#define COUNT 0x04
/* Setting program*/
/* Operation is based on external signal, and prescaler is not set */
TM0OC = COUNT; /* Set timer value */
TM0MD = TM0CAS | TM0EN | TM0CK;
This sample is stored in the CD.
Stored directory: Sample\chapter3,4\Initial\ASM\TIMER\EVENT8\
Stored directory: Sample\chapter3,4\Initial\C\TIMER\EVENT8\
Timer pulse output setting
The timer pulse output can provide a pulse signal at an arbitrary frequency.
The period of the timer pulse output is twice as long as the period set on the compare register.
To provide timer pulse, set the output mode register (special register) of the port 1 to the timer output,
and set the input/output setting register to output. See "3.7.2 Port 1".)
The timer setting for timer pulse output setting is identical to that for the inte rval timer.
PWM operation
The PWM output generates the PWM basic component and provides it from the timer output pin when the
binary counter and the compare register of a timer match or on the overflow timing of the binary counter.
Since the PWM output uses the overflow of the binary counter, you can use only the frequency component
generated by the overflow of the timer. The resolution of the PWM output is fixed to the one 255th due to
the 8-bit counter.
The PWM output provides "1" until it counts up to the count set on the compare register after count start
(00), and then provides "0" until it overflows after the match to the compare register.
Since the frequency components use the timer overflow, they are determined by the prescaler setting. This
sample uses the low speed oscillation clock (assuming its oscillation is at 32.768 kHz) to set the 1/4 duty
output for the 128 Hz frequency.
66
Page 15
TMxIO
(x is the timer
number)
Chapter 3 Register Setup of Each Function
Compare register value
8-bit timer overflow cycle
(128 Hz)
Figure 3 8-bit timer PWM operation timing chart
The following section describes a sample program.
/* Control data declaration */
#define TM4MOD 0x00
The synchronous output operation provides the output from the port D at the count up timing of the
timer. You can use the timer 1 and 2 for the synchronous output.
You use the port D to set the synchronous output operation. See "3.7.12 Port D".)
You can use the timer setting both in the interval timer mode and event count mode. You can also set
67
Page 16
Chapter 3 Register Setup of Each Function
the interval output for the interval timer.
Serial interface transfer clock generation
You can use the ouput signal from a timer to generate a serial transfer clock.
You can use the interval timer and timer output setting to set the timer.
The following timers are available for the serial interface communication.
Timer 2 Timer 3 Timer 4
Serial 0 Available Not available Available
Serial 1 Not available Not available Available
Serial 2 Not available Available Not available
Serial 3 Not available Available Not available
When you use the timer as transfer clock for the serial interface communication, the transfer speed will be
the half of the setting value.
Declare the setting value in advance because it varies depending on the communication transfer speed.
This sample uses the case when the communication transfer speed is 19200 bps.
See the setting value list of the serial interface transfer speed in the LSI User's Manual for the setting
value.
This sample is stored in the CD.
Stored directory: Sample\chapter3,4\Initial\ASM\TIMER\Sclock\
Stored directory: Sample\chapter3,4\Initial\C\TIMER\Sclock\
(*(volatile unsigned char *)TM2BC_adr)
(*(volatile unsigned char *)TM2OC_adr)
(*(volatile unsigned char *)TM2MD_adr)
(*(volatile unsigned char *)CK2MD_adr)
Simple pulse width measurement
The simple pulse width measurement uses timer count to measure the pulse width when the interrupt input
Chapter 3 Register Setup of Each Function
/* Set prescaler */
/* Set timer value */
signal stays "Low". 3 timers, timers 0, 2, and 4, are available for the simple pulse width measurement.
The following section describes a sample program.
/* Control data declaration */
#define TM0MOD 0x20
#define TM0PWM 0x00
#define TM0EN 0x08
/* Determine time for interval timer */
#define TIME