Go Down

Topic: Interrupts and include headers (Read 768 times) previous topic - next topic

tubos

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 ?

PaulS

Change stuff from what version?

tubos

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

PaulS

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.

tubos

#4
Aug 17, 2011, 05:50 pm Last Edit: Aug 17, 2011, 09:08 pm by tubos Reason: 1
Here ya go :)
Code: [Select]

// 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
}


PaulS

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.

tubos


Go Up