-
-
Save anonymous/f9ad700db61cbb36756e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#define F_CPU 1000000UL // 1 MHz | |
#include <util/delay.h> | |
int counter = 0; | |
int main(void) | |
{ | |
//We have an LED on PORTA0, which starts on | |
//Configure PORTA0 as output, and set it high. | |
DDRA = (1 << DDRA0); | |
PORTA = (1 << PORTA0); | |
//We have a button on PORTD2 (INT0) which pulls it to ground when pressed | |
//Set PORTD2 as input and activate the internal pull-up resistor | |
DDRD = (0 << DDRD2); | |
PORTD = (1 << PORTD2); | |
//Configure INT0 to trigger on falling edge and then enable it | |
EICRA = (1 << ISC01) & (0 <<ISC00); | |
EIMSK = (1 << INT0); | |
//enable interrupts | |
sei(); | |
while(1){ | |
//do nothing | |
} | |
} | |
ISR(INT0_vect) | |
{ | |
counter++; | |
if(counter % 5 == 0) { | |
//toggle the LED on PORTA0 | |
PORTA ^= (1 << PORTA0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment