English
Language : 

R8C-MS Datasheet, PDF (1/22 Pages) Renesas Technology Corp – Sample Program: Musical Scales
R8C/Tiny Series
Sample Program: Musical Scales
APPLICATION NOTE
1. Abstract
The musical-scale sample program uses the following functions:
• Timer X (timer mode)
• Timer Z (programmable waveform generation mode)
• A-D converter (repeat mode)
2. Introduction
The example described in this application note is intended for use in the R8C/17 group of
microcomputers.
This program can also be used when operating other microcomputers within the R8C/Tiny, provided
they have the same SFR (Special Function Registers) as the R8C/17 microcomputers. However, since
it is possible that some functions of the R8C/Tiny series will have been altered for functional
enhancements, etc., please be sure to obtain the SFR header file from the Renesas Web site shown
below.
http://www.renesas.com/en/r8ctiny
Operation (1) The musical-scale sample program has the following two separate modes:
• Standby mode
• Musical scale output mode
After reset
SW4(INT0)
Key pressed
Standby mode
Musical scale output mode
(2) After reset, the microcomputer goes to standby mode.
(3) If SW4 (INT0) is pressed during standby mode, the microcomputer goes to musical scale
output mode.
(4) If SW4 (INT0) is pressed during musical scale output mode, the microcomputer goes to
standby mode.
(5) In musical scale output mode, the microcomputer outputs the tones of a diatonic scale
repeatedly from the buzzer in order of lower-key do → re → mi → fa → sol → la → si →
higher-key do → no sound (500 ms) → higher-key do → si → la → sol → fa → mi → re →
lower-key do → no sound (500 ms) → lower-key do → re → mi and so on.
(6) Tones of a diatonic scale are changed every second. The frequencies (Hz) of tones are
listed in Table 1.
Table 1:
Scale
Lower-key
do (C) re (D)
mi (E) fa (F)
sol (G) la (A)
si (B)
Higher-key
do (C)
Frequency (Hz) 523.25 587.32 659.25 698.45 783.98 880.00 987.76 1046.50
(7) The buzzer output duty cycle is determined based on the A-D value that is obtained as
valid data as described below in (9). The output sound volume changes as does the duty
cycle. The duty cycles are listed in Table 2.
Table 2:
Valid A-D value 00-1F 20-3F 40-5F 60-7F 80-9F A0-BF C0-DF E0-FF
Duty cycle (%) 25.00 33.75 42.50 50.00
56.25 62.50 68.75
75.00
(8) The analog input is converted to digital quantity by using a control (VR1). The A-D
input is taken into the device in repeat mode, with the P10/AN8 pin used for it.
(9) For the A-D input, the A-D converted value on P10/AN8 is sampled four times at 10 ms
intervals, the average value of which is obtained as valid data. The calculation method
is shown below.
REJ05B0273-0200Z/Rev.2.00
July 2004
Page 1 of 22