Hi, I don't understand the variables difference between "volatile" and not "volatile", such as "volatile char" and "char". I appreciate your help.
admin's test signature
Volatile means that the variable can change for no obvius reason to the compiler
so you instruct the compiler to actually read the contents of that variable
every time you use it in your program.
Otherwise the compiler does optimisation tricks and instead of reading the actual contents of the variable it replaces that with a copy (probably constant)
The compiler thinks " nobody is changing that variable so let's save ram and program memory by replacing it with a constant.
For example if you use that variable in an interrupt the program will not work untill
you declare that variable as volatile because the interrupt routine can change the value of the variable without the compiler knowing it.
Or it can be any hardware that interacts with the particular variable.
I hope that the above help's you.
Thank you very much, Chris. It does help me greatly.
© 2020 Microchip Technology Inc.