l am designing an interrupt based number counter which shows the values as they increment on 8 LEDs using an atmega32. My problem is my ISR(interrupt service routine)is not able to light up the LEDs as l increment from INT0below is the code l made, only the ISR is not lighting the LEDs
Asked
Active
Viewed 141 times
-1
-
https://stackoverflow.com/help/how-to-ask – 0___________ May 12 '21 at 17:21
-
**DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob May 12 '21 at 17:34
1 Answers
0
In SR
, the count
variable is on the stack. Its value does not persist across invocations.
Here is your original code [with annotations]:
SR(INT0_vect)
{
DDRA = 0xFF;
// NOTE/BUG: this is on the stack and is reinitialized to zero on each
// invocation
unsigned char count = 0;
// NOTE/BUG: this will _always_ output zero
PORTA = count;
// NOTE/BUG: this has no effect because count does _not_ persist upon return
count++;
return;
}
You need to add static
to get the value to persist:
void
SR(INT0_vect)
{
DDRA = 0xFF;
static unsigned char count = 0;
PORTA = count;
count++;
}

Craig Estey
- 30,627
- 4
- 24
- 48