Other Parts Discussed in Thread: MSP430G2553
Some of my students are trying to teach themselves the MSP340G2553 in a LaunchPad. On the LaunchPad they want to program the push button at P1.3. They want to program the input pushbutton to have a pull up resistor so they can read the state of the switch as either pressed or not ie 1/0. Below is their code:
#include <msp430g2553.h>
unsigned int i = 0;
unsigned int z = 1;
#define BTN BIT3
#define red_LED BIT0
#define grn_LED BIT6
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x41;
P1REN |= BIT3;
P1OUT = BIT3;
for (;;)
{
while ((P1IN & BTN) != BTN)
{
if(P1OUT & red_LED == red_LED)
{
P1OUT ^= red_LED;
}
P1OUT ^= grn_LED;
for (i = 0; i < 7000; i++);
}
P1OUT = 0x48;
while ((P1IN & BTN) == BTN)
{
P1OUT ^= red_LED;
P1OUT ^= grn_LED;
for (i = 0; i < 15000; i++);
}
}
}
They are claiming the only way to continue to use P1.3 as an input with the internal pull up resistor was to continually output P1OUT.BIT3 as 1 whenever they used P1OUT. That seems redundant. I researched the specsheets and user's manual and did not find a clear example on the use of P1REN. Does the PullUp/PullDown have to be set each time P1OUT is used?