Forum: µC & Digital Electronics Pin Change Interrupt - External Interrupt with Internal Interrupt

Author: Nice Chai (crazyinterrupts)
Posted on:

Rate this post
0 useful
not useful
Here in the program, am cycling through LEDs using timer interrupt & if 
someone presses a switch, it should stop the first interrupt & trigger 
second one that should lit the led according to the switch pressed. 
Here, am a little confused which interrupt is being called. I referred 
some books for Pin Change Interrupt & wrote a few lines for setting 
PCMSK2. The output am getting is "initially all leds are cycling, when a 
switch is pressed...cycling of leds stops & starts over again (which 
means that program is reading input, just not triggering the second 
interrupt). It doesn't stop or pause & doesn't lit subsequent led." 
Could anyone help, please?

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

volatile unsigned int intrs, i=1;

void enable_ports(void);
void delay(void);

extern void __vector_23 (void) _attribute_ ((interrupt));

extern void __vector_25 (void) _attribute_ ((signal));

void enable_ports()
    DDRB = 0xff;   //PORTB as output for leds

    PORTB = 0xff;

    DDRK = 0x00;  //PORTK as input from switches


    PCMSK2 = PINK_MASK;     //ENABLE PCMSK2, Setting interrupts

    PCICR = 0x04;

    PCIFR = 0x04;

    TCCR0B = 0x03;      //Setting TIMER

    TIMSK0 = 0x01;

    TCNT0 = 0x00;

    intrs = 0;
void __vector_23 (void)
    if(intrs > 60)
        intrs = 0;
        PORTB = (0xff<<i);

        i++ ;
        if(i == 10 )
            PORTB = 0xff;
            i = 1 ;

void __vector_25 (void)
    unsigned char switches;

    switches = ((~PINK) & (PINK_MASK)); //Reading from switches

    if(switches & (1<<PINK0))
        PORTB = (PORTB<<PINK0);

    else if (switches & (1<<PINK1))
        PORTB = (PORTB<<PINK1);

    else if (switches & (1<<PINK2))
        PORTB = (PORTB<<PINK2);

    else if (switches & (1<<PINK3))
        PORTB = (PORTB<<PINK3);

    else if (switches & (1<<PINK4))
        PORTB = (PORTB<<PINK4);

    else if (switches & (1<<PINK5))
        PORTB = (PORTB<<PINK5);

    else if (switches & (1<<PINK6))
        PORTB = (PORTB<<PINK6);

    else if (switches & (1<<PINK7))
        PORTB = (PORTB<<PINK7);

int main(void)




Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.