What does TIMSK1 = bit (TOIE1); mean ??

I’m studying the tutorial by Nick Gammon

http://www.gammon.com.au/timers

I’ve pretty much managed to find out what all the different C commands mean except for this one:

TIMSK1 = bit (TOIE1);

Could anyone explain that one to me.

Cheers,

Keith.

That's covered in the datasheet - he's setting the TOIE1 bit in the TIMSK1 register. From memory, that enables the timer 1 overflow interrupt.

(Timer Overflow Interrupt Enable 1, Timer Interrupt MaSK 1)

See datasheet for the details

beefy23: managed to find out what all the different C commands mean

Most of them are (more or less) simple assignment, not special 'C commands'.

Many of the acronyms represent registers that can be used like normal C-variables, they are just predefined in a special way to enshure the correct access pattern.

Others represent bits, bit-positions, and macros moving bits to the right place, combining them, ...

Its not an extension of the C++ language.

Thanks very much.

I have started reading the datasheet but wanted to understand what the instructions mean first.

I know what the “TIMSK1” and “TOIE1” are. I suppose I was asking what is the instruction doing. So the

“= bit” means set to 1

Or put another way, the whole instruction means “in register TIMSK1, set bit TOIE1 to 1”.

The instructions I’ve commonly seen to do the same thing are like this:

TIMSK1 |= (1 << TOIE1);

so I was wondering if TIMSK1 = bit (TOIE1); had a different meaning. Guess it’s just different ways to do the same thing.

That actually has me wondering about using this instruction to CLEAR a bit. Would it be NOT bit:

TIMSK1 = !bit (TOIE1);

Keith.

And it with a mask representing the bitwise complement.

TIMSK1 &= ~bit (TOIE1);

And setting the bit would better be (this does not disturb the other bits in the register)

TIMSK1 |= bit (TOIE1);

See: https://www.arduino.cc/en/Reference/Bit

The boolean not ! and the bitwise not ~ are different operators.

Ah great, thank you all very much.

Keith.

beefy23: so I was wondering if TIMSK1 = bit (TOIE1); had a different meaning. Guess it's just different ways to do the same thing.

I think it's just a bit of hand-holding for people that might be startled by the C bit operators.