Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/23/06 09:17
Read: times


 
#112850 - What else would it do?
Responding to: ???'s previous message
Sanoop Thorai said:
... after the execution of the last line of the program, it starts to execute my program from the begining of the program ...

This has nothing to do with bit variables.

When you run a program on a computer system like a PC, it runs, it finishes, then it returns to the operating system (DOS, UNIX, Windoze, whatever).

On an embedded system like yours, there is no operating system; there is nothing to return to.
So, unless you specifically do something to stop it, the processor will just continue incrementing the Program Counter, fetching bytes from the CODE memory, and executing them as instructions. Eventually, it will reach the end of the CODE memory, and the next Program Counter increment will bring it right back to address 0000 - which is where it started in the first place!
And so on, ad infinitum.

Typically, an embedded system just keeps performing its function the whole time that it is switched on - so its main() function looks something like this:
void main( void )
{
   // do initialisation stuff
   :
   :

   for( ;; ) // infinite loop
   {
      // do regular stuff
      :
      :
   }
}
Some people like to call this a "Super Loop" - but that seems to me to imply that it's something special, when it isn't.

If you really want a "one-shot" system - ie, does something, then stops - its main() function would look something like this:
void main( void )
{
   // do initialisation stuff
   :
   :

   // do one-off stuff

   for( ;; ) ; // infinite loop - "hang" here
}
Rather than an infinite loop at the end, you might put the processor into some powerdown or idle mode that can only be exited by a Reset...


For an infinite loop, note that
   for( ;; );
is equivalent to
   while( 1 );


List of 12 messages in thread
TopicAuthorDate
c programming            01/01/70 00:00      
   Read the C51 user's guide            01/01/70 00:00      
      rtfm            01/01/70 00:00      
         embdd c programming            01/01/70 00:00      
            What else would it do?            01/01/70 00:00      
               Andy, why did you answer            01/01/70 00:00      
                  forgiven            01/01/70 00:00      
   bit data type            01/01/70 00:00      
      Read the error message carefullly            01/01/70 00:00      
      error message            01/01/70 00:00      
         Not too helpful            01/01/70 00:00      
            You seem not to have            01/01/70 00:00      

Back to Subject List