Home Code PIC16F873 and a buzzer

PIC16F873 and a buzzer

by shedboy71

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

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

Share

You may also like

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