We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I am sure this a newbie question but I don't know where I can find the answer.
I don't know how to change a variable inside an interrupt I've created.
The problem is that keil give an error of non-defined for any variable wich I modified inside my interrupt function that I've declared on the main program.
I've proved to create the same variabble inside the function interrupt code but it gives another error.
Can anyone tell me how you can create a variable that can be modified in the interrupt function and in the main program?
Thanks.
volatile char my_variable;
Optionally specify if it should be stored in idata, data, xdata, ...
Should always be volatile if modified by an interrupt handler, so the normal code will retrieve the changes instead of trying to cache the variable in a register.
As you can see, there is nothing magic with a variable declaration, so in this case, I would recommend that you post your code, so people can see what is wrong with it.
Just remember to read the posting instructions for code. And avoid using tab characters - indent with space.
It's pretty certain that interrupts have nothing to with that, actually. What you don't know is how to share a variable between different functions, or between different source files.
For more specific answers, you'll have to ask a better question. Instead of
keil give an error
you have to show that error message, verbatim. And you'll have to show what your code actually looks like. Reduce it to the smallest compilable example case that still shows your problem.