user11876: Explain this line in simple words.
TCCR0B=TCCR0B&0b11111000|0x01;

As the variuos arduinos have different chips. They also have different timers and different pins which use them.
Lately i want to rewrite a code(Arduino Uno) to make it work on a Arduino Micro.
I need to understand how this works in simple words. I normally write web based code(javascript,php...). Just lately i started writing in c++ or a "simplified" c++ in the arduino ide. It's not that hard. But some specific parameters are hard to understand for me.
Shortcuts like the following.
TCCR0B=TCCR0B&0b11111000|0x01;

What does that?
TCCR0B

TCCR = Prefix for timers. Correct?
0 = Timer1 or 0 call it however you want.
B = What is A,B,C and sometimes D for? What does this?why in that code is the programmer using B and not A,C or D
TCCR0B= Timer 0 B is equal to:
TCCR0B& if Timer 0 B return True .. exists "&" ?
0b11111000 What is this? i already asked this and the answer was something like "clears the low-order 3 bits". Like i said, i'm not very familiar with c++, bits and other stuff regarding the arduino. I now less about the various chips and also about how they implemented the various parameters from arduino ide to work with those chips. I know that i have here 8 values that i can change from 0 to 1. What does those values change relative to the timer. Please think of me as a 6 year old.
|0x01; I got this... it sets the prescaler... 1,8,32.. some timers have differnet values... no problem. I need it at 1.

user7856: The answer, at high level, is: each bit (or group of bits) in a register is, in practice, like a knob that can configure certain parts of the HW.
For each peripheral you want to control, you have to understand the block diagrams, the related knobs and in which registers those knobs are located.
Sometimes there are multiple (almost) identical instances of a certain HW block and in the ATMega case these instances are often addressed with letters.
So registers that have almost identical names, apart from A, B, C, are basically identical, but each of them will affect a separate instance of a certain peripheral.
Depending on which pins or interrupt you want to use, you can choose the specific instance of a certain peripheral.
You should check the ATMega328p programmer's manual (it's 2k pages, but it's easy to find the desired section.)

user70625: To add to Majenko's very thorough and excellent answer (which I can't yet upvote because I'm very newbie):
Let's try to hone in on the line of code you need:
TCCR0B=TCCR0B&0b11111000|0x01;

On that particular Ardiuno, TCCR0B is the register that controls the rate of that particular timer. More specifically, the lowest 3 bits (the last in the 8-bit value) control the prescaler. The manufacturer labels those as CS02, CS01, and CS00. The combination of 1s and 0s in those three bits determines if the clock time is scaled or not, and by how much (or even if there is an external clock source). The reproduced table 14-9 will tell you how much the clock is "slowed down". This lets you create a 1Hz (1-second) timer, for example, rather than the 16Mhz (or whatever your particular board runs at) by scaling down how fast the timer "ticks".
If you google "Arduino hardware timer calculator" or similar, you can find very helpful tools to help you set the clock frequency you want. Do that, since there are dangers to setting the wrong values, and your compiler may not catch what can be a serious error.
I only learned about hardware timers after exploring Arduino for a few years. Turns out they are very, very useful!

user4143: First I'll tackle what
TCCR0B=TCCR0B&0b11111000|0x01;

means from a pure programming perspective:
Let's break it down into parts:
TCCR0B = TCCR0B & 0b11111000 | 0x01;

TCCR0B is a register. It could be any variable really - it's just "a value" in this context. Just because it happens to control one of the timers is besides the point.
0b11111000 is a binary representation of a value.  It's the same as the hexadecimal number 0xF8.  F is 15.  15 in binary is 1111.  8 is 8 in both hexadecimal and decimal.  8 in binary is 1000.  Put the two together and you have 11111000.  Incidentally, in decimal that is 248.
0x01 is hexadecimal for 1 in decimal - it's also 1 in binary.
Between them are bitwise operators - & is a bitwise AND operation, and | is a bitwise OR operation.  AND calculates which bits in a pair of binary numbers are both on, and OR calculates which bits in a pair of binary numbers are on in either of the numbers.
So take the first one first.  Say the TCCR0B register contains the value 0x6F, which is 157 in decimal, or 01101111 in binary.  The first operation is to AND that with 11111000:
01101111
11111000 AND
--------
01101000

You can see that the last three bits of the value have been cleared because they aren't 1 in both the left and right operands to the & operator.
Ok, so the next operation is to OR it with 0x01:
01101000
00000001 OR
--------
01101001

Effectively the two operands have been overlaid on each other and any bits that are set in either operand will be reflected in the result.
So finally the value is then stored in TCCR0B.
In summary that specific operation clears the lower three bits then sets the lowest bit of TCCR0B.
Now what that actually means with respect to what the TCCR0B register does can be gleaned from the datasheet for the chip.  For instance, take the ATMega328P chip from the Arduino UNO board.  Section 14.9.2 "TCCR0B – Timer/Counter Control Register B" of the datasheet describes that register in detail.  The bit-wise overview looks like this:

Those bits all correspond 1:1 to the binary bits from above in the same order.  So the first stage, clearing of the lowest three bits, sets CS02, CS01 and CS00 to 0.  The second stage, ORing 0x01, then sets CS00 to 1.
The datasheet goes on to tell you what those mean:


Bits 2:0 – CS02:0: Clock Select

The three Clock Select bits select the clock source to be used by the Timer/Counter.

And a table to show the different meanings of the possible values:

The value that has been masked and created for those three bits is, of course, 001, which in that table is "CLK I/O / (No prescaling)", which is the timer running at the frequency of the IO clock.  If you were to set those bits to 010, you'd get "CLK I/O / 8 (From prescaler)".  So your masking would change to:
TCCR0B = TCCR0B & 0b11111000 | 0x02;

Or more explicitly so you can see the bits easier:
TCCR0B = TCCR0B & 0b11111000 | 0b010;

As to what the "A" and "B" mean (TCCR0A and TCCR0B), there are two registers that are used to control the timer.  They each serve a different purpose.  TCCR0A has bits that control PWM, and TCCR0B has bits that control the timer itself.
Not to be confused with OCR0A and OCR0B which are two separate numeric values that are compared to the timer's counter value TCNT0 to provide two separate PWM outputs (OC0A as Uno pin D6, and OC0B as Uno pin D5) synchronised from the same timebase. (See sections 14.9.4 OCR0A – Output Compare Register A and 14.9.4 OCR0B – Output Compare Register B in the datasheet)

11876: <p><strong>Explain this line in simple words.</strong></p>

<pre><code>TCCR0B=TCCR0B&amp;0b11111000|0x01;
</code></pre>

<p>As the variuos arduinos have different chips. They also have different timers and different pins which use them.</p>

<p>Lately i want to rewrite a code(Arduino Uno) to make it work on a Arduino Micro.</p>

<p>I need to understand how this works in simple words. I normally write web based code(javascript,php...). Just lately i started writing in c++ or a "simplified" c++ in the arduino ide. It's not that hard. But some specific parameters are hard to understand for me.
Shortcuts like the following.</p>

<pre><code>TCCR0B=TCCR0B&amp;0b11111000|0x01;
</code></pre>

<p>What does that?</p>

<pre><code>TCCR0B
</code></pre>

<p><code>TCCR</code> = Prefix for timers. Correct?</p>

<p><code>0</code> = Timer1 or 0 call it however you want.</p>

<p><code>B</code> = <strong>What is A,B,C and sometimes D for?</strong> What does this?why in that code is the programmer using B and not A,C or D</p>

<p><code>TCCR0B=</code> Timer 0 B is equal to:</p>

<p><code>TCCR0B&amp;</code> <strong>if Timer 0 B return True .. exists "&amp;" ?</strong></p>

<p><code>0b11111000</code> <strong>What is this?</strong> i already asked this and the answer was something like "clears the low-order 3 bits". Like i said, i'm not very familiar with c++, bits and other stuff regarding the arduino. I now less about the various chips and also about how they implemented the various parameters from arduino ide to work with those chips. I know that i have here 8 values that i can change from 0 to 1. What does those values change relative to the timer. Please think of me as a 6 year old.</p>

<p><code>|0x01;</code> I got this... it sets the prescaler... 1,8,32.. some timers have differnet values... no problem. I need it at 1.</p>
 7856: <p>The answer, at high level, is: each bit (or group of bits) in a register is, in practice, like a knob that can configure certain parts of the HW.
For each peripheral you want to control, you have to understand the block diagrams, the related knobs and in which registers those knobs are located.
Sometimes there are multiple (almost) identical instances of a certain HW block and in the ATMega case these instances are often addressed with letters.
So registers that have almost identical names, apart from A, B, C, are basically identical, but each of them will affect a separate instance of a certain peripheral.
Depending on which pins or interrupt you want to use, you can choose the specific instance of a certain peripheral.
You should check the ATMega328p programmer's manual (it's 2k pages, but it's easy to find the desired section.)</p>
 70625: <p>To add to Majenko's very thorough and excellent answer (which I can't yet upvote because I'm very newbie):
Let's try to hone in on the line of code you need:</p>
<pre><code>TCCR0B=TCCR0B&amp;0b11111000|0x01;
</code></pre>
<p>On that particular Ardiuno, TCCR0B is the register that controls the rate of that particular timer. More specifically, the lowest 3 bits (the last in the 8-bit value) control the prescaler. The manufacturer labels those as CS02, CS01, and CS00. The combination of 1s and 0s in those three bits determines if the clock time is scaled or not, and by how much (or even if there is an external clock source). The reproduced table 14-9 will tell you how much the clock is &quot;slowed down&quot;. This lets you create a 1Hz (1-second) timer, for example, rather than the 16Mhz (or whatever your particular board runs at) by scaling down how fast the timer &quot;ticks&quot;.
If you google &quot;Arduino hardware timer calculator&quot; or similar, you can find very helpful tools to help you set the clock frequency you want. <em>Do that,</em> since there are dangers to setting the wrong values, and your compiler may not catch what can be a serious error.</p>
<p>I only learned about hardware timers after exploring Arduino for a few years. Turns out they are very, very useful!</p>
 4143: <p>First I'll tackle what</p>
<pre><code>TCCR0B=TCCR0B&amp;0b11111000|0x01;
</code></pre>
<p>means from a pure programming perspective:</p>
<p>Let's break it down into parts:</p>
<pre><code>TCCR0B = TCCR0B &amp; 0b11111000 | 0x01;
</code></pre>
<p><code>TCCR0B</code> is a register. It could be any variable really - it's just &quot;a value&quot; in this context. Just because it happens to control one of the timers is besides the point.</p>
<p><code>0b11111000</code> is a binary representation of a value.  It's the same as the hexadecimal number <code>0xF8</code>.  F is 15.  15 in binary is 1111.  8 is 8 in both hexadecimal and decimal.  8 in binary is 1000.  Put the two together and you have 11111000.  Incidentally, in decimal that is 248.</p>
<p><code>0x01</code> is hexadecimal for 1 in decimal - it's also 1 in binary.</p>
<p>Between them are <em>bitwise</em> operators - <code>&amp;</code> is a bitwise <code>AND</code> operation, and <code>|</code> is a bitwise <code>OR</code> operation.  <code>AND</code> calculates which bits in a pair of binary numbers are both on, and <code>OR</code> calculates which bits in a pair of binary numbers are on in either of the numbers.</p>
<p>So take the first one first.  Say the <code>TCCR0B</code> register contains the value <code>0x6F</code>, which is 157 in decimal, or 01101111 in binary.  The first operation is to <code>AND</code> that with 11111000:</p>
<pre><code>01101111
11111000 AND
--------
01101000
</code></pre>
<p>You can see that the last three bits of the value have been cleared because they aren't 1 in both the left and right operands to the <code>&amp;</code> operator.</p>
<p>Ok, so the next operation is to <code>OR</code> it with 0x01:</p>
<pre><code>01101000
00000001 OR
--------
01101001
</code></pre>
<p>Effectively the two operands have been overlaid on each other and any bits that are set in either operand will be reflected in the result.</p>
<p>So finally the value is then stored in <code>TCCR0B</code>.</p>
<p>In summary that specific operation <em>clears the lower three bits then sets the lowest bit</em> of TCCR0B.</p>
<p>Now what that actually means with respect to what the TCCR0B register does can be gleaned from the datasheet for the chip.  For instance, take the ATMega328P chip from the Arduino UNO board.  Section 14.9.2 &quot;TCCR0B – Timer/Counter Control Register B&quot; of <a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf" rel="nofollow noreferrer">the datasheet</a> describes that register in detail.  The bit-wise overview looks like this:</p>
<p><a href="https://i.stack.imgur.com/eQKLG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eQKLG.png" alt="enter image description here" /></a></p>
<p>Those bits all correspond 1:1 to the binary bits from above in the same order.  So the first stage, clearing of the lowest three bits, sets CS02, CS01 and CS00 to 0.  The second stage, ORing 0x01, then sets CS00 to 1.</p>
<p>The datasheet goes on to tell you what those mean:</p>
<blockquote>
<ul>
<li>Bits 2:0 – CS02:0: Clock Select</li>
</ul>
<p>The three Clock Select bits select the clock source to be used by the Timer/Counter.</p>
</blockquote>
<p>And a table to show the different meanings of the possible values:</p>
<p><a href="https://i.stack.imgur.com/eMoHl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eMoHl.png" alt="enter image description here" /></a></p>
<p>The value that has been masked and created for those three bits is, of course, 001, which in that table is &quot;CLK I/O / (No prescaling)&quot;, which is the timer running at the frequency of the IO clock.  If you were to set those bits to 010, you'd get &quot;CLK I/O / 8 (From prescaler)&quot;.  So your masking would change to:</p>
<pre><code>TCCR0B = TCCR0B &amp; 0b11111000 | 0x02;
</code></pre>
<p>Or more explicitly so you can see the bits easier:</p>
<pre><code>TCCR0B = TCCR0B &amp; 0b11111000 | 0b010;
</code></pre>
<p>As to what the &quot;A&quot; and &quot;B&quot; mean (TCCR0A and TCCR0B), there are two registers that are used to control the timer.  They each serve a different purpose.  TCCR0A has bits that control PWM, and TCCR0B has bits that control the timer itself.</p>
<p>Not to be confused with OCR0A and OCR0B which are two separate numeric values that are compared to the timer's counter value TCNT0 to provide two separate PWM outputs (OC0A as Uno pin D6, and OC0B as Uno pin D5) synchronised from the same timebase. (See sections 14.9.4 OCR0A – Output Compare Register A and 14.9.4 OCR0B – Output Compare Register B in the datasheet)</p>
