> When I simulate the following code in MPLAB, > > int test; > /************* START OF MAIN FUNCTION ***************/ > int main ( void ) > { > test = 1; > while (test < 10) > { > test ++; > } > } > > when the last bracket is reached, a software reset occurs. Why? In a "normal" C environment, main() is "called" by the overlying operating system and there is an implied return following the end of main(). Roughly, this is handled through cooperation between the operating system's process creation and the C run-time library. An embedded system does not have an overlying operating system (usually, Microchip certainly doesn't provide one). At the end of main(), the C run-time has only two choices: (1) branch to the CPU's reset vector or (2) continue executing instructions (random bit patterns that may frequently be 0xFF) that follows main() in memory. Apparently, MPSIM chose to branch to the reset vector. Lee Jones -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist