This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can I use a global variable in the Interrupt routine?

The variable is defined in *.h:

static unsigned char cPwLe[3] = {0};

Its value is changed in the Main():
cPwLe[cCh] = Power_Level(cP[cCh]);  //Here  value is right

Its value is transfered to T0 Interrutpt service routine:
cPower = cPwLe[cCh]; //Here value is  always 0

How can I correct the errors?
Thanks all!

Parents
  • It's called a global variable because it's recognized almost everywhere, just like your American express card. The danger is modifying it in an isr and using it several places in main loop code assuming it is doesn't get modified between reads. It usually leads to much hair-pulling and cursing.

Reply
  • It's called a global variable because it's recognized almost everywhere, just like your American express card. The danger is modifying it in an isr and using it several places in main loop code assuming it is doesn't get modified between reads. It usually leads to much hair-pulling and cursing.

Children