0
void TimerFunction()
{
TIMSK=(1<<TOIE0);
TCNT0=0x00;
TCCR0 |= (0<<CS02) | (1<<CS00) | (0<<CS01);
}

//##############################################################################
ISR(TIMER0_OVF_vect)
{
    // process the timer0 overflow here
  countClock ++;
  count++;
  delay++;
//some extra code 
}

then

void main()
{
 //someCode
 TimerFunction();
}

but it doesnt work for me ,so is that the right way to start the timer 0 and its interrupt service routine ??

3 Answers3

0

At first sight I'd say you miss

sei();  // set global interrupt flag

if this is not within //someCode ... in any case I recommend turning on the global interrupt enable flag only after initializing all specific interrupt sources (timers, USART, etc)

MikeD
  • 8,861
  • 2
  • 28
  • 50
0

Yes, in your code global interrupt flag is not set. If solutions which purposed MikeD are not working, try this:

asm{sei};
Dmitry
  • 1
0

use SREG.SREG_I = 1; to enable global interrupts

Soheil Paper
  • 1
  • 2
  • 8
  • 25