Pages: [1]   Go Down
Author Topic: Interrupts and include headers  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have arduino 022 and I'm using some interrupt function
when I disable //#include <avr/interrupt.h > in my sketch
It still compiles fine.

Is it automatically loading or did they change stuff in 022 ?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46213
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change stuff from what version?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually the question should be why does it work without the header file?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46213
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm using some interrupt function
when I disable //#include <avr/interrupt.h > in my sketch
It still compiles fine.

Quote
Actually the question should be why does it work without the header file?

Without seeing the sketch, any answer would just be guesswork.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here ya go smiley
Code:
// Blink Led using Timer2 Overflow interrupt
//#include <avr/interrupt.h >
//#include <avr/io.h >
#define PS1024 0x07 // Prescaler 1024

volatile int Iscaler = 0;
int ledpin= 7 ;                                         // Change this for your led default=13
volatile int state = 0;

// 16 Mhz / 1024 / 256 is Iscaler=61 for about 1 sec
ISR(TIMER2_OVF_vect)                                    // Timer2 Overflow interrupt
{
  Iscaler += 1;
  if (Iscaler == 61)
  {
    Iscaler = 0;                                        // Reset the counter
    state^=1;                                           // Change state for Led
    digitalWrite(ledpin,state);                         // and update the Led
  }
}

void setup() {
  pinMode(ledpin, OUTPUT);
  TCCR2A = 0;                                           // Normal mode
  TCCR2B =PS1024;                                // Timer2 Prescaler /1024
  TIMSK2 |= (1 << TOIE2);                               // Timer2 Overflow Interrupt Enable
  TCNT2 = 0;                                            // Tmr overflow 256
  sei();                                                // Enable interrupts
}

void loop()                                             // Here we can do other stuff
{                                                       // while the led keeps blinking
}

« Last Edit: August 17, 2011, 02:08:15 pm by tubos » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46213
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hold down the shift key when clicking the verify button. You will get lots more output, including the path where the temporary files are created during the compile process. One of the files will be a cpp file created from your sketch. You will be able to see what the IDE does to your sketch, including what header files it adds. Some of them include other stuff, so you may have to dig to see where interrupts.h gets included, if indeed it does.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thx for the useful tip.
Logged

Pages: [1]   Go Up
Jump to: