MIKR/lectures/Timer/timer-interrupt.c

44 lines
558 B
C
Raw Permalink Normal View History

2024-04-16 20:18:18 +02:00
#include<avr/io.h>
#include<util/delay.h>
#include <avr/interrupt.h>
#define DELAY_TIME 150
volatile uint8_t id;
volatile uint8_t state;
ISR(TIMER2_OVF_vect, ISR_NAKED)
{
if(state == 0){
PORTC &= ~(1<<id);
state++;
}else{
PORTC |= (1<<id);
state = 0;
id++;
if(id == 8)
id = 0;
}
reti();
}
void set_led(int id){
PORTC &= ~(1<<id);
_delay_ms(DELAY_TIME);
PORTC |= (1<<id);
_delay_ms(DELAY_TIME);
}
int main(void) {
DDRC = (0xff);
PORTC = (0xff);
TCCR2B |= (0b111);
TIMSK2 |= 0b1;
sei();
for(;;);
return 0;
}