Skip to content

Instantly share code, notes, and snippets.

Created May 28, 2013 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f9ad700db61cbb36756e to your computer and use it in GitHub Desktop.
Save anonymous/f9ad700db61cbb36756e to your computer and use it in GitHub Desktop.
#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