This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hi I am new to the embedded land and am trying to create a simple code to switch on and off the on board LED on my launchpad. I want to have the default state LED ON and LED OFF if the button is pushed. If I create a pull-up manually to the switch my code works, otherwise it does not. I think I am doing something incorrectly with the pull-up (P1REN) register.
What am I doing wrong?
Code:
#include <msp430.h>
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5_L; //Disable Low Power Mode
PASEL0 = 0;
PAOUT = 0;
PADIR = 0xFFFF;
P1REN = 0b00000010;
P1DIR &= ~(BIT1);
while (1){
if ((P1IN & 0x02) == 0x00)
{
P1OUT = 0b00000000; //P1OUT = Pull Up Resistor Configurations (P1 OUT = 0 OUTPUT IS PULLED DOWN, P1OUT = 1 OUTPUT IS PULLED UP)
}
else
{
P1OUT = 0b00000001; //P1OUT = Pull Up Resistor Configurations (P1 OUT = 0 OUTPUT IS PULLED DOWN, P1OUT = 1 OUTPUT IS PULLED UP)
}
}
}
hint: for an INPUT bit... a set bit in P1REN can result in a internal pull up OR A PULLDOWN.
see SLAU367 section 12.4.8
**Attention** This is a public forum