Showing posts with label 11_L293D Motor Driver 89c51. Show all posts
Showing posts with label 11_L293D Motor Driver 89c51. Show all posts

Saturday, 8 September 2018

8051: L293D Motor Interface Code:



Description:

The IC L293D is used for interfacing 8051with DC motor as shown in the block diagram. The two input buttons can be used to control the output PWM generated by the microcontroller. This output signal is then fed to DC motor through motor driver.L293D contains four H bridge drivers are enabled in pairs.EN1 is used to enable pair 1(IN1-OUT1, IN2-OUT2) and EN1 is used to enable pair 1(IN3-OUT3, IN4-OUT4).In this diagram, switch were connected, if switch 1 pressed the both DC motor rotates forward direction. If switch 2 pressed the both DC motor rotates reverse direction. If switch 3 pressed first motor rotates forward and second rotates reverse direction. If switch 4 pressed first motor rotates reverse and second rotates forward direction.


Code:
#include<reg51.h>

sbit m1f =P2^0;
sbit m1r =P2^1;
sbit m2f =P2^2;
sbit m2r =P2^3;

sbit a =P3^0;
sbit b =P3^1;
sbit c =P3^2;
sbit d =P3^3;

void delay(int);
void main()
{
if(a==0)
{
m1f=0;
m1r=1;
m2f=0;
m2r=1;
}
else if(b==0)
{
m1f=1;
m1r=0;
m2f=1;
m2r=0;
}
else if(c==0)
{
m1f=0;
m1r=1;
m2f=1;
m2r=0;
}
else if(d==0)
{
m1f=1;
m1r=0;
m2f=0;
m2r=1;
}
else
{
m1f=1;
m1r=1;
m2f=1;
m2r=1;
}
delay(100);
}

void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}







Circuit Diagram: