We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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!
P0 is a port, so if it is initialized to output '51 ports can not be "initialized to output"
"'51 ports can not be "initialized to output""
Dependong on what '51 we talk about. Classic design or some of the souped-up versions.
See: www.8052.com/.../120176
As Per says, that applies to the "Classic" 8051 "quasi-bidirectional" port structure - some modern derivatives do have other options; some with direction control...
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
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!