Author: Not specified Language: c
Description: Not specified Timestamp: 2017-09-26 18:27:53 +0000
View raw paste Reply
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
int main(void){
        sei(); //enables interrupts
        DDRD = 0xF7; //sets all pins except pin 3 to output
        EIMSK = 0x02; // sets the EIMSK to enable interrupt through pin INT0
        EICRA = 0x08; //sets the EICRA to generate interrupt on the falling edge of INT1
        for(;;){
                PORTD = 0b10001000; //sets pins 7 and 3 to high
                _delay_ms(500); //delay of half a second
                PORTD = 0b01001000; //sets pins 6 and 3 to high
                _delay_ms(500);
                PORTD = 0b00101000; //sets pins 5 and 3 to high
                _delay_ms(500);
        }
       
}

ISR(INT1_vect){
        int i;
        for(i=0; i<3; i++){ //to blink simultaneously three times
                PORTD = 0b00001000; //sets all output pins to low to switch off all LEDs
                _delay_ms(500);
                PORTD = 0b11101000; //sets all output pins to high to switch on all LEDs
                _delay_ms(500);
        }
        PORTD = 0b00001000; //sets all output pins to low to switch off all LEDs
}
View raw paste Reply