Skip to content

Instantly share code, notes, and snippets.

@s-estay
Last active September 7, 2016 22:39
Show Gist options
  • Save s-estay/ea79a6fee017e13ba86811920c984e39 to your computer and use it in GitHub Desktop.
Save s-estay/ea79a6fee017e13ba86811920c984e39 to your computer and use it in GitHub Desktop.
msp430: turning on LED1 when S2 is pressed
// 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