Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Button Press Launches Interrupt | ||
Here a button (pulled high, grounded when pressed) causes an interrupt. | ||
|
||
```C | ||
|
||
#include <avr/interrupt.h> | ||
|
||
ISR(INT0_vect){ | ||
// runs when the button is pressed | ||
} | ||
|
||
void SetupButton(){ | ||
MCUCR=(1<<ISC01); // falling edge of INT0 generates interrupt | ||
GIMSK=(1<<INT0); // INT0 causes interrupt request | ||
EIFR=(1<<INTF0); // INT0 change Interrupt Flag | ||
PCMSK=(1<<PCINT1); // watch these pins | ||
sei(); // enable global interrupts | ||
} | ||
|
||
|
||
int main(void){ | ||
SetupButton(); | ||
for(;;){} | ||
} | ||
``` |