2022-05-11 20:21:21 +00:00
|
|
|
#include <avr/io.h>
|
2022-05-12 23:24:38 +00:00
|
|
|
#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);
|
|
|
|
|
2022-05-12 16:25:38 +00:00
|
|
|
/* Select clock. Prescaler of 8 */
|
2022-05-12 23:24:38 +00:00
|
|
|
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:
|
|
|
|
*/
|
2022-05-12 23:24:38 +00:00
|
|
|
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);
|
2022-05-12 23:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ISR(TIMER0_COMPA_vect)
|
|
|
|
{
|
|
|
|
PORTB |= (1 << PB2);
|
|
|
|
}
|