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.

Compiler/MSP430G2553: msp430g2553

Part Number: MSP430G2553

Tool/software: TI C/C++ Compiler

I got 3 switches. they are x, y, z.  x means 0 and y means 1 and z is to activate led if the password correct .  password already created in the code . for example 1100 . I push switches and  if I type correct switches and  led is on . I am doing something wrong . I can't figure out where I am doing wrong . can you please help me . 

#include <msp430g2553.h>

int PASSWORD = 0xC;

int pass = 0;

int state = 0;

enum states {

    idle = 0,

    first_char,

    wait_second,

    second_char,

    wait_third,

    third_char,

    wait_forth,

    forth_char,

    check

};

/**

 * blink.c

 */

void main(void)

{

WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

P1DIR |= BIT0; // Output LED showing if password is correct

P1DIR &= ~BIT1;                 // input x

P1DIR &= ~BIT2;                 // input y

P1DIR &= ~BIT3;                 // input z

P1DIR |= BIT5;                  // Output LED showing if password is wrong

P2DIR = 0xFF;

volatile unsigned int i; // volatile to prevent optimization

while(1)

{

switch(state)

{

case idle:          //This is the wait state where there has been no character of password been entered

    P1OUT &= ~BIT0;

    P1OUT &= ~BIT5;

    if(P1IN == BIT1)

    {

        pass = (pass << 1) | 0;

        state = first_char;

    }

    else if(P1IN == BIT2)

    {

        pass = (pass << 1) | 1;

        state = first_char;

    }

    else if(P1IN == BIT3)

    {

        state = check;

    }

break;

         case first_char:

             P1OUT &= ~BIT0;

             if(P1IN == 0 )

             {

                 state = wait_second;

             }

             else

             {

                 state = first_char;

             }

         break;

         case wait_second:

             P1OUT &= ~BIT0;

             if(P1IN == BIT1)

             {

                 pass = (pass << 1) | 0;

                 state = second_char;

             }

             else if(P1IN == BIT2)

             {

                 pass = (pass << 1) | 1;

                 state = second_char;

             }

             else if(P1IN == BIT3)

             {

                 state = check;

             }

          break;

         case second_char:

             P1OUT &= ~BIT0;

             if(P1IN == 0 )

             {

                 state = wait_third;

             }

             else

             {

                 state = second_char;

             }

         break;

         case wait_third:

             P1OUT &= ~BIT0;

             if(P1IN == BIT1)

             {

                 pass = (pass << 1) | 0;

                 state = third_char;

             }

             else if(P1IN == BIT2)

             {

                 pass = (pass << 1) | 1;

                 state = third_char;

             }

             else if(P1IN == BIT3)

             {

                 state = check;

             }

          break;

         case third_char:

             P1OUT &= ~BIT0;

             if(P1IN == 0 )

             {

                 state = wait_forth;

             }

             else

             {

                 state = third_char;

             }

         break;

         case wait_forth:

             P1OUT &= ~BIT0;

             if(P1IN == BIT1)

             {

                 pass = (pass << 1) | 0;

                 state = forth_char;

             }

             else if(P1IN == BIT2)

             {

                 pass = (pass << 1) | 1;

                 state = forth_char;

             }

             else if(P1IN == BIT3)

             {

                 state = check;

             }

          break;

         case forth_char:          //This is the wait state where there has been no character of password been entered

            P1OUT &= ~BIT0;

            if(P1IN == BIT3)

            {

                state = check;

            }

            else

                state = forth_char;

         break;

         case check:          //This is the wait state where there has been no character of password been entered

            if(pass == PASSWORD)

            {

               P1OUT |= BIT0;

               if(P1IN == BIT0)

                   state = idle;

            }

            else

            {

               P1OUT |= BIT5;

               if(P1IN == BIT5)

                   state = idle;

            }

         break;

}

P2OUT = state;

}

}

**Attention** This is a public forum