How to make calling bell use PIC Microcontroller with code
Welcome to MINA TECHNOLOGY.
In this tutorial we will learn how to make a calling bell use PIC Microcontroller. Here I am use PIC16F877A Microcontroller and MikroC Pro for PIC compiler for code editing. The mikroC PRO for PIC provides a Sound Library to supply users with routines necessary for sound signalization in their applications. Sound generation needs additional hardware, such as piezo-speaker.
You can watch the following video or read the written tutorial below.
Circuit Diagram:
Code Explain:
First time we define switch connection at RD4 pin. Next we write three different tone at different frequency. We generate melody sound use these three tons. In void main function RB0 pin is outpur by clearing TRISB register. Then we initialize Sound_Init function. Next we generate biff sound in 880Hz which duration 500ms. Then we create a while loop. In while loop function we create a "if" condition. While RB4 pin is high the piezo crystal generate melody sound.
Mikro C Code:
Click the download button for source code:
In this tutorial we will learn how to make a calling bell use PIC Microcontroller. Here I am use PIC16F877A Microcontroller and MikroC Pro for PIC compiler for code editing. The mikroC PRO for PIC provides a Sound Library to supply users with routines necessary for sound signalization in their applications. Sound generation needs additional hardware, such as piezo-speaker.
You can watch the following video or read the written tutorial below.
Circuit Diagram:
Code Explain:
First time we define switch connection at RD4 pin. Next we write three different tone at different frequency. We generate melody sound use these three tons. In void main function RB0 pin is outpur by clearing TRISB register. Then we initialize Sound_Init function. Next we generate biff sound in 880Hz which duration 500ms. Then we create a while loop. In while loop function we create a "if" condition. While RB4 pin is high the piezo crystal generate melody sound.
Mikro C Code:
# define SW PORTD.RD4 // Push button switch is connected RD4 pin
void tone1(){
Sound_Play(657,250); // Frequency: 657Hz and Duration: 250ms
}
void tone2(){
Sound_Play(698,250); // Frequency: 698 and Duration: 250ms
}
void tone3(){
Sound_Play(784,250); // Frequency: 784 and Duration: 250ms
}
void melody(){ // Plays the melody "Yellow house"
tone1();tone2();tone3();tone3();
tone1();tone2();tone3();tone3();
tone1();tone2();tone3();
tone1();tone2();tone3();tone3();
tone1();tone2();tone3();
tone3();tone3();tone2();tone2();tone1();
}
void main() {
TRISB0_bit = 0; // RB0 pin is Output
PORTB.F0 = 0; // RB0 pin is Clear
Sound_Init(&PORTB,0); // Initialize the pin RB0 for playing sound
Sound_Play(880,500); // Frequency: 880Hz Duration: 500 ms
while(1){
if(SW==1){
melody(); // Play the melody
}
//Delay_ms(1000); // 10 second delay
}
}
Click the download button for source code:
download |
Hello Guy's this information was very usefully.
ReplyDeleteOur Services - ip camera
home security
security systems
security cameras
video doorbell