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.

CCS/MSP430G2533: Project

Part Number: MSP430G2533

Tool/software: Code Composer Studio

I have a project , where assign one internal button to turn on both leds , other two external buttons to trun on red led and the other one tho trun on green led I make a code in C , but I dosent work I dont know what I miss to make my code funtional can this community help me ??

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x41; 
P1OUT |= BIT3;
P1OUT |= BIT4;
P1OUT |= BIT5;
P1REN |= BIT3;
P1REN |= BIT4;
P1REN |= BIT5;
P1OUT &= ~BIT6;
P1OUT &= ~BIT0;
while (1) // Infinite Loop
{
while (P1IN & BIT3){
__delay_cycles(50000);
}
if ((BIT3 & P1IN)){ 
P1OUT &= ~BIT6; 
P1OUT &= ~BIT0;
}

if ((BIT4 & P1IN))
{
P1OUT&= ~BIT0;
}

if ((BIT5 & P1IN))
{
P1OUT &= ~BIT6;
}
else
{
P1OUT &= ~BIT6;
P1OUT &= ~BIT0;}

}}

  • Hey Bertha,

    What GPIO are your LEDs connected to?  Are these working correctly?  

    What IOs are you buttons connected to?  Are these IOs working as expected?  

    I would suggest just blinking the LED's first to make sure you have the GPIO setup and working as you expect.  Then I would implement a single button polling and test it with your working LEDs.  

    We have some example code available, but it may be using different pins than in your application.  Blinking example  

    Thanks,

    JD

  • > if ((BIT4 & P1IN))
    >{
    > P1OUT&= ~BIT0;
    >}

    1) You've configured (P1OUT/P1REN) your buttons to be active low (that's the usual way), so a button push makes the pin go low (=0).
    2) To turn the LED on, you need to set the pin high.
    Try:

    > if ((BIT4 & P1IN) == 0) // Button on P1.4 pushed?
    > {
    > P1OUT |= BIT0; // Turn on P1.0 LED
    > }

**Attention** This is a public forum