documentdc

Download Documentdc

If you can't read please download the document

Upload: nalinevasanth

Post on 26-Dec-2015

4 views

Category:

Documents


3 download

DESCRIPTION

code for dc motor

TRANSCRIPT

#includesbit sw1=P3^2;sbit sw2=P3^3;sbit L293D_A = P1^0; //Make positive of motor 1sbit L293D_B = P1^1; //Make negative of motor 0sbit L293D_E = P1^2; //Enable L293Dvoid rotate_f(void); //Forward run funtionvoid rotate_b(void); //Backward run functionvoid breaks(void); //Motor stop functionvoid delay(void); //Some delayvoid main(){P3=0xFF;P1=0x00;//Our main functionwhile(1){ //Infinite loopif(sw1==1 && sw2==0){rotate_f(); //Run forwarddelay(); //Some delaybreaks(); //Stopdelay(); //Some delay}if(sw2==1 && sw1==0){rotate_b(); //Run Backwardsdelay(); //Some delaybreaks(); //Stopdelay(); //Some delay} //Do this infinitely}}void rotate_f(){L293D_A = 1; //Make positive of motor 1L293D_B = 0; //Make negative of motor 0L293D_E = 1; //Enable L293D}void rotate_b(){L293D_A = 0; //Make positive of motor 0L293D_B = 1; //Make negative of motor 1L293D_E = 1; //Enable L293D}void breaks(){L293D_A = 0; //Make positive of motor 0L293D_B = 0; //Make negative of motor 0L293D_E = 0; //Disable L293D}void delay(){ //Some delay...unsigned char i,j,k;for(i=0;i