Last active
September 7, 2016 22:39
-
-
Save s-estay/ea79a6fee017e13ba86811920c984e39 to your computer and use it in GitHub Desktop.
msp430: turning on LED1 when S2 is pressed
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
// Source: Programmable Microcontrollers with Applications, p.115 | |
// Turning on the red LED when the push button is pressed | |
// MSP430 LaunchPad Rev.1.5 | |
#include <msp430g2553.h> | |
#define LED BIT0 // P1.0 | |
#define BUTTON BIT3 // P1.3 | |
void main(void){ | |
WDTCTL = WDTPW|WDTHOLD; // stop WDT | |
P1DIR = LED; // P1.0 set as output | |
P1REN = BUTTON; // internal resistor connected to S2 enabled, p.112 | |
P1OUT = BUTTON; // internal resistor set as pull-up | |
/* check input from the push button */ | |
while(1){ | |
if((P1IN & BUTTON) == 0x00) // active low input, p.113 | |
P1OUT |= LED; // turn on LED | |
else | |
P1OUT &= ~LED; // turn off LED | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment