inv-sw-32u4/src/timer.c
Marco 3fd547f2ea Toggle PD6 instead of PC7 when timer compare interrupt occurs.
Move timer interrupt routine to timer.c
Change timer parameters
2022-05-13 01:24:38 +02:00

45 lines
682 B
C

#include <avr/io.h>
#include <avr/interrupt.h>
#include "include/timer.h"
void initCtcTimer0(void)
{
/* Initialize counter 0 */
TCNT0 = 0;
/* Enable Counter0 Compare Match A Interrupt */
TIMSK0 |= (1 << OCIE0A);
/* Select clock. Prescaler of 8 */
TCCR0B |= (1 << CS02) | (1 << CS00);
/* Use CTC Mode */
TCCR0A |= (1 << WGM01);
/*
* OCR0A contains TOP value for counter:
*/
OCR0A = 100;
}
void initOverflowTimer0(void)
{
/* Prescaler = 0 */
TCCR0B |= (1<<CS00);
/* Enable Timer Overflow Interrupt */
TIMSK0 |= (1<<TOIE0);
}
void initOverflowTimer1(void)
{
TCCR1B |= (1<<CS11);
TIMSK1 |= (1<<TOIE1);
}
ISR(TIMER0_COMPA_vect)
{
PORTB |= (1 << PB2);
}