ATmega8 Externer Interrupt

Einfacher C Code für den ATmega8 Externer Interrupt


Erscheint am Eingang PD3 eine steigende Flanke, wird der externe Interrupt 1 gestartet. In der Interruptroutine wird der Ausgang PB0 getoggelt.


AVR Mikrocontroller
Programmierung in C

C Sourcecode

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)

    DDRB = 0x01;                        // Setup P0 as output
    PORTD |= 0x08;                      // Activate Apullupressistor of PD3
    GICR |= (1 << INT1);                // Enable INT1
    MCUCR |= (1 << ISC10)|(1 << ISC11)// INT1 is executed on rising edge

    sei();                              // Set the I-bit in SREG

    for(;;);                            // The main loop stays empty and
                                        // could contain some code you want.

    return 0;                           // This line will never be executed

// Interrupt subroutine for external interrupt 0
    PORTB ^= 0x01;                      // Toggle PB0


Download C-Sourcefile mit ASCII-Schema: C-Sourcefile mit ACII-Schema


Externer Interrupt 1 Plot

Gelb: Digitalausgang PB0

Blau: Interrupteingang INT1