This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Comparing Register Values

Sirs,

I am trying to compare a register value to a hex code value as shown below:

if(P0 == 0xAA)
{
        P0 = 0x00;
}
else if(P0 == 0x00)
{
        P0 = 0xAA;
}

in my code, I have it declared as:

sfr P0     = 0x80;

and initialized as:

P0 = 0x00;

Currently, the value of P0 is 0x00. Unfortunately, it isn't entering the else if loop as I would expect (so my program isn't setting P0 to 0xAA). I'm guessing it's because I am handling a register value incorrectly or can't compare a register value to a hex code. I'm guessing it's probably a pretty simple fix or there is a better approach to this. Can you help me understand what I am doing incorrectly? Thanks!

Parents Reply Children
  • a post appear "8051" and no further detail is given.

    in that case I always assume (as one shoudn't) the classic.

    anyhow, even the most advanced derivatives do not have "output mode", they have "push pull configuration" thus the reference to "output mode" made me go for the old misconception of modes for the classic '51 port.

    Erik

  • Sirs,

    Reading the register was more trouble than it was worth. I changed the code to:

    Initialization:

    bit CodeLocked = 0
    

    Running Code:

    if(CodeLocked==0)
    {
            P0 = 0xAA;
            CodeLocked = 1;
    }
    else if(CodeLocked==1)
    {
            P0 = 0x00;
            CodeLocked = 0;
    }
    

    Thank you for your help!