inv-sw-32u4/src/timer.c

45 lines
682 B
C
Raw Normal View History

2022-05-11 20:21:21 +00:00
#include <avr/io.h>
#include <avr/interrupt.h>
2022-05-11 20:21:21 +00:00
#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);
2022-05-11 20:21:21 +00:00
/* Use CTC Mode */
TCCR0A |= (1 << WGM01);
/*
* OCR0A contains TOP value for counter:
*/
OCR0A = 100;
2022-05-11 20:21:21 +00:00
}
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);
}