Basic Level     Skills: Not specified    
Author email
[email protected]
Author website



There are seven pitch classes which are represented by first seven letters of Latin alphabets (A, B, C, D, E, F and G). A musical note is represented by Pitch class and octave level, So according to pitch classes there are basic 7 notes and 8th note is represented with as same pitch class as first but double the frequency. The octave is used to differentiate between two notes and is a representation of frequency ratio of two.

Musical notes start from C0, c0#, D0, D0#,.... the lowest note frequency i.e. for C0 is 16.35Hz (based on center frequency A4, 440Hz). Another major component of musical note is duration. There are total 10 durations which are Quarter, Whole, Half, Eighth, Sixteenth, Thirty Two, Sixtyfour, six, twelve and twenty four. These durations vary depending on tempo (beats per minute) of the music/tone.

In music library we focused on notes from C5 to B6 as they coveres almost all variations for simple tone generation and octave level is produce good sound level on hardware (lower frequency means lower sound, higher the frequency higher the sound).


Generating a particular frequency is nothing but a square wave with desired time period. We can use one of the 8051's timer to generate a particular frequency. Lets say if you want to generate C5 note which has a frequency of 523.25Hz, the time period for C5 will be 1911.132µS. The output square wave with 50% duty cycle will have high and low time of 955.566µS (= 1911.132/2).

Lets say your controller running at 12Mhz oscillator will have one Machine cycle of 1µs. To generate 955.566µs we need 956 (~=955.566/1) machine cycles. We can load timer with a value of 64580 (65536-956) and toggle any I/O pin at that interval will give us the reqired frequency. Now this I/o pin can be connected to a speaker to produce sound for that note.

In the library provided we are using Timer2 in auto reload mode for square wave generation. You can use any timer i.e. timer0 or timer1 in 16bit mode for frequency generation. For your convenience I have provided an excel sheet that will generate timer values for a given crystal oscillator frequency.

You can also download the sample tone recorded and tested using this library:

The sample program and hex file produces following tones:
1. Adam's Family
2. Looney Toons
3. Flintstones
4. Pink Panther
5. Beethoven Play
6. SaReGaMa (Basic Indian sound 7 tones in forward and reverse order).

If you have any doubt regarding this library please make use of forum

Tags play music 8051tone generation 8051pwm sound 8051musical notes 8051play musical notes 8051

32.28 kB





03 Apr 2019: 16:36 PM
Can i see the circuit diagram please?
(Required; Min length 5)
(Required; will not be displayed)


Sat May 15 2021, 11:47 AM
Derek Wolcott
Geometric Energy Corporation announced the dogecoin-funded mission on Sunday, with DOGE-1 representing a 40 kilogram cube satellite flying as a payload on a Falcon 9 rocket.
Thu May 13 2021, 07:18 PM
Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly. Trisha Trisha
Wed May 12 2021, 01:23 PM
Jed Roan
Now you can promote your site all over the internet for FREE:
Wed May 12 2021, 08:20 AM
If some one wants to be updated with most recent technologies afterward he must be visit this web page and be up to date every day. annual credit report
Wed May 12 2021, 06:11 AM
Great website. A lot of useful information here. I'm sending it to some pals ans also sharing in delicious. And of course, thanks on your effort! annual credit report



Thu Jun 25 2020, 03:46 PM
Mon Jun 22 2020, 03:03 PM
Tue Jun 16 2020, 05:10 PM
Sat Jun 13 2020, 09:43 PM
Thu May 21 2020, 12:44 PM
Thu May 21 2020, 01:28 AM
Wed May 20 2020, 07:05 PM
Wed May 20 2020, 11:52 AM


Guests: 110, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123