Sample Program API Manual

SQ003116E101
ML610Q400 Series
Sample Program API Manual
3rd Edition
Issue Date: April 16, 2010
NOTICE
No copying or reproduction of this document, in part or in whole, is permitted without the consent of LAPIS Semiconductor
Co., Ltd.
The content specified herein is subject to change for improvement without notice.
The content specified herein is for the purpose of introducing LAPIS Semiconductor's products (hereinafter "Products"). If you
wish to use any such Product, please be sure to refer to the specifications, which can be obtained from LAPIS Semiconductor
upon request.
Examples of application circuits, circuit constants and any other information contained herein illustrate the standard usage and
operations of the Products. The peripheral conditions must be taken into account when designing circuits for mass production.
Great care was taken in ensuring the accuracy of the information specified in this document. However, should you incur any
damage arising from any inaccuracy or misprint of such information, LAPIS Semiconductor shall bear no responsibility for
such damage.
The technical information specified herein is intended only to show the typical functions of and examples of application
circuits for the Products. LAPIS Semiconductor does not grant you, explicitly or implicitly, any license to use or exercise
intellectual property or other rights held by LAPIS Semiconductor and other parties. LAPIS Semiconductor shall bear no
responsibility whatsoever for any dispute arising from the use of such technical information.
The Products specified in this document are intended to be used with general-use electronic equipment or devices (such as
audio visual equipment, office-automation equipment, communication devices, electronic appliances and amusement devices).
The Products specified in this document are not designed to be radiation tolerant.
While LAPIS Semiconductor always makes efforts to enhance the quality and reliability of its Products, a Product may fail or
malfunction for a variety of reasons.
Please be sure to implement in your equipment using the Products safety measures to guard against the possibility of physical
injury, fire or any other damage caused in the event of the failure of any Product, such as derating, redundancy, fire control and
fail-safe designs. LAPIS Semiconductor shall bear no responsibility whatsoever for your use of any Product outside of the
prescribed scope or not in accordance with the instruction manual.
The Products are not designed or manufactured to be used with any equipment, device or system which requires an extremely
high level of reliability the failure or malfunction of which may result in a direct threat to human life or create a risk of human
injury (such as a medical instrument, transportation equipment, aerospace machinery, nuclear-reactor controller, fuel-controller
or other safety device). LAPIS Semiconductor shall bear no responsibility in any way for use of any of the Products for the
above special purposes. If a Product is intended to be used for any such special purpose, please contact a ROHM sales
representative before purchasing.
If you intend to export or ship overseas any Product or technology specified herein that may be controlled under the Foreign
Exchange and the Foreign Trade Law, you will be required to obtain a license or permit under the Law.
Copyright 2009 - 2011 LAPIS Semiconductor Co., Ltd.
ML610Q400 Series
Sample Program API Manual
Table of Contents
1.
2.
3.
Overview ......................................................................................................................................................................1
Module APIs.................................................................................................................................................................1
Module Description......................................................................................................................................................2
3.1. SA-ADC Module..................................................................................................................................................2
3.1.1.
Overview of Functions .................................................................................................................................2
3.1.2.
List of APIs...................................................................................................................................................2
3.1.3.
List of Constants...........................................................................................................................................3
3.1.4.
API Details ...................................................................................................................................................5
3.1.4.1.
saAdc_init Function..............................................................................................................................5
3.1.4.2.
saAdc_short_CH0CH1_on Function ....................................................................................................7
3.1.4.3.
saAdc_short_CH0CH1_off Function ...................................................................................................7
3.1.4.4.
saAdc_execute Function.......................................................................................................................8
3.1.4.5.
saAdc_checkFin Function ....................................................................................................................9
3.1.4.6.
saAdc_getResult Function ..................................................................................................................10
3.2. RC-ADC Module ............................................................................................................................................... 11
3.2.1.
Overview of Functions ............................................................................................................................... 11
3.2.2.
List of APIs................................................................................................................................................. 11
3.2.3.
List of Constants......................................................................................................................................... 11
3.2.4.
API Details .................................................................................................................................................13
3.2.4.1.
rcAdc_init Function............................................................................................................................13
3.2.4.2.
rcAdc_setCounter Function ................................................................................................................15
3.2.4.3.
rcAdc_execute Function .....................................................................................................................16
3.2.4.4.
rcAdc_checkFin Function...................................................................................................................17
3.2.4.5.
rcAdc_getResult Function ..................................................................................................................18
3.2.4.6.
rcAdc_monitor_on Function...............................................................................................................19
3.2.4.7.
rcAdc_monitor_off Function ..............................................................................................................20
3.3. Temperature Calculation Module .......................................................................................................................21
3.3.1.
Overview of Functions ...............................................................................................................................21
3.3.2.
List of APIs.................................................................................................................................................21
3.3.3.
List of Constants.........................................................................................................................................21
3.3.4.
Structures....................................................................................................................................................21
3.3.5.
API Details .................................................................................................................................................22
3.3.5.1.
temp_calc Function.............................................................................................................................22
3.4. UART Module ....................................................................................................................................................23
3.4.1.
Overview of Functions ...............................................................................................................................23
3.4.2.
List of APIs.................................................................................................................................................23
3.4.3.
Callback Function.......................................................................................................................................23
3.4.4.
List of Constants.........................................................................................................................................24
3.4.5.
Structures....................................................................................................................................................25
3.4.6.
List of Variables..........................................................................................................................................25
3.4.7.
API Details .................................................................................................................................................26
3.4.7.1.
uart_init Function ...............................................................................................................................26
3.4.7.2.
uart_startSend Function......................................................................................................................29
3.4.7.3.
uart_startReceive Function .................................................................................................................31
3.4.7.4.
uart_continue Function .......................................................................................................................32
3.4.7.5.
uart_stop Function ..............................................................................................................................34
3.4.7.6.
uart_checkIRQ Function.....................................................................................................................35
3.4.7.7.
uart_clearIRQ Function ......................................................................................................................35
3.4.7.8.
uart_getTransSize Function ................................................................................................................36
3.4.7.9.
uart_PortClear Function .....................................................................................................................37
3.4.7.10. uart_PortSet Function .........................................................................................................................37
3.5. UART Baud Rate Correction Module ................................................................................................................38
3.5.1.
Overview of Functions ...............................................................................................................................38
3.5.2.
List of APIs.................................................................................................................................................38
3.5.3.
List of Constants.........................................................................................................................................38
3.5.4.
List of Variables..........................................................................................................................................39
3.5.5.
Details of APIs............................................................................................................................................40
3.5.5.1.
adjustBaudrate_startCount Function...................................................................................................40
3.5.5.2.
adjustBaudrate_checkCountFin Function...........................................................................................42
Contents − 1
ML610Q400 Series
Sample Program API Manual
3.5.5.3.
adjustBaudrate_getCount Function.....................................................................................................42
3.5.5.4.
adjustBaudrate_setBRT Function .......................................................................................................43
3.5.5.5.
adjustBaudrate_intCount Function .....................................................................................................44
3.5.5.6.
adjustBaudrate_intCountTM3 Function .............................................................................................46
3.6. I2C Module.........................................................................................................................................................47
3.6.1.
Overview of Functions ...............................................................................................................................47
3.6.2.
List of APIs.................................................................................................................................................47
3.6.3.
Callback Function.......................................................................................................................................47
3.6.4.
List of Constants.........................................................................................................................................48
3.6.5.
Structure .....................................................................................................................................................48
3.6.6.
List of Variables..........................................................................................................................................49
3.6.7.
Details of APIs............................................................................................................................................49
3.6.7.1.
i2c_init Function.................................................................................................................................49
3.6.7.2.
i2c_startSend Function .......................................................................................................................54
3.6.7.3.
i2c_startReceive Function ..................................................................................................................56
3.6.7.4.
i2c_continue Function ........................................................................................................................58
3.6.7.5.
i2c_stop Function ...............................................................................................................................66
3.6.7.6.
i2c_checkIRQ Function ......................................................................................................................67
3.6.7.7.
i2c_clearIRQ Function .......................................................................................................................68
3.6.7.8.
i2c_getTransSize Function .................................................................................................................69
3.7. EEPROM Module ..............................................................................................................................................70
3.7.1.
Overview of Functions ...............................................................................................................................70
3.7.2.
List of APIs.................................................................................................................................................70
3.7.3.
List of Constants.........................................................................................................................................70
3.7.4.
Structure .....................................................................................................................................................71
3.7.5.
List of Variables..........................................................................................................................................71
3.7.6.
Details of APIs............................................................................................................................................72
3.7.6.1.
eeprom_init Function..........................................................................................................................72
3.7.6.2.
eeprom_write Function.......................................................................................................................73
3.7.6.3.
eeprom_read Function ........................................................................................................................74
3.7.6.4.
eeprom_continue Function .................................................................................................................75
3.7.6.5.
eeprom_stop Function ........................................................................................................................77
3.7.6.6.
eeprom_getStatus Function ................................................................................................................78
3.7.6.7.
eeprom_writeProtect Function............................................................................................................79
3.8. LCD Module.......................................................................................................................................................80
3.8.1.
Overview of Functions ...............................................................................................................................80
3.8.2.
List of APIs.................................................................................................................................................80
3.8.3.
List of Subroutines .....................................................................................................................................80
3.8.4.
List of Constants.........................................................................................................................................81
3.8.5.
API Details .................................................................................................................................................87
3.8.5.1.
lcd_init Function.................................................................................................................................87
3.8.5.2.
lcd_setContrast Function ....................................................................................................................89
3.8.5.3.
lcd_setLCDMode Function ................................................................................................................90
3.8.5.4.
lcd_dispHour Function .......................................................................................................................91
3.8.5.5.
lcd_dispMin Function.........................................................................................................................92
3.8.5.6.
lcd_dispSec Function..........................................................................................................................93
3.8.5.7.
lcd_dispMain Function .......................................................................................................................94
3.8.5.8.
lcd_disp1Digit Function .....................................................................................................................95
3.8.5.9.
lcd_disp2Digit Function .....................................................................................................................97
3.8.5.10. lcd_disp4Digit Function .....................................................................................................................99
3.8.5.11.
lcd_dispMark Function.....................................................................................................................101
3.8.5.12. lcd_dispTemp Function ....................................................................................................................102
3.8.5.13. lcd_dispMode Function ....................................................................................................................103
3.8.5.14. lcd_dispClear Function.....................................................................................................................104
3.9. Key Read-In Module ........................................................................................................................................105
3.9.1.
Overview of Functions .............................................................................................................................105
3.9.2.
Key Read-In Timing Diagram ..................................................................................................................105
3.9.3.
List of APIs...............................................................................................................................................106
3.9.4.
List of Constants.......................................................................................................................................106
3.9.5.
List of Variables........................................................................................................................................106
3.9.6.
API Details ...............................................................................................................................................107
3.9.6.1.
key_init Function..............................................................................................................................107
Contents − 2
ML610Q400 Series
Sample Program API Manual
3.9.6.2.
key_start Function ............................................................................................................................108
3.9.6.3.
key_stop Function.............................................................................................................................109
3.9.6.4.
key_getEvent Function ..................................................................................................................... 110
3.10.
Melody Module ............................................................................................................................................ 111
3.10.1. Overview of Functions ............................................................................................................................. 111
3.10.2. List of APIs............................................................................................................................................... 111
3.10.3. List of Constants....................................................................................................................................... 112
3.10.4. Structure ................................................................................................................................................... 114
3.10.5. List of Variables........................................................................................................................................ 114
3.10.6. Melody Output Data Format..................................................................................................................... 114
3.10.7. Details of APIs.......................................................................................................................................... 115
3.10.7.1. melody_init Function........................................................................................................................ 115
3.10.7.2. melody_start Function ...................................................................................................................... 116
3.10.7.3. melody_stop Function ...................................................................................................................... 117
3.10.7.4. melody_continue Function ............................................................................................................... 118
3.10.7.5. melody_checkoutput Function.......................................................................................................... 119
3.10.7.6. melody_checkIRQ Function.............................................................................................................120
3.10.7.7. melody_clearIRQ Function ..............................................................................................................121
3.10.7.8. buzzer_start Function .......................................................................................................................122
3.10.7.9. buzzer_stop Function........................................................................................................................124
3.11.
Real Time Clock Control Module ................................................................................................................125
3.11.1. Overview of Functions .............................................................................................................................125
3.11.2. List of APIs...............................................................................................................................................125
3.11.3. List of Constants.......................................................................................................................................126
3.11.4. Structure ...................................................................................................................................................127
3.11.5. Details of APIs..........................................................................................................................................128
3.11.5.1.
rtc_setTime Function ........................................................................................................................128
3.11.5.2.
rtc_getTime Function........................................................................................................................131
3.11.5.3.
rtc_start Function..............................................................................................................................132
3.11.5.4.
rtc_stop Function ..............................................................................................................................132
3.11.5.5.
rtc_setRegularInt Function ...............................................................................................................133
3.11.5.6.
rtc_setAlarm0 Function ....................................................................................................................134
3.11.5.7.
rtc_setAlarm1 Function ....................................................................................................................136
3.11.5.8.
rtc_getAlarm0 Function....................................................................................................................139
3.11.5.9.
rtc_getAlarm1 Function....................................................................................................................140
3.12.
Timer Module ...............................................................................................................................................141
3.12.1. Overview of Functions .............................................................................................................................141
3.12.2. List of APIs...............................................................................................................................................141
3.12.3. List of Constants.......................................................................................................................................141
3.12.4. API Details ...............................................................................................................................................142
3.12.4.1. tm_init Function ...............................................................................................................................142
3.12.4.2. tm_start Function..............................................................................................................................144
3.12.4.3. tm_stop Function ..............................................................................................................................145
3.12.4.4. tm_checkOvf Function .....................................................................................................................146
3.12.4.5. tm_clearOvf Function.......................................................................................................................147
3.12.4.6. tm_checkFmFunction .......................................................................................................................148
3.13.
Clock Control Module..................................................................................................................................149
3.13.1. Overview of Functions .............................................................................................................................149
3.13.2. List of Functions.......................................................................................................................................149
3.13.3. List of System Definition Functions.........................................................................................................149
3.13.4. List of Constants.......................................................................................................................................150
3.13.5. List of Variables........................................................................................................................................150
3.13.6. Details of APIs..........................................................................................................................................151
3.13.6.1. clk_setSysclk Function .....................................................................................................................151
3.13.6.2. clk_getSysclk Function.....................................................................................................................154
3.13.6.3. clk_setHsclk Function ......................................................................................................................156
3.13.6.4. clk_enaHsclk Function .....................................................................................................................158
3.13.6.5. clk_disHsclk Function ......................................................................................................................158
3.13.6.6. clk_getHsclk Function......................................................................................................................159
3.13.6.7. clk_enaLsclk2 Function....................................................................................................................160
3.13.6.8. clk_disLsclk2 Function.....................................................................................................................160
3.13.7. System Definition Function......................................................................................................................161
Contents − 3
ML610Q400 Series
Sample Program API Manual
3.13.7.1. clk_wait500us Function....................................................................................................................161
3.14.
Time Base-Counter Control Module ............................................................................................................162
3.14.1. Overview of Functions .............................................................................................................................162
3.14.2. List of APIs...............................................................................................................................................162
3.14.3. List of Constants.......................................................................................................................................162
3.14.4. Details of APIs..........................................................................................................................................163
3.14.4.1. tb_setHtbdiv Function ......................................................................................................................163
3.14.4.2. tb_getHtbdiv Function......................................................................................................................164
3.15.
1kHz Timer Control Module ........................................................................................................................165
3.15.1. Overview of Functions .............................................................................................................................165
3.15.2. List of APIs...............................................................................................................................................165
3.15.3. List of Constants.......................................................................................................................................165
3.15.4. Details of APIs..........................................................................................................................................166
3.15.4.1. t1k_init Function ..............................................................................................................................166
3.15.4.2. t1k_start Function .............................................................................................................................166
3.15.4.3. t1k_stop Function .............................................................................................................................167
3.15.4.4. t1k_getT1KCR Function ..................................................................................................................167
3.15.4.5. t1k_clrT1KCR Function ...................................................................................................................168
3.15.4.6. t1km_checkOvf Function .................................................................................................................168
3.16.
Stopwatch Module........................................................................................................................................169
3.16.1. Overview of Functions .............................................................................................................................169
3.16.2. List of APIs...............................................................................................................................................169
3.16.3. List of Constants.......................................................................................................................................169
3.16.4. Structure ...................................................................................................................................................170
3.16.5. List of Variables........................................................................................................................................170
3.16.6. Details of APIs..........................................................................................................................................171
3.16.6.1. chrono_init Function.........................................................................................................................171
3.16.6.2. chrono_start Function .......................................................................................................................172
3.16.6.3. chrono_stop Function .......................................................................................................................172
3.16.6.4. chrono_getHz100 Function ..............................................................................................................172
3.16.6.5. chrono_getTime Function.................................................................................................................173
3.16.6.6. chrono_checkOvf Function ..............................................................................................................174
3.16.6.7. chrono_clrOvf Function ...................................................................................................................174
3.16.6.8. chrono_Stop_S1 Function ................................................................................................................175
3.16.6.9. chrono_Run_S1 Function .................................................................................................................176
3.16.6.10. chrono_Stop_S2 Function................................................................................................................177
3.16.6.11. chrono_Run_S2 Function ................................................................................................................178
3.16.6.12. chrono_int32Hz Function ................................................................................................................179
3.16.6.13. chrono_int1kHz_Split Function.......................................................................................................180
3.16.6.14. chrono_int1kHz_Run Function........................................................................................................181
3.16.6.15. chrono_Int_S1 Function ..................................................................................................................181
3.16.6.16. chrono_Int_S2 Function ..................................................................................................................182
3.16.6.17. chrono_get_ProcSts Function ..........................................................................................................182
3.16.6.18. chrono_get_DspReq Function .........................................................................................................183
3.16.6.19. chrono_clr_DspReq Function ..........................................................................................................183
3.16.6.20. chrono_get_DspTim Function .........................................................................................................184
3.17.
BLD Module.................................................................................................................................................185
3.17.1. Overview of Functions .............................................................................................................................185
3.17.2. List of APIs...............................................................................................................................................185
3.17.3. List of Constants.......................................................................................................................................185
3.17.4. List of Variables........................................................................................................................................185
3.17.5. Details of APIs..........................................................................................................................................186
3.17.5.1. bld_start_levelCheck Function .........................................................................................................186
3.17.5.2. bld_getLevel Function......................................................................................................................187
3.17.5.3. bld_check Function...........................................................................................................................188
3.17.5.4. bld_on Function................................................................................................................................188
3.17.5.5. bld_off Function ...............................................................................................................................189
4. Revision History.......................................................................................................................................................190
Contents − 4
ML610Q400 Series
Sample Program API Manual
1. Overview
This document describes the functions of the standard APIs provided to control hardware devices that the ML610Q400
Series MCU (hereafter called the MCU) has.
Since a wide variety of API functions that can be of reference to software developers are provided, refer to them in
designing a program. Refer also to the AP Notes provided separately.
2. Module APIs
Table 2-1 lists the module APIs.
Table 2-1
Module APIs
Module name
Description
1
SA-ADC Module
successive-approximation type A/D converter
2
RC-ADC Module
RC oscillation-type A/D converter
3
Temperature Calculation Module
Temperature Calculation by RC-ADC
4
UART Module
UART
5
Baud rate adjustment Module
UART
6
I2C Module
I2C
7
EEPCOM Module
EEPROM control by I2C
8
LCD Module
LCD Driver
9
Key Read In Module
Port 0 Input port function
10
Melody Module
Melody Driver
11
Real time clock Module
RTC
12
Timer Module
Timer
13
Clock control Module
Clock generator
14
Time base counter Module
Time base counter
15
1kHz timer control Module
1kHz Timer
16
Stop Watch Module
Stop Watch by 1kHz timer
17
BLD Module
BLD circuit
1
ML610Q400 Series
Sample Program API Manual
3. Module Description
3.1. SA-ADC Module
3.1.1. Overview of Functions
The SA-ADC module controls the SA-ADC (successive-approximation type A/D converter) of the MCU.
The measurement function by use of SA-ADC is achieved by APIs that perform operations such as initialization (setting
of conversion count, operating mode, the 2nd amp and so on), releasing the short-circuit between/short-circuiting the
AIN0 and AIN1 pins, termination judgment, and conversion result acquisition.
3.1.2. List of APIs
Table 3-1 lists the SA-ADC module APIs.
Table 3-1 SA-ADC Module APIs
Function name
saAdc_init function
saAdc_short_CH0CH1_on function
saAdc_short_CH0CH1_off function
saAdc_execute function
saAdc_checkFin function
saAdc_getResult function
Description
Specifies the number of times conversion is performed by the SA-ADC
(once/continuous), selects the clock frequency range of the HSCLK being
used, specifies the operating mode, and sets the offset and gain of the 2nd
amplifier.
Short-circuits the input pins AIN0 and AIN1. *Only enabled at the time of
differential amplification input
Release the short-circuit between the input pins AIN0 and AIN1.
Starts/stops SA-ADC conversion.
Judges whether SA-ADC conversion has been terminated.
Acquires SA-ADC conversion results (12 bits).
2
ML610Q400 Series
Sample Program API Manual
3.1.3. List of Constants
The following tables list the constants used in the SA-ADC module.
Table 3-2 Constants for Arguments (1)
Constant name
SAADC_CH_CH0
SAADC_CH_CH1
SAADC_CH_CH0_CH1
SAADC_LP_ONESHOT
SAADC_LP_CONTINUE
SAADC_CK_LOW
SAADC_CK_HIGH
SAADC_EN_CH0NML_CH1NML
SAADC_EN_CH0NML_CH1AMP
SAADC_EN_CH0AMP_CH1AMP
SAADC_EN_DIFF
SAADC_OFFSET_M1_5
SAADC_OFFSET_M1_0
SAADC_OFFSET_M0_5
SAADC_OFFSET__0_0
SAADC_OFFSET_P0_5
SAADC_OFFSET_P1_0
SAADC_OFFSET_P1_5
SAADC_OFFSET_P2_0
SAADC_OFFSET_P2_5
SAADC_OFFSET_P3_0
SAADC_OFFSET_P3_5
SAADC_OFFSET_P4_0
SAADC_OFFSET_P4_5
SAADC_OFFSET_P5_0
SAADC_OFFSET_P5_5
SAADC_OFFSET_P6_0
SAADC_OFFSET_M9_5
SAADC_OFFSET_M9_0
SAADC_OFFSET_M8_5
SAADC_OFFSET_M8_0
SAADC_OFFSET_M7_5
SAADC_OFFSET_M7_0
SAADC_OFFSET_M6_5
SAADC_OFFSET_M6_0
SAADC_OFFSET_M5_5
Defined
value
1
2
3
0
1
0
1
0
1
2
3
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Description
Performs conversion. Specifies channel 0 only, as the
channel of the SA-ADC.
Performs conversion. Specifies channel 1 only, as the
channel of the SA-ADC.
Performs conversion. Specifies both channel 0 and channel
1, as the channels of the SA-ADC.
Performs conversion only once, then stops.
Performs conversion continuously.
Specify when HSCLK is set between 375 kHz and 1.1 MHz.
Specify when HSCLK is set between 1.99 MHz and 4.2 MHz.
Channel 0: Direct input, Channel 1: Direct input
Channel 0: Direct input, Channel 1: Amp input
Channel 0: Amplified input, Channel 1: Amp input
Differential amp input
Offset adjustment: -1.5[%]
Offset adjustment: -1.0[%]
Offset adjustment: -0.5[%]
Offset adjustment: 0[%]
Offset adjustment: 0.5[%]
Offset adjustment: 1.0[%]
Offset adjustment: 1.5[%]
Offset adjustment: 2.0[%]
Offset adjustment: 2.5[%]
Offset adjustment: 3.0[%]
Offset adjustment: 3.5[%]
Offset adjustment: 4.0[%]
Offset adjustment: 4.5[%]
Offset adjustment: 5.0[%]
Offset adjustment: 5.5[%]
Offset adjustment: 6.0[%]
Offset adjustment: -9.5[%]
Offset adjustment: -9.0[%]
Offset adjustment: -8.5[%]
Offset adjustment: -8.0[%]
Offset adjustment: -7.5[%]
Offset adjustment: -7.0[%]
Offset adjustment: -6.5[%]
Offset adjustment: -6.0[%]
Offset adjustment: -5.5[%]
3
ML610Q400 Series
Sample Program API Manual
Table 3-3 Constants for Arguments (2)
Constant name
SAADC_OFFSET_M5_0
SAADC_OFFSET_M4_5
SAADC_OFFSET_M4_0
SAADC_OFFSET_M3_5
SAADC_OFFSET_M3_0
SAADC_OFFSET_M2_5
SAADC_OFFSET_M2_0
SAADC_GAIN_1_0
SAADC_GAIN_1_5
SAADC_GAIN_2_0
SAADC_GAIN_2_5
SAADC_GAIN_3_0
SAADC_GAIN_3_5
SAADC_GAIN_4_0
SAADC_GAIN_4_5
SAADC_GAIN_5_0
SAADC_GAIN_5_5
SAADC_GAIN_6_0
SAADC_GAIN_6_5
SAADC_GAIN_7_0
SAADC_GAIN_7_5
SAADC_GAIN_8_0
SAADC_GAIN_8_5
Defined
value
25
26
27
28
29
30
31
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Description
Offset adjustment: -5.0[%]
Offset adjustment: -4.5[%]
Offset adjustment: -4.0[%]
Offset adjustment: -3.5[%]
Offset adjustment: -3.0[%]
Offset adjustment: -2.5[%]
Offset adjustment: -2.0[%]
Amp gain: 1x
Amp gain: 1.5x
Amp gain: 2x
Amp gain: 2.5x
Amp gain: 3x
Amp gain: 3.5x
Amp gain: 4x
Amp gain: 4.5x
Amp gain: 5x
Amp gain: 5.5x
Amp gain: 6x
Amp gain: 6.5x
Amp gain: 7x
Amp gain: 7.5x
Amp gain: 8x
Amp gain: 8.5x
Table 3-4 Constants for Return Values
Constant name
SAADC_R_OK
SAADC_R_ERR_CH
SAADC_R_ERR_LP
SAADC_R_ERR_CK
SAADC_R_ERR_EN
SAADC_R_ERR_OFFSET
SAADC_R_ERR_GAIN
SAADC_R_NOT_FIN
SAADC_R_FIN
Defined
value
0
-1
-2
-3
-4
-5
-6
0
1
Description
Processing succeeded.
The channel No./channel bit setting is outside the range.
The conversion count is outside the range.
The HSCLK setting is outside the range.
The operating mode is outside the range.
The amount of input offset is outside the range.
The gain setting is outside the range.
Conversion has never been terminated.
Conversion has been terminated at least once.
4
ML610Q400 Series
Sample Program API Manual
3.1.4. API Details
This section describes details of the SA-ADC module.
3.1.4.1.
saAdc_init Function
This function initializes the SA-ADC of the MCU. It initializes conversion count, HSCLK setting, operating mode, and
the 2nd amp.
Function
name:
Arguments:
Return
values:
Processing:
int saAdc_init(
unsigned char lp,
unsigned char ck,
unsigned char en,
unsigned char offset,
unsigned char gain
)
unsigned char lp … Conversion count
Convert only once: SAADC_LP_ONESHOT(=0)
Convert continuously: SAADC_LP_CONTINUE(=1)
unsigned char ck … HSCLK setting
Sets HSCLK to 375 kHz to 1.1 MHz: SAADC_CK_LOW(=0)
Sets HSCLK to 1.99 MHz to 4.2 MHz: SAADC_CK_HIGH(=1)
unsigned char en … Operation mode
Channel 0 = Direct input, Channel 1 = Direct input: SAADC_EN_CH0NML_CH1NML(=0)
Channel 0 = Direct input, Channel 1 = Direct input: SAADC_EN_CH0NML_CH1AMP(=1)
Channel 0 = Amp input, Channel 1 = Amp input: SAADC_EN_CH0AMP_CH1AMP(=2)
Differential amp input: SAADC_EN_DIFF(=3)
unsigned char offset … Input offset of the 2nd amplifier
Offset adjustment: -1.5[%]: SAADC_OFFSET_M1_5(=0)
… (* For details, see Table 3-2 and Table 3-3.)
Offset adjustment: -2.0[%]: SAADC_OFFSET_M2_0(=31)
unsigned char gain … Gain of the 2nd amplifier
Amp gain 1x: SAADC_GAIN_1_0(=0)
… (For details, see Table 3-3.)
Amp gain 8.5x: SAADC_GAIN_8_5(=15)
int
Initialization succeeded: SAADC_R_OK(=0)
The conversion count is outside the range: SAADC_R_ERR_LP(=-2)
The HSCLK setting is outside the range: SAADC_R_ERR_CK(=-3)
The operating mode is outside the range: SAADC_R_ERR_EN(=-4)
The amount of input offset is outside the range: SAADC_R_ERR_OFFSET(=-5)
The gain setting is outside the range: SAADC_R_ERR_GAIN(=-6)
See next page.
5
ML610Q400 Series
Sample Program API Manual
6
ML610Q400 Series
Sample Program API Manual
3.1.4.2.
saAdc_short_CH0CH1_on Function
This function short-circuits the input pins AIN0 and AIN1. Only enabled at differential amplifier input (when
SAADC_EN_DIFF is specified for the argument “en” of the saAdc_init function).
Function
name:
Arguments:
Return
values:
Processing:
3.1.4.3.
void saAdc_short_CH0CH1_on( void )
None
None
saAdc_short_CH0CH1_off Function
This function releases the short-circuit between the input pins AIN0 and AIN1.
Function
name:
Arguments:
Return
values:
Processing:
void saAdc_short_CH0CH1_off( void )
None
None
7
ML610Q400 Series
Sample Program API Manual
3.1.4.4.
saAdc_execute Function
This function starts/stops SA-ADC conversion.
Function
name:
Arguments:
Return
values:
int saAdc_execute( unsigned char chBit )
unsigned char chBit … Channel setting
Stops SA-ADC conversion: SAADC_CHBIT_OFF(=0)
Channel 0 only: SAADC_CHBIT_CH0(=1)
Channel 1 only: SAADC_CHBIT_CH1(=2)
Channels 0 and 1: SAADC_CHBIT_CH0_CH1(=3)
int
Start/stop processing succeeded: SAADC_R_OK(=0)
The channel setting is outside the range: SAADC_R_ERR_CH (=-1)
Processing:
Start/stop SA-ADC conversion
saAdc_execute function
Parameter check
Is “channel setting” within the range?
(The set value is “3” or less)
No
Yes
Return “SAADC_R_ERR_CH”
Register setting
Stop SA-ADC conversion
[SA-ADC control register 1]
Clear [SARUN]
Select the channel on which SA-ADC conversion is
to be performed
[SA-ADC mode register 0]
Store “channel setting” in [SACH0-1]
Is the “Channel setting” set to other than
“Stops SA-ADC conversion”?
(The set value is not “0”)
Yes
Start SA-ADC conversion
[SA-ADC control register 1]
Set [SARUN]
Return “SAADC_R_OK”
8
No
ML610Q400 Series
Sample Program API Manual
3.1.4.5.
saAdc_checkFin Function
This function checks the QSAD bit of the interrupt request register of the MCU to judge whether SA-ADC conversion
has been terminated or not.
Function
name:
Arguments:
Return
values:
int saAdc_checkFin( void )
None
Judgment result as to whether conversion has been terminated or not.
Conversion has been terminated at least once: SAADC_R_FIN(=1)
Conversion has never been terminated: SAADC_R_NOT_FIN(=0)
Processing:
9
ML610Q400 Series
Sample Program API Manual
3.1.4.6.
saAdc_getResult Function
This function reads the H/L value of the SA-ADC result register and acquires the SA-ADC conversion result (12-bit).
Function
name:
Arguments:
Return
values:
int saAdc_getResult(
unsigned char chNo,
unsigned short *result
)
unsigned char chNo … SA-ADC channel No. (0 to 1)
unsigned char *result … Pointer to the area that stores the SA-ADC conversion result (12-bit)
int
Acquisition succeeded: SAADC_R_OK(=0)
The channel No. is outside the range: SAADC_R_ERR_CH (=-1)
Processing:
10
ML610Q400 Series
Sample Program API Manual
3.2. RC-ADC Module
3.2.1.
Overview of Functions
The RC-ADC module controls the RC-ADC (RC oscillation-type A/D converter) of the MCU.
The RCAD measurement function is achieved by APIs that perform operations such as initialization (setting of
oscillation mode and reference clock), RC-ADC counter setting, RC-ADC conversion start/stop, termination judgment,
conversion result acquisition, and RC oscillation monitor output On/Off control.
3.2.2. List of APIs
The following table lists the RC-ADC module APIs.
Table 3-5 RC-ADC Module APIs
Function name
rcAdc_init function
rcAdc_setCounter function
rcAdc_execute function
rcAdc_checkFin function
rcAdc_getResult function
rcAdc_monitor_on function
rcAdc_monitor_off function
Description
Specifies the RC-ADC oscillation mode and sets the reference clock.
Sets a value in the RC-ADC counter.
Executes RC-ADC conversion start/stop processing.
Checks whether RC-ADC conversion has terminated or not.
Acquires the conversion result (24 bits) of the specified RC-ADC counter.
Enables the RC oscillation monitor output.
Disables the RC oscillation monitor output.
3.2.3. List of Constants
The following tables list the constants used in the RC-ADC module.
Table 3-6 Constants for Arguments
Constant name
RCADC_MODE0
RCADC_MODE1
RCADC_MODE2
RCADC_MODE3
RCADC_MODE4
RCADC_MODE5
RCADC_MODE6
RCADC_MODE6
RCADC_CK_LOW
RCADC_CK_LOW2
RCADC_CK_HIGH
RCADC_CK_HIGH_DIV2
RCADC_CK_HIGH_DIV4
RCADC_CK_HIGH_DIV8
RCADC_A
RCADC_B
RCADC_OFF
RCADC_RUN
Defined
value
0
1
2
3
4
5
6
7
0
1
2
3
4
5
0
1
0
1
Description
Oscillation mode: IN0 pin external clock input mode
Oscillation mode: RS0-CS0 oscillation mode
Oscillation mode: RT0-CS0 oscillation mode
Oscillation mode: RT0-1-CS0 oscillation mode
Oscillation mode: RS0-CT0 oscillation mode
Oscillation mode: RS1-CS1 oscillation mode
Oscillation mode: RT1-CS1 oscillation mode
Oscillation mode: IN1 pin external clock input mode
Reference clock of counter A: LSCLK
Reference clock of counter A: LSCLK×2
Reference clock of counter A: HSCLK
Reference clock of counter A: 1/2 HSCLK
Reference clock of counter A: 1/4 HSCLK
Reference clock of counter A: 1/8 HSCLK
Specifies counter A.
Specifies counter B.
Stops A/D conversion.
Starts A/D conversion.
Table 3-7 Constants for Return Values
11
ML610Q400 Series
Sample Program API Manual
Constant name
RCADC_R_OK
RCADC_R_ERR_MODE
RCADC_R_ERR_CK
RCADC_R_ERR_CNTNO
RCADC_R_ERR_CNTVAL
SAADC_R_ERR_RUN
Defined
value
Description
0
-1
-2
-3
-4
-5
Processing succeeded.
The oscillation mode setting is outside the range.
The reference clock setting is outside the range.
The counter No. is outside the range.
The count value is outside the range.
The A/D conversion stop/start specified is outside the range.
12
ML610Q400 Series
Sample Program API Manual
3.2.4. API Details
This section describes details of the RC-ADC module.
3.2.4.1.
rcAdc_init Function
This function specifies the oscillation mode of the RC-ADC and sets the reference clock.
Function
name:
Arguments:
Return
values:
Processing:
int rcAdc_init(
unsigned char mode,
unsigned char ck
)
unsigned char mode … Oscillation mode of the RC oscillation circuit
IN0 pin external clock input mode: RCADC_MODE0(=0)
RS0-CS0 oscillation mode: RCADC_MODE1(=1)
RT0-CS0 oscillation mode: RCADC_MODE2(=2)
RT0-1-CS0 oscillation mode: RCADC_MODE3(=3)
RS0-CT0 oscillation mode: RCADC_MODE4(=4)
RS1-CS1 oscillation mode: RCADC_MODE5(=5)
RT1-CS1 oscillation mode: RCADC_MODE6(=6)
IN1 pin external clock input mode: RCADC_MODE7(=7)
unsigned char ck … Reference clock of counter A (BSCLK)
LSCLK: RCADC_CK_LOW(=0)
LSCLK×2: RCADC_CK_LOW2(=1)
HSCLK: RCADC_CK_HIGH(=2)
1/2 HSCLK: RCADC_CK_HIGH_DIV2(=3)
1/4 HSCLK: RCADC_CK_HIGH_DIV4(=4)
1/8 HSCLK: RCADC_CK_HGIH_DIV8(=5)
int
Initialization succeeded: RCADC_R_OK(=0)
The setting value of the oscillation mode is outside the range: RCADC_R_ERR_MODE(=-1)
The setting value of the reference clock is outside the range: RCADC_R_ERR_CK(=-2)
See next page.
13
ML610Q400 Series
Sample Program API Manual
14
ML610Q400 Series
Sample Program API Manual
3.2.4.2.
rcAdc_setCounter Function
This function sets a count value in the counters of the RC-ADC. If a value is set in counter A, counter B is cleared to 0,
and vice versa.
Function
name:
Arguments:
Return
values:
int rcAdc_setCounter(
unsigned char cntNo,
unsigned long value
)
unsigned char cntNo … Counter No.
Counter A: RCADC_A(=0)
Counter B: RCADC_B(=1)
unsigned long value … Count value (0x00000001 to 0x01000000)
int
Setting succeeded: RCADC_R_OK(=0)
The counter No. is outside the range: RCADC_R_ERR_CNTNO(=-3)
The count value is outside the range: RCADC_R_ERR_CNTVAL(=-4)
Processing:
15
ML610Q400 Series
Sample Program API Manual
3.2.4.3.
rcAdc_execute Function
This function starts/stops RC-ADC conversion.
Function
name:
Arguments:
Return
values:
int rcAdc_execute(
unsigned char run
)
unsigned char run … Stop/start of A/D conversion
Stop: RCADC_OFF(=0)
Start: RCADC_RUN(=1)
unsigned long value … Count value (0x00000001 to 0x01000000)
int
Setting succeeded: RCADC_R_OK(=0)
Stop/start setting is outside the range: RCADC_R_ERR_RUN(=-5)
Processing:
Start RC-ADC conversion
rcAdc_execute function
Parameter check
No
Is “start/stop setting” within the range ?
(The set value is “1” or less)
Yes
Return “RCADC_R_ERR_RUN”
Register setting
Clear RC-ADC interrupt request
[Interrupt request register 4]
Clear [QRAD]
Start/stop RC-ADC conversion
[RC-ADC control register]
Store the “start/stop setting” value in [RARUN]
Return “RCADC_R_OK”
16
ML610Q400 Series
Sample Program API Manual
3.2.4.4. rcAdc_checkFin Function
This function judges whether RC-ADC conversion has been completed or not.
Function
name:
Arguments:
Return
values:
int rcAdc_execute( void )
None
int
Conversion has not been completed yet: RCADC_R_NOT_FIN(=0)
Conversion ha been completed: RCADC_R_FIN(=1)
Processing:
17
ML610Q400 Series
Sample Program API Manual
3.2.4.5. rcAdc_getResult Function
This function acquires conversion result (24 bits) from the specified counter of the RC-ADC.
Function
name:
Arguments:
Return
values:
int rcAdc_getResult(
unsigned char cntNo,
unsigned long *result
)
unsigned char cntNo … Counter No.
Counter A: RCADC_A(=0)
Counter B: RCADC_B(=1)
unsigned long *result …Pointer to the area that stores the conversion result (24 bits)
int
Acquisition succeeded: RCADC_R_OK(=0)
Counter No. is outside the range: RCADC_R_ERR_CNTNO(=-3)
Processing:
18
ML610Q400 Series
Sample Program API Manual
3.2.4.6.
rcAdc_monitor_on Function
This function enables RC oscillation monitor output.
Function
name:
void rcAdc_monitor_on( void )
Arguments:
None
Return
values:
Processing:
None
19
ML610Q400 Series
Sample Program API Manual
3.2.4.7. rcAdc_monitor_off Function
This function disables RC oscillation monitor output.
Function
name:
Arguments:
Return
values:
Processing:
void rcAdc_monitor_off( void )
None
None
20
ML610Q400 Series
Sample Program API Manual
3.3. Temperature Calculation Module
3.3.1. Overview of Functions
The temperature calculation module calculates a temperature based on the RC-ADC (RC oscillation type A/D converter)
conversion result.
3.3.2. List of APIs
The following table lists the temperature calculation module APIs.
Table 3-8 Temperature Calculation Module APIs
Function name
Description
temp_calc function
Calculates temperature from the RC-ADC count value.
3.3.3. List of Constants
The following table lists the constants used in the temperature calculation module.
Table 3-9 Constants for Return Values
Defined
value
Constant name
TEMP_R_OK
TEMP_R_ERR_L
TEMP_R_ERR_H
0
-1
-2
Description
Processing succeeded.
The count value is smaller than the minimum value.
The count value is greater than the maximum value.
3.3.4. Structures
This section describes the structures referred in the temperature calculation module.
Temperature calculation table
typedef struct {
unsigned long
unsigned long
signed long
} tTempTableList;
baseCnt;
divStep;
offset;
// Frequency count ratio
// Temperature slope
// Temperature offset
* About the example of the value setting of the temperature calculation table value, see the chapter "Temperature
Calculation Module" in the "ML610Q400 Series Sample Program AP Notes For Sensor/Measurement Application".
21
ML610Q400 Series
Sample Program API Manual
3.3.5. API Details
This section describes details of the temperature calculation module APIs.
3.3.5.1.
temp_calc Function
This function obtains temperature from the count value of the RC-ADC.
Function
name:
Arguments:
Return
values:
int temp_calc(
unsigned long adcCnt,
signed short *temp
tTempTableList *pTbl;
)
unsigned long adcCnt … Count value of the RC-ADC
signed short *temp … Pointer to the area that stores the temperature values (in 0.1°C steps)
Example: For –10.5°C, “–105” will be stored.
tTempTableList *pTbl … Pointer to the temperature calculation table
int
Acquisition succeeded: TEMP_R_OK(=0)
The count value is less than the minimum value: TEMP_R_ERR_L(= –1)
The count value is greater than the maximum value: TEMP_R_ERR_H(= –2)
Processing:
Temperature calculation
temp_calc function
Parameter check
Is the "ADC count value" greater than or equal to
the minimum value?
(The count value is greater than or equal to
"18120")
Yes
Is the "ADC count value" less than or equal to the
maximum value?
(The count value is less than or equal to
"412491")
Yes
No
Return "TEMP_R_ERR_L"
No
Return "TEMP_R_ERR_H"
* Temperature value = ((adcCnt - baseCnt) * divStep) + offset
Temperature calculation
table search
Temperature calculation
Temperature calculation [1]
: Subtract the reference count value from the ADC count value
(Subtract "baseCnt", which is a member of temperature calculation
table [n], from the "adcCnt")
Set "Table No." to "0"
Check temperature calculation tables [1] to [15]
Temperature calculation [2]
: Multiply the above calculation result by the temperature slope value
(Multiply the above calculation result
by "divStep", which is a member of temperature calculation table [n])
Is the "ADC count value" greater than or equal to the
"minimum count value", which is a member of the
temperature calculation table [n+1]?
(n="Table No.")
No
Temperature calculation [3]
: Add the temperature offset value from the above calculation result
(Add "offset", which is a member of temperature calculation table [n]
from the above calculation result)
Yes
Add "1" to the "Table No."
Store the above calculation result in the "area that stores temperature
values"
Check temperature calculation tables [1] to [15]
Return "TEMP_R_OK"
22
ML610Q400 Series
Sample Program API Manual
3.4. UART Module
3.4.1. Overview of Functions
The UART module controls the UART (asynchronous serial interface) of the MCU.
The UART communication function is achieved by APIs that perform operations such as initialization (sets settings for
the clock to be input to the baud rate generator, communication mode, and baud rate), data transmission/reception
start/stop, continuation of data transmission/reception, transmit/receive interrupt request acquisition and clear, and
transmit/receive size acquisition.
3.4.2. List of APIs
The following table lists the UART module APIs.
Table 3-10 UART Module APIs
Function name
uart_init function
uart_startSend function
uart_startReceive function
uart_continue function
uart_stop function
uart_checkIRQ function
uart_clearIRQ function
uart_getTransSize function
uart_PortClear function
uart_PortSet function
Description
Selects the clock to be input to the baud rate generator and sets the
communication mode (data length = 8 bits, no parity bit, 2 stop bits, positive
logic, LSB first) and baud rate.
Executes data transmission start processing.
Executes data reception start processing.
Executes data transmission/reception continuation processing.
Executes data transmission/reception stop processing.
Checks if a transmit/receive interrupt request is present or absent.
Clears the transmission/reception interrupt request.
Checks the size of the data transmitted/received
Initializes the transmission/reception port setting.
Set the transmission/reception port for UART communication.
3.4.3. Callback Function
This section describes the callback function specified by the uart_startSend function or uart_startReceive function.
The callback function is called upon completion of transmission/reception from the UART module. Describe processing
required upon completion of transmission/reception within the callback function.
Definition of the callback function
typedef void (*cbfUart)( unsigned int size, unsigned char errStat )
<Example of Definition>
Function
name:
Arguments:
Return
values:
void uart_callback(
unsigned int size, unsigned char errStat
)
unsigned int size … Size of transmitted/received data
unsigned char errStat … Transmission/reception result
bit0 … 0 = No framing error /1 = Framing error
bit1 … 0 = No overrun error /1 = Overrun error
bit2 … 0 = No parity error /1 = Prity error
None
23
ML610Q400 Series
Sample Program API Manual
3.4.4. List of Constants
The following tables list the constants used in the UART module.
Table 3-11 Constants for Arguments
Constant name
UART_CK_LSCLK
UART_CK_LSCLK2
UART_CK_HSCLK
UART_BR_2400BPS
UART_BR_4800BPS
UART_BR_9600BPS
UART_BR_19200BPS
UART_BR_38400BPS
UART_BR_57600BPS
UART_BR_115200BPS
UART_LG_8BIT
UART_LG_7BIT
UART_LG_6BIT
UART_LG_5BIT
UART_PT_EVEN
UART_PT_ODD
UART_PT_NON
UART_STP_1BIT
UART_STP_2BIT
UART_NEG_POS
UART_NEG_NEG
UART_DIR_LSB
UART_DIR_MSB
Defined
value
0
1
2
2400
4800
9600
19200
38400
57600
115200
0
1
2
3
0
1
2
0
1
0
1
0
1
Description
Specifies LSCLK as the clock to be input to the baud rate generator.
Specifies LSCLK×2 as the clock to be input to the baud rate generator.
Specifies HSCLK as the clock to be input to the baud rate generator.
Specifies 2400 bps as the baud rate.
Specifies 4800 bps as the baud rate.
Specifies 9600 bps as the baud rate.
Specifies 19200 bps as the baud rate.
Specifies 38400 bps as the baud rate.
Specifies 57600 bps as the baud rate.
Specifies 115200 bps as the baud rate.
Specifies 8-bit length as the communication date length.
Specifies 7-bit length as the communication date length.
Specifies 6-bit length as the communication date length.
Specifies 5-bit length as the communication date length.
Specifies an even parity bit.
Specifies an odd parity bit.
Specifies no parity.
Specifies 1 bit as the stop bit length.
Specifies 2 bits as the stop bit length.
Specifies positive logic.
Specifies negative logic.
Specifies LSB first.
Specifies MSB first.
Table 3-12 Constants for Return Values
Constant name
Defined
value
UART_R_OK
UART_R_ERR_CS
UART_R_ERR_BR
UART_R_ERR_LG
UART_R_ERR_PT
UART_R_ERR_STP
UART_R_ERR_NEG
UART_R_ERR_DIR
UART_R_TRANS_FIN
UART_R_TRANS_CONT_OK
0
-1
-2
-3
-4
-5
-6
-7
1
0
UART_R_TRANS_CONT_NG
UART_R_TRANS_FIN_NG
UART_R_IRQ
UART_R_NON_IRQ
-1
-2
1
0
Description
Processing succeeded.
The input clock setting is outside the range.
The specified baud rate is unsettable.
The communication data length is outside the range.
The parity setting is outside the range.
The stop bit length is outside the range.
The positive logic/negative logic specification is outside the range.
The LSB/MSB specification is outside the range.
Transmit/receive processing terminated.
The transmit/receive processing is going on (transmission
succeeded)
The transmit/receive processing is going on (transmission failed)
Transmit/receive processing terminated (termination failed).
Transmit/receive complete interrupt request is present.
Transmit/receive complete interrupt request is absent.
24
ML610Q400 Series
Sample Program API Manual
3.4.5. Structures
This section describes the structures used in the UART module.
UART setting parameters
typedef struct {
unsigned long
unsigned char
unsigned char
unsigned char
unsigned char
unsigned char
} tUartSetParam;
br;
lg;
pt;
stp;
neg;
dir;
// Specify the baud rate.
// Specify the communication data length.
// Select even parity/odd parity/no parity.
// Select the stop bit length.
// Select positive logic/negative logic.
// Select LSB first/MSB first.
For the setting values, see Table 3-11
Callback functions
typedef void (*tCallBack)( unsigned int size, unsigned char errStat )
UART transmit/receive control parameters
typedef struct {
unsigned char *
unsigned int
unsigned int
tCallBack
unsigned char
} tUartCtrlParam;
data;
size;
cnt;
callBack
errStat
// Pointer to the area that contains transmit/receive data
// Transmit/receive data size
// Size of transmitted/received data
// Callback function
// Error status
3.4.6. List of Variables
The following table lists the variables used in the UART module.
Variable name
static
tUartCtrlParam _gsCtrlParam
Initial value
data: NULL
size: 0
cnt: 0
callBack: NULL
errStat: 0
25
Description
Variable to manage the data for UART
transmission/reception
ML610Q400 Series
Sample Program API Manual
3.4.7. API Details
This section describes details of the UART module APIs.
3.4.7.1.
uart_init Function
This function initializes the UART of the MCU. It selects the clock to be input to the baud rate generator and sets the
HSCLK frequency and communication settings (such as character length, parity, and baud rate).
Function
name:
Arguments:
Return
values:
Processing:
int uart_init(
unsigned char cs,
unsigned short kHz,
tUartSetParam *prm
)
unsigned char cs … Selection of the clock to be input to the baud rate generator
LSCLK: UART_CS_LSCLK(=0)
LSCLK×2: UART_CS_LSCLK2(=1)
HSCLK: UART_CS_HSCLK(=2)
unsigned short kHz … Frequency of HSCLK (* Referenced only when HSCLK is selected)
tUartSetParam *prm … Setting parameter
int
Initializing succeeded: UART_R_OK(=0)
The selected input clock is outside the range: UART_R_ERR_CS(=-1)
The baud rate setting is outside the range: UART _R_ERR_BR(=-2)
The communication data length is outside the range: UART _R_ERR_LG(=-3)
The parity setting is outside the range: UART _R_ERR_PT(=-4)
The stop bit length is outside the range: UART _R_ERR_STP(=-5)
The positive logic/negative logic specified is outside the range: UART _R_ERR_NEG(=-6)
LSB/MSB specified is outside the range: UART _R_ERR_DIR(=-7)
See next page.
26
ML610Q400 Series
Sample Program API Manual
UART module initialization
uart_init function
Parameter check
Branch according to the selected input clock
LSCLK
Retain 32768[Hz]
as the baud rate clock
LSCLK×2
Retain 32768×2 [Hz]
as the baud rate clock
Acquire baud rate count value
“baud rate clock” ÷ “specified baud rate”
Is the baud rate count value settable?
(Value: “0”)
Yes
Is the communication data length
within the range?
(The set value is “3” or less)
Yes
Is the parity setting
within the range?
(The set value is “2” or less)
Yes
Is the stop bit length
within the range?
(The set value is “1” or less)
Yes
Is the positive logic/negative logic
specified within the range?
(The set value is “1” or less)
Yes
Is LSB/MSB specified
within the range?
(The set value is “1” or less)
Yes
HSCLK
Others
Retain
“HSCLK frequency”×1000 [Hz]
as the baud rate clock
Return “UART_R_ERR_CS”
No
Return “UART _R_ERR_BR”
No
Return “UART _R_ERR_LG”
No
Return “UART _R_ERR_PT”
No
Return “UART _R_ERR_STP”
No
Return “UART _R_ERR_NEG”
No
Return “UART _R_ERR_DIR”
[1]
Continued on next page
27
ML610Q400 Series
Sample Program API Manual
28
ML610Q400 Series
Sample Program API Manual
3.4.7.2.
uart_startSend Function
This function performs data transmission start processing. If this function is called during data transmission/reception,
the transmission/reception being performed at the time stops and transmission processing newly starts.
Function
name:
Arguments:
Return
values:
Processing:
void uart_startSend(
unsigned char *data,
unsigned int size,
tCallBack func
)
unsigned char *data … Pointer to the area that contains transmit data
unsigned int size …. Transmit data size (bytes)
tCallBack func … Function to be executed upon transmission completion
None
See next page.
29
ML610Q400 Series
Sample Program API Manual
30
ML610Q400 Series
Sample Program API Manual
3.4.7.3. uart_startReceive Function
This function performs data reception start processing. If this function is called during data transmission/reception, the
transmission/reception being performed at the time stops and reception processing newly starts.
Function
name:
Arguments:
Return
values:
Processing:
void uart_startReceive(
unsigned char *data,
unsigned int size,
tCallBack func
)
unsigned char *data … Pointer to the area that stores receive data
unsigned int size … Receive data size (bytes)
tCallBack func … Function to be executed upon reception completion
None
Start receive processing
uart_startReceive function
Stop communication operation
[UART0 control register]
· Clear [U0EN]
Set transfer mode to “receive mode”
[UART0 mode register 0]
· Set [U0IO]
Set transmit/receive control parameters
· Set “pointer to the area that stores transmit/receive data” to
“pointer to the area that stores receive data”
· Set “transmit/receive data size” to “receive data size”
· Set “transmitted/received data size” to “0”
· Set “callback function” to “function to be executed upon reception completion”
· Set “error status” to “0”
Is the “receive data size” larger than “0”?
Yes
Start communication operation
[UART0 control register]
· Set [U0EN]
End of processing
31
No
ML610Q400 Series
Sample Program API Manual
3.4.7.4.
uart_continue Function
This function performs data transmission/reception continuation processing.
Function
name:
Arguments:
Return
values:
int uart_continue( void )
None
Int
Transmit/receive processing terminated: UART_R_TRANS_FIN(=1)
Transmit/receive processing continuing (transmission/reception succeeded): UART_R_TRANS_CONT_OK(=0)
Transmit/receive processing continuing (transmission/reception failed): UART_R_TRANS_CONT_NG(=-1)
Transmit/receive processing terminated (termination failed): UART_R_TRANS_FIN_NG(=-2)
Processing:
Transmission/reception continuation processing
uart_continue function
Check transfer mode
[UART0 mode register 0]
· Read U0IO]
No
Transmit mode?
([U0IO] is “0”)
Yes
[1]
Is transmit data remaining?
Does “transmit data size” disagree with “transmitted
data size”?
No
Yes
Check transmit status
[UART0 control register]
· Read [U0EN]
Check transmit buffer status
[UART0 status register]
· Read [U0FUL]
No data in transmit buffer?
([U0FUL] is “0”)
No
Transmission completed?
([U0EN] is “0”)
Yes
Yes
No
Is the “function to be executed upon
transmission completion”
registered?
(Setting: Not “NULL”)
Transfer the start data of transmit data to transmit/receive buffer
[UART0 transmit/receive buffer]
· Store the data in “transmit data storing area” in [U0B0-7]
No
Yes
Execute the “function to be executed
upon transmission completion”
(Transmit “transmit data size” and
“error status” as arguments)
* Execute the callback function set at
transmission start
Set transmit/receive control parameters
· Advance “pointer to the area that contains transmit/receive data”
by 1 byte
· Add “1” to “transmitted/received data size”
Set the “function to be executed upon
transmission completion” to NULL
Start communication operation
[UART0 control register]
· Set [U0EN]
Return
“UART_R_TRANS_CONT_OK”
Return
“UART_R_TRANS_CONT_NG”
Continued on next page
32
Return
“UART_R_TRANS_CONT_OK”
Return
“UART_R_TRANS_FIN_NG”
ML610Q400 Series
Sample Program API Manual
[1]
Is receive data remaining?
Does “receive data size” disagree with “received
data size”?
Reception termination processing
No
Yes
Acquire error status
[UART0 status register]
Read [U0FER], [U0OER], and [U0PER]
Retain error status internally
Clear error status
[UART0 status register]
Clear [U0FER], [U0OER], and [U0PER]
Acquire receive data
[UART0 transmit/receive buffer]
Read [U0B0-7] and store it in the receive data storing area
Set transmit/receive control parameters
Advance “pointer to the area that contains transmit/receive data”
by 1 byte
Add “1” to “transmitted/received data size”
Has all-data reception completed?
Does “receive data size” disagree with “received
data size”?
No
Reception termination processing
Yes
Is the “function to be executed upon reception
completion” registered?
(Setting: Not “NULL”)
Yes
Execute the “function to be executed upon
reception completion”
(Transmit “receive data size” and “error status”
as arguments)
* Execute the callback function
set at reception start
Set the “function to be executed upon reception
completion” to NULL.
Return
“UART_R_TRANS_CONT_OK”
Return “UART_R_TRANS_FIN”
33
No
ML610Q400 Series
Sample Program API Manual
3.4.7.5.
uart_stop Function
This function performs data transmission/reception stop processing.
Function
name:
Arguments:
Return
values:
Processing:
void uart_stop( void )
None
None
34
ML610Q400 Series
Sample Program API Manual
3.4.7.6.
uart_checkIRQ Function
This function checks the QUA0 bit of the interrupt request register 4 to check whether a transmit/receive interrupt
request is present.
Function
name:
Arguments:
Return
values:
int uart_checkIRQ( void )
None
int
Transmit/receive interrupt requested: UART_R_IRQ
No transmit/receive interrupt: UART_R_NON_IRQ
Processing:
3.4.7.7.
uart_clearIRQ Function
This function clears the transmit/receive interrupt request (QUA0 bit of the interrupt request register 4).
Function
name:
Arguments:
Return
values:
Processing:
void uart_clearIRQ( void )
None
None
35
ML610Q400 Series
Sample Program API Manual
3.4.7.8.
uart_getTransSize Function
This function acquires the transmitted/received data size. If the uart_stop function is called, the transmitted/received data
size is cleared.
Function
name:
Arguments:
Return
values:
unsigned int uart_getTransSize( void )
None
unsigned int
Transmitted/received data size
(* Indicates the data size that was transferred from the execution of the uart_startSend function or the
uart_startReceive function to the call made to this function)
Processing:
36
ML610Q400 Series
Sample Program API Manual
3.4.7.9. uart_PortClear Function
This function initializes the port P43 (TXD0 : output) and the port P42 (RXD0 : input).
Function
name:
Arguments:
Return
values:
Processing:
void uart_PortClear( void )
None
None
This function initializes P43 and P42 to the following setting.
Port
P43
Input/output mode
output
High-impedance output
P42
output
High-impedance output
Input/output state
Function
Primary function :
General-purpose
input/output
Primary function :
General-purpose
input/output
3.4.7.10. uart_PortSet Function
This function sets the port P43 (TXD0 : output) and the port P42 (RXD0 : input) for UART data output and input port
respectively. Please be sure to call this function after you call uart_init function and at least before you start UART
transmit or receive operation by uart_startSend or uart_startReceive function.
Function
name:
Arguments:
Return
values:
Processing:
void uart_PortSet( void )
None
None
This function set P43 and P42 to the following setting.
Port
P43
Input/output mode
output
Input/output state
P42
input
High-impedance input
37
CMOS output
Function
Secondary function :
UART0 output
Secondary function :
UART0 input
ML610Q400 Series
Sample Program API Manual
3.5. UART Baud Rate Correction Module
A high-speed clock frequency is known to fluctuate at about ±15% depending on the temperature change in cases where
the high-speed clock of the ML610Q431 is operating in RC oscillation mode. Also note that for the baud rate of UART,
a communication error occurs if the baud rate clock frequency fluctuates exceeding ±2%. In other words, UART
communication is expected to stop if there is a change in the ambient temperature.
The aim of the UART baud rate correction module is to make UART communication continue by measuring a
high-speed clock frequency by use of the low-speed 32 kHz crystal oscillation clock and then correcting the UART baud
rate timer value from the clock frequency obtained.
3.5.1. Overview of Functions
This module measures a high-speed clock frequency using Timers 2 and 3 and the 128Hz interrupt, calculates the setting
value of the UART baud rate timer register and then corrects the UART baud rate timer value.
3.5.2. List of APIs
The following table lists the baud rate correction module APIs.
Table 3-13 Baud Rate Correction Module APIs
Function name
Description
adjustBaudrate_startCount function
Starts baud rate correction counter operation.
Checks whether the baud rate correction counter operation is complete.
Obtains the count value of the baud rate correction counter.
Sets the baud rate register.
Performs 128Hz interrupt processing for baud rate correction. Used in cases
where the frequency measurement function is not provided.
Performs timer 3 interrupt processing for baud rate correction. Used in cases
where the frequency measurement function is provided.
adjustBaudrate_checkFin function
adjustBaudrate_getCount function
adjustBaudrate_setBRT function
adjustBaudrate_intCount function
adjustBaudrate_intCountTM3 function
3.5.3. List of Constants
The following table lists the constants used in the baud rate correction module.
Table 3-14 List of Constants for Arguments
Defined
value
Constant name
Description
ADJUSTBAUDRATE_NOT_USE_FM
0
The 16-bit frequency measurement function is not used.
ADJUSTBAUDRATE_USE_FM
ADJUSTBAUDRATE_2400BPS
ADJUSTBAUDRATE_4800BPS
ADJUSTBAUDRATE_9600BPS
ADJUSTBAUDRATE_19200BPS
ADJUSTBAUDRATE_38400BPS
1
0
1
2
3
4
The 16-bit frequency measurement function is used.
Specifies 2400 bps as the baud rate.
Specifies 4800 bps as the baud rate.
Specifies 9600 bps as the baud rate.
Specifies 19200 bps as the baud rate.
Specifies 38400 bps as the baud rate.
Table 3-15 List of Constants for Return Values
Constant name
ADJUSTBAUDRATE_R_OK
ADJUSTBAUDRATE_R_NG
ADJUSTBAUDRATE_R_FIN
ADJUSTBAUDRATE_R_NOT_FIN
Defined
value
0
-1
1
0
Description
Processing succeeded.
Processing failed.
Baud rate correction terminated.
Baud rate correction is being done.
38
ML610Q400 Series
Sample Program API Manual
3.5.4. List of Variables
The following tables list the variables used in the baud rate correction module.
Table 3-16 List of Variables
Variable name
Initial
value
static
unsigned short _cntTimer
0
static
int _cnt128Hz
0
static
unsigned long _cnt437c
0
Description
This is a variable used to retain the difference in the 16-bit timer
count value for each 128Hz interrupt.
* Used only when the frequency measurement function is not
provided.
If the frequency measurement function is not provided: This is a
variable (0 to 2) used to retain the remaining number of 128Hz
interrupts required for baud rate correction.
If the frequency measurement function is provided: Variable used
to indicate the frequency measurement status (1: Measurement is
being performed / 0: Measurement is stopped).
This is a variable used to retain the 437C timer count value.
39
ML610Q400 Series
Sample Program API Manual
3.5.5. Details of APIs
This section describes details of the baud rate correction module APIs.
3.5.5.1.
adjustBaudrate_startCount Function
This function enables the 128Hz interrupt, activates the 16-bit timer, and starts baud rate counter operation.
Function
name:
Arguments:
Return
values:
Processing:
int adjustBaudrate_startCount(
unsigned char useFm
)
unsigned char useFm … Specify whether or not to use the 16-bit frequency measurement function.
Do not use the 16-bit frequency measurement function: ADJUSTBAUDRATE_NOT_USE_FM(=0)
Use the 16-bit frequency measurement function: ADJUSTBAUDRATE_USE_FM(=1)
Int
The start processing was successful: ADJUSTBAUDRATE_R_OK(=0)
The 16-bit frequency measurement function is not provided: ADJUSTBAUDRATE_R_NG(=-1)
See next page.
40
ML610Q400 Series
Sample Program API Manual
Start baud rate correction counter operation.
adjustBaudrate_startCount function
Is the frequency measurement function supposed to be used?
(“Use” is specified for the frequency measurement function)
No
Yes
Check if 16-bit frequency measurement mode is
provided or not.
tm_checkFmFunc function
No
Is the frequency measurement function provided?
(The return value of the above function is
"ADJUSTBAUDRATE_R_OK")
Yes
Return
"ADJUSTBAUDRATE_R_NG"
Initialize variables
Initialize the 16-bit timer counter.
(Set it to "0")
Set the frequency measurement status to
"Measurement is being performed"
(set the variable to "1")
Initialize the 128Hz interrupt counter.
(Set it to "2")
Initialize the 437C timer count value
(Set it to "0")
Initialize the 437C timer count value
(Set it to "0")
Start counting
Initialize timers 2 & 3
(Mode: 16-bit frequency measurement mode;
Control clock: HTBCLK;
Count value: 0xFFFF)
Initialize timers 2 & 3
(Mode: 16-bit mode;
Control clock: HTBCLK;
Count value: 0xFFFF)
Clear the interrupt request of the timer 2
& 3 interrupt
Clear the interrupt request of the timer 2
& 3 interrupt and 128Hz interrupt
Enable the timer 3 interrupt
Enable the 128Hz interrupt
Timers 2 & 3 start operating
Timers 2 & 3 start operating
End of processing
41
ML610Q400 Series
Sample Program API Manual
3.5.5.2.
adjustBaudrate_checkCountFin Function
This function checks whether the operation of the baud rate correction counter has been completed.
Function
name:
Arguments:
Return
values:
int adjustBaudrate_checkCountFin( void )
None
int
Baud rate correction completed: ADJUSTBAUDRATE_R_FIN (=1)
Baud rate correction in progress: ADJUSTBAUDRATE_R_NOT_FIN (=0)
Processing:
Check baud rate correction counter operation.
adjustBaudrate_checkCountFin function
Is the baud rate correction counter stopped?
(128Hz interrupt counter value is “0”)
No
Yes
Return
“ADJUSTBAUDRATE_R_FIN”
3.5.5.3.
Return “ADJUSTBAUDRATE_R_NOT_FIN”
adjustBaudrate_getCount Function
This function acquires the count value of the baud rate correction counter.
Function
name:
Arguments:
Return
values:
Processing:
unsigned long adjustBaudrate_getCount( void )
void
unsigned long
Count value of the baud rate correction counter
Returns the value of the variable “_cnt437c”.
⇒ The value that matches the count value when the 437C timer is used is retained in this variable.
42
ML610Q400 Series
Sample Program API Manual
3.5.5.4.
adjustBaudrate_setBRT Function
This function calculates the baud rate count value from the baud rate value and 437C timer count value and sets it in the
baud rate register. The calculation result will be rounded.
Function
name:
Arguments:
Return
values:
int adjustBaudrate_setBRT (
unsigned char baudrateType,
unsigned long cnt437c
)
unsigned char baudrateType … Baud rate clock
2400bps: ADJUSTBAUDRATE_2400BPS(=0)
4800bps: ADJUSTBAUDRATE_4800BPS(=1)
9600bps: ADJUSTBAUDRATE_9600BPS(=2)
19200bps: ADJUSTBAUDRATE_19200BPS(=3)
38400bps: ADJUSTBAUDRATE_38400BPS(=4)
unsigned long cnt437c … 437C timer count value
int
Setting succeeded: ADJUSTBAUDRATE_R_OK(=0)
The parameter is outside the range: ADJUSTBAUDRATE_R_NG(=-1)
Processing:
*1:
43
Baud rate
Shift count
2400
4800
9600
19200
38400
4
5
6
7
8
ML610Q400 Series
Sample Program API Manual
3.5.5.5.
adjustBaudrate_intCount Function
This function reads the count value of the 16-bit timer at 128-Hz intervals and calculates the count value equivalent to
the 437C count value from the difference between the 1st and 2nd reads. The function must be set in the 128Hz interrupt
vector in order to execute it at the timing of the 128Hz interrupt.
Function
name:
Arguments:
Return
values:
void adjustBaudrate_intCount( void )
None
None
44
ML610Q400 Series
Sample Program API Manual
Processing:
45
ML610Q400 Series
Sample Program API Manual
3.5.5.6.
adjustBaudrate_intCountTM3 Function
This function reads the count value of the 16-bit timer at the timer 3 interrupt generation timing and calculates the 437C
count value. The function must be set in the timer 3 interrupt vector in order to execute it at the timing of the timer 3
interrupt.
Function
name:
Arguments:
Return
values:
Processing:
void adjustBaudrate_intCountTM3( void )
None
None
Baud rate correction counter interrupt
processing
adjustBaudrate_intCountTM3 function
Is baud rate correction being executed?
(The 128Hz interrupt counter value is “1”)
Yes
Obtain the count value
for baud rate correction
Read the timer counter registers
of timers 2 and 3.
[Read timer 2 and 3 counter registers]
Read [T2C0-7] and [T3C0-7]
Calculate the 437C timer count value
“437C timer count value” = Value read
from the above registers
Correction stop
processing
Stop timer 2 and 3 operation
Clear the interrupt request from timers 2 and 3
Set the 128Hz interrupt counter to “0”
End of processing
46
No
ML610Q400 Series
Sample Program API Manual
3.6. I2C Module
3.6.1. Overview of Functions
The I2C module controls the I2C bus interface (master) of the MCU. To be specific, it can control initialization
(communication speed setting and use/nonuse setting of clock synchronization), data transmission/reception start/stop,
continuation of data transmission/reception, obtaining and clearing of I2C interrupt requests, and acquisition of
transmit/receive size.
When specified, callback functions can be executed upon completion of transmission/reception. Use the i2c_startSend
function or i2c_startReceive function to specify callback functions.
3.6.2. List of APIs
The following table lists the I2C module APIs.
Table 3-17 I2C Module APIs
Function name
i2c_init function
i2c_startSend function
i2c_startReceive function
i2c_continue function
i2c_stop function
i2c_checkIRQ function
i2c_clearIRQ function
i2c_getTransSize function
Description
Selects the communication speed and the use/nonuse of clock synchronization.
Executes address and data transmission start processing.
Executes address and data reception start processing.
Executes address and data transmission/reception continuation processing.
Executes transmission/reception stop processing.
Checks the presence or absence of a transmit/receive interrupt request.
Clears transmit/receive interrupt requests.
Checks the size of the data transmitted/received.
3.6.3. Callback Function
This section describes the callback function specified by the i2c_startSend function or i2c_startReceive function.
The callback function is called upon completion of transmission/reception or upon occurrence of an error from the I2C
module. Describe required processing within the callback function.
Definition of the callback function
typedef void (*cbfI2c)( unsigned int size, unsigned char errStat )
<Example of definition>
Function
name:
Arguments:
Return
values:
void i2c_callback(
unsigned int size, unsigned char errStat
)
unsigned int size … Size of transmitted/received data
unsigned char errStat … Transmission/reception result
I2C_R_OK(=0): Transmission/reception ended normally
I2C_ERR_ACR(=1): Received acknowledgment data “1”
I2C_ERR_SEND_ERR(=2): Transmission error
None
47
ML610Q400 Series
Sample Program API Manual
3.6.4. List of Constants
The following tables list the constants used in the I2C module.
Table 3-18 List of Constants for Arguments
Constant name
I2C_MOD_STD
I2C_MOD_FST
I2C_SYN_OFF
I2C_SYN_ON
Defined
value
Description
0
1
0
1
Specifies standard mode (100 kHz) for communication speed.
Specifies fast mode (400 kHz) for communication speed.
Specifies the nonuse of the clock synchronization function.
Specifies the use of the clock synchronization function.
Table 3-19 List of Constants for Return Values
Constant name
Defined
value
I2C_R_OK
I2C_R_ERR_SYN
0
-1
I2C_R_ERR_MODE
I2C_R_ERR_FREQ
I2C_R_TRANS_START_OK
I2C_R_BUS_BUSY
I2C_R_TRANS_FIN
I2C_R_TRANS_CONT_OK
-2
-3
0
-1
1
0
I2C_R_IRQ
I2C_R_NON_IRQ
1
0
Description
Processing succeeded.
The specified value for the clock synchronization function is outside
the range.
The specified communication speed was unsettable.
The high-speed clock frequency is outside the range.
Transmit/receive start processing terminated.
I2C bus busy state
Transmit/receive processing terminated.
The transmit/receive processing is going on (transmission
succeeded)
Transmit/receive complete interrupt request is present.
Transmit/receive complete interrupt request is absent.
3.6.5. Structure
This section describes the structures used in the I2C module.
I2C transmit/receive control parameters
typedef struct {
unsigned char
unsigned char *
unsigned int
unsigned char *
unsigned int
unsigned int
tCallBack
unsigned char
unsigned char
tI2cCtrlParam;
mode
addr;
addr_size;
data;
data_size;
cnt;
callBack
errStat
status
// Transmit/receive mode (0: Transmission, 1: Reception)
// Pointer to the area that contains address data
// Address size
// Pointer to the area that contains transmit/receive data
// Transmit/receive data size
// Size of transmitted/received data
// Callback function
// Error status
// Transmit/receive status
48
ML610Q400 Series
Sample Program API Manual
3.6.6. List of Variables
The following table lists the variables used in the I2C module.
Variable name
static
tI2cCtrlParam_gsCtrlParam
Initial value
mode: 0
addr: NULL
addr_size: 0
data: NULL
data_size: 0
cnt: 0
callBack: NULL
errStat: 0
status: 0
Description
Variable to manage the data for I2C
transmission/reception
3.6.7. Details of APIs
This section describes details of the I2C module APIs.
3.6.7.1. i2c_init Function
This function initializes the I2C bus interface of the MCU. In the initialization, the function selects communication
speed and the use/nonuse of the clock synchronization function.
Function
name:
Arguments:
Return
values:
int i2c_init(
unsigned char mode,
unsigned short kHz,
unsigned char syn
)
unsigned char mode … Selection of communication speed
Standard mode (100kHz): I2C_MOD_STD (=0)
Fast mode (400kHz): I2C_MOD_FST (=1)
unsigned short kHz … Frequency of HSCLK [kHz]
unsigned char syn …Use or nonuse of the clock synchronization function
Do not use the clock synchronization: I2C_SYN_OFF (=0)
Use the clock synchronization: I2C_SYN_ON (=1)
int
Initialization succeeded: I2C_R_OK(=0)
The specified value for the clock synchronization function is outside the range: I2C_R_ERR_SYN (=-1)
The specified communication speed was unsettable: I2C_R_ERR_MODE (=-2)
The selected high-speed clock is outside the range: I2C_R_ERR_FREQ (=-3)
49
ML610Q400 Series
Sample Program API Manual
Processing:
(1/4)
Initialize I2C module
i2c_init function
Is clock synchronization enabled?
(syn <= I2C_SYN_ON)
No
Yes
Standard mode (100kHz)?
(mode = I2C_MOD_STD)
The specified value for the clock synchronization
function is outside the range.
Return value: I2C_R_ERR_SYN
No
Yes
Fast mode (400kHz)?
(mode = I2C_MOD_FST )
No
Yes
HSCLK clock period (tCYC)
rate_cyc = I2C_STD_CYC(=40)
HSCLK clock period (tCYC)
rate_cyc = I2C_FST_CYC(=10)
Standard mode (100kHz)
rate_khz = I2C_STD_KHZ(=100)
Fast mode (400kHz)
rate_khz = I2C_FST_KHZ(=400)
Set communication speed
reduction rate
*See next page
Initialize I2C control parameters
*See next page
Configure port settings
*See next page
[I2C operation mode setting]
Set use/nonuse of clock synchronization function, communication
speed reduction rate, and I2C operation enable
I2C0MOD = (argument syn<<4) | (variable down<< 2) | (mode<<1) |
0x01
Initialization processing succeeded
Return value: I2C_R_OK
50
Unsettable communication speed
Return value: I2C_R_ERR_MODE
ML610Q400 Series
Sample Program API Manual
Processing:
(2/4)
51
ML610Q400 Series
Sample Program API Manual
Processing:
(3/4)
52
ML610Q400 Series
Sample Program API Manual
Processing:
(4/4)
53
ML610Q400 Series
Sample Program API Manual
3.6.7.2.
i2c_startSend Function
This function starts and stops transmission of address and data. If this function is called during data
transmission/reception, I2C_R_BUS_BUSY (=-1) will be returned, terminating the transmission/reception.
Function
name:
Arguments:
Return
values:
int i2c_startSend(
unsigned char slave_adr,
unsigned char *addr,
unsigned int addr_size,
unsigned char *data,
unsigned int data_size,
cbfI2c func )
unsigned char slave_adr …. Address of the transmission destination slave device
unsigned char *addr … Pointer to the area that contains address and data
unsigned int addr_size …. Size of address and data to be transmitted (byte units)
unsigned char *data … Pointer to the area that contains transmit data
unsigned int data_size …. Transmit data sizes (byte units)
tCallBack func … Function to be executed upon completion of transmission
int
Transmit/receive start processing ended: I2C_R_TRANS_START_OK (=0)
I2C bus busy state: I2C_R_BUS_BUSY (=-1)
No transmit data: I2C_R_TRANS_FIN(=-2)
54
ML610Q400 Series
Sample Program API Manual
Processing:
55
ML610Q400 Series
Sample Program API Manual
3.6.7.3.
i2c_startReceive Function
This function starts data reception. If this function is called during data transmission/reception, I2C_R_BUS_BUSY
(=-1) will be returned, terminating the transmission/reception.
Function
name:
Arguments:
Return
values:
int i2c_startReceive(
unsigned char slave_adr,
unsigned char *addr,
unsigned int addr_size,
unsigned char *data,
unsigned int data_size,
cbfI2c func )
unsigned char slave_adr …. Address of the receiving slave device
unsigned char *addr … Pointer to the area that contains the receive start address
unsigned int addr_size …. Size of address and data (byte units)
unsigned char *data … Pointer to the area that stores receive data
unsigned int data_size …. Receive data sizes (byte units)
tCallBack func … Function to be executed upon completion of reception
int
Transmit/receive start processing ended: I2C_R_TRANS_START_OK (=0)
I2C bus busy state: I2C_R_BUS_BUSY (=-1)
No transmit data: I2C_R_TRANS_FIN(=-2)
56
ML610Q400 Series
Sample Program API Manual
Processing:
Data reception start
processing
i2c_startReceive function
Set I2C transmit/receive
control parameters
[Transmit/receive mode]
Set to receive mode
_gsCtrlParam.mode = 1
[Pointer to the address storage area]
_gsCtrlParam.addr = argument "addr”
[Address size]
_gsCtrlParam.addr_size = argument
"addr_size”
[Transmit/receive data storage area]
_gsCtrlParam.data = argument "data”
[Transmit/receive data size]
_gsCtrlParam.data_size = argument
"data_size”
[Size of transmitted/received data]
No transmitted/received data size
_gsCtrlParam.cnt = 0
[Callback function]
_gsCtrlParam.callBack = argument "func”
[Error status]
Error status: No error
_gsCtrlParam.errStat = 0
[Transmit/receive status]
Transmit/receive status: Operation stopped
_gsCtrlParam.status = I2C_TRANS_END
Transmit data present?
(Either _gsCtrlParam.addr_size or
No
_gsCtrlParam.data_size is other than 0)
No receive data
Return value: I2C_R_TRANS_FIN
Yes
I2C bus free state?
(I2C0STAT register's I20BB bit = 0)
No
Yes
I2C bus busy state
Return value: I2C_R_BUS_BUSY
[Transmit/receive status]
Slave address is being transmitted
_gsCtrlParam.status = I2C_SEND_SLAVE_ADDRESS
Transmit address present?
_gsCtrlParam.addr_size is other than 0)
Yes
[I2C slave address setting]
Slave address setting and data transmission mode
I2C0SA register = argument "slave_adr” << 1
[Communication start]
I2C0CON register's I20ST bit = 1
End of processing
57
No
[I2C slave address setting]
Slave address setting and data reception mode
I2C0SA register = argument "slave_adr” << 1 | 0x01
ML610Q400 Series
Sample Program API Manual
3.6.7.4.
i2c_continue Function
This function continues data transmission/reception. If there is any registered callback function upon completion of
transmission/reception or upon occurrence of an error, that callback function will be executed.
Function
name:
Arguments:
Return
values:
int i2c_continue( void )
None
int
Transmit/receive processing ended: I2C_R_TRANS_FIN (=1)
Transmit/receive processing is going on (transmission/reception succeeded): I2C_R_TRANS_CONT_OK (=0)
Transmit/receive processing ended (transmission/reception failed): I2C_R_TRANS_FIN_NG (=-2)
Processing:
(1/8)
58
ML610Q400 Series
Sample Program API Manual
Processing:
(2/8)
59
ML610Q400 Series
Sample Program API Manual
Processing:
(3/8)
60
ML610Q400 Series
Sample Program API Manual
Processing:
(4/8)
61
ML610Q400 Series
Sample Program API Manual
Processing:
(5/8)
62
ML610Q400 Series
Sample Program API Manual
Processing:
(6/8)
63
ML610Q400 Series
Sample Program API Manual
Processing:
(7/8)
Data receive processing
[Receive data acquisition]
*_gsCtrlParam.data =I2C0RD register
[I2C transmit/receive control parameter (data) update]
_gsCtrlParam.data++
_gsCtrlParam.cnt++
Receive data present?
(_gsCtrlParam.data_size !=
_gsCtrlParam.cnt)
No
Yes
Last receive data?
(_gsCtrlParam.mode != 0)
[Transmit/receive status]
Transmit/receive status Operation stopped
_gsCtrlParam.status = I2C_TRANS_END
No
Yes
[I2C operation start & NAK response]
I20ACT register's I20ST bit=0
I20ACT register's I20ACT bit=1
[I2C operation start & ACK response]
I2C0CON register's I20ST bit = 0
I20ACT register's I20ACT bit = 0
Returns “I2C_R_TRANS_CONT_OK”
64
[STOP condition request]
I2C0CON register's I20SP bit=1
ML610Q400 Series
Sample Program API Manual
Processing:
(8/8)
65
ML610Q400 Series
Sample Program API Manual
3.6.7.5.
i2c_stop Function
This function stops data transmission/reception.
Function
name:
Arguments:
Return
values:
Processing:
void i2c_stop( void )
None
None
66
ML610Q400 Series
Sample Program API Manual
3.6.7.6.
i2c_checkIRQ Function
This function checks the QI2C0 bit of the interrupt request register 2 to indicate the presence or absence of an I2C
interrupt request.
Function
name:
Arguments:
Return
values:
int i2c_checkIRQ( void )
None
int
I2C interrupt request is present: I2C_R_IRQ
I2C interrupt request is absent: I2C_R_NON_IRQ
Processing:
67
ML610Q400 Series
Sample Program API Manual
3.6.7.7.
i2c_clearIRQ Function
This function clears the I2C interrupt request (interrupt request register 2’s QI2C0 bit).
Function
name:
Arguments:
Return
values:
Processing:
void i2c_clearIRQ( void )
None
None
68
ML610Q400 Series
Sample Program API Manual
3.6.7.8.
i2c_getTransSize Function
This function acquires the size of transmitted/received data.
If the i2c_stop function is called, the size of transmitted/received data is cleared.
Function
name:
Arguments:
Return
values:
unsigned int i2c_getTransSize( void )
None
unsigned int
Size of transmitted/received data
(*Size of the data that has been transferred after the i2c_startSend or i2c_startReceive function is executed and
before the i2c_getTransSize function is called.)
Processing:
69
ML610Q400 Series
Sample Program API Manual
3.7. EEPROM Module
3.7.1. Overview of Functions
The EEPROM module writes/reads data to/from EEPROM using the I2C of the MCU. Controllable items are N-byte
write, N-byte read, and write protection.
3.7.2. List of APIs
The following table lists the EEPROM module APIs.
Table 3-20 EEPROM APIs
Function name
Function
eeprom_init function
Enables EEPROM write-protect.
eeprom_read function
Starts reading data from EEPROM.
Starts writing data to EEPROM.
Continues data write or read processing.
Stops data write or read processing.
Acquires the EEPROM control module status.
Enables or disables EEPROM write-protect.
eeprom_write function
eeprom_continue function
eeprom_stop function
eeprom_getStatus function
eeprom_writeProtect function
Table 3-21 EEPROM Subroutines
Function name
Description
_i2cFin function
Callback function to be called upon completion of I2C transmission/reception
3.7.3. List of Constants
The following table lists the constants used in the EEPROM module.
Table 3-22 List of Constants for Return Values
Defined
value
Constant name
EEPROM_R_OK
EEPROM_R_NG
EEPROM_R_PROCESS
EEPROM_R_SUCCESS
EEPROM_R_ERROR
0
-1
1
0
-1
Description
Data write/read start processing succeeded
Data write/read start processing failed
Data write/read processing is in progress
Data write/read processing ended normally
Data write/read processing ended abnormally
Table 3-23 List of Constants for EEPROM Customization
Constant name
EEPROM_SLAVE_ADDRESS
EEPROM_PAGE_SIZE
Defined
value
0x50
64
Description
Slave address
Page size
70
ML610Q400 Series
Sample Program API Manual
Table 3-24 List of Constants for Internal Statuses
Constant name
ST_STOP
ST_I2C_SEND_START
ST_I2C_SEND_EXEC
ST_I2C_RECEIVE_START
ST_I2C_RECEIVE_EXEC
ST_EEP_WRITE_START
ST_EEP_WRITE_EXEC
Defined
value
0
1
2
3
4
5
6
Description
Processing stopped
Started data transmission
Data is being transmitted
Started data reception
Data is being received
Start writing to EEPROM
Data is being written to EEPROM
3.7.4. Structure
This section describes the structures used in the EEPROM module.
Control parameters
typedef struct {
unsigned char
unsigned char *
unsigned int
unsigned int
unsigned int
int
int
} tEepromCtrlParam;
address[2];
data;
remain_size;
total_size;
proc_size;
result;
internal_status;
// Write/read start address
// Pointer to the transmit/receive data storage area
// Remaining data size
// Size of the data transmitted/received actually
// Size for one data-write/read
// Execution result
// Internal status
3.7.5. List of Variables
The following table lists the variables used in the EEPROM module.
Table 3-25 List of Variables
Variable name
static
tEepromCtrlParam_gsCtrlParam
Initial value
address: 0x00,0x00
data: NULL
remain_size: 0
total_size: 0
proc_size: 0
result: 0
internal_status: 0
71
Description
Information to be used at read/write
ML610Q400 Series
Sample Program API Manual
3.7.6. Details of APIs
This section describes details of the EEPROM module APIs.
3.7.6.1. eeprom_init Function
This function initializes the EEPROM module. In initialization, the function enables EEPROM write-protect, sets the
initial settings for internal variables, and initializes the I2C module.
Function
name:
Arguments:
Return
values:
Processing:
void eeprom_init(void)
None
None
72
ML610Q400 Series
Sample Program API Manual
3.7.6.2.
eeprom_write Function
This function starts writing to EEPROM. If the transmit data size is larger than EEPROM_PAGE_SIZE, the data is
segmented into EEPROM_PAGE_SIZE size to write to EEPROM.
Function
name:
Arguments:
Return
values:
int eeprom_write(void)
unsigned int address,
unsigned char* data,
unsigned int size
)
unsigned int address …. Device’s address at which to start writing
unsigned char* data … Pointer to the area that contains transmit data
unsigned int size …. Transmit data size (byte units)
Int
EEPROM_R_OK(=0): The starting of writing succeeded.
EEPROM_R_NG(=-1): The starting of writing failed.
Processing:
EEPROM write start processing
eeprom_write function
Processing being stopped?
(_gsCtrlParam.internal_status != ST_STOP)
No
Starting of writing failed
Yes
Return value: EEPROM_R_NG
EEPROM read/write address
_gsCtrlParam.address[0] = Upper byte of argument "address"
_gsCtrlParam.address[1] = Lower byte of argument "address"
EEPROM read/write buffer
_gsCtrlParam.data = argument "data
EEPROM read/write remaining data size
_gsCtrlParam.remain_size = argument "size"
EEPROM read/write size
_gsCtrlParam.total_size = 0
EEPROM read/write processing size
_gsCtrlParam.proc_size = segmented-processing size(*1)
EEPROM read/write execution result
(processing in progress)
_gsCtrlParam.result = EEPROM_R_PROCESS
EEPROM read/write internal status
(I2C data is being transmitted)
_gsCtrlParam.internal_status = ST_I2C_SEND_START
Starting of writing succeeded
Return value: EEPROM_R_OK
73
*1: Indicates the value of
EEPROM_PAGE_SIZE
described above in this page.
ML610Q400 Series
Sample Program API Manual
3.7.6.3.
eeprom_read Function
This function starts reading data from EEPROM.
Function
name:
Arguments:
Return
values:
int eeprom_read(
unsigned int address,
unsigned char* data,
unsigned int size
)
unsigned int address …. Device’s address at which to start reading
unsigned char* data … Pointer to the area that contains receive data
unsigned int size …. Receive data size (byte units)
Int
EEPROM_R_OK(=0): The starting of reading succeeded.
EEPROM_R_NG(=-1): The starting of reading failed.
Processing:
EEPROM read start processing
eeprom_read function
Processing being stopped?
(_gsCtrlParam.internal_status != ST_STOP)
No
Starting of reading failed
Yes
Return value: EEPROM_R_NG
EEPROM read/write address
_gsCtrlParam.address[0] = Upper byte of argument "address"
_gsCtrlParam.address[1] = Lower byte of argument "address"
EEPROM read/write buffer
_gsCtrlParam.data = argument "data”
EEPROM read/write remaining data size
_gsCtrlParam.remain_size = argument "size"
EEPROM read/write size
_gsCtrlParam.total_size = 0
EEPROM read/write processing size
_gsCtrlParam.proc_size = page size or remaining data
size, whichever smaller
EEPROM read/write execution result
(processing in progress)
_gsCtrlParam.result = EEPROM_R_PROCESS
EEPROM read/write internal status
(I2C data is being transmitted)
_gsCtrlParam.internal_status = ST_I2C_RECEIVE_START
Starting of reading succeeded
Return value: EEPROM_R_OK
74
ML610Q400 Series
Sample Program API Manual
3.7.6.4.
eeprom_continue Function
This function continues EEPROM read/write processing.
Function
name:
Arguments:
Return
values:
int eeprom_continue( void )
None
int … EEPROM module processing status
EEPROM_R_PROCESS (= 1) … Read/write processing is being executed
EEPROM_R_ERROR (= 0) … Abnormal end
EEPROM_R_SUCCESS (= -1) … Normal end
Processing:
(1/4)
Processing:
(2/4)
75
ML610Q400 Series
Sample Program API Manual
Processing:
(3/4)
Processing:
(4/4)
76
ML610Q400 Series
Sample Program API Manual
3.7.6.5.
eeprom_stop Function
This function stops EEPROM read/write processing.
Function
name:
Arguments:
Return
values:
Processing:
void eeprom_stop( void )
None
None
Read/write stop processing
eeprom_stop function
Stop I2C transmission/
reception
i2c_stop function call
Management information
initialization
EEPROM read/write address
_gsCtrlParam.address[0] = 0x00
_gsCtrlParam.address[1] = 0x00
EEPROM read/write buffer
_gsCtrlParam.data = (void *)0
EEPROM read/write remaining data size
_gsCtrlParam.remain_size = 0
EEPROM read/write size
_gsCtrlParam.total_size = 0
EEPROM read/write processing size
_gsCtrlParam.proc_size = 0
EEPROM read/write execution result
_gsCtrlParam.result =
EEPROM_R_SUCCESS
EEPROM read/write internal status
_gsCtrlParam.internal_status = ST_STOP
Return the execution result
(_gsCtrlParam.result)
77
ML610Q400 Series
Sample Program API Manual
3.7.6.6. eeprom_getStatus Function
This function acquires the EEPROM module processing status.
Function
name:
Arguments:
Return
values:
int eeprom_getStatus(void)
None
int … EEPROM module processing status
EEPROM_R_PROCESS (= 1) … Processing is being executed
EEPROM_R_ERROR (= 0) … Abnormal end
EEPROM_R_SUCCESS (= -1) … Normal end
Processing:
78
ML610Q400 Series
Sample Program API Manual
3.7.6.7. eeprom_writeProtect Function
This function sets EEPROM write-protect to enabled or disabled.
Function
name:
Arguments:
Return
values:
Processing:
void eeprom_writeProtect(unsigned char wp)
unsigned char wp
0: Write-protect is disabled.
Other than 0: Write-protect is enabled.
None
Setting write-protect to enabled or disabled
eeprom_writeProtect function
Is write-protect enabled?
(Argument “wp” is other than 0)
No
Yes
Enable write-protect
P20D = 1
Disable write-protect
P20D = 0
End of processing
.
79
ML610Q400 Series
Sample Program API Manual
3.8. LCD Module
3.8.1. Overview of Functions
The LCD module controls the LCD driver of the MCU.
Display on the LCD panel is achieved by APIs that perform initialization (setting of bias, duty, frame frequency, etc),
contrast setting, display mode setting, 7-seg or 16-seg display, and mark display.
3.8.2. List of APIs
The following table lists the LCD module APIs.
Table 3-26 LCD Module APIs
Function name
lcd_init function
lcd_setContrast function
lcd_setLCDMode function
lcd_dispHour function
lcd_dispMin function
lcd_dispSec function
lcd_dispMain function
lcd_disp1Digit function
lcd_disp2Digit function
lcd_disp4Digit function
lcd_dipMark function
Description
Initialization
Contrast value setting
LCD display mode setting
Displays hours.
Displays minutes.
Displays seconds.
Displays the 12 digits on the lower part of the panel
Displays a 1-digit numeral.
Displays a 2-digit numeral.
Displays a 4-digit numeral.
Displays various marks.
3.8.3. List of Subroutines
The following table lists the LCD module subroutines.
Table 3-27 LCD Module Subroutines
Function name
_getDSPR function
_getMarkDSPR function
_get7SegPtn function
_dsp7SEG function
_dsp7SEG_Ndigit function
_get16SegPtn function
_dsp16SEG function
_dsp16SEG_Ndigit function
_TableCopyFunc function
Description
Acquisition of a DSPR address
Acquisition of a mark display DSPR address
Acquisition of a 7-seg pattern
7-seg display (1 digit)
7-seg display (multiple digits)
Acquisition of a 16-seg pattern
16-seg display (1 digit)
16-seg display (multiple digits)
Transfers assignment table data for the display assignment registers A and B.
80
ML610Q400 Series
Sample Program API Manual
3.8.4. List of Constants
The following tables list the constants used in the LCD module.
Table 3-28 Constants for Arguments (1)
Constant name
Defined
value
LCD_BSN_32KHZ
0
LCD_BSN_16KHZ
1
LCD_BSN_8KHZ
2
LCD_BSN_4KHZ
3
LCD_BSN_2KHZ
4
LCD_BSN_1KHZ
5
LCD_BSN_512HZ
6
LCD_BSN_256HZ
7
LCD_BSEL_DIV3
LCD_BSEL_DIV4
LCD_DUTY_DIV1
LCD_DUTY_DIV2
LCD_DUTY_DIV3
LCD_DUTY_DIV4
LCD_DUTY_DIV5
LCD_DUTY_DIV6
LCD_DUTY_DIV7
LCD_DUTY_DIV8
LCD_DUTY_DIV9
LCD_DUTY_DIV10
LCD_DUTY_DIV11
LCD_DUTY_DIV12
LCD_DUTY_DIV13
LCD_DUTY_DIV14
LCD_DUTY_DIV15
LCD_DUTY_DIV16
LCD_DUTY_DIV17
LCD_DUTY_DIV18
LCD_DUTY_DIV19
LCD_DUTY_DIV20
LCD_DUTY_DIV21
LCD_DUTY_DIV22
LCD_DUTY_DIV23
LCD_DUTY_DIV24
0
1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Description
Specifies 32 kHz as the voltage multiplication clock of the
bias generation circuit.
Specifies 16 kHz as the voltage multiplication clock of the
bias generation circuit.
Specifies 8 kHz as the voltage multiplication clock of the bias
generation circuit.
Specifies 4 kHz as the voltage multiplication clock of the bias
generation circuit.
Specifies 2 kHz as the voltage multiplication clock of the bias
generation circuit.
Specifies 1 kHz as the voltage multiplication clock of the bias
generation circuit.
Specifies 512 Hz as the voltage multiplication clock of the
bias generation circuit.
Specifies 256 Hz as the voltage multiplication clock of the
bias generation circuit.
Specifies 1/3 bias for the bias generation circuit.
Specifies 1/4 bias for the bias generation circuit.
Specifies 1/1 duty.
Specifies 1/2 duty.
Specifies 1/3 duty.
Specifies 1/4 duty.
Specifies 1/5 duty.
Specifies 1/6 duty.
Specifies 1/7 duty.
Specifies 1/8 duty.
Specifies 1/9 duty.
Specifies 1/10 duty.
Specifies 1/11 duty.
Specifies 1/12 duty.
Specifies 1/13 duty.
Specifies 1/14 duty.
Specifies 1/15 duty.
Specifies 1/16 duty.
Specifies 1/17 duty.
Specifies 1/18 duty.
Specifies 1/19 duty.
Specifies 1/20 duty.
Specifies 1/21 duty.
Specifies 1/22 duty.
Specifies 1/23 duty.
Specifies 1/24 duty.
81
ML610Q400 Series
Sample Program API Manual
Table 3-29 Constants for Arguments (2)
Constant name
Defined
value
LCD_FRM_64HZ
0
LCD_FRM_73HZ
1
LCD_FRM_85HZ
2
LCD_FRM_102HZ
3
LCD_LMD_STOP
LCD_LMD_ALLOFF
LCD_LMD_NORMAL
0
1
2
LCD_LMD_ALLON
LCD_POS_MAIN_01
3
0x00
LCD_POS_MAIN_02
0x01
LCD_POS_MAIN_03
0x02
LCD_POS_MAIN_04
0x03
LCD_POS_MAIN_05
0x04
LCD_POS_MAIN_06
0x05
LCD_POS_MAIN_07
0x06
LCD_POS_MAIN_08
0x07
LCD_POS_MAIN_09
0x08
LCD_POS_MAIN_10
0x09
LCD_POS_MAIN_11
0x0A
LCD_POS_MAIN_12
0x0B
LCD_POS_HOUR_01
LCD_POS_HOUR_10
LCD_POS_HOUR
LCD_POS_MIN_01
LCD_POS_MIN_10
LCD_POS_MIN
LCD_POS_SEC_01
LCD_POS_SEC_10
LCD_POS_SEC
LCD_POS_MODE_01
0x10
0x11
0x10
0x20
0x21
0x20
0x30
0x31
0x30
0x40
LCD_POS_MODE_02
0x41
LCD_POS_MODE_03
0x42
Description
Specifies 64 Hz as the reference frequency of the frame
frequency.
Specifies 73 Hz as the reference frequency of the frame
frequency.
Specifies 85 Hz as the reference frequency of the frame
frequency.
Specifies 102 Hz as the reference frequency of the frame
frequency.
Specifies LCD stop mode as the mode of display.
Specifies LCD all-off mode as the mode of display.
Specifies LCD display mode (normal mode) as the mode of
display.
Specifies LCD all-on mode as the mode of display.
Specifies the display of the 1st digit of the 12 digits on the
lower section.
Specifies the display of the 2nd digit of the 12 digits on the
lower section.
Specifies the display of the 3rd digit of the 12 digits on the
lower section.
Specifies the display of the 4th digit of the 12 digits on the
lower section.
Specifies the display of the 5th digit of the 12 digits on the
lower section.
Specifies the display of the 6th digit of the 12 digits on the
lower section.
Specifies the display of the 7th digit of the 12 digits on the
lower section.
Specifies the display of the 8th digit of the 12 digits on the
lower section.
Specifies the display of the 9th digit of the 12 digits on the
lower section.
Specifies the display of the 10th digit of the 12 digits on the
lower section.
Specifies the display of the 11th digit of the 12 digits on the
lower section.
Specifies the display of the 12th digit of the 12 digits on the
lower section.
Specifies the display of the ones digit of hours.
Specifies the display of the tens digit of hours.
Specifies hour display.
Specifies the display of the ones digit of minutes.
Specifies the display of the tens digit of minutes.
Specifies minute display.
Specifies the display of the ones digit of seconds.
Specifies the display of the tens digit of seconds.
Specifies second display.
Specifies the display of the 1st digit of Mode (the upper-left
four digits on the upper section).
Specifies the display of the 2nd digit of Mode (the upper-left
four digits on the upper section).
Specifies the display of the 3rd digit of Mode (the upper-left
four digits on the upper section).
82
ML610Q400 Series
Sample Program API Manual
LCD_POS_MODE_04
0x43
LCD_POS_MODE_LOW
0x40
LCD_POS_MODE_HIGH
0x42
LCD_POS_MODE
0x40
LCD_TURNOFF
LCD_TURNON
LCD_TYPE_0_DISP
LCD_TYPE_0_BLANK
0
1
0
1
Specifies the display of the 4th digit of Mode (the upper-left
four digits on the upper section).
Specifies the display of the 1st and 2nd digits of Mode (the
upper-left four digits on the upper section).
Specifies the display of the 3rd and 4th digits of Mode (the
upper-left four digits on the upper section).
Specifies the display of Mode (the upper-left four digits on
the upper section).
Specifies turning off the LCD.
Specifies turning on the LCD.
Displays “0” as “0”.
Displays “0” as “blank”.
Table 3-30 Constants for Return Values
Constant name
Defined
value
LCD_R_OK
LCD_R_ERR_BSN
0
-1
LCD_R_ERR_BSEL
-2
LCD_R_ERR_DUTY
LCD_R_ERR_FRM
LCD_R_ERR_LMD
LCD_R_ERR_CNT
LCD_R_ERR_POS
LCD_R_ERR_EN
LCD_R_ERR_TYPE
LCD_R_ERR_DIGIT
LCD_R_ERR_MARKNO
-3
-4
-5
-6
-7
-8
-9
-10
-11
Description
Initialization succeeded
Selection of the voltage multiplication clock for the bias
generation circuit is outside the range.
The bias selection for the bias generation circuit is outside
the range.
The duty selection is outside the range.
The frame frequency selection is outside the range.
The display mode selection is outside the range.
The contrast value is outside the range.
The display position setting is outside the range.
The on/off setting is outside the range.
The display type is outside the range.
The display value is outside the range.
The display position setting is outside the range.
Table 3-31 Constants for LCD Codes
Constant name
LCD_CODE_NUM_0
LCD_CODE_NUM_1
LCD_CODE_NUM_2
LCD_CODE_NUM_3
LCD_CODE_NUM_4
LCD_CODE_NUM_5
LCD_CODE_NUM_6
LCD_CODE_NUM_7
LCD_CODE_NUM_8
LCD_CODE_NUM_9
LCD_CODE_HEX_A
LCD_CODE_HEX_B
LCD_CODE_HEX_C
LCD_CODE_HEX_D
LCD_CODE_HEX_E
LCD_CODE_HEX_F
LCD_CODE_BLANK
LCD_CODE_MINUS
LCD_CODE_G
LCD_CODE_H
LCD_CODE_I
LCD_CODE_J
Defined
value
0x30
0x31
0x32
0x33
0x34
0x35
0x36
0x37
0x38
0x39
0x41
0x42
0x43
0x44
0x45
0x46
0x20
0x2D
0x47
0x48
0x49
0x4A
Description
LCD code corresponding to a display of “0”
LCD code corresponding to a display of “1”
LCD code corresponding to a display of “2”
LCD code corresponding to a display of “3”
LCD code corresponding to a display of “4”
LCD code corresponding to a display of “5”
LCD code corresponding to a display of “6”
LCD code corresponding to a display of “7”
LCD code corresponding to a display of “8”
LCD code corresponding to a display of “9”
LCD code corresponding to a display of “A”
LCD code corresponding to a display of “B”
LCD code corresponding to a display of “C”
LCD code corresponding to a display of “D”
LCD code corresponding to a display of “E”
LCD code corresponding to a display of “F”
LCD code corresponding to a display of “(blank)”
LCD code corresponding to a display of “-”
LCD code corresponding to a display of “G”
LCD code corresponding to a display of “H”
LCD code corresponding to a display of “I”
LCD code corresponding to a display of “J”
83
ML610Q400 Series
Sample Program API Manual
Constant name
LCD_CODE_K
LCD_CODE_L
LCD_CODE_M
LCD_CODE_N
LCD_CODE_O
LCD_CODE_P
LCD_CODE_Q
LCD_CODE_R
LCD_CODE_S
LCD_CODE_T
LCD_CODE_U
LCD_CODE_V
LCD_CODE_W
LCD_CODE_X
LCD_CODE_Y
LCD_CODE_Z
Defined
value
0x4B
0x4C
0x4D
0x4E
0x4F
0x50
0x51
0x52
0x53
0x54
0x55
0x56
0x57
0x58
0x59
0x5A
Description
LCD code corresponding to a display of “K”
LCD code corresponding to a display of “L”
LCD code corresponding to a display of “M”
LCD code corresponding to a display of “N”
LCD code corresponding to a display of “O”
LCD code corresponding to a display of “P”
LCD code corresponding to a display of “Q”
LCD code corresponding to a display of “R”
LCD code corresponding to a display of “S”
LCD code corresponding to a display of “T”
LCD code corresponding to a display of “U”
LCD code corresponding to a display of “V”
LCD code corresponding to a display of “W”
LCD code corresponding to a display of “X”
LCD code corresponding to a display of “Y”
LCD code corresponding to a display of “Z”
84
ML610Q400 Series
Sample Program API Manual
Table 3-32 MARK Code Constants
Constant name
LCD_MARK_DOC1
LCD_MARK_DOF1
LCD_MARK_HPA
LCD_MARK_DOC2
LCD_MARK_DOF2
LCD_MARK_PERCENT
LCD_MARK_COL1
LCD_MARK_COL2
LCD_MARK_C2
LCD_MARK_C1
LCD_MARK_PM
LCD_MARK_AM
LCD_MARK_DATE
LCD_MARK_MONTH
LCD_MARK_YEAR
LCD_MARK_T1
LCD_MARK_T2
LCD_MARK_B1
LCD_MARK_B2
LCD_MARK_B3
LCD_MARK_B4
LCD_MARK_E
LCD_MARK_K
LCD_MARK_M
LCD_MARK_PLUS
LCD_MARK_MINUS
LCD_MARK_MULTI
LCD_MARK_DIV
LCD_MARK_11H
LCD_MARK_12H
LCD_MARK_13H
LCD_MARK_14H
LCD_MARK_15H
LCD_MARK_16H
LCD_MARK_17H
LCD_MARK_18H
LCD_MARK_19H
LCD_MARK_20H
LCD_MARK_21H
LCD_MARK_22H
LCD_MARK_Y16
LCD_MARK_Y15
LCD_MARK_Y14
LCD_MARK_Y13
LCD_MARK_Y12
LCD_MARK_Y11
LCD_MARK_Y10
LCD_MARK_Y9
LCD_MARK_Y8
LCD_MARK_Y7
LCD_MARK_Y6
LCD_MARK_Y5
Defined
value
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
0x0A
0x0B
0x0C
0x0D
0x0E
0x0F
0x10
0x11
0x12
0x13
0x14
0x15
0x16
0x17
0x18
0x19
0x1A
0x1B
0x1C
0x1D
0x1E
0x1F
0x20
0x21
0x22
0x23
0x24
0x25
0x26
0x27
0x28
0x29
0x2A
0x2B
0x2C
0x2D
0x2E
0x2F
0x30
0x31
0x32
0x33
Description
“doC1” mark
“doF1” mark
“hpa” mark
“doC2” mark
“doF2” mark
“%” mark
“COL1” mark
“COL2” mark
“C2” mark
“C1” mark
“PM” mark
“AM” mark
“DATE” mark
“MONTH” mark
“YEAR” mark
“T1” mark
“T2” mark
“B1” mark
“B2” mark
“B3” mark
“B4” mark
“E” mark
“K” mark
“M” mark
“+” mark
“-” mark
“∗” mark
“÷” mark
“11H” mark
“12H” mark
“13H” mark
“14H” mark
“15H” mark
“16H” mark
“17H” mark
“18H” mark
“19H” mark
“20H” mark
“21H” mark
“22H” mark
“Y16” mark
“Y15” mark
“Y14” mark
“Y13” mark
“Y12” mark
“Y11” mark
“Y10” mark
“Y9” mark
“Y8” mark
“Y7” mark
“Y6” mark
“Y5” mark
85
ML610Q400 Series
Sample Program API Manual
Constant name
LCD_MARK_Y4
LCD_MARK_Y3
LCD_MARK_Y2
LCD_MARK_Y1
Defined
value
0x34
0x35
0x36
0x37
Description
“Y4” mark
“Y3” mark
“Y2” mark
“Y1” mark
86
ML610Q400 Series
Sample Program API Manual
3.8.5. API Details
This section describes details of the LCD module.
3.8.5.1.
lcd_init Function
This function initializes the LCD driver section of the MCU according to the specification of the LCD panel used. Bias,
duty, and frame frequency are set by this function.
Function
name:
Arguments:
Return
values:
int lcd_init(
unsigned char bsn,
unsigned char bsel,
unsigned char duty,
unsigned char frm
)
unsigned char bsn … Voltage multiplication clock selection for the bias generation circuit
1/1LSCLK(32kHz): LCD_BSN_32KHZ(=0)
1/2LSCLK(16kHz): LCD_BSN_16KHZ(=1)
1/4LSCLK(8kHz): LCD_BSN_8KHZ(=2)
1/8LSCLK(4kHz): LCD_BSN_4KHZ(=3)
1/16LSCLK(2kHz): LCD_BSN_2KHZ(=4)
1/32LSCLK(1kHz): LCD_BSN_1KHZ(=5)
1/64LSCLK(512Hz): LCD_BSN_512HZ(=6)
1/128LSCLK(256Hz): LCD_BSN_256HZ(=7)
unsigned char bsel … Bias selection for the bias generation circuit
1/3 bias: LCD_BSEL_DIV3(=0)
1/4 bias: LCD_BSEL_DIV4(=1)
unsigned char duty … Duty selection
1/1 duty: LCD_DUTY_DIV1
… (* For details, see Table 3-28.)
1/24 duty: LCD_DUTY_DIV24
unsigned char frm … Selection of frame frequency
Reference frequency 64Hz: LCD_FRM_64HZ(=0)
Reference frequency 73Hz: LCD_FRM_73HZ(=1)
Reference frequency 85Hz: LCD_FRM_85HZ(=2)
Reference frequency 102Hz: LCD_FRM_102HZ(=3)
int
Initialization succeeded: LCD_R_OK(=0)
The selected voltage multiplication clock selected for the bias generation circuit is outside the range:
LCD_R_ERR_BSN(=-1)
The selected bias for the bias generation circuit is outside the range: LCD_R_ERR_BSEL(= -2)
The selected duty is outside the range: LCD_R_ERR_DUTY(=-3)
The selected frame frequency is outside the range: LCD_R_ERR_FRM(= -4)
87
ML610Q400 Series
Sample Program API Manual
Processing:
See next page.
88
ML610Q400 Series
Sample Program API Manual
3.8.5.2.
lcd_setContrast Function
This function sets the contrast of the LCD. It allows 32 levels of contrast adjustment.
Function
name:
Arguments:
Return
values:
int lcd_setContrast(
unsigned char cnt
)
unsigned char cnt … Contrast value (0 to 31)
int
Setting succeeded: LCD_R_OK(=0)
The set contrast value is outside the range: LCD_R_ERR_CNT (=-6)
Processing:
89
ML610Q400 Series
Sample Program API Manual
3.8.5.3.
lcd_setLCDMode Function
This function sets the display mode of LCD by selecting from among four modes including stop mode and display mode.
Function
name:
Arguments:
Return
values:
int lcd_setLCDMode(
unsigned char mode
)
unsigned char mode … LCD display mode
LCD stop mode: LCD_LMD_STOP(=0)
LCD all-off mode: LCD_LMD_ALLOFF(=1)
LCD display mode: LCD_LMD_NORMAL(=2)
LCD all-on mode: LCD_LMD_ALLON(=3)
int
Setting succeeded: LCD_R_OK(=0)
The set LCD display mode is outside the range: LCD_R_ERR_LMD (=-5)
Processing:
90
ML610Q400 Series
Sample Program API Manual
3.8.5.4.
lcd_dispHour Function
This function displays hours (0–99 or blank) on the hours digits (2 digits) of the LCD. If a value of 0 to 99 is specified
for the “argument “hour”, this function displays hours (the tens digit is zero-suppressed). If the argument “hour” is 100
or more, the hours digits (2 digits) are displayed as blanks.
Function
name:
Arguments:
Return
values:
Processing:
void lcd_dispHour(
unsigned char hour
)
unsigned char hour … Display value
None
Displaying of hours digits
lcd_dispHour function
[Initialize LCD code]
Tens digit of hours = LCD_CODE_BLANK
Ones digit of hours = LCD_CODE_BLANK
Is the upper digit of the display
value other than 0?
Yes
No
[Set LCD code for tens digit of hours]
Tens digit of hours = Converted to
segment data for display time
[Set LCD code for ones digit of hours]
Ones digit of hours = Converted to
segment data for display time
When LCD_TYPE = 1:
When LCD_TYPE = 0
[Display ones digit of hours]
Call writeReg function
[Display ones digit of hours]
Call
_lcd_NoMapping_7SEG_Set
function
[Display tens digit of hours]
Call writeReg function
[Display tens digit of hours]
Call
_lcd_NoMapping_7SEG_Set
function
End
91
ML610Q400 Series
Sample Program API Manual
3.8.5.5.
lcd_dispMin Function
This function displays minutes (0–99 or blank) on the minutes digits (2 digits) of the LCD. If a value of 0 to 99 is
specified for the argument “min”, this function displays minutes. If the argument “min” is 100 or more, the minutes
digits (2 digits) are displayed as blanks.
Function
name:
void lcd_dispMin(
unsigned char min
)
Arguments:
Return
values:
Processing:
unsigned char min … Display value
None
Displaying of minutes digits
lcd_dispMin function
[Initialize LCD code]
Tens digit of minutes =
LCD_CODE_BLANK
Ones digit of minutes =
LCD_CODE_BLANK
[Set LCD code for tens digit of minutes ]
Tens digit of minutes = Converted to
segment data for display time
[Set LCD code for ones digit of minutes ]
Ones digit of minutes = Converted to
segment data for display time
When LCD_TYPE = 0:
When LCD_TYPE = 1:
[Display ones digit of minutes]
Call writeReg function
[Display ones digit of minutes]
Call
_lcd_NoMapping_7SEG_Set
function
[Display tens digit of minutes]
Call writeReg function
[Display tens digit of minutes]
Call
_lcd_NoMapping_7SEG_Set
function
End
92
ML610Q400 Series
Sample Program API Manual
3.8.5.6.
lcd_dispSec Function
This function displays seconds (0–99 or blank) on the seconds digits (2 digits) of the LCD. If a value of 0 to 99 is
specified for the argument “sec”, this function displays seconds. If the argument “sec” is 100 or more, the seconds digits
(2-digit) are displayed as blanks.
Function
name:
Arguments:
Return
values:
Processing:
void lcd_dispSec(
unsigned char sec
)
unsigned char sec … Display value
None
Displaying of seconds digits
lcd_dispSec function
[Initialize LCD code]
Tens digit of seconds =
LCD_CODE_BLANK
Ones digit of seconds =
LCD_CODE_BLANK
[Set LCD code for tens digit of seconds ]
Tens digit of seconds = Converted to
segment data for display time
[Set LCD code for ones digit of
seconds]
Ones digit of seconds = Converted to
segment data for display time
When LCD_TYPE = 0:
When LCD_TYPE = 1:
[Display ones digit of seconds]
Call writeReg function
[Display ones digit of seconds]
Call
_lcd_NoMapping_7SEG_Set
function
[Display tens digit of seconds]
Call writeReg function
[Display tens digit of seconds]
Call
_lcd_NoMapping_7SEG_Set
function
End
93
ML610Q400 Series
Sample Program API Manual
3.8.5.7.
lcd_dispMain Function
This function displays figures into the 12 digits (by 8-segment characters) on the lower part of the LCD panel. It
generates font data for display from numeric data and then displays it on the LCD.
Function
name:
void lcd_dispMain(
signed long num
)
Arguments:
signed long num … Display value
Return
values:
Processing:
None
Main display
lcd_dispMain function
[Clear display code buffer]
Set blank data in the display code buffer
Set display data for six digits
[Set display data in the display code buffer]
Display data storing processing
Set display data for six digits
Zero-suppression loop
(Check digits from the 6th to the 2nd digit)
Display code buffer = ?
=0
[Clear display code buffer]
Set blank data in the display code buffer
Zero-suppression loop
[Display multiple digits of 7-seg characters]
_dsp7SEG_Ndigit function
Argument: DSPR address at the 1st digit,
display code buffer storage destination address, number of
digits to display
End
94
Other than 0
ML610Q400 Series
Sample Program API Manual
3.8.5.8.
lcd_disp1Digit Function
This function displays data onto one digit of the LCD panel. The function sets the digit position, LCD On/Off, and zero
suppression enable/disable. It then generates font data for display from numeric data and writes display data to the target
digit to display the data.
Function
name:
Arguments:
Return
values:
Processing:
int lcd_disp1Digit(
unsigned char pos,
unsigned char en,
unsigned char type,
unsigned char digit
)
unsigned int pos … Display position
1st digit of the 12 digits on the lower section: LCD_POS_MAIN_01(=0x00)
2nd digit of the 12 digits on the lower section: LCD_POS_MAIN_02(=0x01)
3rd digit of the 12 digits on the lower section: LCD_POS_MAIN_03(=0x02)
4th digit of the 12 digits on the lower section: LCD_POS_MAIN_04(=0x03)
5th digit of the 12 digits on the lower section: LCD_POS_MAIN_05(=0x04)
6th digit of the 12 digits on the lower section: LCD_POS_MAIN_06(=0x05)
7th digit of the 12 digits on the lower section: LCD_POS_MAIN_07(=0x06)
8th digit of the 12 digits on the lower section: LCD_POS_MAIN_08(=0x07)
9th digit of the 12 digits on the lower section: LCD_POS_MAIN_09(=0x08)
10th digit of the 12 digits on the lower section: LCD_POS_MAIN_10(=0x09)
11th digit of the 12 digits on the lower section: LCD_POS_MAIN_11(=0x0A)
12th digit of the 12 digits on the lower section: LCD_POS_MAIN_12(=0x0B)
Ones digit of second: LCD_POS_SEC_01(=0x10)
Tens digit of second: LCD_POS_SEC_10(=0x11)
Ones digit of minute: LCD_POS_MIN_01(=0x20)
Tens digit of minute: LCD_POS_MIN_10(=0x21)
Ones digit of hour: LCD_POS_HOUR_01(=0x30)
Tens digit of hour: LCD_POS_HOUR_10(=0x31)
1st digit of Mode (upper-left four digits on the upper section): LCD_POS_MODE_01(=0x40)
2nd digit of Mode (upper-left four digits on the upper section): LCD_POS_MODE_02(=0x41)
3rd digit of Mode (upper-left four digits on the upper section): LCD_POS_MODE_03(=0x42)
4th digit of Mode (upper-left four digits on the upper section): LCD_POS_MODE_04(=0x43)
unsigned char en … On/Off
LCD Off: LCD_TURNOFF(=0)
LCD On: LCD_TURNON(=1)
unsigned char type … Display type
Display a value of 0 as “0”: LCD_TYPE_0_DISP(=0)
Display a value of 0 as “blank”: LCD_TYPE_0_BLANK(=1)
unsigned char digit. … Display value(0 to 9)
int
Display succeeded: LCD_R_OK(=0)
Display position setting is outside the range: LCD_R_ERR_POS(=-7)
On/Off setting is outside the range: LCD_R_ERR_EN(=-8)
Display type is outside the range: LCD_R_ERR_TYPE(=-9)
Display value is outside the range: LCD_R_ERR_DIGIT(=-10)
See next page.
95
ML610Q400 Series
Sample Program API Manual
96
ML610Q400 Series
Sample Program API Manual
3.8.5.9.
lcd_disp2Digit Function
This function displays data onto two consecutive digits of the LCD panel. The function sets the digit position, LCD
On/Off, and zero suppression enable/disable for upper digits. It then generates font data for display from 2-digit numeric
data and writes display data to the two digits to display the data.
Function
name:
Arguments:
Return
values:
Processing:
int lcd_disp2Digit(
unsigned char pos,
unsigned char en,
unsigned char type,
unsigned char digit
)
unsigned int pos … Display position
1st and 2nd digits of the 12 digits on the lower section: LCD_POS_MAIN_01(=0x00)
3rd and 4th digits of the 12 digits on the lower section: LCD_POS_MAIN_03(=0x02)
5th and 6th digits of the 12 digits on the lower section: LCD_POS_MAIN_05(=0x04)
7th and 8th digits of the 12 digits on the lower section: LCD_POS_MAIN_07(=0x06)
9th and 10th digits of the 12 digits on the lower section: LCD_POS_MAIN_09(=0x08)
11th and 12th digits of the 12 digits on the lower section: LCD_POS_MAIN_11(=0x0A)
Second: LCD_POS_SEC(=0x10)
Minute: LCD_POS_MIN(=0x20)
Hour: LCD_POS_HOUR(=0x30)
Lower 2 digits for mode display (upper-left 4 digits of the upper section): LCD_POS_MODE_LOW(=0x40)
Upper2 digits for mode display (upper-left 4 digits of the upper section): LCD_POS_MODE_HIGH(=0x42)
unsigned char en … On/Off
LCD Off: LCD_TURNOFF(=0)
LCD On: LCD_TURNON(=1)
unsigned char type … Display type
Display a high-order digit 0 in the two digits as a “0”: LCD_TYPE_0_DISP(=0)
Display a high-order digit 0 in the two digits as a “blank”: LCD_TYPE_0_BLANK(=1)
unsigned char digit. … Display value(0 to 99)
int
Display succeeded: LCD_R_OK(=0)
Display position setting is outside the range: LCD_R_ERR_POS(=-7)
On/Off setting is outside the range: LCD_R_ERR_EN(=-8)
Display type is outside the range: LCD_R_ERR_TYPE(=-9)
Display value is outside the range: LCD_R_ERR_DIGIT(=-10)
See next page.
97
ML610Q400 Series
Sample Program API Manual
98
ML610Q400 Series
Sample Program API Manual
3.8.5.10. lcd_disp4Digit Function
This function displays data onto four consecutive digits of the LCD panel. The function sets the digit position, LCD
On/Off, and zero suppression enable/disable for high-order digits. It then generates font data for display from 4-digit
numeric data and writes display data to the four digits to display the data.
Function
name:
Arguments:
Return
values:
Processing:
int lcd_disp4Digit(
unsigned char pos,
unsigned char en,
unsigned char type,
unsigned short digit
)
unsigned int pos … Display position
1st to 4th digits of the 12 digits on the lower section: LCD_POS_MAIN_01(=0x00)
5th to 8th digits of the 12 digits on the lower section: LCD_POS_MAIN_05(=0x04)
9th to 12th digits of the 12 digits on the lower section: LCD_POS_MAIN_09(=0x08)
1st to 4th digits for mode display (upper-left 4 digits on the upper section): LCD_POS_MODE_01(=0x40)
unsigned char en … On/Off
LCD Off: LCD_TURNOFF(=0)
LCD On: LCD_TURNON(=1)
unsigned char type … Display type
Display 0s of the high-order digits as “0s”: LCD_TYPE_0_DISP(=0)
Display 0s of the high-order digits as “blanks”: LCD_TYPE_0_BLANK(=1)
unsigned short digit. … Display value(0 to 9999)
int
Display succeeded: LCD_R_OK(=0)
Display position setting is outside the range: LCD_R_ERR_POS(=-7)
On/Off setting is outside the range: LCD_R_ERR_EN(=-8)
Display type is outside the range: LCD_R_ERR_TYPE(=-9)
Display value is outside the range: LCD_R_ERR_DIGIT(=-10)
See next page.
99
ML610Q400 Series
Sample Program API Manual
4-digit display of LCD
lcd_disp4Digit function
No
Is the display position
within the range?
Yes
Return “LCD_R_ERR_POS”
No
Is the On/Off setting within the range?
(The set value is “1” or less)
Yes
Return “LCD_R_ERR_EN”
No
Is the display type within the range?
(The set value is “1” or less)
Yes
Return “LCD_R_ERR_TYPE”
No
Is the display value within the range?
(The set value is “9999” or less)
Yes
Return “LCD_R_ERR_DIGIT”
[Acquire DSPR address]
Acquire the DSPR address that corresponds to the
display position from the DSPR conversion table
[Initialize display code]
Display code [0] = LCD_CODE_BLANK
Display code [1] = LCD_CODE_BLANK
Display code [2] = LCD_CODE_BLANK
Display code [3] = LCD_CODE_BLANK
LCD On?
No (Off)
Yes (On)
[Convert the value to LCD code]
Display value, Code storing buffer, Buffer size=4, Display type
Is the display position other than
the Mode position?
No
Yes
[Display value onto 7-seg]
Call dspLCD_SEG7 function
[Display value onto 16-seg]
Call dspLCD_SEG16 functiondigits=4
Return “LCD_R_OK”
100
ML610Q400 Series
Sample Program API Manual
3.8.5.11. lcd_dispMark Function
This function displays one of the LCD marks. It turns on or off the target mark based on the of the mark position setting
and On/Off setting.
Function
name:
Arguments:
Return
values:
int lcd_dispMark(
unsigned char markNo,
unsigned char en
)
unsigned char markNo … Mark No. to be displayed
See Table 3-32, “Constants for Mark Codes.”
unsigned char en … On/Off
Off: LCD_TURNOFF(=0)
On: LCD_TURNON(=1)
int
Display succeeded: LCD_R_OK(=0)
On/Off setting is outside the range: LCD_R_ERR_EN(=-8)
Mark No. is outside the range: LCD_R_ERR_MARKNO(=-11)
Processing:
101
ML610Q400 Series
Sample Program API Manual
3.8.5.12. lcd_dispTemp Function
This function displays the temperature value (XXX.X[°C]).
Function
name:
Arguments:
Return
values:
int lcd_dispTemp(short digit)
short digit … Temperature value (9999 to -999)
* Specify the value obtained by multiplying the actual temperature by 10 for the temperature value.
* Temperatures are displayed as “999.9°C” to “-99.9°C”.
* The position of the decimal point is fixed to XXX.X.
int
Display succeeded: LCD_R_OK(=0)
Display value is outside the range: LCD_R_ERR_DIGIT(=-10)
Mark No. is outside the range: LCD_R_ERR_MARKNO(=-11)
Processing:
102
ML610Q400 Series
Sample Program API Manual
3.8.5.13. lcd_dispMode Function
This function displays a character string (numerals, alphabets, minus sign, blanks) on the “Mode of LCD” display
section (the four digits on the upper left of the LCD panel) of the LCD.
Function
name:
Arguments:
Return
values:
Processing:
void lcd_dispMode(char* str, unsigned char len)
char* str … Character string to display
For displayable characters, see Table 3-31, “Constants for LCD Codes.”
Characters that are not in the table are displayed as blanks if specified.
unsigned char len … Character count (0 to 4)
If 0 is specified, four blank characters are displayed.
If any value greater than 4 is specified, up to the first four characters will be displayed.
None
103
ML610Q400 Series
Sample Program API Manual
3.8.5.14. lcd_dispClear Function
This function clears the display on the LCD panel.
Function
name:
Arguments:
Return
values:
Processing:
void lcd_clear( void )
None
None
104
ML610Q400 Series
Sample Program API Manual
3.9. Key Read-In Module
3.9.1. Overview of Functions
The key read-in module controls key read-in operation.
Key read-in is achieved by APIs that perform initialization (input mode), read-in start/stop, and key status acquisition.
3.9.2.
Key Read-In Timing Diagram
Figure 3-1
Key Read-In Timing Diagram
1 Enable interrupts to port P00–P03 pins.
Specify falling edge interrupt for these ports as the interrupt generation condition.
2 Interrupt occurs (P0xINT: x=0-3):
P0xINT occurs when a key is pressed. Disables interrupts to other ports.
Chattering absorption timer 128Hz interrupt starts (approx. 7.8 ms).
This 128Hz interrupt is generated by the time base counter. Note that the interval of this interrupt is not synchronous
with P0xINT.
3 Absorb chattering (INT128Hz: approx. 7.8 ms):
Key read-in is input to the port until matching of the same key is detected four times or more in a row.
When matching of the same key is detected four times in a row (a short-key-press “push” event is confirmed):
Generates a key status of a short-key-press “push” and continues the processing of 4.
If, after matching of the same key is found less than four times, the key is released, processing returns to 1.
4 Key event confirmed.
If, during matching of the same key occurring four times or more but less than 256 times, the key is released (a
short-key-press “release” event is confirmed): Generates a key status of a short-key-press “release” and returns to the
processing of 1.
When matching of the same key is detected 256 times (when holding it down for approx. 2 seconds) (a
long-key-press event is confirmed): Generates a key status of a long key press and continues processing until the key
is released. Processing returns to 1 when the key is released.
105
ML610Q400 Series
Sample Program API Manual
3.9.3. List of APIs
The following table lists the key read-in module APIs.
Table 3-33 Key Read-In Module APIs
Function name
key_init function
key_start function
key_stop function
key_getEvent function
Description
Sets key read-in port (pull-up input, interrupt at the falling edge, no sampling).
Starts key read-in processing.
Stops key read-in processing.
Acquires a key event.
3.9.4. List of Constants
The following table lists the constants used in the key read-in module.
Table 3-34
Constants for Return Values
Defined
value
Constant name
NO_EVENT
KEY1_SHORT_PUSH _EVENT
KEY2_SHORT_PUSH_EVENT
KEY3_SHORT_PUSH_EVENT
KEY4_SHORT_PUSH_EVENT
KEY1_SHORT_RELEASE_EVENT
KEY2_SHORT_RELEASE_EVENT
KEY3_SHORT_RELEASE_EVENT
KEY4_SHORT_RELEASE_EVENT
KEY1_LONG_EVENT
KEY2_LONG_EVENT
KEY3_LONG_EVENT
KEY4_LONG_EVENT
0x00
0x01
0x02
0x03
0x04
0x11
0x12
0x13
0x14
0x21
0x22
0x23
0x24
Description
No event has been generated
A short S1 key press “push” event generated
A short S2 key press “push” event generated
A short S3 key press “push” event generated
A short S4 key press “push” event generated
A short S1 key press “release” event generated
A short S2 key press “release” event generated
A short S3 key press “release” event generated
A short S4 key press “release” event generated
A long S1 key press event generated
A long S2 key press event generated
A long S3 key press event generated
A long S4 key press event generated
3.9.5. List of Variables
The following table shows the variables used in the key read-in module.
Table 3-35 Variables
Variable name
static unsigned _sKeyNo
static unsigned _sKeyStatus
static unsigned _sKeyEvent
Initial value
0
0
0
static unsigned _sKeyOnCnt
0
Description
Variable used to manage the current key status
Variable used to manage the key read-in status
Variable used to manage the “confirmed” status
Variable used to manage the number of times a key was
pressed
106
ML610Q400 Series
Sample Program API Manual
3.9.6. API Details
This section describes the details of the key read-in module.
3.9.6.1. key_init Function
This function initializes the key read-in module.
Function
name:
Arguments:
Return
values:
Processing:
void key_init(void)
None
None
Initialization of key read-in module
key_init function
Initialize variables:
Set “Key No.” to “No key”.
Set “Key status” to “Waiting for key input”.
Set “Key event” to “No key event”.
Set input mode:
[Port 0 control registers 0, 1]
Set P03C0 to P0C0 and P03C1 to P0C1 to “Input
mode with a pull-up resistor”.
Set interrupt edge:
[External interrupt control registers 0, 1]
Set P03E0 to P00E0 and P03E1 to P00E1
to “Falling edge interrupt”.
Set interrupt edge:
[External interrupt control register 2]
Set P03SM to P00SM
to “Detection without sampling”.
End of processing
107
ML610Q400 Series
Sample Program API Manual
3.9.6.2.
key_start Function
This function starts key-read in operation.
Function
name:
Arguments:
Return
values:
Processing:
void key_start(void)
None
None
108
ML610Q400 Series
Sample Program API Manual
3.9.6.3. key_stop Function
This function stops key read-in operation.
Function
name:
Arguments:
Return
values:
Processing:
void key_stop(void)
None
None
109
ML610Q400 Series
Sample Program API Manual
3.9.6.4.
key_getEvent Function
This function acquires key events.
Function
name:
Arguments:
Return
values:
unsigned char key_getEvent(void)
None
unsigned cahr
Short S1 key press push event: KEY1_SHORT_PUSH_EVENT
Short S2 key press push event: KEY2_SHORT_PUSH_EVENT
Short S3 key press push event: KEY3_SHORT_PUSH_EVENT
Short S4 key press push event: KEY4_SHORT_PUSH_EVENT
Short S1 key press release event: KEY1_SHORT_RELEASE_EVENT
Short S2 key press release event: KEY2_SHORT_RELEASE_EVENT
Short S3 key press release event: KEY3_SHORT_RELEASE_EVENT
Short S4 key press release event: KEY4_SHORT_RELEASE_EVENT
Long S1 key press event: KEY1_LONG_EVENT
Long S2 key press event: KEY2_LONG_EVENT
Long S3 key press event: KEY3_LONG_EVENT
Long S3 key press event: KEY4_LONG_EVENT
No key event has been confirmed for any key: NO_EVENT
Processing:
Key event acquisition
key_getEvent function
Save MIE flag,
and disable interrupt
Branch according to
key event
Short S3 key press push event
Short S1 key press push event
Set “KEY1_SHORT_PUSH_EVENT”
as the return value
Set “KEY3_SHORT_PUSH_EVENT”
as the return value
Short S2 key press push event
Short S4 key press
push event
Set “KEY4_SHORT_PUSH_EVENT”
as the return value
Set “KEY2_SHORT_PUSH_EVENT」”
as the return value
Short S3 key press release event
Short S1 key press release event
Set
Set
“KEY1_SHORT_RELEASE_EVENT”
“KEY3_SHORT_RELEASE_EVENT”
as the return value
as the return value
Short S4 key press
release event
Short S2 key press release event
Set
Set “KEY4_SHORT_RELEASE_EVENT”
“KEY2_SHORT_RELEASE_EVENT”
as the return value
as the return value
Long S3 key press event
Long S1 key press event
Set “KEY1_LONG_EVENT”
as the return value
Set “KEY3_LONG_EVENT”
as the return value
Others
Set “NO_EVENT”
as the return value
Long S2 key press event
Set “KEY2_LONG_EVENT”
as the return value
Set the key read-in status to
“no key read-in” state
Restore MIE flag
Return the set value
110
Long S4 key press event
Set “KEY4_LONG_EVENT”
as the return value
ML610Q400 Series
Sample Program API Manual
3.10. Melody Module
3.10.1. Overview of Functions
The melody module controls the melody driver of the MCU.
This module can control the following: Initialization (melody/buzzer output stop, port secondary function setting),
melody output start/stop, melody output continuation, melody output interrupt request acquisition and clear, and buzzer
output start/stop.
Note: The melody module is available only in the ML610Q431/Q432. The ML610Q411/Q412/Q415 is not provided
with the melody function.
3.10.2. List of APIs
The following table lists the melody module APIs.
Table 3-36 Melody Module APIs
Function name
melody_init function
melody_start function
melody_stop function
melody_continue function
melody_checkoutput function
melody_checkIRQ function
melody_clearIRQ function
buzzer_start function
buzzer_stop function
Description
Initializes the melody control module (stops melody/buzzer output; port
secondary function setting).
Starts melody output.
Stops melody output.
Performs melody output continuation processing.
Checks the presence or absence of melody output.
Checks the presence or absence of a melody output interrupt request.
Clears melody output interrupt request.
Starts buzzer output.
Stops buzzer output.
111
ML610Q400 Series
Sample Program API Manual
3.10.3. List of Constants
The following table lists the constants used in the melody module.
Table 3-37 Melody Module Constants
Constant name
MELODY_TEMPO_480
MELODY_TEMPO_320
MELODY_TEMPO_240
MELODY_TEMPO_192
MELODY_TEMPO_160
MELODY_TEMPO_137
MELODY_TEMPO_120
MELODY_TEMPO_107
MELODY_TEMPO_96
MELODY_TEMPO_87
MELODY_TEMPO_80
MELODY_TEMPO_74
MELODY_TEMPO_69
MELODY_TEMPO_64
MELODY_TEMPO_60
BUZZER_TYPE0
BUZZER_TYPE1
BUZZER_TYPE2
BUZZER_TYPE3
BUZZER_FREQ_4096HZ
BUZZER_FREQ_2048HZ
BUZZER_FREQ_1365HZ
BUZZER_FREQ_1024HZ
BUZZER_FREQ_819HZ
BUZZER_FREQ_683HZ
BUZZER_FREQ_585HZ
BUZZER_FREQ_512HZ
BUZZER_DUTY_1_16
BUZZER_DUTY_2_16
BUZZER_DUTY_3_16
BUZZER_DUTY_4_16
BUZZER_DUTY_5_16
BUZZER_DUTY_6_16
BUZZER_DUTY_7_16
BUZZER_DUTY_8_16
BUZZER_DUTY_9_16
BUZZER_DUTY_10_16
BUZZER_DUTY_11_16
BUZZER_DUTY_12_16
BUZZER_DUTY_13_16
BUZZER_DUTY_14_16
BUZZER_DUTY_15_16
BUZZER_DUTY_16_16
Defined
value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
1
2
3
0
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Description
♪= 480
♪=320
♪=240
♪=192
♪=160
♪≅137
♪=120
♪≅107
♪=96
♪≅87
♪=80
♪≅74
♪≅69
♪=64
♪=60
Specifies intermittent sound 1 as the buzzer output sound.
Specifies intermittent sound 2 as the buzzer output sound.
Specifies single sound as the buzzer output sound.
Specifies continuous sound as the buzzer output.
Specifies 4.096kHz as the buzzer output frequency.
Specifies 2.048 kHz as the buzzer output frequency.
Specifies 1.365 kHz as the buzzer output frequency.
Specifies 1.024 kHz as the buzzer output frequency.
Specifies 819 kHz as the buzzer output frequency.
Specifies 683 kHz as the buzzer output frequency.
Specifies 1585 kHz as the buzzer output frequency.
Specifies 512 kHz as the buzzer output frequency.
Specifies 1/16 duty as the buzzer output duty.
Specifies 2/16 duty as the buzzer output duty.
Specifies 3/16 duty as the buzzer output duty.
Specifies 4/16 duty as the buzzer output duty.
Specifies 5/16 duty as the buzzer output duty.
Specifies 6/16 duty as the buzzer output duty.
Specifies 7/16 duty as the buzzer output duty.
Specifies 8/16 duty as the buzzer output duty.
Specifies 9/16 duty as the buzzer output duty.
Specifies 10/16 duty as the buzzer output duty.
Specifies 11/16 duty as the buzzer output duty.
Specifies 12/16 duty as the buzzer output duty.
Specifies 13/16 duty as the buzzer output duty.
Specifies 14/16 duty as the buzzer output duty.
Specifies 15/16 duty as the buzzer output duty.
Specifies 16/16 duty as the buzzer output duty.
112
ML610Q400 Series
Sample Program API Manual
Table 3-38 List of Constants for Return Values
Constant name
MELODY_R_OK
MELODY_R_IRQ
MELODY_R_NON_IRQ
MELODY_R_OUTPUT
MELODY_R_STOP
BUZZER_R_OK
BUZZER_R_ERR_TYPE
BUZZER_R_ERR_FREQUENCY
BUZZER_R_ERR_DUTY
Defined
value
0
1
0
1
0
0
-1
-2
-3
Description
Processing succeeded.
Melody output interrupt request is present.
No melody output complete interrupt request is present.
Melody is being output.
Melody output is stopped.
Processing succeeded.
Buzzer type is outside the range.
Buzzer output frequency is outside the range.
Buzzer output duty is outside the range.
113
ML610Q400 Series
Sample Program API Manual
3.10.4. Structure
This section describes the structures used in the melody module.
Melody output data control parameters
typedef struct {
unsigned short *
unsigned int
} tMelodyCtrlParam;
data;
size;
// Pointer to the melody data storage area
// Melody data size (the number of note data items)
3.10.5. List of Variables
This section describes the variables used in the melody module.
Variable name
static
tMelodyCtrlParam_gsCtrlParam
Initial value
data: NULL
size: 0
Description
Variable used to manage melody output data
3.10.6. Melody Output Data Format
The following note data is generated continuously to create melody output data.
Note data (16-bit)
Tone length code (8-bit)
Scale code (8-bit)
114
ML610Q400 Series
Sample Program API Manual
3.10.7. Details of APIs
This section describes details of the melody module APIs.
3.10.7.1. melody_init Function
This function initializes the melody module. In the initialization, melody/buzzer output of the MCU is stopped, port 2
(P22), which is used in melody output, is configured as its secondary function, and variables that controls melody output
are initialized.
Function
name:
Arguments:
Return
values:
Processing:
void melody_init( void )
None
None
115
ML610Q400 Series
Sample Program API Manual
3.10.7.2. melody_start Function
This function performs melody output start processing. Melody output is started by setting values in the parameters that
control melody output data and setting the first note data in the MCU. The second and the subsequent melody output
(note data setting) is performed by the melody_continue.
If this function is called during melody output, the melody output being processed is canceled and new melody output
processing is started.
Function
name:
Arguments:
Return
values:
Processing:
void melody_start(unsigned char tempo, unsigned short *data, unsigned int size )
unsigned char tempo … Specify tempo
unsigned short* data … Pointer to the area that contains melody data
unsigned int size …. Melody data size (the number of note data items)
None
116
ML610Q400 Series
Sample Program API Manual
3.10.7.3. melody_stop Function
This function performs melody output stop processing. In the stop processing, melody output of the MCU is stopped,
melody output interrupt request is cleared, and parameters that control melody output are initialized.
Function
name:
Arguments:
Return
values:
Processing:
void melody_stop( void )
None
None
117
ML610Q400 Series
Sample Program API Manual
3.10.7.4. melody_continue Function
This function performs melody output continuation processing. If there is any data remaining, the next data is set in the
MCU. When no data is left, rest data is set in the MCU. After the rest data is output, the melody output of the MCU is
stopped.
Function
name:
Arguments:
Return
values:
Processing:
void melody_continue( void )
None
None
118
ML610Q400 Series
Sample Program API Manual
3.10.7.5. melody_checkoutput Function
This function checks the presence or absence of melody output.
Function
name:
Arguments:
Return
values:
int melody_checkoutput( void )
None
int
MELODY_R_OUTPUT(=1): Melody is being output.
MELODY_R_STOP(=0): Melody output is being stopped.
Processing:
119
ML610Q400 Series
Sample Program API Manual
3.10.7.6. melody_checkIRQ Function
This function checks the presence or absence of the melody output interrupt request. Return values are only valid when
the melody output interrupt of the MCU is not used.
Function
name:
Arguments:
Return
values:
int melody_checkIRQ( void )
None
int
MELODY_R_IRQ(=1): Melody output interrupt request present
MELODY_R_NON_IRQ(=0): No melody output interrupt request present
Processing:
120
ML610Q400 Series
Sample Program API Manual
3.10.7.7. melody_clearIRQ Function
This function clears melody output interrupt request. Use this function only when the melody output interrupt of the
MCU is not used.
Function
name:
Arguments:
Return
values:
void melody_clearIRQ( void )
None
int
MELODY_R_IRQ(=1): Melody output interrupt request is present
MELODY_R_NON_IRQ(=0): No melody output interrupt request is present
Processing:
121
ML610Q400 Series
Sample Program API Manual
3.10.7.8. buzzer_start Function
This function starts buzzer output.
Function
name:
Arguments:
Return
values:
Processing:
int buzzer_start(
unsigned char type,
unsigned char freq,
unsigned char duty )
unsigned char type … Buzzer output sound selection
BUZZER_TYPE0(=0): Intermittent sound 1
BUZZER_TYPE1(=1): Intermittent sound 2
BUZZER_TYPE2(=2): Single sound
BUZZER_TYPE3(=3): Continuous sound
unsigned char freq … Buzzer output frequency selection
BUZZER_FREQ_4096HZ(=0) : 4.096kHz
BUZZER_FREQ_2048HZ(=1) : 2.048kHz
BUZZER_FREQ_1365HZ(=2) : 1.365kHz
BUZZER_FREQ_1024HZ(=3) : 1.024kHz
BUZZER_FREQ_819HZ(=4) : 819Hz
BUZZER_FREQ_683HZ(=5) : 683Hz
BUZZER_FREQ_585HZ(=6) : 585Hz
BUZZER_FREQ_512HZ(=7) : 512Hz
unsigned char duty … Buzzer output duty
BUZZER_DUTY_1_16(=1)
: 1/16DUTY
BUZZER_DUTY_2_16(=2)
: 2/16DUTY
BUZZER_DUTY_3_16(=3)
: 3/16DUTY
BUZZER_DUTY_4_16(=4)
: 4/16DUTY
BUZZER_DUTY_5_16(=5)
: 5/16DUTY
BUZZER_DUTY_6_16(=6)
: 6/16DUTY
BUZZER_DUTY_7_16(=7)
: 7/16DUTY
BUZZER_DUTY_8_16(=8)
: 8/16DUTY
BUZZER_DUTY_9_16(=9)
: 9/16DUTY
BUZZER_DUTY_10_16(=10) : 10/16DUTY
BUZZER_DUTY_11_16(=11) : 11/16DUTY
BUZZER_DUTY_12_16(=12) : 12/16DUTY
BUZZER_DUTY_13_16(=13) : 13/16DUTY
BUZZER_DUTY_14_16(=14) : 14/16DUTY
BUZZER_DUTY_15_16(=15) : 15/16DUTY
BUZZER_DUTY_16_16(=16) : 16/16DUTY
int
BUZZER_R_OK(=0): Processing succeeded
BUZZER_R_ERR_TYPE(=-1): The buzzer type selected is outside the range.
BUZZER_R_ERR_FREQUENCY(=-2): The buzzer frequency selected is outside the range.
BUZZER_R_ERR_DUTY(=-3): The buzzer output duty selected is outside the range.
See next page.
122
ML610Q400 Series
Sample Program API Manual
Buzzer output start processing
buzzer_start function
Is the buzzer type outside the range?
(type £ BUZZER_TYPE3)
Yes
No
[Buzzer type is outside the range]
Return value: BUZZER_R_ERR_TYPE
Is the buzzer output frequency
outside the range?
(freq £ BUZZER_FREQ_512HZ)
Yes
No
[Buzzer output frequency is outside the range]
Return value: BUZZER_R_ERR_FREQUENCY
Is the buzzer output duty
outside the range?
(freq £ BUZZER_DUTY_15_16)
Yes
No
[Buzzer output duty is outside the range]
Return value: BUZZER_R_ERR_DUTY
[Stop buzzer output]
M0RUN = 0
[Select buzzer mode]
BZMD = 1
[Set buzzer type]
MD0TMP = type
[Set buzzer output frequency]
MD0TON = freq
[Set buzzer output duty]
MD0LEN = duty
[Stop buzzer output]
M0RUN = 0
[Normal end]
Return value: BUZZER_R_OK
123
ML610Q400 Series
Sample Program API Manual
3.10.7.9. buzzer_stop Function
This function stops buzzer output.
Function
name:
Arguments:
Return
values:
Processing:
void buzzer_stop( void )
None
None
124
ML610Q400 Series
Sample Program API Manual
3.11. Real Time Clock Control Module
3.11.1. Overview of Functions
The real time clock control module controls the real time clock of the MCU.
Controllable items are: Setting/obtaining/starting/stopping the date (year, month, day, day of the week) counting
function and clock time (hour, minute, second) counting function; setting an interval between periodic interrupts;
setting/obtaining alarm 0 (comparing day of the week, hour, and minute) and alarm 1 (comparing month, day, hour, and
minute).
* This module is available in the ML610Q431/Q432. The ML610Q411/Q412/Q415 is not provided with the real time
clock function.
3.11.2. List of APIs
The following table lists the real time clock control module APIs.
Table 3-39 Real Time Clock Control Module APIs
Function name
rtc_setTime function
rtc_getTime function
rtc_start function
rtc_stop function
rtc_setRegularInt function
rtc_setAlarm0 function
rtc_setAlarm1 function
rtc_getAlarm0 function
rtc_getAlarm1 function
Description
Sets date (year, month, day, day of the week) and clock time (hour, minute, second).
Obtains date (year, month, day, day of the week) and clock time (hour, minute, second).
Starts RTC operation.
Stops RTC operation.
Selects the interval between periodic interrupts.
Sets alarm 0 (day of the week, hour, minute).
Sets alarm 1 (month, day, hour, minute).
Obtains the setting of alarm 0 (day of the week, hour, minute).
Obtains the setting of alarm 1 (month, day, hour, minute).
125
ML610Q400 Series
Sample Program API Manual
3.11.3. List of Constants
The following tables list the constants used in the real time clock control module.
Table 3-40 List of Constants for Arguments
Constant name
RTC_RIN_DISABLE
RTC_RIN_0_5_SEC
RTC_RIN_1_0_SEC
RTC_RIN_1_0_MIN
RTC_ALEN_DIS
RTC_ALEN_ENA
Defined
value
0
1
2
3
0
1
Description
Periodic interrupt: Disabled
Periodic interrupt: Enables 0.5-second interrupt
Periodic interrupt: Enables 1-second interrupt
Periodic interrupt: Enables 1-minute interrupt
Disables the alarm function.
Enables the alarm function.
Table 3-41 List of Constants for Return Values
Constant name
RTC_R_OK
RTC_R_ERR_SEC
RTC_R_ERR_MIN
RTC_R_ERR_HOUR
RTC_R_ERR_WEEK
RTC_R_ERR_DAY
RTC_R_ERR_MON
RTC_R_ERR_YEAR
RTC_R_ERR_ALEN
RTC_R_ERR_RIN
RTC_R_ERR_GETTIME
Defined
value
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
Description
Processing succeeded
The second setting is outside the range
The minute setting is outside the range
The hour setting is outside the range
The day of the week setting is outside the range
The day setting is outside the range
The month setting is outside the range
The year setting is outside the range
The alarm enable/disable setting is outside the range
The periodic interrupt setting is outside the range
Obtaining of date and clock time failed
126
ML610Q400 Series
Sample Program API Manual
3.11.4. Structure
This section describes the structures used in the real time clock control module. Each parameter value must be specified
not by binary-coded decimal (BCD) numbers but by decimal numbers.
Date and watch setting parameters
typedef struct {
unsigned char
unsigned char
unsigned char
unsigned char
unsigned char
unsigned char
unsigned char
} tRtcTime;
sec;
min;
hour;
week;
day;
mon;
year;
// Second data (0 to 59)
// Minute data (0 to 59)
// Hour data (0 to 23)
// Day of the week data (0 to 7)
// Day data (0 to 31)
// Month data (0 to 12)
// Year data (0 to 99)
typedef struct {
unsigned char
unsigned char
min;
hour;
unsigned char
week;
// Minute data (0 to 59)
// Hour data (0 to 23)
// Day of the week data (0 to 7) * If 0 is specified, no day-of-the-week data is
used for comparison.
Alarm 0 setting parameters
} tRtcAlarm0;
Alarm 1 setting parameters
typedef struct {
unsigned char
unsigned char
unsigned char
unsigned char
} tRtcAlarm1;
min;
hour;
day;
mon;
// Minute data (0 to 59)
// Hour data (0 to 23)
// Day data (0 to 31) * If 0 is specified, no day data is used for comparison.
// Month data (0 to 12) * If 0 is specified, no month data is used for comparison.
127
ML610Q400 Series
Sample Program API Manual
3.11.5. Details of APIs
This section describes details of the time clock control module APIs.
3.11.5.1. rtc_setTime Function
This function sets date (year, month, day, day of the week) and clock time (hour, minute, second). If this function is
executed during operation of the RTC, the RTC is once put into a stopped state within this function. Then, data and
clock time are set and after that, the RTC is reactivated.
Function
name:
Arguments:
Return
values:
Processing:
int rtc_setTime(
tRtcTime *prm
)
tRtcTime *prm … Pointer to the area that contains the date (year, month, day, day of the week) and clock time (hour,
minute, second) to be set
int
Setting succeeded: RTC_R_OK(=0)
The second setting is outside the range: RTC_R_ERR_SEC(=-1)
The minute setting is outside the range: RTC_R_ERR_MIN(=-2)
The hour setting is outside the range: RTC_R_ERR_HOUR(=-3)
The day of the week setting is outside the range: RTC_R_ERR_WEEK(=-4)
The day setting is outside the range: RTC_R_ERR_DAY(=-5)
The month setting is outside the range: RTC_R_ERR_MON(=-6)
The year setting is outside the range: RTC_R_ERR_YEAR(=-7)
See next page.
128
ML610Q400 Series
Sample Program API Manual
Continued on next page
129
ML610Q400 Series
Sample Program API Manual
130
ML610Q400 Series
Sample Program API Manual
3.11.5.2. rtc_getTime Function
This function acquires date (year, month, day, day of the week) and clock time (hour, minute, second). In order to
prevent reading of undefined data during counting, read every register twice and check that the read two values match.
Function
name:
Arguments:
Return
values:
int rtc_getTime(
tRtcTime *prm
)
tRtcTime *prm … Pointer to the area that stores date (year, month, day, day of the week) and clock time (hour,
minute, second)
int
Acquisition succeeded (values match): RTC_R_OK(=0)
Acquisition failed (values do not match): RTC_R_ERR_GETTIME(=-10)
Processing:
Data & clock time acquisition
rtc_getTime function
Register read
Read second, minute, hour, day of the week, day,
month, and year in a batch
(1st time)
[Real time clock second register]
[Real time clock minute register]
[Real time clock hour register]
[Real time clock week register]
[Real time clock day register]
[Real time clock month register]
[Real time clock year register]
Read second, minute, hour, day of the week, day,
month, and year in a batch
(2nd time)
[Real time clock second register]
[Real time clock minute register]
[Real time clock hour register]
[Real time clock week register]
[Real time clock day register]
[Real time clock month register]
[Real time clock year register]
Do the two “date and clock time” values
that have been read match?
Store setting
values
No
Yes
Store the “date and clock time” values that
have been read in the specified area
Return “RTC_R_OK”
131
Return
“RTC_R_ERR_GETTIME”
ML610Q400 Series
Sample Program API Manual
3.11.5.3. rtc_start Function
This function starts RTC operation.
Function
name:
Arguments:
Return
values:
Processing:
void rtc_start( void )
None
None
RTC operation start
rtc_start function
Register setting
Start RTC operation
[Real time clock control register]
Set [RTCEN]
End of processing
3.11.5.4. rtc_stop Function
This function stops RTC operation.
Function
name:
Arguments:
Return
values:
Processing:
void rtc_stop( void )
None
None
RTC operation stop
rtc_start function
Register setting
Stop RTC operation
[Real time clock control register]
Clear [RTCEN]
End of processing
132
ML610Q400 Series
Sample Program API Manual
3.11.5.5. rtc_setRegularInt Function
This function sets settings for periodic interrupt.
Function
name:
Arguments:
Return
values:
int rtc_setRegularInt(
unsigned char rin
)
unsigned char rin … Periodic-interrupt setting
Disable periodic interrupts: RTC_RIN_DISABLE(=0)
Enable 0.5-second interrupt: RTC_RIN_0_5_SEC(=1)
Enable 1-second interrupts: RTC_RIN_1_0_SEC(=2)
Enable 1-minute interrupts: RTC_RIN_1_0_MIN(=3)
int
Setting succeeded: RTC_R_OK(=0)
Periodic interrupt setting is outside the range: RTC_R_ERR_RIN(=-9)
Processing:
133
ML610Q400 Series
Sample Program API Manual
3.11.5.6. rtc_setAlarm0 Function
This function sets alarm 0.
Function
name:
Arguments:
Return
values:
Processing:
int rtc_setAlarm0(
unsigned char alen,
tRtcAlarm0* prm
)
unsigned char alen … Alarm 0 enable/disable setting
Disable alarm 0: RTC_ALEN_DIS(=0)
Enable alarm 0: RTC_ALEN_ENA(=1)
tRtcAlarm0* prm …Pointer to the area that contains the alarm 0 setting (day of the week, hour, minute)
- If 0 is specified for day of the week, no day-of-the-week data is used as comparison data for alarm 0.
int
Setting succeeded: RTC_R_OK(=0)
The minute setting is outside the range: RTC_R_ERR_MIN(=-2)
The hour setting is outside the range: RTC_R_ERR_HOUR(=-3)
The day of the week setting is outside the range: RTC_R_ERR_WEEK(=-4)
The enable/disable setting is outside the range: RTC_R_ERR_ALEN(=-9)
See next page.
134
ML610Q400 Series
Sample Program API Manual
135
ML610Q400 Series
Sample Program API Manual
3.11.5.7. rtc_setAlarm1 Function
This function sets alarm 1.
Function
name:
Arguments:
Return
values:
Processing:
int rtc_setAlarm1(
unsigned char alen,
tRtcAlarm1* prm
)
unsigned char alen … Alarm 1 enable/disable setting
Disable alarm 1: RTC_ALEN_DIS(=0)
Enable alarm 1: RTC_ALEN_ENA(=1)
tRtcAlarm1* prm …Pointer to the area that contains the alarm 1 setting (month, day, hour, minute)
- If 0 is specified for month, no month data is used as comparison data for alarm 1.
- If 0 is specified for day, no day data is used as comparison data for alarm 1.
int
Setting succeeded: RTC_R_OK(=0)
The minute setting is outside the range: RTC_R_ERR_MIN(=-2)
The hour setting is outside the range: RTC_R_ERR_HOUR(=-3)
The day setting is outside the range: RTC_R_ERR_DAY(=-5)
The month setting is outside the range: RTC_R_ERR_MON(=-6)
The enable/disable setting is outside the range: RTC_R_ERR_ALEN(=-9)
See next page.
136
ML610Q400 Series
Sample Program API Manual
Continued on next page.
137
ML610Q400 Series
Sample Program API Manual
138
ML610Q400 Series
Sample Program API Manual
3.11.5.8. rtc_getAlarm0 Function
This function acquires the alarm 0 setting.
Function
name:
Arguments:
Return
values:
Processing:
void rtc_getAlarm0(
tRtcAlarm0 *prm
)
tRtcAlarm0 *prm … Pointer to the area that stores the alarm 0 setting (day of the week, hour, minute)
None
139
ML610Q400 Series
Sample Program API Manual
3.11.5.9. rtc_getAlarm1 Function
This function acquires the alarm 1 setting.
Function
name:
Arguments:
Return
values:
Processing:
void rtc_getAlarm1(
tRtcAlarm1*prm
)
tRtcAlarm1 *prm … Pointer to the area that stores the alarm 1 setting (month, day, hour, minute)
None
140
ML610Q400 Series
Sample Program API Manual
3.12. Timer Module
3.12.1. Overview of Functions
The timer module controls the timer of the MCU.
Control of the timer is achieved by APIs that perform initialization (operating clock setting, 8/16-bit mode setting,
overflow interval specification), timer start/stop, and timer overflow flag acquisition and clear.
3.12.2. List of APIs
The following table lists the timer module APIs.
Table 3-42 Timer Module APIs
Function name
tm_init function
tm_start function
tm_stop function
tm_checkOvf function
tm_clearOvf function
tm_checkFmFunc function
Description
Executes operating clock setting, 8-bit or 16-bit mode setting, and overflow interval
setting.
Starts timer operation. Operation setting is performed with tm_init function.
Stops timer operation.
Checks the timer overflow flag status.
Executes timer overflow flag clear operation.
Checks whether the 16-bit frequency measuring mode is enabled or disabled.
3.12.3. List of Constants
The following tables list the constants used in the timer module.
Table 3-43 Constants for Arguments
Constant name
TM_M16_8BIT
TM_M16_16BIT
TM_CS_LSCLK
TM_CS_HTBCLK
TM_CS_EXTCLK
Defined
value
0
1
0
1
3
Description
Specifies 8-bit mode as the operating mode.
Specifies 16-bit mode as the operating mode.
Specifies LSCLK as the operating clock.
Specifies HTBCLK as the operating clock.
Specifies an external clock as the operating clock.
Table 3-44 Constants for Return Values
Constant name
Defined
value
Description
TM_R_OK
TM_R_ERR_CHNO
TM_R_ERR_M16
TM_R_ERR_CS
TM_R_ERR_CNT
TM_R_OVF
TM_R_NOT_OVF
0
-1
-2
-3
-4
1
0
Processing succeeded.
The channel No. is outside the range.
The operating mode setting is outside the range.
The operating clock setting is outside the range.
The overflow interval is outside the range.
Overflow has occurred.
Overflow has not occurred yet.
TM_R_FM_ENA
TM_R_FM_DIS
1
0
16-bit frequency measuring mode is enabled.
16-bit frequency measuring mode is disabled.
141
ML610Q400 Series
Sample Program API Manual
3.12.4. API Details
This section describes details of the timer module.
3.12.4.1. tm_init Function
This function sets timer’s operating clock, selects 8- or 16-bit mode, and specifies the overflow interval.
Function
name:
Arguments:
Return
values:
Processing:
int tm_init(
unsigned char chNo,
unsigned char m16,
unsigned char cs,
unsigned short cnt,
)
unsigned char chNo … Timer channel No. (0 to 3)
unsigned char m16 … Operating mode
8-bit mode: TM_M16_8BIT(=0)
16-bit mode: TM_M16_16BIT(=1)
16-bit frequency measuring mode: TM_M16_FM(=3)
unsigned char cs … Operating clock
LSCLK: TM_CS_LSCLK(=0)
HTBCLK: TM_CS_HTBCLK(=1)
External clock: TM_CS_EXTCLK(=3)
unsigned short cnt … Overflow interval (specified with count)
int
Initialization succeeded: TM_R_OK(=0)
The channel No. is outside the range: TM_R_ERR_CHNO(= -1)
The operating mode setting is outside the range: TM_R_ERR_M16(= -2)
The operating clock setting is outside the range: TM_R_ERR_CS(= -3)
The overflow interval is outside the range: TM_R_ERR_CNT(= -4)
See next page.
142
ML610Q400 Series
Sample Program API Manual
Timer module initialization
tm_init function
Parameter check
Is the operating clock setting
within the range?
(The set value is "0", "1", "3")
Yes
No
Return "TM_R_ERR_CS"
Is the operating mode "8-bit mode"?
No
Yes
No
Is the operating mode
"16-bit mode”?
Yes
Is the operating mode
"16-bit frequency measuring mode"?
No
Yes
Obtain information as to whether the frequency
measurement function is enabled or disabled
[Timer 2 control register 0]
[Set timer control register 1]
See [T2FMA4-7]
No
Is the frequency measurement function
enabled?
([T2FMA4-7] value is 0xA)
Yes
Is the channel No. within the range?
(The set value is "3" or less)
Yes
Is the channel No. within the range?
(The set value is "0" or "2")
Return "TM_R_ERR_CHNO"
Is the “overflow interval”
within the range?
(between 00h and FFh)
Yes
No
Yes
No
Yes
Yes
Register setting
No
Yes
Stop the timer operation on the [specified channel No.] and
[specified channel No.+1]
[Set the timer control register 1]
Clear [TnRUN] and [T(n+1)RUN]
Clear the timer counter on the specified
channel No.
[Set the timer counter register]
Set “0” in [TnC0-7]
Clear the timer counter registers on the [specified channel
No.] and [specified channel No.+1]
[Set the timer counter register]
Set “0” in [TnC0-7] and [T(n+1)C0-7]
Set the overflow count value of the specified
channel No.
[Set the timer data register]
Set "overflow interval" in [TnD0-7]
Store the calculated setting values in the timer data
registers on the [specified channel No.] and [specified
channel No.+1]
[Set the timer data register]
Set "overflow interval" in [TnD0-7] and [T(n+1)D0-7]
Set the operating mode and operating clock
on the specified channel No.
[Set timer control register 0]
Set “0” in [TnM16]
Set “operating clock” in [TnCS0-1]
Set the operating mode and operating clock on the
specified channel
[Set timer control register 0]
Set “operating mode” in [TnM16]
Set “operating clock” in[TnCS0-1]
Return "TM_R_OK"
143
No
Return "TM_R_ERR_CHNO"
Is the operating clock setting within
the range?
(The set value is "1")
Return "TM_R_ERR_CNT"
Stop the timer operation on the specified
channel No.
[Set the timer control register 1]
Clear [TnRUN]
Is the channel No. within the range?
(The set value is "2")
Return "TM_R_ERR_CHNO"
No
Is the operating mode "8-bit mode"?
Return "TM_R_ERR_M16"
No
Return "TM_R_ERR_CS"
ML610Q400 Series
Sample Program API Manual
3.12.4.2. tm_start Function
This function starts timer operation. Set the overflow interval using the tm_init function.
Function
name:
Arguments:
Return
values:
int tm_start(
unsigned char chNo
)
unsigned char chNo … Timer channel No. (0 to 3)
int
Start processing succeeded: TM_R_OK(=0)
The channel No. is outside the range: TM_R_ERR_CHNO(=-1)
Processing:
Start of timer operation
tm_start function
Is the channel No. within the range?
(The set value is “3” or less)
Yes
Start timer operation of the specified
channel No.[Set timer control register 1]
Set [TnRUN]
Return “TM_R_OK”
144
No
Return “TM_R_ERR_CHNO”
ML610Q400 Series
Sample Program API Manual
3.12.4.3. tm_stop Function
This function stops timer operation.
Function
name:
Arguments:
Return
values:
int tm_stop(
unsigned char chNo
)
unsigned char chNo … Timer channel No. (0 to 3)
int
Stop processing succeeded: TM_R_OK(=0)
The channel No. is outside the range: TM_R_ERR_CHNO(=-1)
Processing:
Stop of timer operation
tm_stop function
No
Is the channel No. within the range?
(The set value is “3” or less)
Yes
Return “TM_R_ERR_CHNO”
Stop timer operation of the specified channel No.
[Timer control register 1]
Clear [TnRUN]
Return “TM_R_OK”
145
ML610Q400 Series
Sample Program API Manual
3.12.4.4. tm_checkOvf Function
This function checks the status of the timer overflow flag (QTMn of the interrupt request register). However, since the
MCU clears the timer overflow flag during the use of interrupts, this function always returns “No overflow has occurred
yet: TM_R_NOT_OVF(=0)”.
Function
name:
Arguments:
Return
values:
int tm_checkOvf(
unsigned char chNo
)
unsigned char chNo … Timer channel No. (0 to 3)
int
Overflow has occurred: TM_R_OVF(=1)
No overflow has occurred yet: TM_R_NOT_OVF(=0)
The channel No. is outside the range: TM_R_ERR_CHNO(=-1)
Processing:
146
ML610Q400 Series
Sample Program API Manual
3.12.4.5. tm_clearOvf Function
This function performs timer overflow flag clear processing (QTMn of the interrupt request register).
Function
name:
Arguments:
Return
values:
int tm_clearOvf(
unsigned char chNo
)
unsigned char chNo … Timer channel No.(0 to 3)
int
Clear processing succeeded: TM_R_OK(=0)
The channel No. is outside the range: TM_R_ERR_CHNO(=-1)
Processing:
147
ML610Q400 Series
Sample Program API Manual
3.12.4.6. tm_checkFmFunction
This function checks whether the 16-bit frequency measuring mode is enabled or disabled.
Function
name:
Arguments:
Return
values:
int tm_checkFmFunc( void )
None
int
16-bit frequency measuring mode is enabled: TM_R_FM_ENA(=1)
16-bit frequency measuring mode is disabled: TM_R_FM_DIS(=-0)
Processing:
148
ML610Q400 Series
Sample Program API Manual
3.13. Clock Control Module
3.13.1. Overview of Functions
The clock control module controls clocks of the MCU.
Clock control is achieved by functions that perform operations such as system clock selection and acquisition,
high-speed clock divide ratio selection, selection of the operating mode of high-speed clock, start/stop of the oscillation
of the high-speed clock oscillation circuit, and start/stop of the low-speed 2x clock.
3.13.2. List of Functions
The clock control module APIs and system definition functions are listed below.
Table 3-45 Clock Control Module APIs
Function name
clk_setSysclk function
clk_getSysclk function
clk_setHsclk function
clk_enaHsclk function
clk_disHsclk function
clk_getHsclk function
clk_enaLsclk2 function
clk_disLsclk2 function
Description
Selects low-speed clock or high-speed clock as the system clock; selects the divide ratio
of high-speed clock; selects the operating mode of the high-speed clock generation circuit;
sets the clock frequency to be used.
Acquires the system clock settings (LSCLK/HSCLK selection, system clock frequency).
Selects the divide ratio of high-speed clock; selects the operating mode of the high-speed
clock generation circuit; sets the clock frequency to be used.
Starts oscillation of the high-speed clock oscillation circuit.
Stops oscillation of the high-speed clock oscillation circuit.
Acquires the high-speed clock frequency.
Starts the operation of the low-speed 2x clock.
Stops the operation of the low-speed 2x clock.
3.13.3. List of System Definition Functions
The following table lists the system definition functions of the clock control module. When using a system definition
function, it is necessary to create internal processing according to the system used.
Table 3-46 System Definition Functions of Clock Control Module
Function name
clk_wait500us function
Description
Waits for 500 µs.
149
ML610Q400 Series
Sample Program API Manual
3.13.4. List of Constants
The following tables list the constants used in the clock control module.
Table 3-47 Constants for Arguments
Constant name
Defined
value
CLK_SYSCLK_LSCLK
CLK_SYSCLK_HSCLK
CLK_SYSC_OSCLK
CLK_SYSC_OSCLK_DIV2
CLK_SYSC_OSCLK_DIV4
CLK_SYSC_OSCLK_DIV8
CLK_OSCM_RC
CLK_OSCM_CRYSTAL
0
1
0
1
2
3
0
1
CLK_OSCM_PLL
2
CLK_OSCM_EXTCLK
3
Description
Selects low-speed clock as the system clock.
Selects high-speed clock as the system clock.
When high-speed clock selected: Selects OSCLK.
When high-speed clock selected: Selects 1/2OSCLK
When high-speed clock selected: Selects 1/4OSCLK
When high-speed clock selected: Selects 1/8OSCLK
When high-speed clock selected: Selects RC oscillation mode.
When high-speed clock selected: Selects crystal/ceramic oscillation
mode.
When high-speed clock selected: Selects internal PLL oscillation
mode.
When high-speed clock selected: Selects external clock input
mode.
Table 3-48 Constants for Return Values
Constant name
CLK_R_OK
CLK_R_ERR_SCLK
CLK_R_ERR_SYSC
CLK_R_ERR_OSCM
CLK_R_ERR_ENOSC
Defined
value
0
-1
-2
-3
-4
Description
Processing succeeded.
The selected system clock is outside the range.
The selected divide ratio is outside the range.
The selected high-speed clock is outside the range.
High-speed oscillation is operating.
3.13.5. List of Variables
The following table lists the variables used in the clock control module.
Table 3-49 List of Variables
Variable name
Static
unsigned short _gsHsclk
Initial value
4096
Description
Variable for storing the frequency when the crystal/ceramic
oscillation mode or external clock input mode is selected. Since the
input clock in the above modes is externally connected, it is
necessary to retain the specified value inside the module.
150
ML610Q400 Series
Sample Program API Manual
3.13.6. Details of APIs
This section describes details of the clock control module.
3.13.6.1. clk_setSysclk Function
This function selects low-speed clock or high-speed clock as the system clock; selects the divide ratio of high-speed
clock; selects the operating mode of the high-speed clock oscillation circuit; sets the clock frequency to be used.
Function
name:
Arguments:
Return
values:
Processing:
int clk_setSysclk(
unsigned char sysclk,
unsigned char sysc,
unsigned char oscm,
unsigned short kHz
)
unsigned char sysclk … Select system clock
Low-speed clock: CLK_SYSCLK_LSCLK(=0)
High-speed clock: CLK_SYSCLK_HSCLK(=1)
unsigned char sysc … Select the divide ratio of high-speed clock
[When low-speed clock is selected]
No reference
[When high-speed clock is selected]
OSCLK: CLK_SYSC_OSCLK(=0)
1/2OSCLK: CLK_SYSC_OSCLK_DIV2(=1)
1/4OSCLK: CLK_SYSC_OSCLK_DIV4(=2)
1/8OSCLK: CLK_SYSC_OSCLK_DIV8(=3)
unsigned char oscm … Selects the mode of the high-speed clock generation circuit.
[When low-speed clock is selected]
No reference
[When high-speed clock is selected]
RC oscillation mode: CLK_OSCM_RC(=0)
Crystal/ceramic oscillation mode: CLK_OSCM_CRYSTAL(=1)
Internal PLL oscillation mode: CLK_OSCM_PLL(=2)
External clock input mode: CLK_OSCM_EXTCLK(=3)
unsigned short kHz … Input frequency (kHz)
[When low-speed clock is selected]
No reference
[When high-speed clock is selected]
Referenced only when external clock input mode is selected.
int
Initialization succeeded: CLK_R_OK(=0)
The selected system clock is outside the range: CLK_R_ERR_SCLK(=-1)
The selected divide ratio is outside the range: CLK_R_ERR_SYSC(=-2)
The selected high-speed clock is outside the range: CLK_R_ERR_OSCM(=-3)
See next page.
151
ML610Q400 Series
Sample Program API Manual
Continued on next page
152
ML610Q400 Series
Sample Program API Manual
153
ML610Q400 Series
Sample Program API Manual
3.13.6.2. clk_getSysclk Function
This function acquires the system clock settings (LSCLK/HSCLK selection, system clock frequency).
Function
name:
Arguments:
Return
values:
Processing:
void clk_getSysclk(
unsigned char *mode,
unsigned short *kHz
)
unsigned char *mode … Pointer to the area that stores LSCLK/HSCLK selection information
Low-speed clock: CLK_SYSCLK_LSCLK(=0)
High-speed clock: CLK_SYSCLK_HSCLK(=1)
unsigned short * kHz … Area that stores the frequency (stores a value in 1-kHz units)
- The value should be 32.768 kHz during operation with a “low-speed clock”; however, since “1-kHz
units” is specified for this argument, “32” is stored. For this reason, if “low-speed clock” is returned to
the argument “mode”, it is recommended to use a value of “32.768 kHz” without using the value
stored in this argument.
None
See next page.
154
ML610Q400 Series
Sample Program API Manual
Acquisition of system clock setting
clk_getSysclk function
Acquire system clock setting
[Frequency control register 1]
Read [SYSCLK]
Store [SYSCLK] read value in “LSCLK/
HHCLK selection information”
LSCLK being selected?
([SYSCLK] read value is “0”)
No
Yes
Store “LSCLK” in “*mode”
Store “HSCLK” in “*mode”
Acquire divide ratio setting for HSCLK
[Frequency control register 0]
Read [SYSC0-1]
Acquire the operating mode of high-speed
clock generation circuit
[Frequency control register 0]
Read [OSCM0-1]
Branch according to the selected
operating mode when high-speed
clock selected
Store “32” in “*kHz”
(Unit: [kHz])
RC oscillation mode
Crystal/ceramic oscillation mode
Store “500” in “*kHz”
(Unit: [kHz])
Store “4096” in “*kHz”
(Unit: [kHz])
Internal PLL oscillation mode
External clock input mode
Store “8192” in “*kHz”
(Unit: [kHz])
Store “kHz” in “*kHz”
(Unit: [kHz])
Is the selected divide ratio when
high-speed clock selected “1/1
OSCLK”?
Yes
Correct the divide ratio when highspeed clock selected to
“1/2 OSCLK”
Apply the divide ratio when highspeed clock selected to
the acquired "*kHz"
End of processing
155
No
ML610Q400 Series
Sample Program API Manual
3.13.6.3. clk_setHsclk Function
This function selects the divide ratio of high-speed clock; selects the operating mode of the high-speed clock generation
circuit; sets the clock frequency to be used.
Function
name:
Arguments:
Return
values:
Processing:
int clk_setHsclk(
unsigned char sysc,
unsigned char oscm,
unsigned short kHz
)
unsigned char sysc …Select the divide ratio of high-speed clock
OSCLK: CLK_SYSC_OSCLK(=0)
1/2OSCLK: CLK_SYSC_OSCLK_DIV2(=1)
1/4OSCLK: CLK_SYSC_OSCLK_DIV4(=2)
1/8OSCLK: CLK_SYSC_OSCLK_DIV8(=3)
unsigned char oscm … Select the operating mode of the high-speed clock generation circuit
RC oscillation mode: CLK_OSCM_RC(=0)
Crystal/ceramic oscillation mode: CLK_OSCM_CRYSTAL(=1)
Internal PLL oscillation mode: CLK_OSCM_PLL(=2)
External clock input mode: CLK_OSCM_EXTCLK(=3)
unsigned short kHz … Input frequency (kHz).
Referenced only when external clock input mode is selected.
int
Setting succeeded: CLK_R_OK(=0)
The selected divide ratio is outside the range: CLK_R_ERR_SYSC(=-2)
The selected high-speed mode is outside the range: CLK_R_ERR_OSCM(=-3)
High-speed oscillation is operating: CLK_R_ERR_ENOSC(=-4)
See next page.
156
ML610Q400 Series
Sample Program API Manual
High-speed clock setting
clk_setHsclk function
Acquire operating status of high-speed clock
oscillation circuit
[Frequency control register 1]
· Read [ENOSC]
Is high-speed clock oscillation circuit
stopped?
([ENOSC] is “0”)
Yes
No
Return “CLK_R_ERR_ENOSC”
Is the selected
divide ratio within the range?
(The set value is “3” or less)
Yes
In the selected operating mode within the
range?
(The set value is “3” or less)
Yes
No
Return “CLK_R_ERR_SYSC”
No
Return “CLK_R_ERR_OSCM”
Select divide ratio
[Frequency control register 0]
· Store “divide ratio selection” in [SYSC0-1]
Select the operating mode for high-speed
oscillation circuit
[Frequency control register 0]
· Store “mode selection” in [OSCM0-1]
Is the selected operating
mode “external clock
input mode”?
Yes
Internally retain “high-speed clock
frequency”
Return “CLK_R_OK”
157
No
ML610Q400 Series
Sample Program API Manual
3.13.6.4. clk_enaHsclk Function
This function starts the operation of the high-speed clock oscillation circuit.
Function
name:
Arguments:
Return
values:
Processing:
void clk_enaHsclk( void )
None
None
3.13.6.5. clk_disHsclk Function
This function stops the operation of the high-speed clock oscillation circuit.
Function
name:
Arguments:
Return
values:
Processing:
void clk_disHsclk( void )
None
None
158
ML610Q400 Series
Sample Program API Manual
3.13.6.6. clk_getHsclk Function
This function acquires the high-speed clock frequency.
Function
name:
Arguments:
Return
values:
Processing:
unsigned long clk_getHsclk( void )
None
unsigned short
Frequency of HSCLK (kHz units)
Acquisition of high-speed clock (HSCLK)
frequency
clk_getHsclk function
Acquire the status of high-speed clock
oscillation circuit
[Frequency control register 1]
Read [ENOSC]
Is high-speed clock
oscillation circuit operating?
([ENOSC] is “1”)
No
Yes
Acquire HSCLK divide ratio setting
[Frequency control register 0]
Read [SYSC0-1]
Acquire the operating mode of high-speed
clock
generation circuit
[Frequency control register 0]
Read [OSCM0-1]
Branch according to the selected
operating mode when high-speed
clock selected
RC oscillation mode
Crystal/ceramic oscillation mode
Store “500” in "*kHz"
(Unit: [kHz])
Store “4096” in "*kHz"
(Unit: [kHz])
Store “0” in "*kHz"
(Unit: [kHz])
Internal PLL oscillation mode
External clock input mode
Store “8192” in "*kHz"
(Unit: [kHz])
Store “kHz” in "*kHz"
(Unit: [kHz])
Is the selected divide ratio when
high-speed clock selected
“1/1 OSCLK”?
Yes
Correct the divide ratio when highspeed clock selected to
“1/2 OSCLK”
Apply selected divide ratio when
high-speed clock selected to
the acquired "*kHz"
Return the acquired "*kHz"
159
No
ML610Q400 Series
Sample Program API Manual
3.13.6.7. clk_enaLsclk2 Function
This function starts the operation of the low-speed 2x clock.
Function
name:
Arguments:
Return
values:
Processing:
void clk_enaLsclk2( void )
None
None
3.13.6.8. clk_disLsclk2 Function
This function stops the operation of the low-speed 2x clock.
Function
name:
Arguments:
Return
values:
Processing:
void clk_disLsclk2( void )
None
None
160
ML610Q400 Series
Sample Program API Manual
3.13.7. System Definition Function
3.13.7.1. clk_wait500us Function
This function waits for 500 µs. Create the function according to the system used.
Function
name:
Arguments:
Return
values:
Processing:
void clk_wait500us( void )
None
None
• Waits for 500 µs within the function.
161
ML610Q400 Series
Sample Program API Manual
3.14. Time Base-Counter Control Module
3.14.1. Overview of Functions
The time-base counter module controls the high-speed side time-base counter of the MCU.
Control of the time-base counter is achieved by setting and acquiring the divide ratio of the high-speed side time-base
counter.
3.14.2. List of APIs
The following table lists the time-base counter control module APIs.
Table 3-50 Time-Base Counter Control Module APIs
Function name
tb_setHtbdiv function
tb_getHtbdiv function
Description
Sets the divide ratio of the time-base counter on the high-speed side.
Acquires the divide ratio of the time-base counter on the high-speed side.
3.14.3. List of Constants
The following tables list the constants used in the time-base counter control module
Table 3-51 Constants for Arguments
Constant name
TB_HTD_1_16
TB_HTD_1_15
TB_HTD_1_14
TB_HTD_1_13
TB_HTD_1_12
TB_HTD_1_11
TB_HTD_1_10
TB_HTD_1_9
TB_HTD_1_8
TB_HTD_1_7
TB_HTD_1_6
TB_HTD_1_5
TB_HTD_1_4
TB_HTD_1_3
TB_HTD_1_2
TB_HTD_1_1
Defined
value
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Description
Divide ratio of HTB: 1/16
Divide ratio of HTB: 1/15
Divide ratio of HTB: 1/14
Divide ratio of HTB: 1/13
Divide ratio of HTB: 1/12
Divide ratio of HTB: 1/11
Divide ratio of HTB: 1/10
Divide ratio of HTB: 1/9
Divide ratio of HTB: 1/8
Divide ratio of HTB: 1/7
Divide ratio of HTB: 1/6
Divide ratio of HTB: 1/5
Divide ratio of HTB: 1/4
Divide ratio of HTB: 1/3
Divide ratio of HTB: 1/2
Divide ratio of HTB: 1/1
Table 3-52 Constants for Return Values
Constant name
TB_R_OK
TB_R_ERR_HTD
Defined
value
0
-1
Description
Processing succeeded.
The divide ratio setting is outside the range.
162
ML610Q400 Series
Sample Program API Manual
3.14.4. Details of APIs
This section describes details of the time-base counter module.
3.14.4.1. tb_setHtbdiv Function
This function sets the divide ratio of the time-base counter on the high-speed side.
Function
name:
Arguments:
Return
values:
int tb_setHtbdiv(
unsigned char htd
)
unsigned char htb … Divide ratio setting
Frequency divided by 16 (HTBCLK=256kHz): TB_HTD_1_16(=0)
… (*For details see Table 3-51)
1/1 divide (HTBCLK=4096kHz): TB_HTD_1_1(=15)
int
Setting succeeded: TB_R_OK(=0)
The divide ratio setting is outside the range: TB_R_ERR_HTD(=-1)
Processing:
Divide ratio setting for high-speed side
time-base counter
tb_setHtbdiv function
Parameter check
Is the divide ratio set
within the range?
(The set value is “15” or less)
Yes
No
Return “TB_R_ERR_HTD”
Register setting
Set divide ratio of HTB
[High-speed side time-base counter divide register]
Store “dive ratio setting” in [HTD0-3]
Return “TB_R_OK”
163
ML610Q400 Series
Sample Program API Manual
3.14.4.2. tb_getHtbdiv Function
This function acquires the divide ratio of the high-speed side time-base counter.
Function
name:
Arguments:
Return
values:
Processing:
unsigned char tb_getHtbdiv( void )
None
unsigned char
Divide ratio (1 to 16)
164
ML610Q400 Series
Sample Program API Manual
3.15. 1kHz Timer Control Module
3.15.1. Overview of Functions
The 1kHz timer control module controls the 1kHz timer of the MCU.
3.15.2. List of APIs
The following table lists the 1kHz timer control module APIs.
Table 3-53 List of APIs
Function name
t1k_init function
t1K_start function
t1k_stop function
t1k_getT1KCR function
t1k_clrT1KCR function
t1k_checkOvf function
Description
Initializes the 1kHz timer interrupt.
Starts timer operation.
Stops timer operation.
Reads the T1KCR register.
Clears the contents of the T1KCR register.
Checks the status of the timer overflow flag.
3.15.3. List of Constants
The following table lists the constants used in the kHz timer control module.
Table 3-54 List of Constants for APIs
Constant name
Defined
value
T1KSEL_10HZ
0
T1KSEL_1HZ
1
Description
Selects the interrupt cycle of the 1 kHz timer: Selects 10Hz
interrupt.
Selects the interrupt cycle of the 1 kHz timer: Selects 1Hz interrupt.
165
ML610Q400 Series
Sample Program API Manual
3.15.4. Details of APIs
This section describes details of the 1kHz timer control module APIs.
3.15.4.1. t1k_init Function
This function sets the 1Hz/10Hz interrupts, stops the timer, and clears T1KCR.
Function
name:
Arguments:
Return
values:
Processing:
void t1k_init( unsigned char set_T1KSET_Hz )
unsigend char set_T1KSET_Hz Timer interrupt setting value
10Hz : T1KSEL_10HZ(=0)
1Hz : T1KSEL_1HZ(=1)
None
1kHz timer initialization processing
t1k_init function
Stop 1kHz timer operation
[1kHz timer control register]
Clear [T1KRUN register]
Set the interrupt cycle to 1Hz interrupt
[1kHz timer control register]
Set [T1KSEL register]
End of processing
3.15.4.2. t1k_start Function
This function starts the 1kHz timer.
Function
name:
Arguments:
Return
values:
Processing:
void t1k_start( void )
None
None
166
ML610Q400 Series
Sample Program API Manual
3.15.4.3. t1k_stop Function
This function stops the 1kHz timer.
Function
name:
Arguments:
Return
values:
Processing:
void t1k_stop( void )
None
None
3.15.4.4. t1k_getT1KCR Function
This function reads the value of the T1KCR register.
Function
name:
Arguments:
Return
values:
Processing:
unsigned short t1k_getT1KCR( void )
None
unsigned short T1KCR register value
T1KCR register value read
t1k_getT1KCR
Read [1kHz timer count register]
(1st time)
Read [1kHz timer count register]
(2nd time)
As a result of comparison between the
[1kHz timer count register] read values,
do they match?
Unmatch
Read [1kHz timer count register]
(3rd time)
Return [1kHz timer count register]
that has been read
167
Match
ML610Q400 Series
Sample Program API Manual
3.15.4.5. t1k_clrT1KCR Function
This function stops the 1kHz timer and clears the T1KCR register value.
Function
name:
Arguments:
Return
values:
Processing:
void t1k_clrT1KCR( void )
None
None
3.15.4.6. t1km_checkOvf Function
This function checks the status of the timer overflow flag.
Function
name:
Arguments:
Return
values:
unsigned char t1k_chechOvf( void )
None
Status of the timer overflow flag
1: Overflow occurred
0: No overflow occurred
Processing:
168
ML610Q400 Series
Sample Program API Manual
3.16. Stopwatch Module
3.16.1. Overview of Functions
The stopwatch module provides a stopwatch function by using the 1kHz timer module.
3.16.2. List of APIs
The following table lists the stopwatch module APIs.
Table 3-55 Stopwatch Module APIs
Function name
chrono_init function
chrono_start function
chrono_stop function
chrono_getHz100 function
chrono_getHz1000 function
chrono_getTime function
chrono_checkOvf function
chrono_clrOvf function
chrono_int32Hz function
chrono_int1kHz_Spilt function
chrono_int1kHz_Run function
chrono _Stop_S1 function
chrono _Stop_S2 function
chrono _RUN_S1 function
chrono _RUN_S2 function
chrono_Int_S1 function
chrono_Int_S2 function
chrono_get_ProcSts function
chrono_get_DspReq function
chrono_clr_DspReq function
chrono_get_DspTim function
Description
Initializes the stopwatch.
Starts the stopwatch.
Stops the stopwatch.
Reads the value of a tenth and a hundredth of a second.
Reads the value of a tenth, a hundredth, and a thousandth of a second.
Reads the value of minute, second, a tenth, a hundredth, and a thousandth of a
second.
Checks the stopwatch’s 60-minute overflow flag.
Clears the stopwatch’s 60-minute overflow flag.
Performs 32Hz timer interrupt processing for screen update.
Performs 1kHz timer interrupt processing during SPLIT.
Performs 1kHz timer interrupt processing during RUN.
Performs S1 key event processing while the stopwatch status is STOP.
Performs S2 key event processing while the stopwatch status is STOP.
Performs S1 key event processing while the stopwatch status is RUN or SPLIT.
Performs S2 key event processing while the stopwatch status is RUN or SPLIT.
Performs S1 key event interrupt processing.
Performs S2 key event interrupt processing.
Obtains the stopwatch status.
Obtains display update request.
Clears display update request.
Obtains the display time.
3.16.3. List of Constants
The following table lists the constants used in the stopwatch module.
Table 3-56 Stopwatch Module Constants
Constant name
CHR_STS_STOP
CHR_STS_RUN
CHR_STS_SPLIT
Defined
value
0
1
2
Description
Stopwatch status: STOP state
Stopwatch status: RUN state
Stopwatch status: SPLIT state
169
ML610Q400 Series
Sample Program API Manual
3.16.4. Structure
This section describes the structures used in the stopwatch module. Set each parameter value using binary-coded decimal
(BCD) numbers.
Watch setting parameters
typedef struct {
unsigned char
unsigned char
unsigned char
unsigned char
} t1K_Time;
1ms;
ms;
sec;
min;
// 1/1000 data (0x00 to 0x99)
// 1/10 and 1/100 data (0x00 to 0x99)
// Second data (0x00 to 0x59)
// Minute data (0x00 to 0x59)
3.16.5. List of Variables
The following table lists the variables used in the stopwatch module.
Table 3-57 List of Variables
Variable name
Initial value
1ms :0
ms :0
sec :0
min:0
t1K_Time _chrono_Tim
t1K_Time _Dsp_Tim
unsigned char_Ovf_Flg
unsigned char_chrono_proc_Sts
static const vfv _chrono_tbls_S1_Event[3](*1)
static const vfv _chrono_tbls_S2_Event[3](*1)
Description
Clock time (internal time)
1ms :0
ms :0
sec :0
min:0
0
CHR_STS_STOP
Stopwatch overflow flag
Stopwatch status
0
0
S1 key event processing function table
S2 key event processing function table
Clock time for display
*1: The interface specification of the functions to be called upon generation of the S1 or S2 key event is as follows:
typedef void( *vfv )( void );
Also, Table 3-58 lists the functions to be executed upon generation of the S1 or S2 key event.
Table 3-58 S1 and S2 Key Event Processing Function Table
Index(status)
S1 key event table
_chrono_tbls_S1_Event
S2 key event table
_chrono_tbls_S2_Event
0 (STOP)
1 (RUN)
2 (SPLIT)
chrono_Stop_S1
chrono_Run_S1
chrono_Run_S1
chrono_Stop_S2
chrono_Run_S2
chrono_Run_S2
170
ML610Q400 Series
Sample Program API Manual
3.16.6. Details of APIs
This section describes details of the stopwatch module APIs.
3.16.6.1. chrono_init Function
This function initializes the stopwatch.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_init( void )
None
None
171
ML610Q400 Series
Sample Program API Manual
3.16.6.2. chrono_start Function
This function starts the stopwatch.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_start( void )
None
None
3.16.6.3. chrono_stop Function
This function stops the stopwatch.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_stop( void )
None
None
3.16.6.4. chrono_getHz100 Function
This function reads the value of a tenth and a hundredth of a second.
Function
name:
Arguments:
Return
values:
Processing:
unsigned char chrono_getHz100( void )
None
Data of a tenth and a hundredth of a second
chrono_getHz100 function
Read [1kHz timer count register H]
Return “read-out result”
172
ML610Q400 Series
Sample Program API Manual
3.16.6.5. chrono_getTime Function
This function reads the value of minute, second, a tenth, a hundredth, and a thousandths of a second.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_getTime( void )
t1K_Time
None
chrono_getTime function
NO
1kHz timer interrupt request present?
YES
Update the internal clock time
Clear the 1kHz timer interrupt request
Read [1kHz timer count register]
(1st time)
Read [1kHz timer count register]
(2nd time)
As a result of comparison between the [1kHz timer
Match
count register] read values, do they match?
Unmatch
Read [1kHz timer count register]
(3rd time)
NO
Has a 1kHz timer interrupt request been issued?
YES
Update the internal clock time
Clear the 1kHz timer interrupt request
Obtain the clock time of minute and second
Obtain the clock time of 1/10, 1/100, and 1/
1000 second
Return “obtained result”
173
ML610Q400 Series
Sample Program API Manual
3.16.6.6. chrono_checkOvf Function
This function obtains the status of the stopwatch’s 60-minute overflow flag.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_checkOvf( void )
None
Status of the stopwatch’s 60-minute overflow flag
3.16.6.7. chrono_clrOvf Function
This function clears the status of the stopwatch’s 60-minute overflow flag.
Function
name:
Arguments:
Return
values:
Processing:
unsigned char chrono_clrovf( void )
None
None
174
ML610Q400 Series
Sample Program API Manual
3.16.6.8. chrono_Stop_S1 Function
This function performs S1 key event processing while the stopwatch status is STOP.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Stop_S1 ( void )
None
None
175
ML610Q400 Series
Sample Program API Manual
3.16.6.9. chrono_Run_S1 Function
This function performs S1 key event processing while the stopwatch status is RUN or SPLIT.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Run_S1( void )
None
None
S1 key event processing during RUN
chrono_Run_S1
Stop the stopwatch
chrono_stop function
Obtain the display time
chrono_getTime function
Request updating of LCD display
[Update of the display of all digits]
Change the stopwatch status
“Change the status to STOP”
Register a handler function (dummy) to the
1kHz timer interrupt
Register a handler function (dummy) to the
32kHz timer interrupt
Clear the 32Hz timer interrupt request
Disable the 32Hz timer interrupt
End of processing
176
ML610Q400 Series
Sample Program API Manual
3.16.6.10. chrono_Stop_S2 Function
This function performs S2 key event processing while the stopwatch status is STOP.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Stop_S2( void )
None
None
177
ML610Q400 Series
Sample Program API Manual
3.16.6.11. chrono_Run_S2 Function
This function performs S2 key event processing while the stopwatch status is RUN or SPLIT.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Run_S2 ( void )
None
None
178
ML610Q400 Series
Sample Program API Manual
3.16.6.12. chrono_int32Hz Function
This function performs 32kHz timer interrupt processing.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_int32Hz( void )
None
None
179
ML610Q400 Series
Sample Program API Manual
3.16.6.13. chrono_int1kHz_Split Function
This function performs 1kHz timer interrupt processing while the stopwatch status is SPLIT.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_int1kHz_Split ( void )
None
None
180
ML610Q400 Series
Sample Program API Manual
3.16.6.14. chrono_int1kHz_Run Function
This function performs 1kHz timer interrupt processing while the stopwatch status is RUN.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_int1kHz_Run( void )
None
None
3.16.6.15. chrono_Int_S1 Function
This function performs S1 key event interrupt processing.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Int_S1 ( void )
None
None
181
ML610Q400 Series
Sample Program API Manual
3.16.6.16. chrono_Int_S2 Function
This function performs S2 key event interrupt processing.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_Int_S2 ( void )
None
None
3.16.6.17. chrono_get_ProcSts Function
This function obtains the stopwatch status.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_get_ProcSts ( void )
None
None
182
ML610Q400 Series
Sample Program API Manual
3.16.6.18. chrono_get_DspReq Function
This function acquires a display update request.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_get_DspReq ( void )
None
None
3.16.6.19. chrono_clr_DspReq Function
This function clears display update request.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_clr_DspReq ( unsigned char Req )
Req : Display update No.
1: Request for updating of the minute and second display
2: Request for updating of the 1/10, 1/100, and 1/1000 second display
None
183
ML610Q400 Series
Sample Program API Manual
3.16.6.20. chrono_get_DspTim Function
This function acquires the display time.
Function
name:
Arguments:
Return
values:
Processing:
void chrono_get_DspTim (t1K_Time *pTim )
pTim: Display time storage destination address
None
184
ML610Q400 Series
Sample Program API Manual
3.17. BLD Module
3.17.1. Overview of Functions
The BLD module controls the battery level detector (BLD) of the MCU and obtains the battery level.
3.17.2. List of APIs
The following table lists the BLD module APIs.
Table 3-59 BLD Module APIs
Function name
bld_start_levelCheck function
bld_getLevel function
Description
Obtains battery level detection.
Obtains the battery level (17 levels in all).
bld_check function
bld_on function
bld_off function
Checks whether the battery voltage is lower or higher than the threshold voltage.
Turns on the BLD.
Turns off the BLD.
3.17.3. List of Constants
The following table lists the constants used in the BLD module.
Table 3-60 BLD Module Constants
Constant name
Value
BLD_CHECK_STOP
0
BLD_CHECK_FIRST
1
BLD_CHECK_TBL_MAX
7
BLD_R_HIGH
0
BLD_R_LOW
1
Description
Indicates the state where the battery level detection by the BLD is
stopped.
Indicates the state where the battery level detection has been
started.
Indicates the state where battery level detection has been
completed.
Indicates that the battery voltage is higher than the threshold
voltage.
Indicates that the battery voltage is lower than the threshold
voltage.
3.17.4. List of Variables
The following table lists the variables used in the BLD module.
Table 3-61 BLD Module Variables
Variable name
Initial value
Description
Determined measurement value of battery level, which is
determined by the BLD module
vol_level
0
vol_judge_level
0
Measurement value during execution of the BLD module
bld_check_counter
0
Indicates the status of the BLD module while it is being processed.
185
ML610Q400 Series
Sample Program API Manual
3.17.5. Details of APIs
This section describes details of the BLD module APIs.
3.17.5.1. bld_start_levelCheck Function
This function starts battery level detection.
Function
name:
Arguments:
Return
values:
Processing:
void
bld_start_levelCheck( void )
None
None
Battery level check start processing
bld_start_levelCheck function
Is battery level check in operation?
“bld_check_counter !=0?”
Yes
Start battery level check
“bld_chek_counter=
BLD_CHECK_FIRST”
Stop the BLD
bld_off function
Initialize the measurement value
to 0x0F
Set vol_judge_evel to “0x0F”
Turn on the BLD
bld_on function (argument “vol_judge_level”)
RT
186
No
ML610Q400 Series
Sample Program API Manual
3.17.5.2. bld_getLevel Function
This function acquires the battery level. Call this function at 1-ms intervals until the return value becomes “0” (be sure to
call the bld_check_start function before using this function).
Function
name:
Arguments:
Return
values:
Processing:
unsigned char bld_getLevel( void )
None
unsigned char
Acquisition of the current battery level
bld_get_level function
Battery level check terminated?
"bld_chek_counter=0?"
Yes
No
get_bld_result = bld_chekckl()
Processing to determine whether the
battery voltage is lower or higher than
the threshold voltage
RT (bld_check_counter)
Set the next state
Will battery level check processing be
continued?
No
Is the voltage less than 1.35V or greater than
2.9V?
"bld_check_counter<=2?"
Yes
Update the measurement value for the
next measurement
"vol_judge_level += bld_judge"
Yes
Determine the battery level measurement value
vol_judge_level = bld_tbl[(bld_check_counter-1)][2]
Update the counter value for the next
measurement
bld_chek_counter++
Battery level check terminated?
"bld_check_counter>=BLD_CHECK_TBL_MAX?"
Terminate battery level acquisition processing
"bld_chek_counter=BLD_CHECK_TBL_MAX"
No
Yes
Determine the battery level
measurement value
vol_level = vol_judge_level_
Terminate battery level check
"bld_chek_counter=BLD_CHECK_STOP"
RT (bld_check_counter)
187
Turn on the BLD
bld_on function (argument “vol_level”)
No
ML610Q400 Series
Sample Program API Manual
3.17.5.3. bld_check Function
This function checks whether the battery voltage is lower or higher than the threshold voltage.
Function
name:
Arguments:
Return
values:
unsigned char bld_check (void)
None
unsigned char Judgment result as to whether the battery voltage is lower or higher than the threshold
voltage
Higher than the threshold voltage: BLD_R_HIGH
Lower than the threshold voltage: BLD_R_LOW
Processing:
Processing to determine whether the battery
voltage is lower or higher than the threshold voltage
bld_check function
Is the measured value of battery level higher
than the threshold voltage?
[BLDF]="0"?
No
Yes
ret=BLD_R_HIGH
Turn off the BLD
"bld_off"
RT (ret)
3.17.5.4. bld_on Function
This function turns on the BLD.
Function
name:
Arguments:
Return
values:
Processing:
Void bld_on ( unsigned char bld_Idx )
unsigned char bld_Idx
0 to 15: “vol_level”
None
188
ret=BLD_R_LOW
ML610Q400 Series
Sample Program API Manual
3.17.5.5. bld_off Function
This function turns off the BLD.
Function
name:
Arguments:
Return
values:
Processing:
void bld_off (void)
None
None
189
ML610Q400 Series
Sample Program API Manual
4. Revision History
Page
Revision
Date
Previous
Edition
Current
Edition
1
June. 26, 2009
–
–
First edition
–
37
uart_PortClear and uart_PortSet function are added.
42
43
Setting value in UART0 baud rate register is
corrected.
52
53
Port setting of P41 and P40 is corrected to Nch
open-drain output.
109
110
Interrupts are disabled in key_getEvent function.
40
40
Section title for adjustBaudrate_startCount function is
added.
2
3
January. 27, 2010
April. 16, 2010
190
Description