Difference between revisions of "Interfacing Seven Segment with 8051"
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 | + | <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
/* 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; } } }