DC Motor interfacing with Microcontrollers tutorial: C programming for DC motor control free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
DC Motor interfacing with Microcontrollers tutorial: Programming Microcontroller


►Assembly programming
CODE:
L293D_A   equ P2.0          ;L293D A - Positive of Motor
L293D_B   equ P2.1          ;L293D B - Negative of Motor
L293D_E   equ P2.2          ;L293D E - Enable pin of IC

         org 0H
Main:
         acall rotate_f     ;Rotate motor forward
         acall delay        ;Let the motor rotate
         acall break        ;Stop the motor
         acall delay        ;Wait for some time
         acall rotate_b     ;Rotate motor backward
         acall delay        ;Let the motor rotate
         acall break        ;Stop the motor
         acall delay        ;Wait for some time
         sjmp  Main         ;Do this in loop
                 
rotate_f:
         setb  L293D_A      ;Make Positive of motor 1
         clr   L293D_B      ;Make negative of motor 0
         setb  L293D_E      ;Enable to run the motor
         ret                ;Return from routine
         
rotate_b:
         clr   L293D_A      ;Make positive of motor 0
         setb  L293D_B      ;Make negative of motor 1
         setb  L293D_E      ;Enable to run the motor
         ret                ;Return from routine
         
break:
         clr   L293D_A      ;Make Positive of motor 0
         clr   L293D_B      ;Make negative of motor 0
         clr   L293D_E      ;Disable the o/p
         ret                ;Return from routine
         
delay:                      ;Some Delay
         mov   r7,#20H
back:    mov   r6,#FFH
back1:   mov   r5,#FFH
here:    djnz  r5, here
         djnz  r6, back1
         djnz  r7, back
         ret
 



►C programming
CODE:
#include <AT89X51.H>#define L293D_A P2_0         //Positive of motor
#define L293D_B P2_1         //Negative of motor
#define L293D_E P2_2         //Enable of L293D

// Function Prototypes
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(){                 //Our main function
    while(1){                //Infinite loop
                rotate_f();          //Run forward
                delay();             //Some delay
                breaks();            //Stop
                delay();             //Some delay
                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++);
}
◄ Previous Page  |  Next Page ►

Back to Index


DC Motor Tutorial Index
DC Motor Introduction
Interfacing L293D
BJT Based H-Bridge
Programming for DC Motor


Google Search for Microcontrollers!

Google
 

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems