V
V
Vadim kyklaed2018-06-07 09:26:13
Electronics
Vadim kyklaed, 2018-06-07 09:26:13

Bit shift and mode setting on MK atmega8?

Hello, tell me. I'm learning atmega8 - I've just started.
I do not understand how the timer modes are set, etc.
for example, under the 16-bit timer
TCCR1B |= (1 << WGM12); // setting the mode - reset by coincidence
TCCR1B |= (1 << CS12);//set the divisor. frequency divider = 256
we enter the settings in the same register only in different bits. if you look at the table in the datasheet, then
WGM12 - corresponds to 0100
CS12 - corresponds to 100
then
TCCR1B |= (1 << CS12) equals 0b00001000 - why? How did it happen ?
what is 1 = 0001 in this case?
how much does it move?
first, the action in brackets is performed, then TCCR1B =TCCR1B | (1<<CS12)
TCCR1B = 0b00000000
не понимаю как считать (1 << CS12)
далее
TCCR1B |= (1 << CS12); равняется 0b00001100 + после предыдущего сдвига
TCCR1B = 0b00001000

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ocelot, 2018-06-07
@kyklaed

WGM12 равен трём.
(1 << WGM12) равно 0b00001000 (единица, сдвинутая на три бита влево)
TCCR1B |= (выражение) это побитовое или, устанавливает в единицу те биты регистра TCCR1B, которые у правого операнда равны единице, а остальные не трогает. Например:
TCCR1B = 0b10101010;
TCCR1B |= 0b00001111;
теперь TCCR1B будет равен 0b10101111;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question