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

keil STM32 and bit operation

Im from slovakia so please excuse my english

im newbie in programic mcu
i need to write if clause where i wat to do something if pin is in high level.

for example
if ((P1^1)==1{
something to do
};

but it wont work
how can i do this
please help me :)

thanx very much

  • Note that P1^1 means two different things if using the C51 compiler, i.e. 8051 code.

    If used to declare a bit variable, it will tell which pin of the P1 port the variable is associated with.

    If used inside the program, then the ^ operator is the standard xor bit operator available in C. So your code in this case takes the 8-bit value from P1 and xor with the 8-bit value 0x01 and then check if the result is 1. That means that the == will depend on the 7 other pins of P1...

    In your case, you have specified the ARM architecture, in which case ^ only has a meaning as xor operator. But for the ARM chips, you may not even have a P1 port - the name used to read values from the port depends on what specific ARM chip you have.

    So if you do use an 8051 chip - do check the manual for the C51 compiler how to declare bit variables.

    And if you do use an ARM chip - make sure you use the correct register name for your specific processor and then just do:

    if (PROCESSOR_PORT & 0x00000001) { ... }