I have an 8051 MCU which I use keil to program it with C. My problem is that the micro-controller restarts at the end of some functions while they should return.
Using a debugger I tried to check it line by line. And I figured out the the MCU is not restated right after the end of the function. The PC(progam counter) goes to somewhere else (sometime somewhere that there is not any code to execute) and then it increases one by one until the end of code. It is very strange for me because I write my code in C and never seen the type of error previously.
I think this problem might be related to the compiler settings and thus I post the settings here:
Assembler settings: XR GEN DB EP NOMOD51
Compiler settings: DB OE BR LARGE OPTIMIZE(11, SIZE) DEFINE(SILABS_PLATFORM_WMB912) DEFINE(SILABS_WMCU_SI106x)
Linker settings: CODE REMOVEUNUSED CLASSES(BIT(0x20.0-0x2F.7), DATA(D:0-D:0x7F), IDATA(I:0-I:0xFF), XDATA(X:0-X:0xFFF), CODE(C:0-C:0xFBFF), CONST(C:0-C:0xFBFF))
I tried both large and small settings but the problem remains. Kindly help me if you know the reason.