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