??? 09/07/07 17:06 Read: times |
#144125 - How microcontroller programs end (or don't) Responding to: ???'s previous message |
Prateek said:
So could this be the reason, (END at the end of the code) that any program i write runs in an infinte loop??? I'm not sure I understand your question, but maybe I can answer it anyway. First of all, please read this: http://www.8052.com/faqs.phtml?FAQ=143904 As the FAQ says, if you want your program to "stop", you must put intentionally put it into an infinie loop. by putting at the end something like this: stop: sjmp stop ; Loop here foreverif you are writing in assembly language, or this: while (1) ; /* Loop here forever */if you are writing in C. However, most microcontroller programs are not supposed to stop. They are supposed to run forever until the power is removed. To make that work, you run the entire program inside an infinite loop, like this: top: ; Do everyting here jmp top ; Go do everything againif you are writing in assembly language, or this: while (1) { /* Loop forever */ /* Do everything here */ } /* End 'loop forever' */if you are writing in C. If you do not intentionally put your program into an infinite loop, then when it "runs off the end", the processor will try to execute whatever is in the code space immediately after your program. If that memory contains all 0xFFs, as it would in an unprogrammed flash device or EPROM, the processor will execute to the end of the memory. At that point it may wrap back around to address zero and start your program over again (sort of) as though a reset had occurred. Or it may not! In any case, you should never let your program "run off the end". You should always code an explicit infinite loop to make it behave the way you want it to. -- Russ |
Topic | Author | Date |
Assembler Directive DB | 01/01/70 00:00 | |
Hmmm... Looks suspiciously like... | 01/01/70 00:00 | |
see the list file | 01/01/70 00:00 | |
movbe the db's to the end | 01/01/70 00:00 | |
Formatted again | 01/01/70 00:00 | |
highlight | 01/01/70 00:00 | |
What do you mean? | 01/01/70 00:00 | |
Keil DB syntax | 01/01/70 00:00 | |
I think i found the problem | 01/01/70 00:00 | |
you don't need to do that... | 01/01/70 00:00 | |
You are Right | 01/01/70 00:00 | |
Another Bug found | 01/01/70 00:00 | |
What is the crystal frequency? | 01/01/70 00:00 | |
I doubt it | 01/01/70 00:00 | |
Another Mode Added ,19200 problem solved | 01/01/70 00:00 | |
how do you mean this? | 01/01/70 00:00 | |
Couldnt get your query | 01/01/70 00:00 | |
END is not an instruction | 01/01/70 00:00 | |
END is not an instruction!!! | 01/01/70 00:00 | |
Got the point ; query about program loop | 01/01/70 00:00 | |
How microcontroller programs end (or don't) | 01/01/70 00:00 | |
Alternative to infinite loop | 01/01/70 00:00 | |
what is an infinite loop? | 01/01/70 00:00 | |
That must be the reason...![]() | 01/01/70 00:00 |