First I'll tackle what
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
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:
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
Ok, so the next operation is to
OR it with 0x01:
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
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. Page 109 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 OCCR0A and OCCR0B which are two separate numeric values that are compared to the timer's counter value TCNT0 to provide two separate PWM outputs synchronised from the same timebase.