Another problem bring up is that:
When I tried to use the following instrution to write the code for my 89C51 chip. It can be compiled successfully. But it does not work in 8051 when I burn the code. here is the code: If(c!='A' | c!='B' | c!='O' | c!='P') { send_serial("Invalid command"); send_serial(crlf); } Look like it does not take it when I write the format like above. Why ? I cannot understand. I think Keil C Uvison can take care it.
However, if I use only one if (c!='A') { send_serial("Invalid command"); send_serial(crlf); } if (c!='B') { send_serial("Invalid command"); send_serial(crlf); } if (c!='O') { send_serial("Invalid command"); send_serial(crlf); } if (c!='P') { send_serial("Invalid command"); send_serial(crlf); } The 89C51 will recognize and run my code properly. Can you expalin what is happening?
"Look like it does not take it ..."
What does that mean, precisely?
Anyway, you're using bitwise-OR, not logical-OR operators.
And you probably want logical-ANDs, not logical-ORs.
Your code is wrong.
You need to correct the code so that it correctly represents what you want it to do.
You have a basic 'C' language problem - it is nothing specifically to do with Keil or the 8051.
It can be compiled successfully. But it does not work...
That compiling is ok does not impose, that the code runs like you expect it to run...
Ask yourself, if the code is ok, before pushing the blame on the tool.
First off - think about use of "and" or "or" - what is the difference?
Second - what logic operation does your second alternative use? Have you tried with both acceptable and non-acceptable characters?
... and remember that the 'C' language provides two different "and" operators, and two different "or" operators...
Before you blame the Keil C tools, you should verify it in a general desktop C compiler, such as gcc , msvc, etc.