#define F_CPU 16000000UL // Define clock speed for potential delays (good practice)
#include <avr/io.h>
#include <avr/interrupt.h>
// Interrupt Service Routine for INT0
ISR(INT0_vect)
{
PORTB |= (1 << PB5); // Turn LED ON
}
// Interrupt Service Routine for INT1
ISR(INT1_vect)
{
PORTB |= (1 << PB5); // Turn LED OFF
}
int main(void) {
// --- SETUP ---
// (This code runs once at the beginning)
// Set PB5 (pin 13) as output (LED)
DDRB |= (1 << DDB5);
// Set PD2 and PD3 as inputs (INT0, INT1)
// When interrupts are enabled on these pins, they often default to input,
// but explicitly setting them is good practice.
DDRD &= ~((1 << DDD2) | (1 << DDD3));
// Enable internal pull-ups (connect button to GND)
PORTD |= (1 << PORTD2) | (1 << PORTD3);
// Enable external interrupts INT0, INT1 in EIMSK register
EIMSK |= (1 << INT0) | (1 << INT1);
// Configure trigger for FALLING edge in EICRA register
// Set ISC01 = 1, ISC00 = 0 for INT0 falling edge
// Set ISC11 = 1, ISC10 = 0 for INT1 falling edge
EICRA |= (1 << ISC01) | (1 << ISC11); // Set bits 1 and 3
EICRA &= ~((1 << ISC00) | (1 << ISC10)); // Clear bits 0 and 2
// Enable global interrupt flag in SREG register
sei();
// --- LOOP ---
// (This code runs forever after setup)
while (1) {
// Main loop does nothing, waits for interrupts
// The CPU can do other tasks here or sleep
}
}