Interfacing DC Motor To 8051
Interfacing DC Motor To 8051
This article shows how to interface a DC motor to an 8051 microcontroller. Interfacing DC motor
to 8051 forms an essential part in designing embedded robotic projects. A well designed 8051-
DC motor system has essentially two parts. Firstly an 8051 with the required software to control
the motor and secondly a suitable driver circuit. Most of the DC motors have power
requirements well out of the reach of a microcontroller and more over the voltage spikes
produced while reversing the direction of rotation could easily damage the microcontroller. So it
is not wise to connect a DC motor directly to the microcontroller. The perfect solution is to use a
motor driver circuit in between the microcontroller and the DC motor.
In the circuit components R1, S1 and C3 forms a debouncing reset circuitry. C1, C2 and X1 are
related to the oscillator. Port pins P1.0 and P1.1 are connected to the corresponding input pins of
the L293 motor driver. The motor is connected across output pins 3 and 6 of the L293. The
software is so written that the logic combinations of P1.0 and P1.1 controls the direction of the
motor. Initially when power is switched ON, P1.0 will be high and P1.1 will be low. This condition
is maintained for a preset amount of time (around 1S) and for this time the motor will be running
in the clockwise direction (refer the function table of L293). Then the logic of P1.0 and P1.1 are
swapped and this condition is also maintained for the same duration . This makes the motor to
run in the anti clockwise direction for the same duration and the entire cycle is repeated.
Program.
Program.
Checking whether a particular push button is pressed is done using the CJNE (compare and
jump if not equal) instruction. In simple words the CJNE instuction compares two operands and
jump to a predefined LABEL if the operands are not equal. If the two operands are equal nothing
happens and the next instruction is executed. Whenever push button S2 is pressed the status of
P3 will be 00000001B .This status is moved to accumulator A and compared with 00000001B
using the CJNE instruction. Both operands are equal means S2 is pressed and the next
instruction (MOV P1,#00000001B) which makes the motor run clockwise is executed. If the
operands are not equal that means the S2 is not pressed and the controller jumps to LABEL1
which is to check the S3. To check S3, status of P3 is moved to A again and it is compared with
00000010B using the CJNE instruction. Both operands are equal means the S3 is pressed and
the next instruction (MOV P1,#00000010B) which makes the motor run anti clockwise is
executed. Both operands are not equal means S3 is not pressed and the controller goes to check
S2 again and this cycle is repeated.
Notes.
The maximum current capacity of L293 is 600mA/channel. So do not use a motor that consumes
more than that.
The supply voltage range of L293 is between 4.5 and 36V DC. So you can use a motor falling in
that range.