Declarations


GENERAL,

In the declaration part is where you assign value to names. This makes the whole program a bit more readable.These are so called "constant declarations".
You also use this area to declare "global variables". Which means that those names are available through the whole program. You also can have "local variables" but they have to be declared into the function itself


/* Constant Declarations for PFC Shutter & Filter Control Unit               */

#define Nack           0x15              /* Used for communications with Mom */
#define Ack            0x06
/*****************************************************************************/
/* Signal Definitions For Driving the Electronics                            */
/*****************************************************************************/
#define gate           0x1b0
#define Reset          0x0              /* All bits on Port 1 Low            */
#define Enable         0x1              /* Set Enable Bit on Port 1 High     */
#define Mux            0x2              /* Set Mux Bit on Port 1 High        */
#define PSnot          0x4              /* Set PS Bit on Port 1 High         */
#define RSTnot         0x8              /* Set RST Bit on Port 1 High        */
#define PSandRWlow     0xf3             /* PS and R/W low rest high          */
#define PSLow          0xf7             /* PS bit Low on port 1              */
#define RWNot          0xfb             /* R/W bit low                       */
#define MuxLow         0xfd             /* Mux bit low on port 1             */
#define EnableNot      0xfe             /* Enable Bit Low                    */
#define ShutterAddress 0x40             /* The Address where the board is    */
#define FilterAddress  0x41             /*  "     "      "    "    "    "    */
#define DetentAddress  0x50
#define SwitchAddress  0x60
/*****************************************************************************/
/* Command Definitions Form LM628                                            */
/*****************************************************************************/
#define RESET          0x00            /* Resets the LM628                   */
#define PORT8          0x05            /* Sets output port to 8-bits         */
#define PORT12         0x06            /* Sets output port to 12-bits        */
#define DFH            0x02            /* Define Home                        */
#define SIP            0x03            /* Set Index Position                 */
#define LPEI           0x1b            /* Load Position Error For Interrupt  */
#define LPES           0x1a            /* Load Position error for Stopping   */
#define SBPA           0x20            /* Set BreakPoint Absolute            */
#define SBPR           0x21            /* Set BreakPoint Relative            */
#define BPR            0x25            /* Sys can ask Breakpoint Values      */
#define MSKI           0x1c            /* Mask Interrupt                     */
#define RSTI           0x1d            /* Reset Interrupt                    */
#define LFIL           0x1e            /* Load Filter Parameters             */
#define UDF            0x04            /* Update Filter                      */
#define LTRJ           0x1f            /* Load Trajectory Parameters         */
#define STT            0x01            /* Start Motion Control               */
#define RDSIGS         0x0c            /* Read Signal Register               */
#define RDIP           0x09            /* Read Index Position                */
#define RDDP           0x08            /* Read Desired Position              */
#define RDRP           0x0a            /* Read Real Position                 */
#define RDDV           0x07            /* Read Desired Velocity              */
#define RDRV           0x0b            /* Read Real Velocity                 */
#define RDSUM          0x0d            /* Read Integration Summation Value   */
/*****************************************************************************/
/* Commands Defining Communications with SYS                                 */
/*****************************************************************************/
#define Micro         0x01             /* Micro as whole message             */
#define ShutterWheel  0x02             /* Shutter Wheel Service Message      */
#define FilterWheel   0x04             /* Filter Wheel Service Message       */
#define Detent        0x08             /* Detent Service Message             */
#define FilterSwitch  0x10             /* Filter Micro Switch Service Mess   */
#define ExposureTime  0x20             /* Exposure Timing Mech. Message      */
#define FilterAccess  0x40             /* Filter Door Access Message         */
/*****************************************************************************/
/* Sub. Commands belonging to message above                                  */
/* Sub. Commands for the LM device to be taken from above                    */
/*****************************************************************************/
#define RST            0x01            /* Reset for Micro as whole           */
#define ZeroSet        0x02            /* Zeroset for Micro as whole         */
#define Syn            0x04            /* Synchronice for Micro as whole     */
#define In_Det         0x02            /* In command for Detent              */
#define Out_Det        0x01            /* Out command for Detent             */
#define State_Det      0x04            /* Status Request for Detent          */
#define State_Switch   0x01            /* Status Request Filter Switches     */
#define State_Filt     0x01            /* Status Request Filter Door         */
#define Guard          0x02            /* Guarding the FIlter Door           */
#define Define         0x01            /* Define for Exposure Timing         */
#define Zero           0x02            /* Zero timing command for Timing     */
#define State_Ex       0x04            /* State Request Command for Timing   */
#define Test           0x08            /* Test for reading THTL2 + Calc      */

#define ActToShutter 1
#define ActToFilter  2
#define ShutterToAct 3
#define FilterToAct  4

/* Variable Declarations for PFC Shutter & Filter Control Unit               */

   struct servosetting
   {
    long          acc, vel, pos, breakpoint, reavel, desvel,
                  index, desired, realpos;
    int           intsum, whichload;
    unsigned int  kp, ki, kd, il, sigs;
    unsigned char dersample;
   }xdata act;

   struct servosetting xdata filter, xdata shutter;
   struct servosetting xdata *helppointer1,
                             *helppointer2;

   unsigned char xdata ShutOpenPos [4];
   unsigned char xdata ShutClosePos [4];

   unsigned long xdata ExposureTimingOpen, ExposureTimingClose;
   unsigned long xdata ShutOpenVal, ShutCloseVal, ShutOpenPulses, ShutClosePulses;

   struct ReceiveData
   {
    unsigned char ControlByte [1];
             char MechName    [1];
             char MechAction  [1];
    unsigned char Argument   [14];
    unsigned char CheckSum    [1];
   }xdata ReceivedInfo;


   struct SendData
   {
             char ACK         [1];
    unsigned char Argument   [14];
    unsigned char CheckSum    [1];
   }xdata SendInfo;


   unsigned char xdata status,
                 xdata switches,
                 xdata detentstatus;

   int xdata SignalData,
       xdata Address;
       xdata ReceiveStatus;
       xdata TransMitStatus;
       xdata TimeOut;
       xdata Guarding;
       xdata MessageRec;
       xdata FiltDoorOpen;
       xdata InterruptCnt;
       xdata TimeOutSet;
       xdata NumbOfChars;
       xdata OpenFlag;
       xdata PulsShutter;
       xdata PulsFilter;


   unsigned long xdata  THTL2, HelpVariable, Help;

/* Function Declarations                                                     */

   void stscpy (int direction);
   void Time_Out(void);
   void Shutter_Timing_Open_Close (void);
   void Write_Command (int);
   void Write_Address (void);
   void Write_Data (int NumberWrites, unsigned char Data[14]);
   void Write_Byte (int DataOut);
   void Read_Data_LM628 (int NumbersReads, unsigned char inputdata[4]);
   void Read_Data (int NumbersReads, unsigned char inputdata[4]);
   void Read_Detent_Status (void);
   void Read_Switches(void);
   unsigned char Read_Status   (void);
   int  Shutter_Timing (void);
   void Receive_Char (void);
   void TransMit_Char (int CharsToSend);
   void Clear_SendInfo(void);
   void Clear_ReceivedInfo(void);
   void SubInterp_Message(void);
   unsigned char Calc_CheckSum(char *);
   void Calc_Degree_Pulses(void);
   void Calc_Degree_Pulses_F_W (void);
   void One_Turn_Pulses(void);
   int  Shutter_Wheel (void);
   int  Position_Server (void);
   int  Filter_Wheel (void);
   void Detent_Task (int In_Out);
   void Turn_Off_Ltrj(void);
   void Pos_Ltrj(void);
   void Ltrj(void);
   void Find_Index(void);
   int  Monitor_Mode_Server (void);
   void Sys_Req_Init(void);
   void Init_System_Task (void);
   int  Index_Bit (void);
   void Server_Shutter (void);
   void Server_Timing (void);
   void main (void);                           /* know "C" knowing why       */
/*****************************************************************************/
/* Next Functions Deal With Commands To/From the LM 628                      */
/*****************************************************************************/
   void ReSet  (void);                          /* Initialse Reset LM628     */
   void Port8  (void);                          /* Select 8 bit output       */
   void Port12 (void);                          /* Select 12 bit output      */
   void Dfh    (void);                          /* Define Home               */
   void Sip    (void);                          /* Set Index Position        */
   void Lpei   (void);                          /* Interrupt on error        */
   void Lpes   (void);                          /* Stop on error             */
   void Sbpa   (void);                          /* Set Breakpoint Absolute   */
   void Sbpr   (void);                          /* Set Breakpoint Relative   */
   void Mski   (void);                          /* Mask Interrupt            */
   void Rsti   (void);                          /* Reset Interrupt           */
   void Lfil   (void);                          /* Load Filter Parameters    */
   void Udf    (void);                          /* Update Filter             */
   void Ltrj   (void);                          /* Load Trajectory           */
   void Stt    (void);                          /* Start Motion              */
   void Rdstat (void);                          /* Read Status Byte          */
   void Rdsigs (void);                          /* Read Signal Register      */
   void Rdip   (void);                          /* Read Index Position       */
   void Rddp   (void);                          /* Read Desired Position     */
   void Rdrp   (void);                          /* Read Real Position        */
   void Rddv   (void);                          /* Read Desired Velocity     */
   void Rdrv   (void);                          /* Read Real Velocity        */
   void Rdsum  (void);                          /* Read Integration Sum      */

Back to Index Page.