Documente Academic
Documente Profesional
Documente Cultură
External Clock
Pin
Current timer/
counter value
Output Compare
Register
Output
Compare Pin
Timer Registers
Registers
Timer/Counter Control Register – TCCR0
A special case occurs when OCR0 equals TOP and COM01 is set. In this
case, the Compare Match is ignored, but the set or clear is done at TOP
Timer/Counter Control Register – TCCR0
N++;
if(N==61)
{
PORTC=~PORTC; //Invert the Value of PORTC
N=0;
}
}
// File: timer0.c
// Date modified: 17 Sept 2012
// By: Yudi Gondokaryono
volatile uint8_t N;
int main(void)
{
// Prescaler = FCPU/1024
TCCR0|=(1<<CS02)|(1<<CS00);
//Enable Overflow Interrupt Enable
TIMSK|=(1<<TOIE0);
//Initialize Counter
TCNT0=0;
//Initialize our variable
N=0;
//Port C[3,2,1,0] as output
DDRC|=0x0F;
PORTC=0x0F; // Turn off LEDs
//Enable Global Interrupts
sei();
//Infinite loop
while(1);
}
ISR(TIMER0_OVF_vect)
{
//This is the interrupt service routine for TIMER0 OVERFLOW Interrupt.
//CPU automatically call this when TIMER0 overflows.