Results 1 to 2 of 2

Thread: help in interrupt,mega8

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2005
    Location
    New Delhi
    Posts
    11

    Default help in interrupt,mega8

    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

  2. #2
    Senior Member Cyborg devpriya's Avatar
    Join Date
    Jul 2005
    Location
    Seattle, WA, USA
    Posts
    275

    Default

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •