-2

What is the meaning of

TIFR0 = 1<<TOV0;

Is it means we are writing 1 to TOV0 bit of TIFR0?

  • 1
    Read about the shift left operator. – Vlad from Moscow Oct 17 '22 at 18:48
  • 2
    And `0` to all the other bits. It shifts `1` left to the bit position specified by `TOV0`. But it would be more general as `1u << TOV0`. – Weather Vane Oct 17 '22 at 18:57
  • You can't do embedded systems programming without studying the utter basics of C first. That includes all bitwise operations, binary notation, hex notation. Start with reading a beginner-level book then take it from there. – Lundin Oct 18 '22 at 10:51

1 Answers1

2

No. That means we are writing 1 to a bit at position TOV0, while writing 0 to all other bits in TIFR0 register.

<< is a bitwise shift left operation, which results equals to all bits of the source number, shifted left in their binary representation.

1 is a number where only the first bit (i.e. the bit at position #0) is set. Therefore 1 << n moves that bit n positions left, and gives you a number where only bit #n is set, but all other bits are cleared.

TOV0 is a macro, which defines the position of bit TOV0.

Be careful when using simple assignment like that, because it will clear all other bits.

If you want to modify the only bit, you may use a bitwise or:

TIFR0 |= 1<<TOV0;

AterLux
  • 4,566
  • 2
  • 10
  • 13