MSP430 LaunchPad: Anti-Mosquito Device

Mosquitoes are the plague of the summer time. Luckily ultrasounds can help against them. Why don’t developing an ultrasounds generator with the LaunchPad ? A quite easy task…

My code produces a 10kHz squared wave to the pin of the green led. A little 386-based audio amplifier is wired as well, to transform the signal in an audible sound.

Actually, 10kHz is still audible by humans: it’s just for testing the audio system. If you can hear the high pitched sound everything is OK; now you can switch to 14 or 15 kHz by pressing the S2 button (each press increments the frequency by 1000). These high frequencies are still audible by mosquitoes and they’ll keep them away.

# This software is released under GPLv3 license:

#include <io.h>
#include <signal.h>

// Hertz
#define CLOCK         16000000
#define FREQ        10000
#define DELTA_F    1000

#define     LED0                  BIT0
#define     LED1                  BIT6
#define     LED_DIR               P1DIR
#define     LED_OUT               P1OUT

#define     BUTTON                BIT3
#define     BUTTON_OUT            P1OUT
#define     BUTTON_DIR            P1DIR
#define     BUTTON_IN             P1IN
#define     BUTTON_IE             P1IE
#define     BUTTON_IES            P1IES
#define     BUTTON_IFG            P1IFG
#define     BUTTON_REN            P1REN

static void __inline__ delay(register unsigned int n);

int i;

int main(void)
// Watch Dog settings
WDTCTL = WDTPW|WDTHOLD;        // Stop watchdog timer

// Clock settings
BCSCTL1 = CALBC1_16MHZ;        // clock 1MHz

// Leds settings

// TimerA settings
TACCR0 = CLOCK/(2*FREQ);            // Timer end value
TACTL = TASSEL_2 + MC_1 + ID_0;    // SMCLK/1, up mode
TACCTL0 = CCIE;                        // Timer Interrupt Enable

// Button settings
i = 0;
BUTTON_DIR &= ~BUTTON;    // input
BUTTON_OUT |= BUTTON;    // high (for pull resistor)
BUTTON_REN |= BUTTON;    // pull up
BUTTON_IES |= BUTTON;    // high to low interrupt
BUTTON_IFG &= ~BUTTON;    // clear interrupt
BUTTON_IE |= BUTTON;        // interrupt enable

// Interrupts settings
__bis_SR_register(GIE);                // General Interrupts Enable

while(1) ;

return 0;

interrupt(TIMERA0_VECTOR) timer_int(void)

interrupt(PORT1_VECTOR) button_int(void)
BUTTON_IFG = 0;              // clear Interrupt Flag Register
BUTTON_IE &= ~BUTTON;    // disable Button Int (debounce)


BUTTON_IE |= BUTTON;        // enable Button Int


// Delay Routine from mspgcc help file
static void __inline__ delay(register unsigned int n)
__asm__ __volatile__ (
“1: \n”
” dec %[n] \n”
” jne 1b \n”
: [n] “+r”(n));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s