Line 2: Line 2:
 
=Schematic=
 
=Schematic=
 
[[File:Schematic 8051 Interfacing DC_Motor.JPG|680px]]
 
[[File:Schematic 8051 Interfacing DC_Motor.JPG|680px]]
/* This program demonstrates, control of 2 DC Motors using L293D DriverFour switches connected to P1 Drive 2 motors connected to P2.For more details visit the tutorial Page:http://exploreembedded.com/wiki/*/#include<reg51.h>  #define Motors P2#define Switches P1#define Forward 0x05#define Backward 0x0a#define Left 0x06#define Right 0x09#define stop 0x00void main(){  unsigned char SwitchInput;  Switches = 0x0f; //Configure Switches  as Input    Motors = 0X00;  //Configure both Motors as Output.  while(1)  {   SwitchInput = (0x0f & Switches);   //read switch status and mask lower byte.      switch(SwitchInput)   {   case 1: Motors = Forward; break;   case 2: Motors = Backward; break;   case 4: Motors = Left; break;   case 8: Motors = Right; break;   default: Motors =stop;   }  }}
+
<syntaxhighlight>
 +
/* This program demonstrates, control of 2 DC Motors using L293D Driver.
 +
Four switches connected to P1 Drive 2 motors connected to P2.
 +
For more details visit the tutorial Page:http://exploreembedded.com/wiki/*/
 +
#include<reg51.h>   
 +
#define Motors P2
 +
#define Switches P1
 +
#define Forward 0x05
 +
#define Backward 0x0a
 +
#define Left 0x06
 +
#define Right 0x09
 +
 
 +
#define stop 0x00
 +
void main()
 +
{   
 +
unsigned char SwitchInput;   
 +
Switches = 0x0f; //Configure Switches  as Input     
 +
Motors = 0X00;  //Configure both Motors as Output.   
 +
while(1)   
 +
{  
 +
   SwitchInput = (0x0f & Switches);//read switch status and mask lower byte.       
 +
  switch(SwitchInput)
 +
  {
 +
  case 1: Motors = Forward; break;    
 +
  case 2: Motors = Backward; break;    
 +
  case 4: Motors = Left; break;    
 +
  case 8: Motors = Right; break;    
 +
  default: Motors =stop;
 +
  }   
 +
}
 +
}
 +
</syntaxhighlight>
  
 
=Download=
 
=Download=
 
* [http://exploreembedded.com/wiki/images/2/25/Schematic_8051_Interfacing_DC_Motor.pdf '''Schematic''']
 
* [http://exploreembedded.com/wiki/images/2/25/Schematic_8051_Interfacing_DC_Motor.pdf '''Schematic''']

Revision as of 14:01, 14 July 2014

Schematic

Schematic 8051 Interfacing DC Motor.JPG

  1. /* This program demonstrates, control of 2 DC Motors using L293D Driver.
  2. Four switches connected to P1 Drive 2 motors connected to P2.
  3. For more details visit the tutorial Page:http://exploreembedded.com/wiki/*/
  4. #include<reg51.h>
  5. #define Motors P2
  6. #define Switches P1
  7. #define Forward 0x05
  8. #define Backward 0x0a
  9. #define Left 0x06
  10. #define Right 0x09
  11.  
  12. #define stop 0x00
  13. void main()
  14. {
  15. unsigned char SwitchInput;
  16. Switches = 0x0f; //Configure Switches as Input
  17. Motors = 0X00; //Configure both Motors as Output.
  18. while(1)
  19. {
  20. SwitchInput = (0x0f & Switches);//read switch status and mask lower byte.
  21. switch(SwitchInput)
  22. {
  23. case 1: Motors = Forward; break;
  24. case 2: Motors = Backward; break;
  25. case 4: Motors = Left; break;
  26. case 8: Motors = Right; break;
  27. default: Motors =stop;
  28. }
  29. }
  30. }

Download