MIKR/lectures/Timer/timer-idk.c
Dawid Pietrykowski 8749f5e3a9 First commit
2024-04-16 20:18:18 +02:00

51 lines
684 B
C

#include<avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t id;
volatile uint8_t state;
volatile int8_t dir = -1;
ISR(TIMER2_OVF_vect)
{
if(state == 0){
PORTC &= ~(1<<id);
}else{
PORTC |= (1<<id);
id = (id + dir) % 8;
}
state = (state+1) % 2;
}
ISR(PCINT1_vect){
if(dir == 1)
dir = -1;
else
dir = 1;
}
int main(void) {
DDRC = (0xff);
PORTC = (0xff);
DDRB &= ~_BV(DDB0);
PORTB |= _BV(PORTB0);
// timer int
TCCR2B |= _BV(CS22) | _BV(CS21) | _BV(CS20);
TIMSK2 |= _BV(TOIE2);
EICRA |= _BV(ISC11) | _BV(ISC10);
EIMSK |= _BV(INT1);
// enable for pin 8 - PB0
PCMSK1 |= _BV(PCINT8);
PCICR |= _BV(PCIE1);
sei();
for(;;);
return 0;
}