Advertisement
tobast

Untitled

Jan 6th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <msp430g2553.h>
  2.  
  3. #define LED0 0x01
  4. #define LED1 0x40
  5. #define BTN1 0x08
  6.  
  7. #define BLINK_STATE 0x01
  8.  
  9. unsigned volatile int i;
  10. unsigned int state = BLINK_STATE;
  11.  
  12. int main(void)
  13. {
  14.     WDTCTL = WDTPW + WDTHOLD;
  15.     P1DIR |= LED0 + LED1; // Set LED0 and LED1 to OUTPUT
  16.     P1DIR &= ~(BTN1); // BTN1 to INPUT state
  17.  
  18.     // Switch LED0 on, LED1 off
  19.     P1OUT |= LED0;
  20.     P1OUT &= ~(LED1);
  21.     P1REN |= BTN1;
  22.  
  23.     while(1) {
  24.         if(!(P1IN & BTN1)) // Button is pressed
  25.             state ^= BLINK_STATE;
  26.  
  27.         if(state & BLINK_STATE)
  28.             P1OUT ^= LED0 | LED1;
  29.         for(i=0; i<50000; i++);
  30.     }
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement