Variable in interrupt

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
(...)
sei();

uint8_t i = 0;

int main(void)
{
i = 5; // <- I WOULD LIKE TO CHANGE I-VARIABLE HERE

while(1);
}

ISR(TIMER1_COMPA_vect)
{
 PORTB = i;  //<- BUT THERE IS STILL i=0
}

What should I do, to change i-variable in ISR { } ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i needs to be declared as volatile

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ravender,

Your question suggests that maybe you haven't stumbled across the manual yet...

http://www.nongnu.org/avr-libc/u...

(see FAQ#1)