4.4.3 How Do I Share Data Between Interrupt and Main-line Code?

Variables accessed from both interrupt and main-line code can easily become corrupted or misread by the program. The volatile qualifier tells the compiler to avoid performing optimizations on such variables. This will fix some of the issues associated with this problem.

Other issues arise because the way variables are accessed can vary from statement to statement. Therefore it is usually best to avoid these issues entirely by disabling interrupts prior to the variable being accessed in main-line code, then to re-enable the interrupts afterwards. For more information on these solutions, see the following sections of this user’s guide:

9.8.2 Volatile Type Qualifier

15.6 Enabling/Disabling Interrupts - dsPIC33C/E/F and dsPIC30 Devices Only [DD]