Main Function.


The Main function of "C" is where everything normally starts. First it calls the initialization routine. I've done that twice because of some problems I had in initialy startup. But since the program uses startup.a51 it's therefore probebly not needed any more.
After initialization is were the program goes into an forever loop. Loop for ever is done by using the statement for (;;). Ones in this loop it then first check to see if any message has been received from MCAD. If it has received an message it will executed the command before it returns into main. After it has check the message it then checks the status of the filter-door to see if it is opened or not. If the door is opened it then check for the guarding flag which also comes from MCAD. If then the door is open and the guard flag is set it then sends the LM628 command to stop the filterwheel from moving. Watch the element EAL. This bit-field is used to stop the system receiving interrupts. EAL=0 stops the interrupt mechanism and EAL=1 enables it again. Don't take these out because at those points the program is generating the control-bus signals for the electronics which never may be interrupted.


FlowChart of Main Function.



Listing Part, Main Function.


/*===========================================================================*/
/* FunctionName  : Main                                                      */
/* FunctionInput : NONE.                                                     */
/* FunctionOutput: NONE.                                                     */
/* CommonVarUse  : Address, FiltDoorOpen, detentstatus                       */
/* StructureUse  :                                                           */
/* Description   : Main is always the start_point from here we call first    */
/*               : some other functions to initialies the system.            */
/*               : After that main check the filter-door contantly to see if */
/*               : was openend or not, if open then check guard if set then  */
/*               : stop filter-wheel immediately                             */
/* LastUpdated   : ../../96 [.... Test]                                      */
/*===========================================================================*/
void main(void)
{
  Init_System_Task();                  /* Set all needed defaults            */
  for(;;)                              /* Loop for ever                      */
    {
      Interp_Message();                /* Check for any Request              */ 
      Address = DetentAddress;         /* Set Detent Board address           */
      EAL=0;                           /* No interrupts allow, elect. signals*/
      Write_Address();                 /* Write Address Bus                  */
      Read_Detent_Status();            /* Read Status of Switches            */
      EAL=1;                           /* Interrupts allowed                 */
      if(detentstatus & 0x08)          /* Check If door was opened           */
        {
         FiltDoorOpen=1;               /* If so set flag.                    */
        }
      else
        {
         FiltDoorOpen=0;               /* Else reset flag                    */
        }
      if (Guarding && FiltDoorOpen)    /* Door OPen And Guarding Set ?       */
        {
         EAL=0;                        /* Yes, then stop interrupt handling  */
         Address=FilterAddress;        /* Select Filter LM628 board          */
         Write_Address();              /* Write address bus                  */
         Turn_Off_Ltrj();              /* Turn_Off Filterwheel motor         */
         EAL=1;                        /* Interrupts allowed again.          */
        }
      EAL=1;                           /* This one is not needed             */
    }                                  /* Loop again, never getting tired    */
}

Back to Index page.