Hi Joshi,
from your description, I wonder the problem is due to variable optimization.
Optimization problem commonly exists in embedded C language design. Sometimes, the Codewarrior compiler considers some variables or codes not used, so it optimizes the associating codes. We can disable some optimization but we can’t disable all the optimization.
There are three methods normally used to avoid optimization:
Solution 1: set compiler optimization settings.
Go to ALT+F7, “Compiler for HC12”, “Options”, “Optimization”, there are list of compiler optimization you can choose to disable

Solution 2: use keyword “volatile” to prevent the local variable optimized The common way for us to prevent compiler optimize variable is to add key word “volatile”, for example:
Volatile int var_name;
This will prevent var_name to be optimized.
Solution 3: prevent global variable or function optimized. If a variable or function is never used by program, it may be optimized by compiler. In this case, we need take use of “ENTRIES”.
in prm file, there is a section called “ENTRIES”, insert the global variables or functions into this section can avoid they optimized by compiler. For example,
ENTRIES
var1 var2 func1 func2
END
Thus variable var1, var2 and function func1,func2 will not be optimized by compiler.
can this help?
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------