Chapter 6: C Functions and Program Structures
for(int i = 0; i < 10; i++)
TIFR2 = 0xFF; // delete TIFR2 flags
(TIFR2 && (1<<OCF2A)) ); // wait for timer2 compareflag
TCCR1B = 0; // stop timer1
sei(); // __enable_interrupt(); // enable global interrupt
if ( (TIFR1 && (1<<TOV1)) )
{
temp = 0xFFFF; // if timer1 overflows, set the temp to 0xFFFF
}
else
{ // read out the timer1 counter value
tempL = TCNT1L;
temp = (temp << 8);
temp += tempL;
OSCCAL
OSCCAL
CCR1B = (1<<CS10); // start timer1
e makefile:
while((ASSR & 0x01) | (ASSR & 0x04));
// wait for external crystal to stabilise
_delay_loop_2(30000);
while(!calibrate)
{
cli(); // mt __disable_interrupt(); // disable global interrupt
TIFR1 = 0xFF; // delete TIFR1 flags
TCNT1H = 0; // clear timer1 counter
TCNT1L = 0;
TCNT2 = 0; // clear timer2 counter
while (!
temp = TCNT1H;
}
if (temp > 6250)
{
OSCCAL--; // the internRC oscillator runs to fast, decrease the
}
else if (temp < 6120)
{
OSCCAL++; // the internRC oscillator runs to slow, increase the
}
else
calibrate = 1;//TRUE; // the interRC is correct
T
}
}
Save this file as PC_Comm.c.
Finally make these changes to th