Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


he Ti gister B, TCCR1B and the Timer/Counter2
re set to start timer1 and timer2 with no

<CS10);

egisters we wait for the TCNT2 and the TCRU2B registers
ter2 Update
usy, T
e ASS

) | (ASSR & 0x04));

it a z

;

LL T TING YET!

r can be a

e start calibrating by running a loop in which you make adjustments to the
terna ernal clock, looping until

t a fl

librate = FALSE;

T mer/Counter1 Control Re
Control Register A, TCCR2A, a
prescaling:


TCCR1B = (1<
TCCR2A = (1<<CS20);

After setting all these r
to be set from temporary memory, by waiting for the Timer/Coun
B CN2UB, and the Timer/Counter2 Update Register Busy,TCCR2A, bits of
th R register to be cleared (p 139 data book).


while((ASSR & 0x01

Wa while for the crystal to stabili e:


Delay(1000)

A HIS AND WE HAVEN’T EVEN STARTED CALIBRA


Getting registers set properly to do much of anything in a microcontrolle
long and frustrating exercise, and another good reason to steal code where
possible.


W
in l oscillator and comparing the results to the ext
you get it right.


Se ag:


unsigned char ca

to terminate the loop when true:


while(!calibrate)

On each pass you do the following:

Free download pdf