32 lines
766 B
C++
32 lines
766 B
C++
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include <util/delay.h>
|
|
#include "photointerrupter.h"
|
|
|
|
namespace photointerrupter {
|
|
void init() {
|
|
TCCR2 |= (1<<WGM21); //CTC TOP OCR2
|
|
TCCR2 |= (1<<COM20); //Toggle OC0
|
|
TCCR2 |= (1<<CS20); //No prescale
|
|
OCR2 |= 105;
|
|
//DDRB |= (1<<PB3);
|
|
DDRD |= (1<<PD6)|(1<<PD7);
|
|
//TIMSK |= (1<<OCIE0);
|
|
|
|
MCUCR |= (1<<ISC11)|(1<<ISC10); //INT1 rising edge
|
|
GICR |= (1<<INT1);
|
|
|
|
sei();
|
|
}
|
|
|
|
ISR(TIMER2_COMP_vect) {
|
|
volatile static int count;
|
|
count++;
|
|
if(count == 60) TCCR2 &= ~(1<<CS20);
|
|
if(count > 600) {
|
|
TCCR2 |= (1<<CS20);
|
|
count = 0;
|
|
}
|
|
}
|
|
} // namespace photointerrupter
|