Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * AT2313_InterruptHandler.c
- *
- * Created: 2/7/2012 3:59:47 PM
- * Author: grist.carrigafoyl
- */
- #define F_CPU 8000000UL // 8Mhz
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- // Digit to pin mapping.
- const uint8_t LED_PIN = _BV(PD4);
- uint8_t mode = 0; // will be changed on interrupt to set the led on or off
- int main(void)
- {
- // Set the pin mode for output
- DDRD = LED_PIN;
- // Set Pin 6 (PIND2) as the interrupt pin
- PCMSK |= (1<<PIND2);
- // interrupt on falling edge
- MCUCR = _BV(ISC01) | _BV(ISC00);
- // Turn on interrupts
- GIMSK |= _BV(INT0);
- sei();
- // loop forever
- for(;;)
- {
- // turn the led on or off depending on the current value of mode
- if (mode == 1) {
- PORTD |= LED_PIN; // on
- } else {
- PORTD &= ~LED_PIN; // off
- }
- }
- }
- //----------------------------------------------------------------------------
- // Interrupt Handler
- //----------------------------------------------------------------------------
- SIGNAL (SIG_INT0) {
- // Flip the mode
- mode = 1 - mode;
- }
- //----------------------------------------------------------------------------
- // Functions
- //----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement