1
\$\begingroup\$

I have used ATmega 8 and have simulated a circuit to use interrupts, when i give an external interrupt i.e. when a push button is pressed all the LEDs connected to PORTB supposed to be lit up, but i am getting this error, What to do? This is the code i have used

#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#define F_CPU 4000000UL
#define DataDDR     DDRB


#define DataPort    PORTB
ISR(INT0_vect)
{
    unsigned char i, temp;

    _delay_ms(500); // Software debouncing control

    temp = DataPort;    // Save current value on DataPort

    /* This for loop blink LEDs on Dataport 5 times*/
    for(; ; )
    {

        DataPort = 0xFF;

    }

    DataPort = temp;    //Restore old value to DataPort 
}   

int main(void)
{
    DDRD = 1<<PD2;      // Set PD2 as input (Using for interupt INT0)
    PORTD = 1<<PD2;     // Enable PD2 pull-up resistor

    DataDDR = 0xFF;     // Configure Dataport as output
    DataPort = 0x01;    // Initialise Dataport to 1

    GICR = 1<<INT0;                 // Enable INT0
    MCUCR = 1<<ISC01 | 1<<ISC00;    // Trigger INT0 on rising edge

    sei();              //Enable Global Interrupt

    while(1)
    {
        if(DataPort >= 0x80)
            DataPort = 1;
        else
            DataPort = DataPort << 1;   // Shift to the left

        _delay_ms(500); // Wait 5 seconds

    }
}
\$\endgroup\$
8
  • 2
    \$\begingroup\$ Please post your code \$\endgroup\$ Apr 11, 2013 at 16:55
  • \$\begingroup\$ it's been posted, please have a look \$\endgroup\$
    – user75736
    Apr 11, 2013 at 17:11
  • 1
    \$\begingroup\$ There's no way to ever exit the interrupt handler, although I don't think that's causing your problem. \$\endgroup\$
    – pjc50
    Apr 11, 2013 at 17:59
  • \$\begingroup\$ Are you sure you compiled the program for the same controller as ISIS Proteus is configured? \$\endgroup\$
    – jippie
    Apr 11, 2013 at 20:04
  • \$\begingroup\$ yes i have cross checked that! , it is running but when an interrupt is given , it fails and shows error \$\endgroup\$
    – user75736
    Apr 11, 2013 at 20:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.