PDA

View Full Version : help in interrupt,mega8



vibhorkhanna
05-14-2006, 07:35 PM
hi all,
i m planning to blink an led using timer0 overflow interrupt and use this to extend it later....
but i m not able to do so....the interrupt works just once.....
below is the code....... i m using c and compiling using winavr

#include <avr\io.h>
#include<avr\interrupt.h>
#include<avr\signal.h>

void init(void)
{
TIMSK=0x01;
TCCR0=0x05;
TCNT0=0x00;
DDRB=0xff;
PORTB=0x00;
sei();
}
SIGNAL (SIG_OVERFLOW0)
{
TCNT0=0x00;
PORTB|=~(1<<PB1);
cbi(TIFR, TOV0);
//sei();
}

int main( void )
{
init();
while(1)
{
}

}

i commented out cbi() instruction but still to no change

pls ...help

devpriya
05-15-2006, 04:25 PM
First of all for blinking why dont you use XOR, so the code becomes PORTB^=0xff;

Now for the interrupt now triggering again ummmmmm....... well i am not seeing any probs there ...... are you compiling it for the correct microcontroller ? I hope you are doing it right.

Do one more thing , may be it sounds wierd but change the order in which you initialize the registers

TCNT0=0x00;
TCCR0=0x05;
TIMSK=0x01;
asm("SEI");

Use only interrupt.h and remove signal.h , you dont need both of them together.

And one more thing, you need not clear the flags manually inside the overflow routine, so dont worry about that, just remove that piece of code from there.

You try this while i will run your code in my STK500 and see what happens


:D