Chapter 8: C Pointers and Arrays
peration AS2: Asynchronous Timer/Counter2, AS2
Register, ASSR.
= (1<<AS2);
lear the Timer/Counter 2, TCNT2, count register.
TCNT2 = 0;
egister,
econd and 128*256 =
nd overflows once per
UB: Timer/Counter2 Update Busy and the TCR2UB:
r/Counter Control Register2 Update Busy bits of the, ASSR, to be cleared.
| (ASSR & 0x04));
R2 = 0xFF;
mer/Counter 2 Output Interrupt Enable, TOIE2, bit in the Timer/Counter
, to enable the timer output interrupt enable.
bi(TIMSK2, TOIE2);
l interrupts.
ow the SIGNAL(SIG_OVERFLOW2) function will be called once per second
s shown in the code section) so we can use it to keep track of seconds.
Converting Computer Time to Human Readable Time
We can keep a count of seconds, but what good does it do us if our watch reads
40241? If the count started at midnight then this number of seconds would
Select Timer2 asynchronous o
bit in the Asynchronous Status
ASSR
C
Select the divide by 128 prescale factor in the Timer Counter Control R
TCCR2A. The watch crystal pulses 32768 times in one s
32768, so with a 128 prescaler, the timer counts to 256 a
second.
TCCR2A |= (1<<CS22) | (1<<CS20);
Wait for the TCN2
Time
while((ASSR & 0x01)
Clear the Timer/Counter2 Interrupt Flags Register, TIFR2.
TIF
Set the Ti
2 Interrupt Mask Register, TIMSK2
s
And finally, enable the globa
sei();
N
(a