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
  • The variable is defined in *.h:

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

    That "static" is an error. This keyword should quite exactly never appear in a header file. Please refer back to your C textbook to understand what it does, and why that's not what you want to do, here.

    Furthermore, you should never define a variable in a header file, either. It may only be declared there. If the distinction between these two terms isn't clear to you, stop what you're doing right now, and get back to that C textbook.

Reply
  • The variable is defined in *.h:

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

    That "static" is an error. This keyword should quite exactly never appear in a header file. Please refer back to your C textbook to understand what it does, and why that's not what you want to do, here.

    Furthermore, you should never define a variable in a header file, either. It may only be declared there. If the distinction between these two terms isn't clear to you, stop what you're doing right now, and get back to that C textbook.

Children
More questions in this forum