U20029EJ1V0ANF0
U20029EJ1V0ANF0
U20029EJ1V0ANF0
On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology
Corporation, and Renesas Electronics Corporation took over all the business of both
companies. Therefore, although the old company name remains in this document, it is a valid
Renesas Electronics document. We appreciate your understanding.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation and also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
Application Note
78K0R/Lx3
This application note describes a sample program that executes 24-hour clock display by using an LCD controller/driver
and a real-time counter.
2009
Printed in Japan
• The information in this document is current as of July, 2009. The information is subject to change without notice. For actual
design-in, refer to the latest publications of NEC Electronics data sheets or data books, etc., for the most up-to-date
specifications of NEC Electronics products. Not all products and/or types are available in every country. Please check with an
NEC Electronics sales representative for availability and additional information.
• No part of this document may be copied or reproduced in any form or by any means without the prior written consent of NEC
Electronics. NEC Electronics assumes no responsibility for any errors that may appear in this document.
• NEC Electronics does not assume any liability for infringement of patents, copyrights or other intellectual property rights of
third parties by or arising from the use of NEC Electronics products listed in this document or any other liability arising from the
use of such products. No license, express, implied or otherwise, is granted under any patents, copyrights or other intellectual
property rights of NEC Electronics or others.
• Descriptions of circuits, software and other related information in this document are provided for illustrative purposes in
semiconductor product operation and application examples. The incorporation of these circuits, software and information in
the design of a customer's equipment shall be done under the full responsibility of the customer. NEC Electronics assumes no
responsibility for any losses incurred by customers or third parties arising from the use of these circuits, software and
information.
• While NEC Electronics endeavors to enhance the quality, reliability and safety of NEC Electronics products, customers agree
and acknowledge that the possibility of defects thereof cannot be eliminated entirely. To minimize risks of damage to property
or injury (including death) to persons arising from defects in NEC Electronics products, customers must incorporate sufficient
safety measures in their design, such as redundancy, fire-containment and anti-failure features.
• NEC Electronics products are classified into the following three quality grades: "Standard", "Special" and "Specific". The
"Specific" quality grade applies only to NEC Electronics products developed based on a customer-designated "quality
assurance program" for a specific application. The recommended applications of an NEC Electronics product depend on its
quality grade, as indicated below. Customers must check the quality grade of each NEC Electronics product before using it in
a particular application.
"Standard": Computers, office equipment, communications equipment, test and measurement equipment, audio and visual
equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots.
"Special": Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster systems, anti-
crime systems, safety equipment and medical equipment (not specifically designed for life support).
"Specific": Aircraft, aerospace equipment, submersible repeaters, nuclear reactor control systems, life support systems and
medical equipment for life support, etc.
The quality grade of NEC Electronics products is "Standard" unless otherwise expressly specified in NEC Electronics data
sheets or data books, etc. If customers wish to use NEC Electronics products in applications not intended by NEC Electronics,
they must contact an NEC Electronics sales representative in advance to determine NEC Electronics' willingness to support a
given application.
(Note 1) "NEC Electronics" as used in this statement means NEC Electronics Corporation and also includes its majority-owned
subsidiaries.
(Note 2) "NEC Electronics products" means any product developed or manufactured by or for NEC Electronics (as defined
above).
(M8E0909)
This sample program executes 24-hour clock display by using an LCD controller/driver and a real-time counter. The
time set by the real-time counter is stored in the A pattern area of the LCD data memory and is converted into time
display each time the real-time counter’s periodic interrupt occurs (at one-minute intervals).
The hour and minute settings can be changed by pressing the SET key a specified number of times and then
pressing the UP and DOWN keys.
[Operation overview]
<Output>
<Clock display>
LCD output
78K0R/Lx3
microcontroller
Key input
<Hours setting>
<Input>
ON
Note When the SET key is input the third time and onward, the status changes from the start (i.e., from when the
number of times of inputting the SET key is zero).
Notes 1. These settings are for the 78K0R/LH3. When the 78K0R/LF3 is used, SEG4 to SEG30 are used for
segment output. When the 78K0R/LG3 is used, SEG4 to SEG39 are used for segment output.
2. For details of the low-voltage detector, refer to the User’s Manual.
After the initial settings have been completed, the microcontroller enters the HALT mode. It is released from the
HALT mode by the constant-period interrupt of the real-time counter or detection of the falling edge of the UP, DOWN,
or SET key. If the microcontroller has been released from the HALT mode by the constant-period interrupt of the real-
time counter, the displayed time is changed. If it has been released by input of the UP, DOWN, or SET key, an action
to avoid chattering is taken. When input of a key has been determined, time is set to the clock.
When the SET key is input the first time, hours can be set. When it is input the second time, minutes can be set.
When the SET key is input the third time, the clock display function is returned and the set time is displayed. While
hours are being set, inputting the UP key increments the time by 1 hour. While minutes are displayed, inputting the
UP key increments the time by 1 minute. Likewise, inputting the DOWN key decrements the time by 1 hour or 1
minute.
Caution For cautions when using the device, refer to the User’s Manual.
LCD panel
…
VDD VDD
VREFOUT/AVREFP
RESET
EVDD
AVDD0 SEG30
…
AVDD1
VDD SEG4
0.47 to 1 μF COM7
REGC
…
AVSS
COM0
EVSS 78K0R/LF3
microcontroller
VSS
VLC0
XT2
32.768 kHz VLC1
XT1
VLC2
P32
CAPL
Cautions 1. Use the microcontroller at a voltage in the range of VDD = 5.0 V (because a low voltage is
detected within in a range of 4.22 ±0.1 V < VDD).
2. Make EVDD, AVDD0, AVDD1, VLC0, and VREFOUT/AVREFP the same potential as VDD.
3. Make AVSS the same potential as EVSS or VSS and connect it directly to GND.
4. Connect REGC to VSS via a capacitor (0.47 to 1 μF).
5. Handle unused pins that are not shown in the circuit diagram as follows:
• I/O ports: Set them to output mode and leave them open (unconnected).
• Input ports: Connect them independently to VDD or VSS via a resistor.
6. When using the XT1 oscillator, wire as follows in the area enclosed by the broken lines in the
above figures to avoid an adverse effect from wiring capacitance.
• Keep the wiring length as short as possible.
• Do not cross the wiring with the other signal lines.
• Do not route the wiring near a signal line through which a high fluctuating current flows.
• Always make the ground point of the oscillator capacitor the same potential as VSS.
• Do not ground the capacitor to a ground pattern through which a high current flows.
• Do not fetch signals from the oscillator.
7. The XT1 oscillator is designed as a low-amplitude circuit for reducing power consumption,
and is more prone to malfunction due to noise than the X1 oscillator. Particular care is
therefore required with the wiring method when the XT1 clock is used.
8. Use a non-polar capacitor between CAPH and CAPL.
9. In this sample program, the P40/TOOL0 and P41/TOOL1 pins are used for on-chip debugging.
10. Twenty-seven segment signal output pins and eight common signal output pins on the LCD
panel are used.
11. An on-chip pull-up resistor is connected to the P30, P31, and P32 pins.
LCD panel
…
VDD VDD
VREFOUT/AVREFP
RESET
EVDD
AVDD0 SEG39
…
AVDD1
VDD SEG4
0.47 to 1 μF COM7
REGC
…
AVSS
COM0
EVSS 78K0R/LG3
microcontroller
VSS
VLC0
XT2
32.768 kHz VLC1
XT1
VLC2
0.47 to 1 μF 0.47 to 1 μF
VLC3 0.47 to 1 μF 0.47 to 1 μF
P30
0.47 to 1 μF
P31
CAPH
P32
CAPL
Cautions 1. Use the microcontroller at a voltage in the range of VDD = 5.0 V (because a low voltage is
detected within in a range of 4.22 ±0.1 V < VDD).
2. Make EVDD, AVDD0, AVDD1, VLC0, and VREFOUT/AVREFP the same potential as VDD.
3. Make AVSS the same potential as EVSS or VSS and connect it directly to GND.
4. Connect REGC to VSS via a capacitor (0.47 to 1 μF).
5. Handle unused pins that are not shown in the circuit diagram as follows:
• I/O ports: Set them to output mode and leave them open (unconnected).
• Input ports: Connect them independently to VDD or VSS via a resistor.
6. When using the XT1 oscillator, wire as follows in the area enclosed by the broken lines in the
above figures to avoid an adverse effect from wiring capacitance.
• Keep the wiring length as short as possible.
• Do not cross the wiring with the other signal lines.
• Do not route the wiring near a signal line through which a high fluctuating current flows.
• Always make the ground point of the oscillator capacitor the same potential as VSS.
• Do not ground the capacitor to a ground pattern through which a high current flows.
• Do not fetch signals from the oscillator.
7. The XT1 oscillator is designed as a low-amplitude circuit for reducing power consumption,
and is more prone to malfunction due to noise than the X1 oscillator. Particular care is
therefore required with the wiring method when the XT1 clock is used.
8. Use a non-polar capacitor between CAPH and CAPL.
9. In this sample program, the P40/TOOL0 and P41/TOOL1 pins are used for on-chip debugging.
10. Twenty-seven segment signal output pins and eight common signal output pins on the LCD
panel are used.
11. An on-chip pull-up resistor is connected to the P30, P31, and P32 pins.
LCD panel
…
VDD VDD
VREFOUT/AVREFP
RESET
EVDD
AVDD0 SEG53
…
AVDD1
VDD SEG4
0.47 to 1 μF COM7
REGC
…
AVSS
COM0
EVSS 78K0R/LH3
microcontroller
VSS
VLC0
XT2
32.768 kHz
VLC1
XT1
VLC2
0.47 to 1 μF 0.47 to 1 μF
VLC3 0.47 to 1 μF 0.47 to 1 μF
P30
0.47 to 1 μF
P31 CAPH
P32 CAPL
Cautions 1. Use the microcontroller at a voltage in the range of VDD = 5.0 V (because a low voltage is
detected within in a range of 4.22 ±0.1 V < VDD).
2. Make EVDD, AVDD0, AVDD1, VLC0, and VREFOUT/AVREFP the same potential as VDD.
3. Make AVSS the same potential as EVSS or VSS and connect it directly to GND.
4. Connect REGC to VSS via a capacitor (0.47 to 1 μF).
5. Handle unused pins that are not shown in the circuit diagram as follows:
• I/O ports: Set them to output mode and leave them open (unconnected).
• Input ports: Connect them independently to VDD or VSS via a resistor.
6. When using the XT1 oscillator, wire as follows in the area enclosed by the broken lines in the
above figures to avoid an adverse effect from wiring capacitance.
• Keep the wiring length as short as possible.
• Do not cross the wiring with the other signal lines.
• Do not route the wiring near a signal line through which a high fluctuating current flows.
• Always make the ground point of the oscillator capacitor the same potential as VSS.
• Do not ground the capacitor to a ground pattern through which a high current flows.
• Do not fetch signals from the oscillator.
7. The XT1 oscillator is designed as a low-amplitude circuit for reducing power consumption,
and is more prone to malfunction due to noise than the X1 oscillator. Particular care is
therefore required with the wiring method when the XT1 clock is used.
8. Use a non-polar capacitor between CAPH and CAPL.
9. In this sample program, the P40/TOOL0 and P41/TOOL1 pins are used for on-chip debugging.
10. Twenty-seven segment signal output pins and eight common signal output pins on the LCD
panel are used.
11. An on-chip pull-up resistor is connected to the P30, P31, and P32 pins.
COM7
…
COM0
…
SEG49 SEG0
0 1 2 3 4
5 6 7 8 9 :
Caution When the 78K0R/LF3 is used, the segment signal output ports run short. Therefore, the dot
pattern “:” is rewritten by the following contents.
This chapter describes the files included in the compressed file to be downloaded, internal peripheral functions of
the microcontroller to be used, and initial settings and provides an operation overview of the sample program and a
flow chart.
The following table shows the files included in the compressed file to be downloaded.
main.asm Source file for hardware initialization processing and main zNote zNote
(Assembly language version) processing of microcontroller
main.c
(C language version)
op.asm Assembler source file for setting the option byte z z
(This file is used for setting up the watchdog timer, selecting
the internal high-speed oscillator frequency, and setting up the
LVI default start function.)
78K0RLx3_sample_program.prw Work space file for integrated development environment PM+ z
78K0RLx3_sample_program.prj Project file for integrated development environment PM+ z
Note “main.asm” is included with the assembly language version, and “main.c” with the C language version.
: The files to be used with integrated development environment PM+ are included.
The following internal peripheral functions of the microcontroller are used in this sample program.
In this sample program, initial settings including the selection of the clock frequency, setting of the I/O ports, setting
of the real-time counter, setting of the timer array unit, and setting of the LCD controller/driver are performed.
After completion of the initial settings, the microcontroller enters the HALT mode. It is released from the HALT
mode by the constant-period interrupt of the real-time counter or detection of the falling edge of P30, P31, or P32. If
the microcontroller has been released from the HALT mode by the constant-period interrupt of the real-time counter,
the displayed time is changed. If it has been released by input of the UP, DOWN, or SET key, an action to avoid
chattering is taken. When input of a key has been determined, time is set to the clock.
When the SET key is input for the first time, hours can be set. When it is input the second time, minutes can be set.
When the SET key is input the third time, the clock display function is returned and the set time is displayed. While
hours are being set, inputting the UP key increments the time by 1 hour. While minutes are displayed, inputting the
UP key increments the time by 1 minute. Likewise, inputting the DOWN key decrements the time by 1 hour or 1
minute.
The details are described in the state transition diagram shown below.
Initial settings
<Option byte settings>
• Disabling the watchdog timer
• Setting the internal high-speed oscillation clock frequency to 8 MHz
• Disabling LVI from being started by default
• Enabling on-chip debug to operate
<Settings during initialization immediately after a reset ends>
• Setting up I/O ports
• Setting SEG4 to SEG53Note for segment output
• Setting COM0 to COM7 for common output
• Setting INTP1, INTP2, and INTP5 to be detected at the falling edge
• Securing a supply voltage of 4.2 V or more by using the function of low-voltage detector
• Specifying that the CPU/peripheral hardware clock run on the internal high-speed oscillation clock (8
MHz)
• Stopping the X1 oscillator
• Starting operation of the XT1 oscillator
• Setting up the real-time counter
• Setting the real-time counter to generate the constant-period interrupt once every minute
• Setting to not use the interval interrupt of the real-time counter
• Setting the current time to 00:00:00 a.m.
• Setting to not use the alarm interrupt
• Setting up timer array unit
• Setting channel 4 in interval timer mode of about 10 ms
• Setting up LCD controller/driver
• Selecting Internal voltage boosting method for the LCD drive voltage generator
• Setting an LCD display mode of 8-time division and 1/4 bias
• Setting LCD display data in the RAM area
• Setting to display the data of only the A-pattern area
• Setting fCLK/28 as the LCD source clock (fLCD) and fLCD/27 as the LCD clock
(LCD clock: 244 Hz, frame frequency: 61 Hz)
• Setting 1.00 V (LCD drive voltage (VLC0) = 4.00 V) as the reference voltage of the LCD boost level
• Setting the falling edge as the valid edge of INTP1, INTP2, and INTP5
Note These settings are for the 78K0R/LH3. When the 78K0R/LF3 is used, SEG4 to SEG30 are used for
segment output. When the 78K0/LG3 is used, SEG4 to SEG39 are used for segment output.
Start 1
The option byte
Note 1
is
referenced.
Set constant-period interrupt to
generate once every minute.
Disable interrupts.
Note 2
Set interval interrupt
Set up the register bank. to not use. Setting up real-
time counter
MAIN
Notes 1. The option byte is automatically referenced by the microcontroller immediately after a reset ends. In this
sample program, the following settings are specified using the option byte:
• Disabling the watchdog timer
• Setting the internal high-speed oscillator frequency to 8 MHz
• Disabling LVI from being started by default
• Enabling on-chip debug to operate
2. The general-purpose registers of the 78K0R/Lx3 Series microcontrollers are configured in four register
banks so that the registers used for normal processing and those used when an interrupt occurs can be
changed on a bank basis in order to create an efficient program. In this sample program, only register
bank 0 is used.
3. The low-voltage detector is enabled, and then the system is made to wait at least 10 μs until the low-
voltage detector stabilizes.
Caution With the sample program of the C language version, the settings of register banks and stack
pointer are not described in the source program (main.c) because they are made by the start-up
routine. For details of the start-up routine, refer to the CC78K0R Operation User’s Manual.
MAIN 4
Note
Enter the HALT mode .
Yes
Constant-period interrupt
generated?
No
2
No INTP1, INTP2,
or INTP5 interrupt
generated?
Yes
No UP, DOWN,
or SET key
being input?
Yes
Yes
SET key on?
No Yes
Clock display status?
No
3
Yes
Minutes adjustment
status?
No
Yes Set clock display status.
Set hours adjustment
UP key on? status.
Yes
1
Yes Yes
Minutes adjustment Minutes adjustment
status? status?
No No
3 No
Clock display status?
Yes
No
Hours adjustment
status?
Yes
No
Minutes adjustment
status?
Yes
Note The device is released from the HALT mode by the constant-period interrupt of the real-time counter or
generation of interrupt INTP1, INTP2, or INTP5 (by detection of the falling edge of P30 to P32).
This chapter describes how to set up peripheral hardware, real-time counter, and LCD controller/driver. It also
provides software coding examples.
For other initial settings, refer to the 78K0R/Kx3 Sample Program (Initial Settings) LED Lighting Switch
Control Application Note.
For how to set register, refer to the User’s Manual.
For assembler instructions, refer to the 78K0R Series Instructions User’s Manual.
Note
RTCEN DACEN ADCEN IICAEN SAU1EN SAU0EN TAU1EN TAU0EN
Remark The values written in red in the above figure are specified in this sample program.
The following seven registers are used to set up the real-time counter.
[Example of procedure for setting up real-time counter to play back sound data]
<1> Set bit 7 (RTCEN) of peripheral enable register 0 (PER0) to 1 (see 4.1).
<2> Set the real-time counter to generate the constant-period interrupt once every minute.
<3> Set the real-time counter not to generate the interval interrupt.
<4> Set time of starting counting to SEC, MIN, and HOUR.
<5> Set not to generate an interrupt when the current time matches the alarm time.
Note
RCLOE0 RTCCL pin output control
0 Disables output of RTCCL pin (32.768 kHz).
1 Enables output of RTCCL pin (32.768 kHz).
Note RCLOE0 and RCLOE2 must not be enabled at the same time.
Caution If RCLOE0 and RCLOE1 are changed when RTCE = 1, the 32.768 kHz and 1 Hz output signals
may become glitch.
Remark The values written in red in the above figure are specified in this sample program.
Caution If writing is performed to the RTCC1 register with a 1-bit manipulation instruction, the RIFG and
WAFG flags may be cleared. Therefore, to perform writing to the RIFG and WAFG flags, be sure
to use an 8-bit manipulation instruction. At this time, set 1 to the RIFG and WAFG flags to
invalidate writing and not to clear the RIFG and WAFG flags during writing. When the value may
be rewritten because the RIFG and WAFG flags are not being used, the RTCC1 register may be
written by using a 1-bit manipulation instruction.
Remarks 1. The values written in red in the above figure are specified in this sample program.
2. Fixed-cycle interrupts and alarm match interrupts use the same interrupt source (INTRTC). When
using these two types of interrupts at the same time, which interrupt occurred can be judged by
checking the fixed-cycle interrupt status flag (RIFG) and the alarm detection status flag (WAFG)
upon INTRTC occurrence.
Note
RCLOE2 RTCDIV pin output control
0 Disables output of RTCDIV pin
1 Enables output of RTCDIV pin
Note RCLOE0 and RCLOE2 must not be enabled at the same time.
Remark The values written in red in the above figure are specified in this sample program.
Note For details of the sub-count register (RSUBC), refer to the User’s Manual.
Caution Bit 5 (HOUR20) of HOUR indicates AM(0)/PM(1) if AMPM = 0 (if the 12-hour system is selected).
For details, see table below.
The following seven registers are used to control the LCD controller/driver.
0 0 MDSET1 MDSET0 0 0 0 0
Remark The values written in red in the above figure are specified in this sample program.
VLCON Voltage boost circuit and capacitor split circuit operation enable/disable
0 Stops voltage boost circuit and capacitor split circuit operation
1 Enables voltage boost circuit and capacitor split circuit operation
Cautions 1. When LCD display is not performed or necessary, set SCOC and VLCON to 0, in order to
reduce power consumption
2. When the external resistance division method has been set (MDSET1 = MDSET0 = 0), do not
set VLCON to 1.
3. To stop voltage boost circuit and capacitor split circuit operation, be sure to set SCOC and
LCDON to 0 and then set VLCON to 0.
4. Set BLON and LCDSEL to 0 when 8 has been selected as the number of time slices for the
display mode.
Remark The values written in red in the above figure are specified in this sample program.
Remark The values written in red in the above figure are specified in this sample program.
VLCD4 VLCD3 VLCD2 VLCD1 VLCD0 Reference voltage selection VLC0 voltage
(contrast adjustment) 1/3 bias 1/4 bias
0 0 0 0 0 1.75 V 5.25 V Setting
Note
0 0 0 0 1 1.70 V 5.10 V prohibited
0 0 0 1 0 1.65 V 4.95 V
0 0 0 1 1 1.60 V 4.80 V
0 0 1 0 0 1.55 V 4.65 V
0 0 1 0 1 1.50 V 4.50 V
0 0 1 1 0 1.45 V 4.35 V
0 0 1 1 1 1.40 V 4.20 V
0 1 0 0 0 1.35 V 4.05 V
0 1 0 0 1 1.295 V 3.885 V
0 1 0 1 0 1.25 V 3.75 V 5.00 V
0 1 0 1 1 1.20 V 3.60 V 4.80 V
0 1 1 0 0 1.15 V 3.45 V 4.60 V
0 1 1 0 1 1.10 V 3.30 V 4.40 V
0 1 1 1 0 1.05 V 3.15 V 4.20 V
0 1 1 1 1 1.00 V (default) 3.00 V 4.00 V
1 0 0 0 0 0.95 V 2.85 V 3.80 V
1 0 0 0 1 0.90 V 2.70 V 3.60 V
1 0 0 1 0 0.85 V 2.55 V 3.40 V
1 0 0 1 1 0.80 V 2.40 V 3.20 V
Other than above Setting prohibited
Cautions 1. The VLCD setting is valid only when the voltage boost circuit is operating.
2. Be sure to set bits 5 to 7 to “0”.
3. Be sure to change the VLCD value after having stopped the operation of the voltage boost
circuit (VLCON = 0)
4. These values above may change after device evaluation.
Remark The values written in red in the above figure are specified in this sample program.
Remark The port pins to be used alternatively with the segment output pins vary, depending on the product.
• 78K0R/LF3: P50 to P57, P90 to P92, P100, P140 to P147
• 78K0R/LG3: P50 to P57, P90 to P97, P100, P140 to P147
• 78K0R/LH3: P50 to P57, P90 to P97, P100 to P102, P140 to P147
Note
0 PF14H PF14L PF10 PF9H PF9L PF5H PF5L
Caution For 78K0R/LF3, be sure to ser bits 3 and 7 to ‘‘0’’. For 78K0R/LG3 and 78K0R/LH3, be sure to set
bit 7 to ‘‘0’’.
Remark The values written in red in the above figure are specified in this sample program.
Remark The segment output only pins vary, depending on the product.
• 78K0R/LF3: SEG8 to SEG10
• 78K0R/LG3: SEG8 to SEG14
• 78K0R/LH3: SEG8 to SEG26
Notes 1. These bits of the 78K0R/LF3 and 78K0R/LG3 are fixed to “0”.
2. This bit of the 78K0R/LF3 is fixed to “0”.
Remark The values written in red in the above figure are specified in this sample program.
The segment output only pins operated by SEGEN4 to SEGEN0 are as follows.
Table 4-3-1. Segment Output Only Pins Controlled by SEGEN4 to SEGEN0 Bits
SEGEN0 SEG8 to SEG10 pins SEG8 to SEG11 pins SEG8 to SEG11 pins
Remark The segment output pins to be used alternatively with the TI02, TI04, and RxD3 pins vary,
depending on the product.
• 78K0R/LF3: TI04/SEG27/P53, TI02/SEG28/P52, RxD3/SEG30/P50
• 78K0R/LG3: TI04/SEG36/P53, TI02/SEG37/P52, RxD3/SEG39/P50
• 78K0R/LH3: TI04/SEG50/P53, TI02/SEG51/P52, RxD3/SEG53/P50
Remarks 1. The values written in red in the above figure are specified in this sample program.
2. This register must be set up only when the 78K0R/L3 is used.
3. Bits 0 and 1 of ISC are not used with the LCD controller driver.
To use the TI04/SEGxx/P53, TI02/SEGxx/P52, and RxD3/SEGxx/P50 pins, set the PF5L and ISCn (n = 2 to 4)
bits as follows, according to the function to be used.
1 0 Segment output
1 1 Setting prohibited
As a software coding example, initial settings for clock display, clock adjustment processing, and clock display
updating processing performed by the source program of the 78K0R/LH3 are shown below.
LMAIN460:
MOV A, RMIN Increment minutes of time data by +1
ADD A, #1 ; when+UP
Minutes 1 key is on in minutes
ADD A, !BCDADJ ; adjustment status.
Decimal correction
CMP A, #60H ; 60 minutes?
BNZ $LMAIN480 ; No,
• • • (Omitted) • • •
LMAIN560:
Decrement minutes of time data by
MOV A, RMIN
−1 when DOWN key is on in minutes
SUB A, #1 ; Minutes − adjustment
1 status.
SUB A, !BCDADJ ; Decimal correction
BNC $LMAIN580 ; 59 minutes?, No,
LMAIN720:
CLR1 RTCIF ; Clear constant-period interrupt request
Read time data from hour count and
CMP RADJSTAT,#0 ; Clock being displayed?
minute count registers of real-time
BNZ $LMAIN790 ; No, counter in clock display status.
LMAIN740:
SET1 RWAIT ; RTC value read/write mode
BF RWST, $LMAIN740 ; Wait for RTC read/write mode
LMAIN780:
CLR1 RWAIT ; Start RTC count operation
BT RWST, $LMAIN780 ; Wait for start of RTC count operation
MOV A, RMIN
AND A, #0FH ; Digit of 1 minute
MOVW DE, #LOWW SEG28 ; LCD display position
CALL !!SLCDNUM ; Display digit of 1 minute
BR MAIN_LOOP
SLCDNUM:
ADD A, A
MOV X, A ; X = Value*2
Calculate value and read
ADD A, A ; A = Value*4
numeric font from RAM.
ADD X, A ; X = Value*(4+2)
CLRB A ; A = 0
ADDW AX, #LOWW TCHRDATA ; Value font start address
MOVW HL, AX
MOV C, #6 ; Value font size
JLCDN220:
MOV A, [HL] ; Read value font
CMP0 B ;'_' ? ‘_’ in hours and minutes
Append
BZ $JLCDN260 ; No,adjustment statuses.
RET
(2) C language
<1> Initial settings for clock display
void hdwinit(void){
Set P30 to P32 as input port for SET,
• • • (Omitted) • • •
UP, and DOWN keys.
PM3 = 0b11100111; /* Specify P33
Setand P34 counter
real-time as outputto ports */
PU3 supplypull-up
= 0b00000111; /* Connect on-chip input clock.
resistors to P30 to P32 */
}
• • • (Omitted) • • •
RWAIT = 0;
/* Set to start RTC count operation */
while(RWST == 1){
/* Wait for start of RTC count operation */
RWAIT = 0;
Switch status from clock /* Set to start RTC count operation */
display → minutes adjustment }
→ hours adjustment → clock
ucAdjStatus = 0x01;
display, and so on when SET
/* Assume minutes being adjusted */
key is on.
break;
RWAIT = 0;
/* Set to start RTC count operation */
while(RWST == 1){
/* Wait for start of RTC count operation */
RWAIT = 0;
/* Set to start RTC count operation */
}
break;
• • • (Omitted) • • •
if(ucMinute == 0x60){
ucMinute = 0x00;
/* Carry correction */
Increment hours of time data by +1 }
when UP key is on in hours break;
adjustment status.
case 0x02: /* Hours being adjusted */
ucHour = adbcdb(ucHour, 1);
/* Hours + 1 */
if(ucHour == 0x24){
ucHour = 0x00;
/* Carry correction */
}
break;
• • • (Omitted) • • •
• • • (Omitted) • • •
void fn_LcdNum(unsigned char *ucSeg, unsigned char ucNum, unsigned char ucUnderbar)
{
• • • (Omitted) • • •
Append ‘_’ in hours and minutes
if(ucUnderbar == 0){ adjustment statuses.
ucFontWork = 0b00000000; /* No underbar */
}
else{
ucFontWork = 0b10000000; /* Underbar */
} Display font data.
Operation PDF
Operation PDF
As a program list example, the 78K0R/LH3 microcontroller source program is shown below.
;===============================================================================
;
; Vector table
;
;===============================================================================
TVECT1 CSEG AT 00000H
DW RESET_START ; 00000H RESET input, POC, LVI, WDT, TRAP
;===============================================================================
;
; Define the memory stack area
;
;===============================================================================
DSTK DSEG BASEP
STACKEND:
DS 20H ; Memory stack area = 32 bytes
STACKTOP: ; Start address of the memory stack area
;===============================================================================
;
; Define the RAM
;
;===============================================================================
DMAINDSEG SADDR
XMAINCSEG UNIT
;*******************************************************************************
;
; Servicing interrupts by using unnecessary interrupt sources
;
;*******************************************************************************
IINIT:
; If an unnecessary interrupt occurred, the processing branches to this line.
; The processing then returns to the initial original processing because no processing
is performed here.
RETI
;*******************************************************************************
;
; Initialization after RESET
;
;*******************************************************************************
RESET_START:
;-------------------------------------------------------------------------------
; Disable interrupts
;-------------------------------------------------------------------------------
DI
;-------------------------------------------------------------------------------
; Set up the register bank
;-------------------------------------------------------------------------------
SEL RB0
;-------------------------------------------------------------------------------
; Initialize the stack pointer
;-------------------------------------------------------------------------------
MOVW SP, #LOWW STACKTOP ; Initialize the stack pointer
;-------------------------------------------------------------------------------
; Specify the I/O port
;-------------------------------------------------------------------------------
CALL !!SINIPORT ; Set all ports that can be specified as output ports as
output ports.
;-------------------------------------------------------------------------------
; Low-voltage detection
;-------------------------------------------------------------------------------
CALL !!SINILVI ; Secure a supply voltage of 4.2 V or more
;-------------------------------------------------------------------------------
; Specify the clock frequency
;-------------------------------------------------------------------------------
CALL !!SINICLK ; Operate internal high-speed oscillation clock at 8 MHz
;-------------------------------------------------------------------------------
; Specify the real-time counter
;-------------------------------------------------------------------------------
; - Set count start time to 0:00:00
; - Set constant-period interrupt (1-minute period) and alarm interrupt
;-------------------------------------------------------------------------------
; Control real-time counter control clock
MOV PER0, #10000000B
; |+++++++------- Be sure to set 0
; +-------------- RTCEN
; [Real-time counter control clock]
; 0: Stops control clock supply
; 1: Supplies control clock
; ||||+---------- AMPM
; |||| [Selection of 12-/24-hour system]
; |||| 0: 12-hour system (a.m. and p.m. are displayed.)
; |||| 1: 24-hour system
; |||+----------- RCLOE0
; ||| [RTCCL pin output control]
; ||| 0: Disables output of RTCCL pin (32.768 kHz)
; ||| 1: Enables output of RTCCL pin (32.768 kHz)
; ||+------------ RCLOE1
; || [RTC1HZ pin output control]
; || 0: Disables output of RTC1HZ pin (1 Hz)
; || 1: Enables output of RTC1HZ pin (1 Hz)
; |+------------- Be sure to set 0
; +-------------- RTCE
; [Real-time counter operation control]
; 0: Stops counter operation
; 1: Starts counter operation
; Set count start time (hour 08, minute 00, second 00)
MOV SEC, #00H ; Second: 00
MOV MIN, #00H ; Minute: 00
MOV HOUR, #00H ; Hour: 00
; Wait until device enters STOP mode immediately after real-time counter starts operating
MOV B, #124 ; * To place the device in the STOP mode immediately after
HINI210: ; RTCE has been set to 1, place the device in the STOP
NOP ; mode after duration of two subsystem clocks (about 62
DEC B ; us) or more after RTCE has been set to 1.
BNZ $HINI210
;-------------------------------------------------------------------------------
; Initialize RAM
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Specify the timer array unit
;-------------------------------------------------------------------------------
; - Channel 4: Used as master channel in interval timer mode
;-------------------------------------------------------------------------------
; Initial settings of timer array unit
SET1 TAU0EN ; Supply input clock of timer array unit
operation function
;|||+------------ CCS04
;||| [Selection of count clock (TCLK) of channel 4]
;||| 0: Operation clock MCK specified by the CKS04 bit
;||| 1: Valid edge of input signal input from TI04 pin/
;||| subsystem clock divided by 4 (fSUB/4)
;|++------------- Be sure to set 0
;+--------------- CKS04
; [Selection of operation clock (MCK) of channel 4]
; 0: Operation clock CK00 set by the TPS0 register
; 1: Operation clock CK01 set by the TPS0 register
;-------------------------------------------------------------------------------
; Specify the LCD driver
;-------------------------------------------------------------------------------
; Set so that the LCD driver function can be used.
;-------------------------------------------------------------------------------
; Wait for reference voltage setup time (2 ms or more) by using TM04 (2 ms)
enabled
CLR1 TMIF04 ; Clear INTTM04 interrupt request
HINI560:
NOP
BF TMIF04,$HINI560 ; Wait 1 ms
;|||||||
;||||||+------- ISC1
;|||||| [Switching channel 7 input of timer array unit]
;|||||| : 0 : Uses the input signal of the TI07 pin as
a timer input
;|||||| : 1 : Uses the input signal of the RxD3 pin as
a timer input
;||||||
;|||+++-------- ISC2 to ISC4:
;|||||| [Control of TI04/SEGxx/P53, TI02/SEGxx/P52, and
RxD3/SEGxx/P50]
;|||||| : PF5L ISCn (2 to 4)
;|||||| : 0 0: Port output
;|||||| : 0 1: Port input, timer input, or serial data
input
;|||||| : 1 0: Segment output
;||||||
;|||||+-------- ISC2
;||||| [RxD3/SEGxx/P50 schmitt trigger buffer control]
;||||| : 0 : Disables input
;||||| : 1 : Enables input
;|||||
;||||+--------- ISC3
;|||| [TI02/SEGxx/P52 schmitt trigger buffer control]
;|||| : 0 : Disables input
;|||| : 1 : Enables input
;||||
;|||+---------- ISC4
;||| [TI04/SEGxx/P53 schmitt trigger buffer control]
;||| : 0 : Disables input
;||| : 1 : Enables input
;|||
;+++----------- Be sure to set 0
; Wait for voltage boost wait time (500 ms or more) by using TM04 (10 ms)
MOV B, #(500/10)+1
MOV TS0L, #00010000B ; Timer channel start register 0
; +----------- TS04
; [Operation enable (start) trigger of channel 4]
; 0: No trigger operation
; 1: TE04 is set to 1 and the count operation becomes
enabled.
CLR1 TMIF04 ; Clear INTTM04 interrupt request
HINI600:
NOP
BF TMIF04,$HINI600 ; Wait 10 ms
DEC B
BNZ $HINI600
; LCD display on
SET1 SCOC ; Output deselected wave from all COM and SEG pins
;-------------------------------------------------------------------------------
; Specify the external interrupt valid edge
;-------------------------------------------------------------------------------
MOV EGN0, #00100110B ; Falling edge of INTP1, INTP2, and INTP5 valid
;-------------------------------------------------------------------------------
; Enable interrupts
DI ; Disable interrupt
CLR1 PIF1 ; Clear key interrupt request
CLR1 PIF2 ; Clear key interrupt request
CLR1 PIF5 ; Clear key interrupt request
;*******************************************************************************
;
; I/O port setting
;
;*******************************************************************************
SINIPORT:
;-------------------------------------------------------------------------------
; Specify the digital I/O
;-------------------------------------------------------------------------------
MOV ADPC, #00010000B ; A/D port configuration register
;|||+++++------- ADPC4 to ADPC0
;||| [Analog input (A)/digital I/O (D) switching]
;||| ++++---------- ANI15 to ANI8/P157 to P150
;||| ||||++++++++-- ANI7 to ANI0/P27 to P20
;||| 00000: AAAAAAAAAAAA
;||| 00001: AAAAAAAAAAAD
;||| 00010: AAAAAAAAAADD
;||| 00011: AAAAAAAAADDD
;||| 00100: AAAAAAAADDDD
;||| 00101: AAAAAAADDDDD
;||| 00110: AAAAAADDDDDD
;||| 00111: AAAAADDDDDDD
;||| 01000: AAAADDDDDDDD
;-------------------------------------------------------------------------------
; Initialize port 0
;-------------------------------------------------------------------------------
MOV P0, #00000000B ; Set the P00 to P02 output latches to low level
MOV PM0, #11111000B ; Specify P00 to P02 as output ports
; P00 to P02: Unused
;-------------------------------------------------------------------------------
; Initialize port 1
;-------------------------------------------------------------------------------
MOV P1, #00000000B ; Set the P10 to P16 output latches to low level
MOV PM1, #00000000B ; Specify P10 to P17 as output ports
; P10 to P17: Unused
;-------------------------------------------------------------------------------
; Initialize port 2
;-------------------------------------------------------------------------------
MOV P2, #00000000B ; Set the P20 to P27 output latches to low level
MOV PM2, #00000000B ; Specify P20 to P27 as output ports
; P20 to P27: Unused
;-------------------------------------------------------------------------------
; Initialize port 3
;-------------------------------------------------------------------------------
MOV P3, #00000000B ; Set the P30 to P34 output latches to low level
MOV PM3, #11100111B ; Specify P33 and P34 as output ports
; P33 and P34: Unused
MOV PU3, #00000111B ; Connect on-chip pull-up resistors to P30 to P32
;-------------------------------------------------------------------------------
; Initialize port 4
;-------------------------------------------------------------------------------
MOV P4, #00000000B ; Set the P40 and P41 output latches to low level
;-------------------------------------------------------------------------------
; Initialize port 5
;-------------------------------------------------------------------------------
MOV P5, #00000000B ; Set the P50 to P57 output latches to low level
MOV PM5, #00000000B ; Specify P50 to P57 as output ports
;-------------------------------------------------------------------------------
; Initialize port 6
;-------------------------------------------------------------------------------
MOV P6, #00000000B ; Set the P60 and P61 output latches to low level
MOV PM6, #11111100B ; Specify P60 and P61 as output ports
; P60 and P61: Unused
;-------------------------------------------------------------------------------
; Initialize port 7
;-------------------------------------------------------------------------------
MOV P7, #00000000B ; Set the P70 to P77 output latches to low level
MOV PM7, #00000000B ; Specify P70 to P77 as output ports
; P70 to P77: Unused
;-------------------------------------------------------------------------------
; Initialize port 8
;-------------------------------------------------------------------------------
MOV P8, #00000000B ; Set the P80 to P87 output latches to low level
MOV PM8, #00000000B ; Specify P80 to P87 as output ports
; P80 to P87: Unused
;-------------------------------------------------------------------------------
; Initialize port 9
;-------------------------------------------------------------------------------
MOV P9, #00000000B ; Set the P90 to P97 output latches to low level
MOV PM9, #00000000B ; Specify P90 to P97 as output ports
; P90 to P97: Unused
;-------------------------------------------------------------------------------
; Initialize port 10
;-------------------------------------------------------------------------------
MOV P10, #00000000B ; Set the P100 output latch to low level
MOV PM10, #11111000B ; Specify P100 to P102 as output ports
; P100 to P102: Unused
;-------------------------------------------------------------------------------
; Initialize port 11
;-------------------------------------------------------------------------------
MOV P11, #00000000B ; Set the P110 and P111 output latches to low level
MOV PM11, #11111100B ; Specify P110 and P111 as output ports
; P110 and P111: Unused
;-------------------------------------------------------------------------------
; Initialize port 12
;-------------------------------------------------------------------------------
MOV P12, #00000000B ; Set the P120 output latch to low level
MOV PM12, #11111110B ; Specify P120 as output port
; P120 to P124: Unused
; * P121 to P124 are input ports.
;-------------------------------------------------------------------------------
; Initialize port 13
;-------------------------------------------------------------------------------
MOV P13, #00000000B ; Set the P130 output latch to low level
; P130: Unused
;-------------------------------------------------------------------------------
; Initialize port 14
;-------------------------------------------------------------------------------
MOV P14, #00000000B ; Set the P140 to P147 output latches to low level
MOV PM14, #00000000B ; Specify P140 to P147 as output ports
; P140 to P147: Unused
;-------------------------------------------------------------------------------
; Initialize port 15
;-------------------------------------------------------------------------------
MOV P15, #00000000B ; Set the P150 to P152, and P157 output latches to low
level
MOV PM15, #01111000B ; Specify P150 to P152, and P157 as output ports
;*******************************************************************************
;
; Low-voltage detection
;
;-------------------------------------------------------------------------------
; Secure a supply voltage of 4.2 V or more by using the function of low-voltage detector.
;*******************************************************************************
SINILVI:
; Set up the low-voltage detector
SET1 LVIMK ; Disable the INTLVI interrupt
CLR1 LVISEL ; Specify VDD as the detection voltage
MOV LVIS, #00000000B ; Low-voltage detection level select register
;||||++++------- LVIS3 to LVIS0
;|||| [Detection level]
;|||| 0000: VLVI0 (4.22 ±0.1 V)
;|||| 0001: VLVI1 (4.07 ±0.1 V)
;|||| 0010: VLVI2 (3.92 ±0.1 V)
;|||| 0011: VLVI3 (3.76 ±0.1 V)
;|||| 0100: VLVI4 (3.61 ±0.1 V)
;|||| 0101: VLVI5 (3.45 ±0.1 V)
;|||| 0110: VLVI6 (3.30 ±0.1 V)
;|||| 0111: VLVI7 (3.15 ±0.1 V)
;|||| 1000: VLVI8 (2.99 ±0.1 V)
;|||| 1001: VLVI9 (2.84 ±0.1 V)
;|||| 1010: VLVI10 (2.68 ±0.1 V)
;|||| 1011: VLVI11 (2.53 ±0.1 V)
;|||| 1100: VLVI12 (2.38 ±0.1 V)
;|||| 1101: VLVI13 (2.22 ±0.1 V)
;|||| 1110: VLVI14 (2.07 ±0.1 V)
;|||| 1111: VLVI15 (1.91 ±0.1 V)
;++++----------- Be sure to set 0
CLR1 LVIMD ; Specify that an interrupt signal is generated when a
low voltage is detected
SET1 LVION ; Enable low-voltage detection
; Make the system wait until the low-voltage detector stabilizes (10 us or more)
; Make the system wait until VLVI is less than or equal to VDD
HRES300:
NOP
BT LVIF, $HRES300 ; VDD < VLVI? Yes,
CLR1 LVION ; Stop the low-voltage detector
RET
;*******************************************************************************
;
; Specify the clock frequency
;
;-------------------------------------------------------------------------------
; Specify the clock frequency so that the device can run on the internal high-speed
oscillation clock.
;*******************************************************************************
SINICLK:
MOV CMC, #00010000B ; Clock operation mode
;|||||||+------- AMPH
;||||||| [Control of high-speed system clock oscillation
frequency]
;||||||| 0: 2 MHz ≤ fMX < 10 MHz
;||||||| 1: 10 MHz < fMX ≤ 20 MHz
;|||||++-------- AMPHS1 and AMPHS0
;||||| [XT1 oscillator oscillation mode selection]
;||||| 00: Low power consumption oscillation (default)
;||||| 01: Normal oscillation
;||||| 10: Ultra-low power consumption oscillation
;||||| 11: Ultra-low power consumption oscillation
;||||+---------- Be sure to set 0
;|||+----------- OSCSELS
;||| [Subsystem clock pin operation mode]
;||| 0: Input port mode
RET
;*******************************************************************************
;
; Main loop
;
;*******************************************************************************
MAIN_LOOP:
HALT ; Wait for port scan timing
NOP
;-------------------------------------------------------------------------------
; Eliminate noise from key input
;-------------------------------------------------------------------------------
LMAIN120:
CLR1 PIF1 ; Clear key input interrupt request
CLR1 PIF2 ; Clear key input interrupt request
CLR1 PIF5 ; Clear key input interrupt request
MOV X, A ;
MOV TS0L, #00010000B ; Enable operation of timer channel 4
CLR1 TMIF04 ; Clear INTTM04 interrupt request
LMAIN160:
NOP
BF TMIF04,$LMAIN160 ; Wait 10 ms
;-------------------------------------------------------------------------------
; Clock adjustment
;-------------------------------------------------------------------------------
LMAIN280:
CLR1 RWAIT ; Start RTC count operation
BT RWST, $LMAIN280 ; Wait for start of RTC count operation
BR LMAIN790
LMAIN320:
MOV RADJSTAT,#1 ; Assume minutes being adjusted
BR LMAIN740
LMAIN360:
MOV RADJSTAT,#2 ; Assume hours being adjusted
BR LMAIN790
; UP key processing
LMAIN400:
CMP RADJSTAT,#0 ; Clock being displayed?
BZ $LMAIN680 ; Yes,
LMAIN460:
MOV A, RMIN
ADD A, #1 ; Minutes + 1
ADD A, !BCDADJ ; Decimal correction
CMP A, #60H ; 60 minutes?
BNZ $LMAIN480 ; No,
LMAIN560:
MOV A, RMIN
SUB A, #1 ; Minutes − 1
SUB A, !BCDADJ ; Decimal correction
BNC $LMAIN580 ; 59 minutes?, No,
LMAIN680:
BR MAIN_LOOP
;-------------------------------------------------------------------------------
; Update clock display
;-------------------------------------------------------------------------------
LMAIN720:
CLR1 RTCIF ; Clear constant-period interrupt request
CMP RADJSTAT,#0 ; Clock being displayed?
BNZ $LMAIN790 ; No,
LMAIN740:
SET1 RWAIT ; RTC value read/write mode
BF RWST, $LMAIN740 ; Wait for RTC read/write mode
LMAIN780:
CLR1 RWAIT ; Start RTC count operation
BT RWST, $LMAIN780 ; Wait for start of RTC count operation
LMAIN790:
MOV B, #0 ; ‘_’ not displayed
CMP RADJSTAT,#2 ; Hours being adjusted?
BNZ $LMAIN820 ; NO,
MOV B, #1 ; ‘_’ displayed
LMAIN820:
MOV A, RHOUR
AND A, #0F0H ; Digit of 10 hours
SHR A, 4
CMP0 A ; Digit of 10 hours = 0?
BNZ $LMAIN860 ; No,
MOV A, RHOUR
AND A, #0FH ; Digit of 1 hour
MOVW DE, #LOWW SEG10 ; LCD display position
CALL !!SLCDNUM ; Display digit of 1 hour
MOV A, RMIN
AND A, #0FH ; Digit of 1 minute
MOVW DE, #LOWW SEG28 ; LCD display position
CALL !!SLCDNUM ; Display digit of 1 minute
BR MAIN_LOOP
;*******************************************************************************
;
; Numeric display
; The numeric value of Acc (BCD) is displayed on the LCD display data memory specified
; by DE. ‘_’ is appended if the value of the B register is other than 0.
;
;*******************************************************************************
SLCDNUM:
ADD A, A
MOV X, A ; X = Value*2
ADD A, A ; A = Value*4
ADD X, A ; X = Value*(4+2)
CLRB A ; A = 0
ADDW AX, #LOWW TCHRDATA ; Value font start address
MOVW HL, AX
MOV C, #6 ; Value font size
JLCDN220:
MOV A, [HL] ; Read value font
CMP0 B ; ‘_’?
BZ $JLCDN260 ; No,
RET
; COM76543210
DB 00111110B ; ‘0’
DB 01000001B
DB 01000001B
DB 01000001B
DB 00111110B
DB 00000000B
; COM76543210
DB 00000000B ; ‘1’
DB 00000000B
DB 00000010B
DB 01111111B
DB 00000000B
DB 00000000B
; COM76543210
DB 01000010B ; ‘2’
DB 01100001B
DB 01010001B
DB 01001001B
DB 01000110B
DB 00000000B
; COM76543210
DB 00100010B ; ‘3’
DB 01001001B
DB 01001001B
DB 01001001B
DB 00110110B
DB 00000000B
; COM76543210
DB 00111100B ; ‘4’
DB 00100010B
DB 00100001B
DB 01111111B
DB 00100000B
DB 00000000B
; COM76543210
DB 00100111B ; ‘5’
DB 01000101B
DB 01000101B
DB 01000101B
DB 00111001B
DB 00000000B
; COM76543210
DB 00111110B ; ‘6’
DB 01001001B
DB 01001001B
DB 01001001B
DB 00110010B
DB 00000000B
; COM76543210
DB 00000001B ; ‘7’
DB 01110001B
DB 00001001B
DB 00000101B
DB 00000011B
DB 00000000B
; COM76543210
DB 00110110B ; ‘8’
DB 01001001B
DB 01001001B
DB 01001001B
DB 00110110B
DB 00000000B
; COM76543210
DB 00100110B ; ‘9’
DB 01001001B
DB 01001001B
DB 01001001B
DB 00111110B
DB 00000000B
; COM76543210
DB 00000000B ; ‘ ’
DB 00000000B
DB 00000000B
DB 00000000B
DB 00000000B
DB 00000000B
; COM76543210
DB 00000000B ; ‘:’
DB 00000000B
DB 00100100B
DB 00000000B
DB 00000000B
DB 00000000B
end
********************************************************************************
78K0R/LH3 Series Sample Program
(LCD Driver, Real-Timer Counter Used)
********************************************************************************
LCD Display Clock
********************************************************************************
<<History>>
2009.3.-- Release
********************************************************************************
<<Overview>>
This sample program shows an example of using the LCD driver and real-time counter.
It displays time in a 24-hour system. Time can be adjusted by using three keys (SET,
UP, and DOWN). The Internal voltage boosting method is selected to drive the LCD driver.
*******************************************************************************/
/*==============================================================================
==============================================================================*/
#pragma SFR /* SFR names can be described at the C source level */
#pragma DI /* DI instructions can be described at the C source level */
#pragma EI /* EI instructions can be described at the C source level */
#pragma NOP /* NOP instructions can be described at the C source level */
/*==============================================================================
==============================================================================*/
void fn_InitPort( void ); /* I/O port setting */
void fn_InitLvi( void ); /* Low voltage detection */
void fn_InitClock( void ); /* Clock frequency setting */
void fn_LcdNum(unsigned char *ucSeg, unsigned char ucNum, unsigned char ucUnderbar);
/* Display number on LCD */
/*==============================================================================
Variable definition
==============================================================================*/
unsigned char ucAdjStatus; /* Clock adjustment status */
unsigned char ucMinute; /* Store minutes data for display and time adjustment */
unsigned char ucHour; /* Store hours data for display and time adjustment */
/*******************************************************************************
*******************************************************************************/
void hdwinit( void )
{
unsigned char count; /* Set work */
unsigned char *wkptr; /* Set work pointer */
/*------------------------------------------------------------------------------
Disable interrupts
------------------------------------------------------------------------------*/
DI(); /* Disable interrupts */
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
Low-voltage detection
------------------------------------------------------------------------------*/
fn_InitLvi(); /* Secure a supply voltage of 4.2 V or more */
/*------------------------------------------------------------------------------
Specify the clock frequency
------------------------------------------------------------------------------*/
fn_InitClock(); /* Operate internal high-speed oscillation clock at 8 MHz */
/*-------------------------------------------------------------------------------
Specify the real-time counter
-------------------------------------------------------------------------------
- Set count start time to 0:00:00
- Set constant-period interrupt (1-minute period) and alarm interrupt
-------------------------------------------------------------------------------*/
/* Control real-time counter control clock */
PER0 = 0b10000000;
/* |+++++++------- Be sure to set 0 */
/* +-------------- RTCEN */
/* [Real-time counter control clock] */
/* 0: Stops control clock supply */
/* 1: Supplies control clock */
day) */
/* ||||| 11x: Once per 1 month (Day 1, hour 00 a.m., minute 00, and second
00 of every month) */
/* ||||+---------- AMPM */
/* |||| [Selection of 12-/24-hour system] */
/* |||| 0: 12-hour system (a.m. and p.m. are displayed.) */
/* |||| 1: 24-hour system */
/* |||+----------- RCLOE0 */
/* ||| [RTCCL pin output control] */
/* ||| 0: Disables output of RTCCL pin (32.768 kHz) */
/* ||| 1: Enables output of RTCCL pin (32.768 kHz) */
/* ||+------------ RCLOE1 */
/* || [RTC1HZ pin output control] */
/* || 0: Disables output of RTC1HZ pin (1 Hz) */
/* || 1: Enables output of RTC1HZ pin (1 Hz) */
/* |+------------- Be sure to set 0 */
/* +-------------- RTCE */
/* [Real-time counter operation control] */
/* 0: Stops counter operation */
/* 1: Starts counter operation */
/* Set count start time (Year 00, month 01, day 01, Saturday, hour 08 a.m., minute 59,
second 50) */
SEC = 0x00; /* Second: 00 */
MIN = 0x00; /* Minute: 00 */
HOUR = 0x00; /* Hour: 00 */
/* Wait until device enters STOP mode immediately after real-time counter starts operating
*/
for(count = 124; count > 0; count--){ /* * To place the device in the STOP mode */
NOP(); /* immediately after RTCE has been set to */
} /* 1, place the device in the STOP mode */
/* after duration of two subsystem clocks
(about 62 us) or more after RTCE has been set to 1. */
/*-------------------------------------------------------------------------------
Specify the timer array unit
-------------------------------------------------------------------------------
Set so that the D/A output and DMA function can be used.
- Channel 4: Used as master channel in interval timer mode
-------------------------------------------------------------------------------*/
/* Initial settings of timer array unit */
TAU0EN = 1; /* Supply input clock of timer array unit */
/*-------------------------------------------------------------------------------
Specify the LCD driver
-------------------------------------------------------------------------------
Set so that the LCD driver function can be used.
-------------------------------------------------------------------------------*/
*/
/*|| */
/*|+------------- SCOC */
/*+-------------- LCDON */
/* [LCD display enable/disable] */
/* LCDON SCOC */
/* 0 0 : Output ground level to segment/common pin */
/* 0 1 : Display off */
/* 1 0 : Output ground level to segment/common pin */
/* 1 1 : Display on */
/* Wait for reference voltage setup time (2 ms or more) by using TM04 (2 ms) */
VLCON = 1; /* Enable voltage boost circuit and capacitor split circuit operation
*/
/* Wait for voltage boost wait time (500 ms or more) by using TM04 (10 ms) */
SCOC = 1; /* Output deselected wave from all COM and SEG pins */
LCDON = 1; /* LCD display on */
/*-------------------------------------------------------------------------------
Specify the external interrupt valid edge
-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------
/* Enable interrupts
/* (To use interrupts, enable interrupts here.)
/*-------------------------------------------------------------------------------*/
/*******************************************************************************
*******************************************************************************/
void fn_InitPort( void )
{
/*------------------------------------------------------------------------------
Specify the digital I/O
------------------------------------------------------------------------------*/
ADPC = 0b00010000; /* A/D port configuration register */
/* |||+++++--- ADPC4 to ADPC0 */
/* ||| [Analog input (A)/digital I/O (D) switching] */
/* ||| +------------- ANI15/P157 */
/* ||| |+++---------- ANI10 to ANI8/P152 to P150 */
/* ||| ||||++++++++-- ANI7 to ANI0/P27 to P20 */
/* ||| 00000: AAAAAAAAAAAA */
/*------------------------------------------------------------------------------
Initialize port 0
------------------------------------------------------------------------------*/
P0 = 0b00000000; /* Set the P00 to P02 output latches to low level */
PM0 = 0b11111000; /* Specify P00 to P02 as output ports */
/* P00 to P02: Unused */
/*------------------------------------------------------------------------------
Initialize port 1
------------------------------------------------------------------------------*/
P1 = 0b00000000; /* Set the P10 to P17 output latches to low level */
PM1 = 0b00000000; /* Specify P10 to P17 as output ports */
/* P10 to P17: Unused */
/*------------------------------------------------------------------------------
Initialize port 2
------------------------------------------------------------------------------*/
P2 = 0b00000000; /* Set the P20 to P27 output latches to low level */
PM2 = 0b00000000; /* Specify P20 to P27 as output ports */
/*------------------------------------------------------------------------------
Initialize port 3
------------------------------------------------------------------------------*/
P3 = 0b00000000; /* Set the P30 to P34 output latches to low level */
/*------------------------------------------------------------------------------
Initialize port 4
------------------------------------------------------------------------------*/
P4 = 0b00000000; /* Set the P40 and P41 output latches to low level */
PM4 = 0b11111100; /* Specify P40 and P41 as output ports */
/* P40 and P41: Unused */
/*------------------------------------------------------------------------------
Initialize port 5
------------------------------------------------------------------------------*/
P5 = 0b00000000; /* Set the P50 to P57 output latches to low level */
PM5 = 0b00000000; /* Specify P50 to P57 as output ports */
/*------------------------------------------------------------------------------
Initialize port 6
------------------------------------------------------------------------------*/
P6 = 0b00000000; /* Set the P60 and P61 output latches to low level */
PM6 = 0b11111100; /* Specify P60 and P61 as output ports */
/* P60 and P61: Unused */
/*-------------------------------------------------------------------------------
Initialize port 7
-------------------------------------------------------------------------------*/
P7 = 0b00000000; /* Set the P70 to P77 output latches to low level */
PM7 = 0b00000000; /* Specify P70 to P77 as output ports */
/* P70 to P77: Unused */
/*------------------------------------------------------------------------------
Initialize port 8
------------------------------------------------------------------------------*/
P8 = 0b00000000; /* Set the P80 to P87 output latches to low level */
PM8 = 0b00000000; /* Specify P80 to P87 as output ports */
/* P80 to P87: Unused */
/*------------------------------------------------------------------------------
Initialize port 9
------------------------------------------------------------------------------*/
P9 = 0b00000000; /* Set the P90 to P97 output latches to low level */
PM9 = 0b00000000; /* Specify P90 to P97 as output ports */
/* P90 to P97: Unused */
/*------------------------------------------------------------------------------
Initialize port 10
------------------------------------------------------------------------------*/
P10 = 0b00000000; /* Set the P100 to P102 output latches to low level */
PM10 = 0b11111000; /* Specify P100 to P102 as output ports */
/* P100 to P102: Unused */
/*------------------------------------------------------------------------------
Initialize port 11
------------------------------------------------------------------------------*/
P11 = 0b00000000; /* Set the P110 and P111 output latches to low level */
PM11 = 0b11111100; /* Specify P110 and P111 as output ports */
/* P110 and P111: Unused */
/*------------------------------------------------------------------------------
Initialize port 12
------------------------------------------------------------------------------*/
P12 = 0b00000000; /* Set the P120 output latch to low level */
PM12 = 0b11111110; /* Specify P120 as output port */
/* P120 to P124: Unused */
/* * P121 to P124 are input-only ports. */
/*-------------------------------------------------------------------------------
Initialize port 13
-------------------------------------------------------------------------------*/
P13 =0b00000000; /* Set the P130 output latch to low level */
/* P130: Unused */
/*------------------------------------------------------------------------------
Initialize port 14
------------------------------------------------------------------------------*/
P14 = 0b00000000; /* Set the P140 to P147 output latches to low level */
/*------------------------------------------------------------------------------
Initialize port 15
------------------------------------------------------------------------------*/
P15 = 0b00000000; /* Set the P150 to P152, and P157 output latches to low level */
PM15 = 0b01111000; /* Specify P150 to P152, and P157 as output ports */
/* P150 to P152, and P157: Unused */
}
/*******************************************************************************
Low-voltage detection
--------------------------------------------------------------------------------
Secure a supply voltage of 4.2 V or more by using the function of low-voltage detector.
*******************************************************************************/
void fn_InitLvi( void )
{
unsigned char ucCounter; /* Count variable */
/* Make the system wait until the low-voltage detector stabilizes (10 us or more) */
for( ucCounter = 0; ucCounter < 4; ucCounter++ ){
NOP();
}
/* Make the system wait until VLVI is less than or equal to VDD */
while( LVIF ){
NOP();
}
LVION = 0; /* Stop the low-voltage detector */
}
/*******************************************************************************
--------------------------------------------------------------------------------
Specify the clock frequency so that the device can run on the internal high-speed oscillation
clock.
*******************************************************************************/
void fn_InitClock( void )
{
CMC = 0b00010000; /* Clock operation mode */
/* |||||||+--- AMPH */
/* ||||||| [Control of high-speed system clock oscillation frequency] */
/* ||||||| 0: 2 MHz ≤ fMX < 10 MHz */
/* ||||||| 1: 10 MHz < fMX ≤ 20 MHz */
/* |||||++---- AMPHS1 and AMPHS0 */
/* ||||| [XT1 oscillator oscillation mode selection] */
/*******************************************************************************
Main loop
*******************************************************************************/
void main(void)
{
unsigned char ucKeyin; /* Key input buffer */
unsigned char ucUnderbarStatus; /* ‘_’ display status */
unsigned char ucNumWork; /* Work for function parameters */
/*-------------------------------------------------------------------------------
Initialize the RAM
-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------
Normal processing
-------------------------------------------------------------------------------*/
while (1){
HALT(); /* Wait for key input or 1 minute */
NOP();
/*-------------------------------------------------------------------------------
Update clock display after 1 minute has passed
-------------------------------------------------------------------------------*/
}
}
/*-------------------------------------------------------------------------------
Eliminate noise from key input
-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------
Key processing
-------------------------------------------------------------------------------*/
default:
;
}
break;
default:
;
}
break;
if(ucMinute == 0x99){
ucMinute = 0x59; /* Borrow correction */
}
break;
default:
;
}
break;
/*-------------------------------------------------------------------------------
Clock display
-------------------------------------------------------------------------------*/
}
fn_LcdNum(&SEG4, ucNumWork, ucUnderbarStatus); /* Display digit of 10 hours */
}
}
/********************************************************************************
Font data definition
********************************************************************************/
const unsigned char aucFontData[12][6] = {
{/* COM76543210 */
0b00111110, /* ‘0’ */
0b01000001,
0b01000001,
0b01000001,
0b00111110,
0b00000000
},
{/* COM76543210 */
0b00000000, /* ‘1’ */
0b00000000,
0b00000010,
0b01111111,
0b00000000,
0b00000000
},
{/* COM76543210 */
0b01000010, /* ‘2’ */
0b01100001,
0b01010001,
0b01001001,
0b01000110,
0b00000000
},
{/* COM76543210 */
0b00100010, /* ‘3’ */
0b01001001,
0b01001001,
0b01001001,
0b00110110,
0b00000000
},
{/* COM76543210 */
0b00111100, /* ‘4’ */
0b00100010,
0b00100001,
0b01111111,
0b00100000,
0b00000000
},
{/* COM76543210 */
0b00100111, /* ‘5’ */
0b01000101,
0b01000101,
0b01000101,
0b00111001,
0b00000000
},
{/* COM76543210 */
0b00111110, /* ‘6’ */
0b01001001,
0b01001001,
0b01001001,
0b00110010,
0b00000000
},
{/* COM76543210 */
0b00000001, /* ‘7’ */
0b01110001,
0b00001001,
0b00000101,
0b00000011,
0b00000000
},
{/* COM76543210 */
0b00110110, /* ‘8’ */
0b01001001,
0b01001001,
0b01001001,
0b00110110,
0b00000000
},
{/* COM76543210 */
0b00100110, /* ‘9’ */
0b01001001,
0b01001001,
0b01001001,
0b00111110,
0b00000000
},
{/* COM76543210 */
0b00000000, /* ‘ ’ */
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
},
{/* COM76543210 */
0b00000000, /* ‘:’ */
0b00000000,
0b00100100,
0b00000000,
0b00000000,
0b00000000
}
};
/********************************************************************************
Numeric display
The numeric value of ucNum (BCD) is displayed on the LCD display data memory specified
by ucSeg. ‘_’ is appended if the value of ucUnderbar is other than 0.
********************************************************************************/
void fn_LcdNum(unsigned char *ucSeg, unsigned char ucNum, unsigned char ucUnderbar)
{
unsigned char ucFontIndex; /* Index for font */
unsigned char ucFontWork; /* Store font for underbar */
unsigned char *ucSegPtr; /* LCD display data memory pointer */
if(ucUnderbar == 0){
ucFontWork = 0b00000000; /* No underbar */
}
else{
NEC Electronics America, Inc. NEC Electronics (Europe) GmbH NEC Electronics (China) Co., Ltd
2880 Scott Blvd. Arcadiastrasse 10 7th Floor, Quantum Plaza, No. 27 ZhiChunLu Haidian
Santa Clara, CA 95050-2554, U.S.A. 40472 Düsseldorf, Germany District, Beijing 100083, P.R.China
Tel: 408-588-6000 Tel: 0211-65030 Tel: 010-8235-1155
800-366-9782 http://www.eu.necel.com/ http://www.cn.necel.com/
http://www.am.necel.com/
Hanover Office Shanghai Branch
Podbielskistrasse 166 B Room 2509-2510, Bank of China Tower,
30177 Hannover 200 Yincheng Road Central,
Tel: 0 511 33 40 2-0 Pudong New Area, Shanghai, P.R.China P.C:200120
Tel:021-5888-5400
Munich Office http://www.cn.necel.com/
Werner-Eckert-Strasse 9
81829 München Shenzhen Branch
Tel: 0 89 92 10 03-0 Unit 01, 39/F, Excellence Times Square Building,
Stuttgart Office No. 4068 Yi Tian Road, Futian District, Shenzhen,
Industriestrasse 3 P.R.China P.C:518048
70565 Stuttgart Tel:0755-8282-9800
Tel: 0 711 99 01 0-0 http://www.cn.necel.com/
United Kingdom Branch
NEC Electronics Hong Kong Ltd.
Cygnus House, Sunrise Parkway Unit 1601-1613, 16/F., Tower 2, Grand Century Place,
Linford Wood, Milton Keynes 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
MK14 6NP, U.K. Tel: 2886-9318
Tel: 01908-691-133 http://www.hk.necel.com/
Succursale Française
9, rue Paul Dautier, B.P. 52 NEC Electronics Taiwan Ltd.
78142 Velizy-Villacoublay Cédex 7F, No. 363 Fu Shing North Road
France Taipei, Taiwan, R. O. C.
Tel: 01-3067-5800 Tel: 02-8175-9600
http://www.tw.necel.com/
Sucursal en España
Juan Esplandiu, 15
NEC Electronics Singapore Pte. Ltd.
28007 Madrid, Spain
238A Thomson Road,
Tel: 091-504-2787
#12-08 Novena Square,
Tyskland Filial Singapore 307684
Täby Centrum Tel: 6253-8311
Entrance S (7th floor) http://www.sg.necel.com/
18322 Täby, Sweden
Tel: 08 638 72 00 NEC Electronics Korea Ltd.
11F., Samik Lavied’or Bldg., 720-2,
Filiale Italiana
Yeoksam-Dong, Kangnam-Ku,
Via Fabio Filzi, 25/A
Seoul, 135-080, Korea
20124 Milano, Italy
Tel: 02-558-3737
Tel: 02-667541
http://www.kr.necel.com/
Branch The Netherlands
Steijgerweg 6
5616 HS Eindhoven
The Netherlands
Tel: 040 265 40 10
G0706