Can someone explain? I changed C source code for a key handler.
The original code was:
What I don't understand is why I need to insert a negation.
Since in the first line,
is true.
So I changed it to
.
But that did not work. The code worked like the key is continuously pressed and released.
When I inserted the negation, it works like before, I have to press the key, and then release it.
Also after the modification, 30 more program words are used. I hoped to save a few but the opposite is true.
Rich (BB code):
unsigned char key_handler(unsigned char k)
{
if(k==0==!(io_0&0x01))return(++k);
if(k==1== (io_0&0x01))return(++k);
return(k);
}
Rich (BB code):
unsigned char key_handler(unsigned char k)
{
if(k==0){if((io_0&0x01)==0){k++;return(k);}}
if(k==1){if((io_0&0x01)==1){k++;return(k);}}
return(k);
}
Since in the first line,
Rich (BB code):
(io_0&0x01)==0
So I changed it to
Rich (BB code):
k==0==(io_0&0x01)
But that did not work. The code worked like the key is continuously pressed and released.
When I inserted the negation, it works like before, I have to press the key, and then release it.
Also after the modification, 30 more program words are used. I hoped to save a few but the opposite is true.