Help with transcript C

I'm trying to figure out some firmware that was written for us. I am not so familiar with C, and I think there are a few shortcuts here that I just don't get. I don’t understand how the code relates to comments, in particular, how you get 70 ms from any of them. Can you help translate into English?

// so the button has to be held for 70 ms to be considered being pressed
// and then has to be released for 70ms to be considered un-pressed
State=(State<<1) | !input(USER_BUTTON) | 0xe000;
if(State==0xe000)
{
    Debounced_Button_Pressed =  TRUE;
    time_button_held++;
}
else if (State==0xffff)
{
    Debounced_Button_Pressed =  FALSE;
}

This is a timer interrupt function and seems to fire every 4.4 ms

Thanks.

+3
source share
3 answers

Let me take this step at a time ...

State=(State<<1) | !input(USER_BUTTON) | 0xe000;

What it is:

  • Move the position to the left (throw out the upper bit, move everything, set the lower bit to 0)
  • Set low bit if input 0 (off)
  • Turn on the top 3 bits.

, 13 , , 13 USER_BUTTON.

if , 13 ( 0xe000) on ( 0xffff). , 13 ; , 13 .

4.4ms * 13 = 57.2ms - 5.385ms.

+13

"" varialbe 16 . < , | , (USER_BUTTON) (! not). , 13 false.

+2

It debuts at the switch, rearranging the switch state patterns into an integer every 4.4 ms. He can then report the actual click on the noise, having seen whether the contents of this integer correspond to a specific hexadecimal value. It looks like he can also tell if he was released according to his definition, comparing it with a different value.

+2
source

Source: https://habr.com/ru/post/1714829/


All Articles