Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} |