Application Notes
M16C/26A Group
Sample Program (Voltmeter)
1.
Summary
This sample program provides the functionality of a voltmeter by using the Renesas Starter Kit for M16C/26A (R0K33026AS000BE).
Turning the potentiometer changes the
voltage
2.
Introduction
Microcomputers: M16C26A
The example described in this document applies to the microcomputers listed below:
This sample program runs on the Renesas Starter Kit for M16C/26A (R0K33026AS000BE).
Prepare an extension board available for the Renesas Starter Kit or create a circuit similar to the one shown in the example circuit.
This program uses RSK_LIB. For details about RSK_LIB, see the RSK_LIB reference manual. (RSK_LIB is the library software provided
for use with the Renesas Starter Kit for M16C/26A.)
REJ05B0815-0110 Rev.1.10
2007.12
Page 1 of 15
M16C/26A Group
Sample Program (Voltmeter)
3.
Port Arrangement
LCD
VR
P93
P91
P90
P63
P62
P61
10MHz
Xin
P60
LCD E
LCD RS
LCD D7
LCD D6
LCD D5
LCD D4
v
o l m e
0
.
t
e r
0 0 0 V
M30260F8AGP
4.
Operational Outline
A voltmeter is displayed on liquid crystal display.
Turning the variable resistor (R9) mounted on the board clockwise lowers the voltage, and turning it counterclockwise raises the voltage.
Liquid crystal display
Volmeter
0.000V
Liquid crystal display
Volmeter
3.000V
Liquid crystal display
Volmeter
0.000V
M16C26A
M16C26A
M16C26A
R9
SW3
SW2
SW1/
BOOT
R9
SW3
SW2
SW1/
BOOT
R9
SW3
SW2
SW1/
BOOT
Turning R9
counterclockwise
raises the voltage
displayed on LCD.
Turning R9
clockwise
lowers the voltage
displayed on LCD.
The operation described above is accomplished using the following microcomputer facilities:
• Timer A0 (timer mode, main 2 ms cycle)
This timer counts 2 milliseconds using the main clock of the microcomputer as the count source.
It is used as the basic timer of RSK_LIB.
Time management, LCD display management and AD input are performed using this timer.
• AD24 (single-shot mode, voltage measurement)
Analog voltages are converted to digital data using the main clock of the microcomputer as a conversion clock.
More specifically, the analog voltages output from the variable resistor (R9) are A/D converted.
REJ05B0815-0110 Rev.1.10
2007.12
Page 2 of 15
M16C/26A Group
Sample Program (Voltmeter)
5.
Operational Specification
(1) Immediately after the reset switch is depressed, the LCD shows “0.000V” until an AD value is fixed.
(2) Then the LCD shows the input voltage from the variable resistor (R9).
* The AD values are set by calling the common function “AD average” (RL_AdVeraging). Within the function, a value is sampled 6
times, and the sampled values except the maximum and minimum values are averaged, the result of which is returned. This average
value is acquired 8 times, the average of which is made a fixed value.
(1) Reset start
v
o l m e
0
.
t
e r
0 0 0 V
v
o l m e
2
.
t
e r
(2) VR (variable resistor)
5 0 0 V
v
o l m e
5
.
t
e r
0 0 0 V
REJ05B0815-0110 Rev.1.10
2007.12
Page 3 of 15
M16C/26A Group
Sample Program (Voltmeter)
6.
Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by
Voltmeter
6.1 Definition of the RSK Functionality
RSKdefine.h file
In this application, the following functionalities (those shown in red) are set.
/*********************************************************
The boot information on CPU is defined
Usually, this mode is used
*********************************************************/
#define _CPU_M16C26A_NORMAL_MOD
/* Use in low power mode can be performed. */
//#define _CPU_M16C26A_32KHZ_MOD
/* Use of access of a flash can be performed. */
//#define _CPU_M16C26A_DATAFLASF_USE
/********************************************************
The hardware function which RSK supports is chosen
/********************************************************/
//#define _USE_KEY
//#define _USE_BUZZER
#define _OPTION_USE_AD
//#define _OPTION_USE_COM_RX
//#define _OPTION_USE_COM_TX
//#define _OPTION_USE_INFRAEDRX
//#define _OPTION_USE_INFRAEDTX
//#define _OPTION_USE_SW
//#define _OPTION_USE_LED
//#define _OPTION_USE_IO
Individual definition of each selected functionality
#if defined _OPTION_USE_AD
/* Define Illumimeter Adc */
//#define _OPTION_USE_AD0
/* Define Vr Adc */
#define _OPTION_USE_AD24
#endif
Potentiometer AD
REJ05B0815-0110 Rev.1.10
2007.12
Page 4 of 15
M16C/26A Group
Sample Program (Voltmeter)
6.2 APIs and Common Functions Used
ApiStatusType RL_Putc_Lcd( char Ylocation, char outc, int *ERcode );
*ERcode );
ApiStatusType RL_Putc_LcdLoc( char Xlocation, char Ylocation, char RvTime, char outc, int *ERcode );
ApiStatusType RL_Puts_LcdLoc( char Xlocation, char Ylocation, char RvTime, const char far* outc, int
*ERcode );
ApiStatusType RL_Start_Adc( int AdIdentfier, int *ERcode );
int RL_AdAveraging( int AdLogicalNo, int *AdAverage, int *ERcode );
void RL_ErrorHook( int FuncNo, int ErrorNo );
For details about the APIs and common functions used by the sample program (voltmeter), see the Renesas Starter Kit Library
V.1.00 Reference Manual.
REJ05B0815-0110 Rev.1.10
2007.12
Page 5 of 15