In all the Arduino docs I don’t see any mention of registers. I’m sure this is because the beginner (the target of Arduino) probably won’t need such low-level access.
But once one sees the advantage of using the timer/counter or other features of the AVR, where does one look for how to do this within Arduino? All the details are in the Atmel manual, but nothing I can find in Arduino docs mentions how to do this.
Specifically, I want to read and reset TCNT1, the 16-bit timer/counter register in the ATmega168.
I found a code sample that sets bits in the timer/counter control register thus:
TCCR2 |= (1< <CS22); //Timer2 Settings: Timer Prescaler /64, TCCR2 &= ~((1<<CS21) | (1<<CS20)); TCCR2 &= ~((1<<WGM21) | (1<<WGM20)); // Use normal mode ASSR |= (0<<AS2); // Use internal clock - external clock not used in Arduino TIMSK |= (1<<TOIE2) | (0<<OCIE2); //Timer2 Overflow Interrupt Enable
I understand all the bitwise stuff. But these register names aren’t declared anywhere in the sample sketch. Are these names automatically linked to the registers without need for declaration? Or should they simply be declared as INT as ordinary variables are?
Any pointers to how to use registers on a simple level in Arduino would be greatly appreciated.
Mac OS X 10.5.2