#include<reg51.h>
sbit sw1=P3^2;
sbit sw2=P3^3;
sbit L293D_A = P1^0; //Make positive of motor 1
sbit L293D_B = P1^1; //Make negative of motor 0
sbit L293D_E = P1^2; //Enable L293D
void rotate_f(void); //Forward run funtion
void rotate_b(void); //Backward run function
void breaks(void); //Motor stop function
void delay(void); //Some delay
void main(){
P3=0xFF;
P1=0x00;
//Our main function
while(1){ //Infinite loop
if(sw1==1 && sw2==0)
{
rotate_f(); //Run forward
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
}
if(sw2==1 && sw1==0)
{
rotate_b(); //Run Backwards
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
} //Do this infinitely
}
}
void rotate_f(){
L293D_A = 1; //Make positive of motor 1
L293D_B = 0; //Make negative of motor 0
L293D_E = 1; //Enable L293D
}
void rotate_b(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 1; //Make negative of motor 1
L293D_E = 1; //Enable L293D
}
void breaks(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 0; //Make negative of motor 0
L293D_E = 0; //Disable L293D
}
void delay(){ //Some delay...
unsigned char i,j,k;
for(i=0;i<0x20;i++)
for(j=0;j<255;j++)
for(k=0;k<255;k++);
}