ATtiny13 timer + interrupt
Pre overenie funkcie časovača a prerušenia je zapojenie obvodu jednoduché:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#define LED0 0
#define LED4 4
#define SWITCH3 3
volatile int hodnota=0;
int main (void)
{
DDRB |= (1 << LED0); // definujem vystupny port pre LED
DDRB |= (1 << LED4); // definujem vystupny port pre LED
DDRB &= ~(1 << SWITCH3); // nastavujem vstup pre tlacitko
PORTB |= (1 << SWITCH3); //aktivujem pull-up
GIMSK |= _BV (PCIE); // Povolenie externych preruseni
PCMSK |= (1< 10) {
PORTB ^= (1 << LED0); // LED on/off
hodnota=0;
// ak svieti LED aktivovana tlacitkom, zhasnem ju
PORTB &= ~(1 << LED4);
}
}
//stlacene tlacitko, rozsvietim LED
ISR(PCINT0_vect)
{
PORTB |= (1 << LED4);
}

- Pridať nový komentár
- prečítané 84x


