You are on page 1of 6

/* functions */ /************************************************************************* * main - Program entry point.

This program will simply receive characters * from the serial port, then send them bac . * * INPUT: N/A * RETURNS: N/A */ #include<reg51.h> sbit L_Motor1F=P3^3; sbit L_Motor1B=P3^4; sbit L_Motor2F=P3^6; sbit L_Motor2B=P3^7; sbit W_Motor1F=P2^0; sbit W_Motor1B=P2^1; sbit W_Motor2F=P2^3; sbit W_Motor2B=P2^4; sbit cam_cloc wise=P2^6; sbit cam_anti=P2^7; sbit laser_gun=P1^0; sbit smo e=P1^6; sbit LDR=P1^7; void delay(unsigned int ); void Updatestatus (char Outpin); void Sendstring(char *string); unsigned char welcome[]="\n\rMILITARY REPTILE ROBOT"; unsigned char string1[] = "\n\rFwd"; unsigned char string2[] = "\n\rLft"; unsigned char string3[] = "\n\rRght"; unsigned char string4[] = "\n\rB wrd"; unsigned char string5[] = "\n\rTrg"; //unsigned char string6[] = "\n\rcam cl "; //unsigned char string7[] = "\n\rcam antcl "; unsigned char string8[] = "\n\r STOP"; unsigned char string9[] = "\n\r SMOKE ALERT!"; unsigned char string10[] = "\n\rNO LGHT!"; unsigned char string11[] = "\n\r SAFE"; int pin_status1(); int pin_status2(); char getCharacter (void); /* read a character from the serial port */ main() { char chr; /* variable to hold characters in */ char i; //int flag1, flag2; i=0; TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */ TH1=0xFD; //TH1 = 0xFE; /* reload value for 9600 baud */ SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */ /* Setting TR1 will start the timer, and serial communications */ TR1 = 1; Sendstring(welcome); //Sendstring(node1_robot);

smo e=1; LDR=1; L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; while (1) { /* read the next character from the serial port */ chr = getCharacter (); Updatestatus(chr); /* send it bac to the original sender */ } } void delay(unsigned int ) { int i,j; for (i=0;i<= ;i++) for (j=0;j<=5750;j++); } void Updatestatus (char Outpin) { int flag1,flag2; switch (Outpin) { case '1': Sendstring (string2); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=1; W_Motor2B=0; delay(1); W_Motor2F=0; brea ; case '2': Sendstring (string4); L_Motor1F=0; L_Motor1B=1; L_Motor2F=0; L_Motor2B=1; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; delay(1); L_Motor1B=0; L_Motor2B=0; brea ; case '3': Sendstring (string3);

L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=1; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; delay(1); W_Motor1F=0; brea ; case '4': Sendstring (string2); L_Motor1F=0; L_Motor1B=0; L_Motor2F=1; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; delay(1); L_Motor2F=0; brea ; case '5': Sendstring (string8); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; brea ;

case '6': Sendstring (string3); L_Motor1F=1; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; delay(1); L_Motor1F=0; brea ; case '7': Sendstring (string4); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0;

W_Motor1F=0; W_Motor1B=1; W_Motor2F=0; W_Motor2B=1; delay(1); W_Motor1B=0; W_Motor2B=0; brea ; case '8': Sendstring (string1); L_Motor1F=1; L_Motor1B=0; L_Motor2F=1; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; delay(1); L_Motor1F=0; L_Motor2F=0; brea ; case '9': Sendstring (string1); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=1; W_Motor1B=0; W_Motor2F=1; W_Motor2B=0; delay(1); W_Motor1F=0; W_Motor2F=0; brea ; case '0': Sendstring (string5); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; laser_gun=1; delay(5); laser_gun=0; brea ; case '*': //Sendstring (string6); L_Motor1F=0;

L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; cam_cloc wise=1; cam_anti=0; delay(1); cam_cloc wise=0; cam_anti=0; brea ; case '#': // Sendstring (string7); L_Motor1F=0; L_Motor1B=0; L_Motor2F=0; L_Motor2B=0; W_Motor1F=0; W_Motor1B=0; W_Motor2F=0; W_Motor2B=0; cam_cloc wise=0; cam_anti=1; delay(1); cam_cloc wise=0; cam_anti=0; brea ; default: flag1 = pin_status1(); flag2=pin_status2; if(flag1==1) { Sendstring (string10); delay(1); } else if(flag2==0) { Sendstring (string9); delay(1); } else { Sendstring (string11); } } } void Sendstring(char *string) { while( *string != '\0') { SBUF = *string; while(TI==0);

TI=0; string++; } } /************************************************************************* * getCharacter - Waits for a new character to arrive in the serial port, * then reads it. */ char getCharacter (void) { char chr; /* now read the value in the serial buffer into the local variable */ while (RI == 0) { ; } chr = SBUF; RI = 0; /* the character is then returned to the calling function. */ return(chr); } int pin_status1() { int flag1 = 0; if(smo e==0) { flag1=1; else{ flag1=0; } return(flag1); } int pin_status2() { int flag2 = 0; if(LDR==1) { flag2=1; } else { flag2=0; } return(flag2); }

You might also like