➦ Programming the 54¢ Micro
Birthday song composition. Figure 5
is the corresponding circuit to build
it. To add to the birthday atmosphere,
two LEDs are turned ON/OFF alternately in program.
Just as for any song composition, we need to write the music
note subroutines for each note that
will be used in the song. The basic
idea on note creation is the same as
described for 440 Hz music tone:
find the note’s frequency, then
calculate its half period T/2; then
drive the speaker high or low in the
For example, in the 784 Hz “G5”
tone subroutine, T/2 = 638 μS, so the
speaker needs to be driven high for
638 μS, then low for 638 μS, and so
To count this time, we utilize
the ATtiny11’s timer interrupt. This
eight-bit timer is an up counter; it
increases its count every clock cycle
NEW! HIDmaker FS for Full Speed FLASH PIC18F4550
Creates complete PC and Peripheral Both PC and Peripheral programs
programs that talk to each other over understand your data items (even odd
USB. Ready to compile and run! sized ones), and give you convenient
• Large data Reports variables to handle them.
64,000 bytes/sec per Interface PIC18F Compilers: PICBASIC Pro,
• Easily creates devices with multiple MPASM, C18, Hi-Tech C.
Interfaces, even multiple Identities!
• Automatically does MULTITASKING PIC16C Compilers: PICBASIC Pro,
• Makes standard or special USB HID MPASM, Hi-Tech C, CCS C.
NEW! “Developers Guide for USB HID PC Compilers: Delphi, C++ Builder,
Peripherals” shows you how to make Visual Basic 6.
devices for special requirements. HIDmaker FS Combo: Only $599.95
DOWNLOAD the HIDmaker FS Test Drive today!
(that is one microsecond); when
reaching a count of 256, it overflows
to zero and generates an interrupt,
and then increases one count per
μS again. Each overflow interrupt
causes the MCU to execute its
associate interrupt service routine,
in this case (see Listing 3), it is TIM-OVF.
Instead of letting the timer
count from zero, we set it to start at
240, so the timer will overflow each
16 μS. Therefore, for T/2=638 μS, the
needed number of overflows is
Each music note takes some time
to play. So the above half period
high/low must be repeated a number
of times. We chose a value of 150,
which sounds good. Of course, you
can change it if you find it too short or
After writing all note subroutines,
the last step is to call these notes to
form a song, as shown in the main
program of Listing 3. Of course, you
need to listen to it, then change it
as necessary, and do this for several
iterations until you get the music how
you want it.
In this article, I presented three
example programs for the ATtiny11
application. But the list can be endless and is only limited by your imagination.
Perhaps the widest use for the
ATtiny11 will be in single-chip music
composing. And since its price is so
low, you won’t have to care about how
many chips you’ll need.
You may even want to build a
“chip music library!” NV
ABOUT THE AUTHOR
G.Y. Xu is an Electrical
Designer specializing in
microprocessor/microcon-troller systems design and
development, both in hardware and software. He can be
reached by email at