Application Notes
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
1.
Summary
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
P105
P106
P107
10MHz
Xin
P91
P90
P63
P62
P61
P60
LCD E
LCD RS
LCD D7
LCD D6
LCD D5
LCD D4
c a
l
c
0
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
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
c a
l
c
0
(2) The “1” key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
Shows the numeral “1”
c a
l
c
1
(3) The “” key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
c a
l
c
1
(4) The “2” key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
Shows the numeral “2”
c a
l
c
2
REJ05B0812-0120 Rev.1.20
2007.11
Page 4 of 18
M16C/26A Group
Sample Program (Electronic Desktop Calculator)
(5) The “0” key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
Shows the numeral “20”
c a
l
c
2 0
(6) The “=“ key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
Shows the calculation result
c a
l
c
2 1
(7) The “AC” key is entered.
7
4
1
0
8
5
2
AC
9
6
3
=
÷
×
-
+
Clears the display
c a
l
c
0
REJ05B0812-0120 Rev.1.20
2007.11
Page 5 of 18