Renesas M16C26A-EDC Sample program (electronic desktop calculator) Datasheet

Application Notes
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
Summary
1.
This sample program provides the functionality of an electronic desktop calculator by using the Renesas Starter Kit for M16C/26A
(R0K33026AS000BE) and an extension board.
0
Input key
Calculation result display
The extension board used here is a product
from PI System Co., Ltd.
2.
Introduction
The example described in this document applies to the microcomputers listed below:
Microcomputers: M16C26A
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 circuit diagram on
page 15 and then connect it to the Starter Kit.
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.)
REJ05B0812-0120 Rev.1.20
2007.11
Page 1 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
3.
Port Arrangement
The key matrix and the buzzer are the facilities mounted on an extension board for the Renesas Starter Kit. To use these facilities,
connect an extension board to the Starter Kit.
LCD
P74
Key matrix
P75
P76
P77
P104
P91
P90
LCD E
P63
LCD RS
LCD D7
P62
LCD D6
P61
P60
LCD D5
LCD D4
c a
l
c
0
P105
P106
P107
10MHz
Xin
M30260F8AGP
REJ05B0812-0120 Rev.1.20
2007.11
Page 2 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
4.
Operational Outline
Calculation results are shown on liquid crystal display.
The display shows the result of operation when calculation results are within 7 digits (from −9999999 to 9999999) or “E” when
calculation results are equal to or more than 8 digits. For example, when you enter “1234  5678 =,” the display will show “6912.” Or
when you enter “1234567  8901234,” the display will show “E.”
When a key is depressed, the buzzer sounds.
Note: In this program, pressing two or more switches at the same time has no effect (i.e., ignored).
This function is materialized 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, key scan, and LCD display management are performed using this timer.
• Timer A1 (pulse modulation mode, buzzer output)
This timer outputs a waveform with different high and low pulse widths using the main clock of the microcomputer as the count
source.
It is used to sound a buzzer each time a key is touched.
REJ05B0812-0120 Rev.1.20
2007.11
Page 3 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
5.
Operational Specification
Example for 1  20 = 21
(1) The display shows the string “calc” and the numeral “0” immediately after the reset switch is pressed.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
c a
l
c
0
(2) The “1” key is entered.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
Shows the numeral “1”
c a
l
c
1
(3) The “” key is entered.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
c a
l
c
1
(4) The “2” key is entered.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
REJ05B0812-0120 Rev.1.20
Shows the numeral “2”
c a
l
c
2
2007.11
Page 4 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
(5) The “0” key is entered.
7
8
9
÷
4
5
6
×
Shows the numeral “20”
1
2
3
-
c a
0
AC
=
+
l
c
2 0
(6) The “=“ key is entered.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
Shows the calculation result
c a
l
c
2 1
(7) The “AC” key is entered.
7
8
9
÷
4
5
6
×
1
2
3
-
0
AC
=
+
REJ05B0812-0120 Rev.1.20
Clears the display
c a
l
c
0
2007.11
Page 5 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
6.
Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by the
Calculator
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 _USE_KEY
/* A key matrix continues pushing and existence is defined.*/
/*When not using
-USE_KEY_CONTINU is made a comment. */
//#define _USE_KEY_CONTINU
#if defined _USE_KEY_CONTINU
#else
#define _CONTINU_SW1
#define _CONTINU_SW2
#define _CONTINU_SW3
#define _CONTINU_SW4
#define _CONTINU_SW5
#define _CONTINU_SW6
#define _CONTINU_SW7
#define _CONTINU_SW8
#define _CONTINU_SW9
#define _CONTINU_SW10
#define _CONTINU_SW11
#define _CONTINU_SW12
#define _CONTINU_SW13
#define _CONTINU_SW14
#define _CONTINU_SW15
#define _CONTINU_SW16
#endif
REJ05B0812-0120 Rev.1.20
Continuous key depression is not used in
this application.
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
_KEY_CONTEINU_OFF
2007.11
Page 6 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
6.2 APIs and Common Functions Used
ApiStatusType RL_SetTimerReq( unsigned int TimerValue, char TimerMode, int *TimerNo, int *ERcode );
ApiStatusType RL_StartTimer( int TimerNo, int *ERcode );
ApiStatusType RL_CheckTimer( int TimerNo, int *ERcode );
ApiStatusType RL_Get_Key( int *Inkey, int *ERcode );
ApiStatusType RL_Start_Buzzer( char freqNo, int *ERcode );
ApiStatusType RL_Stop_Buzzer( int *ERcode );
ApiStatusType RL_Putc_Lcd( char Ylocation, char outc, int *ERcode );
ApiStatusType RL_Puts_LcdLoc( char Xlocation, char Ylocation, char RvTime, const char far* outc, int
*ERcode );
void RL_LengthCpy( char *Dest, char far *Strm, char Len );
void RL_ErrorHook( int FuncNo, int ErrorNo );
For details about the APIs and common functions used by the sample program (electronic desktop calculator), see the Renesas Starter
Kit Library V.1.00 Reference Manual.
REJ05B0812-0120 Rev.1.20
2007.11
Page 7 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
7.
Flowchart
Electronic desktop
Clear display on LCD
Show the initial screen
Request timer setup
Start timers
Input keys
Process buzzer
Process calculations
Process calculation results
REJ05B0812-0120 Rev.1.20
2007.11
Page 8 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
8.
Tutorial
1
Launch the HEW by double-clicking its icon.
2
Change the session name from “default Session” to “SessionM16C_E8_System.”
REJ05B0812-0120 Rev.1.20
2007.11
Page 9 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
3
Select “M30260F8A” for Device.
Select “Download emulator firmware” for Mode.
REJ05B0812-0120 Rev.1.20
2007.11
Page 10 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
Check the box labeled “Power supply is carried out. (MAX 300mA)” and then select “5.0V.”
REJ05B0812-0120 Rev.1.20
2007.11
Page 11 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
4
In the program and the work RAM text boxes of Firmware Location Address, enter “FA0” and “0B8” respectively.
Leave the box labeled “Debug a program using the WDT” unchecked.
REJ05B0812-0120 Rev.1.20
2007.11
Page 12 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
5
Choose Download from the Debug tab and download a module.
The upper-side choices for Download show the location from which a project was downloaded.
REJ05B0812-0120 Rev.1.20
2007.11
Page 13 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
6
Click “Start after Reset” to start program execution.
7
Please do "Cancellation" when "The file is opened" window opens.
REJ05B0812-0120 Rev.1.20
2007.11
Page 14 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
9.
Circuit Diagram
10.
Part List
Part name
Part No.
Q’ty
Manufacturer
Type number
Tact switch
SW1 -SW16
16
OMRON
B3FS-1000P
Switching diode
D2 - D5
4
ROHM
1SS355TE-17
PCB header
JA1,JA2
2
Molex
10-88-1261
REJ05B0812-0120 Rev.1.20
2007.11
Value
Remark
26-pin
Male, 2-row, vertical type
Page 15 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
11.
Web Sitet
Renesas Technology Web site
http://www.renesas.com/
REJ05B0812-0120 Rev.1.20
2007.11
Page 16 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
Revision History
Content of revision
Rev.
Date of issue
1.00
2006.06.30
1.10
2007.07.12
-
Contents of presentation improved
1.20
2007.11.29
-
RSK_LIB APIs supported
REJ05B0812-0120 Rev.1.20
Page
-
Points
First revision issued
2007.11
Page 17 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
REJ05B0812-0120 Rev.1.20
2007.11
Page 18 of 18
Similar pages