Initialization of the program contains two parts. The first part is were all the bit-field from the processor are initialized which includes channels settings, like baudrate for the serial port but also the parallel ports to state if it needs to be input or output. Information on what sort of data you have to write in these registers is availeble from with-in the Hardware section. In the first part is were the routine calls an other part so called "Sys_Req_Init();". This bit has been seperated because MCAD has the abelity to Initialize the program. Since this bit, the first part, is initializing the bit-field registers its therefore not allowed for MCAD to do this bit and therefore seperated.
/*===========================================================================*/ /* FunctionName : System Request for Initialisation */ /* FunctionInput : NONE */ /* FunctionOutput: NONE */ /* CommonVarUse : */ /* StructureUse : servosetting. */ /* Description : In here we have to Initialise various system components */ /* : and system parameters used troughout the program. */ /* : Nothing special or tricky is done, al is straith forward */ /* : */ /* LastUpdated : ../../96 [.... Test] */ /*===========================================================================*/ #pragma disable void Sys_Req_Init(void) { FiltDoorOpen=0; /* FilterDoor Is Closed */ Guarding=0; /* Guarding is Off */ TimeOut=0; TimeOutSet=0; InterruptCnt=0; PulsShutter=20; PulsFilter=40; /* Init the LM628's with default's */ /* First gone fill the Structure of Filter */ filter.acc = 10L; /* Acceleration Value (0-16383) */ filter.vel = 20000L; /* Velocity Range Value (0-16383) */ filter.pos = 0L; /* Position Range (-1073741824 +1073741823) */ filter.breakpoint = 0L; /* Breakpoint Absolute (C0000000 3FFFFFFF) */ filter.kp = 600; /* P from PID */ filter.ki = 100; /* I from PID */ filter.kd = 200; /* D from PID */ filter.il = 100; /* */ filter.dersample = 5; /* */ filter.whichload=0x0f; /* All filters to be loaded */ shutter.acc = 50L; /* Now gone fill the Structure of Shutter */ shutter.vel = 95000L; /* For explanation see above. */ shutter.pos = 0L; shutter.breakpoint = 7300L; shutter.kp = 1000; shutter.ki = 300; shutter.kd = 3000; shutter.il = 5; shutter.dersample = 5; shutter.whichload=0x0f; /* Default all filters */ act.acc = 0L; /* Now gone fill the Structure of Shutter */ act.vel = 0L; /* For explanation see above. */ act.pos = 0L; act.breakpoint = 0L; act.kp = 0; act.ki = 0; act.kd = 0; act.il = 0; act.dersample = 0; act.whichload=0x0f; /* All filters to be loaded */ Clear_SendInfo(); Clear_ReceivedInfo(); OpenFlag=2; /* Next Move to Open */ SignalData=0x18; /* Default for Electronics Signals */ P1=SignalData; Address=ShutterAddress; /* Now write this values to the LM628 */ Write_Command(Reset); /* Reset first the Electronics */ Turn_Off_Ltrj(); stscpy(ShutterToAct); lfil(); Udf(); Pos_Ltrj(); Sbpa(); Rsti(); /* Clear all Interrupts */ stscpy(ActToShutter); Address=FilterAddress; Write_Command(Reset); Turn_Off_Ltrj(); stscpy(FilterToAct); lfil(); Udf(); Pos_Ltrj(); Rsti(); stscpy(ActToFilter); return; }
/*===========================================================================*/ /* FunctionName : Init_System_Task */ /* FunctionInput : NONE */ /* FunctionOutput: NONE */ /* CommonVarUse : P1, P4, P5, PCON, ADCON. (These are Processor Reg's) */ /* StructureUse : servosetting. */ /* Description : In here we have to Initialise various system components */ /* : and system parameters used troughout the program. */ /* : Nothing special or tricky is done, al is straith forward */ /* : */ /* LastUpdated : ../../96 [.... Test] */ /*===========================================================================*/ void Init_System_Task(void) { P1 = 0; /* Set Port 1 to output, Signal Port to Elec.*/ P4 = 0; /* Set Port 4 to Output, Data Out to Electr. */ P5 = 255; /* Set Port 5 to Input, Input from Electr. */ P1 = 24; /* Set PS and RST to High E, MUX & R/W low */ PCON = 128; /* Bit 7 to double baudrate in MODE 1,2,3 */ ADCON = 128; /* Set Bit 7 means Baudrate to 9600 */ TMOD = 34; TH1 = 243; /* Load Timer 1 Values for baudrate */ TL1 = 243; TH0 = 6; /* Load Timer 0 Values for TimeOut */ TL0 = 6; TR1 = 1; T2R0 = 0; /* Setting up timer 2 used for Shutter Timing*/ T2R1 = 1; /* Set Timer 2 for autoreload */ T2I0 = 0; /* This bit is used as start/stop for timer */ T2I1 = 0; /* A combination makes other selections posib*/ CRCH = 0xB1; /* Set preload Reg's to zero */ CRCL = 0xDF; /* Lower one */ SCON = 82; Sys_Req_Init(); /* Sub Section for initialising the system */ Address=ShutterAddress; Write_Address(); Mski(); /* Mask BreakPoint Interrupt */ IP0=0x12; /* Set priorities right */ IP1=0x06; /* two reg's are used for it */ IT1 = 1; /* Make INT1 (LM628) Edge Triggerd */ ES = 1; /* Enable Serial Port Interrupt */ ET0 = 1; /* Enable Timer0 Interrupt */ EX1 = 1; /* Disable External Interrupt (LM628 Shutter) */ ET2 = 1; /* Enable Timer 2 (TF2) interrupt */ EAL = 1; /* GLobal Interrupts Enabled !!!!! */ return; }