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.

Was this compiled correctly ?

I wanted to write a code that would wait for a button to be pressed. This is my code and the compiled result.

For some reason, my while statement has been compiled into a (MOV.B + RETA) instruction set.

I cleaned the project several times, restarted the CCS but it still remains there.

Any idea why this is happening ?

Thank you.

P.S.: This code is working perfectly on another project.

if ((P2IN & BIT1) == 0){
    red_on();
}

  • This source line ...

    while ((P2IN & BIT1) == 0x01) {} ;

    becomes this after preprocessing ...

    while (((PAIN_H) & (0x0002)) == 0x01) {} ;

    And PAIN_H has this definition ...

    extern volatile unsigned char PAIN_H;

    I can see all that by building with --gen_acp_raw and then inspecting the resulting .rl file.  The compiler can see that, no matter the value of PAIN_H, after anding with 2, it will never equal 1.  Because PAIN_H is volatile, it still issues the read instruction.  Then it returns.  

    So, that is what is happening.  I don't know enough about programming MSP430 to tell you how to fix it.

    Thanks and regards,

    -George

  • Oh God, you are right, the solution is easy though:

    while ((P2IN & BIT1) == 0x02) {} ;

    After ANDing 0x02, compare it to 0x02, not 0x01.

    Thanks, it's working now.