Microcontroller › 8051 › Interface 8051 to a 12V dc motor › circuit#include
March 31, 2012 at 6:21 pm
#7369
tarun
Participant
#include<reg51.h>
sbit enable1=P1^0;
sbit enable2=P1^2;
sbit mtr1_1=P1^1;
sbit mtr1_2=P1^7;
sbit mtr2_1=P1^3;
sbit mtr2_2=P1^6;
sbit sw1=P2^2;
sbit sw2=P2^3;
sbit sw3=P2^4;
sbit sw4=P2^5;
void delay(void);
void main()
{
P1=0x00;
P2=0xff;
while(1)
{
enable1=0x00;
enable2=0x00;
delay();
if(sw1==0x00)
{
enable1=0x01;
enable2=0x01;
delay();
mtr1_1=0x01;
mtr1_2=0x00;
mtr2_1=0x01;
mtr2_2=0x00;
}
else if(sw2==0x00)
{
enable1=0x01;
enable2=0x01;
delay();
mtr1_1=0x00;
mtr1_2=0x01;
mtr2_1=0x00;
mtr2_2=0x01;
}
else if(sw3==0x00)
{
enable1=0x01;
enable2=0x01;
delay();
mtr1_1=0x01;
mtr1_2=0x00;
mtr2_1=0x00;
mtr2_2=0x01;
}
else if(sw4==0x00)
{
enable1=0x01;
enable2=0x01;
delay();
mtr1_1=0x00;
mtr1_2=0x01;
mtr2_1=0x01;
mtr2_2=0x00;
}
else if(sw1==0x0f&&sw2==0x0f&&sw3==0x0f&&sw4==0x0f)
{
enable1=0x00;
enable2=0x00;
delay();
}
}
}
void delay()
{
int i,j;
for(i=1;i<=2;i++)
for(j=1;j<=500;j++);
}