Interfacing a DC Motor with LPC2148-Micrcontroller
DC Motors are widely used in embedded systems. This tutorial explains driving a DC motor using ARM-7 Architecture based LPC2148 Microcontroller.
DC motors are available in different ratings. Selection of a motor depends on the application for which the motor is used. In this example we are using a 12-V DC motor. The current required ton drive the motor is provided by a motor driving IC: L293D. This IC is designed to provide up to 600 mA current at 4.5 V- 36 V range.
PIN Configuration:

PIN No. | Description |
1 (EN 1,2) | Enable (Active high) channel 1 and 2 |
2, 7, 10, 15 | Driver Inputs |
3, 6, 11, 14 | Driver Outputs |
9 (EN 3, 4) | Enable (Active High) channel 3 and 4 |
8 (Vcc2) | 4.5 - 36 V |
16 (Vcc1) | 5 v power supply pin for internal logic of the IC |
Circuit Diagram:
A single L293D IC can drive two DC motors. In this example we are only controlling the motor which is connected to OUT1 and OUT2 pins of L293D.

A switch is also connected to P0.26 to turn on and turn off the motor. The system will turn off the motor when the switch is pressed.
Programming:
#include<LPC214x.h>
#include<stdint.h>
void motor1_on(void);
void motor1_off(void);
int main()
{
PINSEL0=0x00000000;
IO0DIR|=(1<<1)|(1<<2);
int a;
while(1)
{
a=IO0PIN & (1<<26);
if(a==0) /* The switch is open */
motor1_on();
else /* The switch is pressed */
motor1_off();
}
return 0;
}
void motor1_on()
{
IO0SET|=(1<<1);
IO0CLR|=(1<<2);
}
void motor1_off()
{
IO0CLR|=(1<<1);
IO0CLR|=(1<<2);