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 PORTK |= PINK_MASK; 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) { intrs++; if(intrs > 60) { intrs = 0; PORTB = (0xff<<i); i++ ; if(i == 10 ) { PORTB = 0xff; i = 1 ; } } sei(); } 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) { enable_ports(); sei(); while(1) { } }
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.