William Chops Westfield wrote: >On Dec 7, 2005, at 12:24 AM, Stephen D. Barnes wrote: > > > >>If an embedded main() never terminates, >>why is the software reset occurring? >> >> > >A C compiler inserts code in your program that does initialization >(the "crt0" that someone mentioned), calls main() as a function with >the appropriate arguments (if any), and then cleans up. In this case, >"cleaning up" apparently means executing a software reset instruction, >which is not at all a bad idea (if your processor HAS a reset >instruction!) > >You should be able to see this by disassembling the code... > > > > >>how do I keep the "main program loop" running. >> >> > >It depends on what you want it to do. Most embedded programs will >have a natural loop that just never happens to exit. You can >add one artificially if you want: > > main() { > while (1) { > /* > * lots of code > */ > } > } > >Or you can define a routine or loop at the end of your program >that does something specific OTHER than randomness: > > main() { > /* > * Lots of code > */ > while (1); /* Done; sit in tight loop forever */ > } > >BillW > > Now I understand! Thanks. Can you clarifiy what you mean by "Most embedded programs will have a natural loop that just never happens to exit"? -- Regards, Stephen D. Barnes -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist