Professional Documents
Culture Documents
long int test=0; //define test char c='a'; //define c, a is use to prevent error, can dun put also
void measure (void) { unsigned int dur=0; //define dur, used in calculation of distance float cal =0; bit responseOK; responseOK =1; //define cal for calculate the distance //define //if sensor is ready, got response
if(receiverRdy()==1) //if receiver is ready, it will proceed otherwise it will continue on { c=getCh(); } if (responseOK) { putCh('\n'); if (cal <= 1000.0) { test++; mPin=0; if (test==15) this is to delay 3 sec { lPin=1; // laser on } //end of loop if (test==15) //to increase test every pulse, 200ms/pulse //motor stop moving when (enemy detected) //because tmr2DlySet(200); which is 200 ms /pulse, //sent each distance to C# software in a new line //get the char sent from C# software
mPin=0; //motor off lPin=0; //laser off buzPin=0; //buzzer off }//end of loop if(c=='E') else { buzPin=1; count=0; //buzzer on //clear count
else // this alternatively means if (cal <= 1000.0) is false, cal>1000mm { if(c=='E') hardware { mPin=0; //motor off lPin=0; //laser off buzPin=0; //buzzer off // E is sent from C# softeware to stop the
else //this alternatively means if (c != 'E') != means not equal { mPin=1; //motor on lPin=0; //laser off test=0; }//end of loop else //clear test
dur=(int)cal; putDecU16LS(dur,5);putStr("mm"); /*this is the distance sent to C# softeware } // end of loop if (ResponseOK) void main (void) { Init_Device(); uartInit(1152); tmr2Init(2); // device initialization //serial port bautrate // Timer, refer to MPI notes
//
basicTest(); mPin=0; lPin=0; //laser off buzPin=0; //busser off c=getCh(); if(c=='S') // get the char sent from C# software //if S is receive then start running
*count: The used of variable count is quite redundant, as its purpose is only for the buzzer to sound each time count reach 500000