C Program interrupt funksjon av INT0 ( PD2 )
Solution:
- #include <avr/io.h>
- #include "LedOgBrytereIOKort.h"
- #include "BitManipulation.h"
- #define F_CPU 16000000L
- #include <util/delay.h>
- #include <avr/interrupt.h>
- static int teller;
- // interrupt funksjonen til INT0 (PD2):
- ISR(INT0_vect)
- {
- teller++;
- skrivTilLeds(~teller);
- }
- ISR(INT1_vect)
- {
- teller = 0;
- skrivTilLeds(~teller);
- }
- int main(void)
- {
- init_LedBryterKort();
- teller=0;
- skrivTilLeds(~teller); //slukke lysa
- //Enable INT0 (PD2):
- EICRA |= (1 << ISC01); // Set INT0 (PD2) to trigger on falling edge
- EIMSK |= (1 << INT0) ; // Turns on INT1 (PD3)
- EICRA |= (1 << ISC11); // Set INT0 (PD2) to trigger on falling edge
- EIMSK |= (1 << INT1) ; // Turns on INT1 (PD3)
- sei(); //Set Enable interrupts
- while(1)
- {
- _delay_ms(10);
- }
- }