1) Motor.c
Here, L293D, DC Motor IC is interfaced with the microcontroller. There are 2 pins each for 2 motors can be connected to the output of this IC.
This IC is a direction control IC.
To explain what I have done in this code,
Look at the table given :
EN | MOTOR1 | MOTOR2 | FUNCTION |
H | H | H | Go Forward |
H | L | L | Opposite direction |
H | H | L | Turn Left |
H | L | H | Turn Right |
L | - | - | Disabled |
//INTERFACE DC MOTOR WITH 8051
#include<reg51.h>
sbit pin1m1=P2^0;
sbit pin2m1=P2^1;
sbit sw1=P2^2;
sbit sw2=P2^3;
sbit pin1m2=P2^5;
sbit pin2m2=P2^6;
sbit sw3=P2^4;
sbit sw4=P2^7;
void main()
{
pin1m1=pin1m2=pin2m1=pin2m2=0;
if(sw1==0)// fwd
{
pin1m1=pin1m2=1;
pin2m1=pin2m2=0;
}
if(sw2==0)// rev
{
pin1m1=pin1m2=0;
pin2m1=pin2m2=1;
}
if(sw3==0)// right
{
pin1m1=1;
pin2m1=pin1m2=pin2m2=0;
}
if(sw4==0)// left
{
pin1m1=pin2m2=pin2m1=0;
pin1m2=1;
}
}
#include<reg51.h>
sbit pin1m1=P2^0;
sbit pin2m1=P2^1;
sbit sw1=P2^2;
sbit sw2=P2^3;
sbit pin1m2=P2^5;
sbit pin2m2=P2^6;
sbit sw3=P2^4;
sbit sw4=P2^7;
void main()
{
pin1m1=pin1m2=pin2m1=pin2m2=0;
if(sw1==0)// fwd
{
pin1m1=pin1m2=1;
pin2m1=pin2m2=0;
}
if(sw2==0)// rev
{
pin1m1=pin1m2=0;
pin2m1=pin2m2=1;
}
if(sw3==0)// right
{
pin1m1=1;
pin2m1=pin1m2=pin2m2=0;
}
if(sw4==0)// left
{
pin1m1=pin2m2=pin2m1=0;
pin1m2=1;
}
}
No comments:
Post a Comment