AVR Atmega16外部中断0的简点应用

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

void port_init(void)
{

    DDRB = 0xff;
    PORTB = 0xff;
    DDRD = 0x00;
    PORTD |= (1 << 2);
}
int main(void)
{
    port_init();
    GICR |= (1 << INT0);
    sei();
    while(1)
    {
    ;
    }
}

ISR(INT0_vect)
{
        PORTB = 0xfe;
        _delay_ms(500);
        PORTB = 0xff;
        _delay_ms(500);   
}

代码
#include <avr/io.h>
#include
<util/delay.h>
#include
<avr/interrupt.h>

void port_init(void)
{

DDRB
=0xff;
PORTB
=0xff;
DDRD
=0x00;
PORTD
|= (1<<2);
}
int main(void)
{
port_init();
GICR
|= (1<< INT0);
sei();
while(1)
{
;
}
}

ISR(INT0_vect)
{
PORTB
=0xfe;
_delay_ms(
500);
PORTB
=0xff;
_delay_ms(
500);
}
原文地址:https://www.cnblogs.com/hnrainll/p/1917550.html