Line 14: Line 14:
 
Motors = 0X00;  //Configure both Motors as Output.   
 
Motors = 0X00;  //Configure both Motors as Output.   
 
while(1)   
 
while(1)   
{    
+
{    
SwitchInput = (0x0f & Switches)//read switch status and mask lower byte.     
+
SwitchInput = (0x0f & Switches)//read switch status and mask lower byte.     
switch(SwitchInput)
+
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; }   
+
{    
}}
+
        case 1: Motors = Forward; break;
 +
        case 2: Motors = Backward; break;    
 +
        case 4: Motors = Left; break;    
 +
        case 8: Motors = Right; break;    
 +
        default: Motors =stop;  
 +
        }   
 +
}
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 13:40, 14 July 2014

  1. #include<reg51.h>
  2. #define Motors P2
  3. #define Switches P1
  4. #define Forward 0x05
  5. #define Backward 0x0a
  6. #define Left 0x06
  7. #define Right 0x09
  8. #define stop 0x00void
  9. main()
  10. {
  11. unsigned char SwitchInput;
  12. Switches = 0x0f; //Configure Switches as Input
  13. Motors = 0X00; //Configure both Motors as Output.
  14. while(1)
  15. {
  16. SwitchInput = (0x0f & Switches)//read switch status and mask lower byte.
  17. switch(SwitchInput)
  18. {
  19. case 1: Motors = Forward; break;
  20. case 2: Motors = Backward; break;
  21. case 4: Motors = Left; break;
  22. case 8: Motors = Right; break;
  23. default: Motors =stop;
  24. }
  25. }
  26. }