Created
July 6, 2011 21:13
-
-
Save biomood/1068336 to your computer and use it in GitHub Desktop.
MSP430 - use an interrupt to set the LEDs on and off using the button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.c | |
// | |
// Use an interrupt to set two LEDs on the MSP430 on and off | |
// Created by David Roberts on 06/07/2011. | |
// | |
#include <io.h> | |
#include <signal.h> | |
#define BUTTON BIT3 | |
#define LED1 BIT0 | |
#define LED2 BIT6 | |
int main (void) | |
{ | |
// disable the watchdog timer | |
WDTCTL = WDTPW + WDTHOLD; | |
// interrupt from high to low | |
P1IES |= BUTTON; | |
// clear the interrupt flag | |
P1IFG &= ~BUTTON; | |
// enable interrupt on BIT3 | |
P1IE |= BUTTON; | |
P1OUT = 0; | |
P1OUT |= LED2; | |
// set bit0, bit6 as output | |
P1DIR |= LED1; | |
P1DIR |= LED2; | |
// enable interrupts | |
_BIS_SR(GIE); | |
while(1); | |
return 0; | |
} | |
// interrupt for PORT1 | |
interrupt(PORT1_VECTOR) p1_isr(void) { | |
// check if BIT3 button has set flag | |
switch (P1IFG & BUTTON) { | |
case BUTTON: | |
P1IFG = P1IFG & ~BUTTON; | |
// flip the LED output | |
P1OUT ^= LED1; | |
P1OUT ^= LED2; | |
break; | |
default: | |
break; | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment