Electronic – Blinking led using interrupts in AVR

avrinterrupts

I want to learn how to work with interrupts and I have done my first try.

I have done a very simple circuit based on ATtiny13.

There's a led in PB1 and a button in PB3. When the button is pressed, PB3 pin change its state from low level to high level, this produces an external interrupt. The code of this interrupt, makes the led turn on for 500ms.

schematic

This is my code, what's wrong here? I'm getting this warning:

'PCINT3_vect' appears to be a misspelled signal handler, missing
__vector prefix [-Wmisspelled-isr]

What's wrong here?

#define F_CPU 9600000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

ISR(PCINT3_vect)
{
        PORTB |= (1<<PB1);
        _delay_ms(500);
        PORTB &= ~(1<<PB1);
        _delay_ms(500);
}

void SystemInit(void)
{
        PCMSK |= (1<<PCINT3);   // pin change mask: listen to portb, pin PB3
        GIMSK |= (1<<PCIE); // enable PCINT interrupt
        sei();          // enable all interrupts

}

int main(void)
{       
    DDRB |= (1<<PB1);
    DDRB |= (1<<PB3);
    SystemInit();

    while (1) 
    {       
    }
}

Thanks guys!

Best Answer

This is the ATTiny13's interrupt vector table.

enter image description here

PCINT3 is not an interrupt vector. You need to change that to PCINT0. It looks like you have the PCI and mask set properly. You should be able to make that change and have your interrupts work. You also need to add initialization to make your push button work.

DDRB |= (0<<PB3); //Pushbutton input
PORTB |= (1<<PB3); //Enable Pushbutton pull-up
DDRB |= (1<<PB1); //LED output

That will enable the internal pull-up and allow an edge to happen on a button press. This will likely work for simulation, but a real circuit will need some debounce either in hardware or software.