Click here to Skip to main content
15,894,825 members
Articles / Internet of Things / Arduino

Arduino Unleashed

Rate me:
Please Sign up or sign in to vote.
4.90/5 (19 votes)
18 Sep 2010CPOL8 min read 171.9K   679   40  
This article is all about empowering you with more powerful tools that let you unleash your creativity without being limited by the default IDE.
  • arduino.zip
    • Arduino
      • .metadata
        • .lock
        • .log
        • .mylyn
          • contexts
          • repositories.xml.zip
        • .plugins
          • de.innot.avreclipse.core
          • org.eclipse.cdt.core
          • org.eclipse.cdt.make.core
          • org.eclipse.cdt.managedbuilder.core
          • org.eclipse.cdt.ui
          • org.eclipse.core.resources
            • .history
              • 0
                • 90178f64a8c1001f13c7f5de4bcffe65
              • 11
                • 90c8cb7aaec1001f1a968c8925716fac
              • 15
                • e003e79caec1001f1a968c8925716fac
              • 16
                • 309eaa2aaac1001f1a968c8925716fac
                • b00fc1e8a7c1001f13c7f5de4bcffe65
              • 17
                • 303f0b1aaac1001f1a968c8925716fac
              • 19
                • 50db879ba9c1001f13c7f5de4bcffe65
                • b0822d6baac1001f1a968c8925716fac
              • 1a
                • a0d01b72aec1001f1a968c8925716fac
              • 1d
                • 9006869ba9c1001f13c7f5de4bcffe65
              • 2
                • 40805c37b3c1001f1a968c8925716fac
              • 24
                • 908eddbfafc1001f1a968c8925716fac
              • 25
                • 60a2bb77aec1001f1a968c8925716fac
              • 26
                • 709c0a3eadc1001f1a968c8925716fac
              • 29
                • b0563bbbafc1001f1a968c8925716fac
              • 2a
                • 50b68fbfa7c1001f13c7f5de4bcffe65
              • 2f
                • 609fb36eaec1001f1a968c8925716fac
              • 3
                • 00b2433ea6c1001f13c7f5de4bcffe65
              • 30
                • e0862b6baac1001f1a968c8925716fac
              • 31
                • e0f5edd5a9c1001f13c7f5de4bcffe65
              • 32
                • 40a6c07eaac1001f1a968c8925716fac
              • 33
                • 7066e74ab3c1001f1a968c8925716fac
                • 80265848a7c1001f13c7f5de4bcffe65
              • 34
                • 00eb51d6adc1001f1a968c8925716fac
              • 35
                • d05a5b48a7c1001f13c7f5de4bcffe65
                • e046fe19aac1001f1a968c8925716fac
              • 36
                • 20ed7c6ba8c1001f13c7f5de4bcffe65
              • 37
                • f03b866ba8c1001f13c7f5de4bcffe65
              • 39
                • 507dde20a9c1001f13c7f5de4bcffe65
              • 3b
                • a0b1ce97aec1001f1a968c8925716fac
              • 3d
                • 0063ef74aec1001f1a968c8925716fac
              • 3e
                • e0191572aec1001f1a968c8925716fac
              • 42
                • 80903869aac1001f1a968c8925716fac
              • 45
                • 10c140a1aec1001f1a968c8925716fac
              • 47
                • 3073473caec1001f1a968c8925716fac
              • 48
                • c0b85d37b3c1001f1a968c8925716fac
              • 4f
                • 70572f6baac1001f1a968c8925716fac
              • 50
                • 30083988b3c1001f1a968c8925716fac
              • 51
                • d0723269a6c1001f13c7f5de4bcffe65
              • 52
                • 902b1441b0c1001f1a968c8925716fac
              • 54
                • d06a4b3caec1001f1a968c8925716fac
              • 56
                • 002c6d00aac1001f13c7f5de4bcffe65
                • b00a8fbdafc1001f1a968c8925716fac
                • b09bbdc9a7c1001f13c7f5de4bcffe65
              • 57
                • b0f54422aac1001f1a968c8925716fac
              • 58
                • d077b7b2afc1001f1a968c8925716fac
              • 5a
                • d05d819faec1001f1a968c8925716fac
              • 5b
                • b0f4b977aec1001f1a968c8925716fac
              • 5c
                • 007bc27eaac1001f1a968c8925716fac
              • 5d
                • 40e5c897aec1001f1a968c8925716fac
                • 608adfbfafc1001f1a968c8925716fac
                • d013899ba9c1001f13c7f5de4bcffe65
              • 5e
                • c0b1af2db3c1001f1a968c8925716fac
              • 5f
                • 3048ecd5a9c1001f13c7f5de4bcffe65
              • 61
                • 404b5cd6adc1001f1a968c8925716fac
              • 67
                • 20740441b0c1001f1a968c8925716fac
              • 68
                • 20aee081aec1001f1a968c8925716fac
              • 6a
                • f0ee1a37a9c1001f13c7f5de4bcffe65
              • 6b
                • d06be49caec1001f1a968c8925716fac
              • 6c
                • 10595034b0c1001f1a968c8925716fac
              • 7
                • d076c47eaac1001f1a968c8925716fac
              • 70
                • 10503ea1aec1001f1a968c8925716fac
                • 30b3ee79a7c1001f13c7f5de4bcffe65
                • e06d6369a6c1001f13c7f5de4bcffe65
              • 71
                • f06556d4a9c1001f13c7f5de4bcffe65
              • 72
                • 40a2011aaac1001f1a968c8925716fac
              • 74
                • 00145534b0c1001f1a968c8925716fac
                • 70add097aec1001f1a968c8925716fac
              • 77
                • 50a0ae2db3c1001f1a968c8925716fac
                • 70271c37a9c1001f13c7f5de4bcffe65
              • 79
                • 20b07f9faec1001f1a968c8925716fac
              • 7a
                • 400092bfa7c1001f13c7f5de4bcffe65
                • 8051a52db3c1001f1a968c8925716fac
              • 7b
                • 703298bdafc1001f1a968c8925716fac
              • 7d
                • 006f493caec1001f1a968c8925716fac
                • 0087c57aaec1001f1a968c8925716fac
                • f063093eadc1001f1a968c8925716fac
              • 7f
                • d033043eadc1001f1a968c8925716fac
              • 80
                • a038c7c9a7c1001f13c7f5de4bcffe65
                • f03e3e22aac1001f1a968c8925716fac
              • 81
                • 402ade9caec1001f1a968c8925716fac
                • 809b876ba8c1001f13c7f5de4bcffe65
              • 84
                • 30698b4ea8c1001f13c7f5de4bcffe65
              • 85
                • 90b7c839aec1001f1a968c8925716fac
              • 87
                • 2040ed74aec1001f1a968c8925716fac
              • 8a
                • 004b6169a6c1001f13c7f5de4bcffe65
                • 60a34622aac1001f1a968c8925716fac
              • 8c
                • 70f2e59caec1001f1a968c8925716fac
              • 8d
                • c02f1241b0c1001f1a968c8925716fac
              • 8f
                • a05b95bfa7c1001f13c7f5de4bcffe65
                • e082e281aec1001f1a968c8925716fac
              • 93
                • 602ce681aec1001f1a968c8925716fac
              • 98
                • 5096829faec1001f1a968c8925716fac
              • 99
                • 309f4822aac1001f1a968c8925716fac
                • b0b13c88b3c1001f1a968c8925716fac
              • a
                • 50b47d9faec1001f1a968c8925716fac
              • a4
                • f04b5937b3c1001f1a968c8925716fac
              • a7
                • b077a4e3a7c1001f13c7f5de4bcffe65
                • c015c5c9a7c1001f13c7f5de4bcffe65
              • aa
                • 70c9a82aaac1001f1a968c8925716fac
              • ab
                • 40411937a9c1001f13c7f5de4bcffe65
                • 60a56b00aac1001f13c7f5de4bcffe65
              • ad
                • 30ea3d88b3c1001f1a968c8925716fac
                • c0125bd6adc1001f1a968c8925716fac
              • ae
                • 9088be77aec1001f1a968c8925716fac
                • b0205b37b3c1001f1a968c8925716fac
              • af
                • d02d5234b0c1001f1a968c8925716fac
              • b
                • 007b4155aac1001f1a968c8925716fac
              • b0
                • 10ec9ae1a7c1001f13c7f5de4bcffe65
              • b2
                • 00a8ed4ab3c1001f1a968c8925716fac
              • b4
                • 6066b6b2afc1001f1a968c8925716fac
              • b5
                • 00caa2e3a7c1001f13c7f5de4bcffe65
              • b9
                • 70880d57aac1001f1a968c8925716fac
              • bb
                • 00e5fa3dadc1001f1a968c8925716fac
                • 10ec7f9ba9c1001f13c7f5de4bcffe65
              • bc
                • 0062bfe8a7c1001f13c7f5de4bcffe65
                • 2077bd77aec1001f1a968c8925716fac
              • c1
                • b04742a1aec1001f1a968c8925716fac
                • e0480641b0c1001f1a968c8925716fac
              • c2
                • 1052e020a9c1001f13c7f5de4bcffe65
                • d008d497aec1001f1a968c8925716fac
              • c5
                • 10fc93bfa7c1001f13c7f5de4bcffe65
              • c6
                • 207294e3a7c1001f13c7f5de4bcffe65
              • c7
                • 40840f57aac1001f1a968c8925716fac
              • c8
                • 900a53d4a9c1001f13c7f5de4bcffe65
                • c0bc1057aac1001f1a968c8925716fac
              • c9
                • 40a743a1aec1001f1a968c8925716fac
                • d0cce481aec1001f1a968c8925716fac
              • ca
                • 3066bde8a7c1001f13c7f5de4bcffe65
              • cb
                • 908ae120a9c1001f13c7f5de4bcffe65
              • cc
                • c02d0a1aaac1001f1a968c8925716fac
                • f08df0d5a9c1001f13c7f5de4bcffe65
              • d0
                • 2085eb4ab3c1001f1a968c8925716fac
              • d3
                • 000c5248a7c1001f13c7f5de4bcffe65
              • d5
                • a08c0b57aac1001f1a968c8925716fac
              • d6
                • 80e0ee4ab3c1001f1a968c8925716fac
              • d8
                • 20d0e3bfafc1001f1a968c8925716fac
              • d9
                • b0f4a62aaac1001f1a968c8925716fac
                • f06d2b69a6c1001f13c7f5de4bcffe65
              • dc
                • c0aece7aaec1001f1a968c8925716fac
              • e0
                • 80db5334b0c1001f1a968c8925716fac
              • e1
                • 00c31337a9c1001f13c7f5de4bcffe65
              • e3
                • 8081dc20a9c1001f13c7f5de4bcffe65
              • e5
                • 507e1d72aec1001f1a968c8925716fac
              • e6
                • 704b50d4a9c1001f13c7f5de4bcffe65
              • e7
                • 106559d6adc1001f1a968c8925716fac
              • e8
                • c0006f00aac1001f13c7f5de4bcffe65
                • c037f174aec1001f1a968c8925716fac
              • e9
                • a091b4b2afc1001f1a968c8925716fac
              • ea
                • 408e846ba8c1001f13c7f5de4bcffe65
              • eb
                • c08496bdafc1001f1a968c8925716fac
              • ec
                • 702d55d4a9c1001f13c7f5de4bcffe65
              • f1
                • b019ad2db3c1001f1a968c8925716fac
                • f0dc3a88b3c1001f1a968c8925716fac
              • f4
                • 50225a48a7c1001f13c7f5de4bcffe65
              • f7
                • 4076cd7aaec1001f1a968c8925716fac
              • f8
                • b0d6ab2aaac1001f1a968c8925716fac
              • fb
                • 10fda6b2afc1001f1a968c8925716fac
            • .projects
              • Arduino
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
                • .markers
              • BlinkenLights
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
            • .root
              • .indexes
                • history.version
                • properties.index
                • properties.version
              • 3.tree
            • .safetable
              • org.eclipse.core.resources
          • org.eclipse.core.runtime
          • org.eclipse.debug.core
          • org.eclipse.debug.ui
          • org.eclipse.epp.usagedata.recording
          • org.eclipse.equinox.p2.ui
          • org.eclipse.ltk.core.refactoring
          • org.eclipse.mylyn.bugzilla.core
          • org.eclipse.mylyn.tasks.ui
          • org.eclipse.team.cvs.core
          • org.eclipse.ui.intro
          • org.eclipse.ui.workbench
        • version.ini
      • Arduino
      • BlinkenLights
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */

/*
  Part of the Wiring project - http://wiring.uniandes.edu.co

  Copyright (c) 2004-05 Hernando Barragan

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
  
  Modified 24 November 2006 by David A. Mellis
*/

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdio.h>

#include "WConstants.h"
#include "wiring_private.h"

volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;

#if defined(__AVR_ATmega8__)
#define EICRA MCUCR
#define EIMSK GICR
#endif

void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
    intFunc[interruptNum] = userFunc;
    
    // Configure the interrupt mode (trigger on low input, any change, rising
    // edge, or falling edge).  The mode constants were chosen to correspond
    // to the configuration bits in the hardware register, so we simply shift
    // the mode into place.
      
    // Enable the interrupt.
      
    switch (interruptNum) {
#if defined(__AVR_ATmega1280__)
    case 2:
      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
      EIMSK |= (1 << INT0);
      break;
    case 3:
      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
      EIMSK |= (1 << INT1);
      break;
    case 4:
      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
      EIMSK |= (1 << INT2);
      break;
    case 5:
      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
      EIMSK |= (1 << INT3);
      break;
    case 0:
      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
      EIMSK |= (1 << INT4);
      break;
    case 1:
      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
      EIMSK |= (1 << INT5);
      break;
    case 6:
      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
      EIMSK |= (1 << INT6);
      break;
    case 7:
      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
      EIMSK |= (1 << INT7);
      break;
#else
    case 0:
      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
      EIMSK |= (1 << INT0);
      break;
    case 1:
      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
      EIMSK |= (1 << INT1);
      break;
#endif
    }
  }
}

void detachInterrupt(uint8_t interruptNum) {
  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
    // Disable the interrupt.  (We can't assume that interruptNum is equal
    // to the number of the EIMSK bit to clear, as this isn't true on the 
    // ATmega8.  There, INT0 is 6 and INT1 is 7.)
    switch (interruptNum) {
#if defined(__AVR_ATmega1280__)
    case 2:
      EIMSK &= ~(1 << INT0);
      break;
    case 3:
      EIMSK &= ~(1 << INT1);
      break;
    case 4:
      EIMSK &= ~(1 << INT2);
      break;
    case 5:
      EIMSK &= ~(1 << INT3);
      break;
    case 0:
      EIMSK &= ~(1 << INT4);
      break;
    case 1:
      EIMSK &= ~(1 << INT5);
      break;
    case 6:
      EIMSK &= ~(1 << INT6);
      break;
    case 7:
      EIMSK &= ~(1 << INT7);
      break;
#else
    case 0:
      EIMSK &= ~(1 << INT0);
      break;
    case 1:
      EIMSK &= ~(1 << INT1);
      break;
#endif
    }
      
    intFunc[interruptNum] = 0;
  }
}

/*
void attachInterruptTwi(void (*userFunc)(void) ) {
  twiIntFunc = userFunc;
}
*/

#if defined(__AVR_ATmega1280__)

SIGNAL(INT0_vect) {
  if(intFunc[EXTERNAL_INT_2])
    intFunc[EXTERNAL_INT_2]();
}

SIGNAL(INT1_vect) {
  if(intFunc[EXTERNAL_INT_3])
    intFunc[EXTERNAL_INT_3]();
}

SIGNAL(INT2_vect) {
  if(intFunc[EXTERNAL_INT_4])
    intFunc[EXTERNAL_INT_4]();
}

SIGNAL(INT3_vect) {
  if(intFunc[EXTERNAL_INT_5])
    intFunc[EXTERNAL_INT_5]();
}

SIGNAL(INT4_vect) {
  if(intFunc[EXTERNAL_INT_0])
    intFunc[EXTERNAL_INT_0]();
}

SIGNAL(INT5_vect) {
  if(intFunc[EXTERNAL_INT_1])
    intFunc[EXTERNAL_INT_1]();
}

SIGNAL(INT6_vect) {
  if(intFunc[EXTERNAL_INT_6])
    intFunc[EXTERNAL_INT_6]();
}

SIGNAL(INT7_vect) {
  if(intFunc[EXTERNAL_INT_7])
    intFunc[EXTERNAL_INT_7]();
}

#else

SIGNAL(INT0_vect) {
  if(intFunc[EXTERNAL_INT_0])
    intFunc[EXTERNAL_INT_0]();
}

SIGNAL(INT1_vect) {
  if(intFunc[EXTERNAL_INT_1])
    intFunc[EXTERNAL_INT_1]();
}

#endif

/*
SIGNAL(SIG_2WIRE_SERIAL) {
  if(twiIntFunc)
    twiIntFunc();
}
*/

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NVIDIA India
India India
I am a software engineer by profession and an electronics engineer by education. Used to be (and still am) a hobby programmer, an electronics enthusiast/DIYer etc.

Some areas which interest me are...compiler construction, operating systems, robotics, science in general etc

Comments and Discussions