Feb 6, 2012
Example with interrupt
Continuous blinking example with msp430.
Button is implemented with interrupts (this is “event” in java world).
#include "bsp.h" #include "mrfi.h" #include "bsp_leds.h" #include "nwk_types.h" #include "nwk.h" #include "nwk_api.h" #define SPIN_ABOUT_A_SECOND NWK_DELAY(1000) void configureClocks(); int main(void){ WDTCTL = WDTPW + WDTHOLD; //stop watchdog timer configureClocks(); // Configure Switch on P1.2 P1REN = BIT2; // P1.2 Enable pullup / pulldown P1OUT = BIT2; // P1.2 pullup P1IE |= BIT2; // P1.2 interrupt enabled P1IES |= BIT2; // P1.2 hi/lo falling edge P1IFG &= ~BIT2; // P1.2 IFG cleared just in case _EINT(); BSP_Init(); while(1){ BSP_TOGGLE_LED1(); SPIN_ABOUT_A_SECOND; } } void configureClocks(){ // Set system DCO to 8MHz BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; // Set LFXT1 to the VLO @ 12kHz BCSCTL3 |= LFXT1S_2; } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { BSP_TOGGLE_LED2(); P1IFG &= ~BIT2; // P1.2 IFG cleared }