PIC16F873 and a buzzer

In this example we will connect a buzzer to our pic and then play a basic tune, we will use mikroC and the Sound library that is available.

Here is the schematic

Schematic

pic16f873 and buzzer

Code

The code was written in mikroC, you can find out the frequencies of the notes used at http://en.wikipedia.org/wiki/Piano_key_frequencies

 

[codesyntax lang=”c”]

void main() 
{

TRISB = 0;
Sound_Init(&PORTB, 0); // Initialize sound o/p pin PORT B 0

do {
//Happy birthday to you
Sound_Play(262, 400);
Delay_ms(100);
Sound_Play(262, 400);
Delay_ms(100);
Sound_Play(294, 800);
Delay_ms(100);
Sound_Play(262, 800);
Delay_ms(100);
Sound_Play(349, 800);
Delay_ms(100);
Sound_Play(330, 1000);

Delay_ms(1000); // Wait for 1 sec and replay

}while(1);
}

[/codesyntax]

 

Links

 

PIC16F873A MICROCHIP DIP28

10pcs 5V Mini Magnetic Active Buzzer

Related posts

DsPIC30F4011 Development Board OLED example

DsPIC30F4011 Development Board push button example

DsPIC30F4011 Development Board flashing LED example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More