The Annoy (A Tiny Intelligent Buzzer)

Program Download:

Project Archive/Main File
Main.c
The_Annoy_PCB.zip

The Software
           Now let's take a look at the software used to generate the pauses and the tones. There's two main parts to the C code for this project.
    -The Main Loop
    -The Tone Generation Functions

           The main loop of this program does little more than act as a gigantic forever while loop generating the tones every 6 minutes using pause functions and tone generation functions.

The Main Loop

------------« Begin Code »------------
/***** MAIN PROGRAM *****/
void main()
{
    //*** Initialization
    // configure port
    TRIS = 0b110000;                // Everything Output (We Only Care About GP1)
    
	//Loop Forever!
    for(;;){
   
    //Low Pitch Noise
    sound_1();
    sound_1();
	..
	..
    sound_1();
    sound_1();
    
    //6 Minute Delay
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();

    //Medium-High Pitch Noise
    sound_4();
    sound_4();
	..
	..
    sound_4();
    sound_4();

    //6 Minute Delay
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();

    //Medium-Low Pitch Noise
    sound_2();
    sound_2();
	..
	..
    sound_2();
    sound_2();

    //6 Minute Delay
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();

    //High Pitch Noise
    sound_5();
    sound_5();
	..
	..
    sound_5();
    sound_5();

    //6 Minute Delay
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();

    //Medium Pitch Noise
    sound_3();
    sound_3();
	..
	..
    sound_3();
    sound_3();

    //6 Minute Delay
    delay();
    delay();
    delay();
    delay();
    delay();
    delay();

    }
}
------------« End Code »------------

           There are 6 unique functions that are used to generate different tones. They're actually all stupidly simple. They flip the I/O bit connected to the speaker on and off with specific timing to generate a low or high frequency.

The Tone Generation Functions

------------« Begin Code »------------
void sound_1(){
    GPIO = 0x00;
    __delay_ms(15);
    GPIO = 0x02;
    __delay_ms(15);
}

void sound_2(){
    GPIO = 0x00;
    __delay_ms(10);
    GPIO = 0x02;
    __delay_ms(10);
}

void sound_3(){
    GPIO = 0x00;
    __delay_ms(3);
    GPIO = 0x02;
    __delay_ms(3);
}

void sound_4(){
    GPIO = 0x00;
    __delay_ms(2);
    GPIO = 0x02;
    __delay_ms(2);
}

void sound_5(){
    GPIO = 0x00;
    __delay_ms(1);
    GPIO = 0x02;
    __delay_ms(1);
}
------------« End Code »------------

           Take a look at the project files above and the main C file to see all the code for this project. Compile it and load the .hex onto your PIC and you're all set to go.