Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 29 lines (26 sloc) 1.051 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// butled2.c - press button to light LED
// Two loops , one for each state of the button
// Launchpad v1.3 board, LED1 active high on P1.0,
// button B1 active high on P1.3
// J H Davies, 2006-06-01;
// Launchpad port: S Reig, 2011-04-23; Code Composer Studio v4.2.3
// ----------------------------------------------------------------------

#include <msp430g2231.h> // Specific device
// Pins for LED and button on port 1
#define LED1 BIT0
#define B1 BIT3

void main (void)
{
  WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
  P1DIR |= LED1; // Set pin with LED1 to output
  
  for (;;) { // Loop forever
    while ((P1IN & B1) == 0) { // Loop while button up
    } // doing nothing
// Actions to be taken when button is pressed
    P1OUT |= LED1; // Turn LED1 on
    while ((P1IN & B1) != 0) { // Loop while button down
    } // doing nothing
// Actions to be taken when button is released
    P1OUT &= ~LED1; // Turn LED1 off
  }
}
Something went wrong with that request. Please try again.