You are on page 1of 4

Home | IR Remotes | RF Remotes | Industrial Automation | Embedded Systems | Robotics | Project Kits | FAQs | Download

DC Motor control

Software program for remote control DC drive

using C++
DC motor control
using VC++
Stepper motor
control using VC++
Industrial DC Motor
Control panel
industrial stepper

Entire program can be well explained by explaining all the functions used in this program.
Start function is a continuous function that will rotate motor in either direction with set speed. Actually it
generates PWM to vary the speed of motor. It will set the direction of motor and then generate PWM on either
P3.6 or P3.7
Intra function is an interrupt enabled function that will receive data byte available on P1. Whenever interrupt
arrives it will be automatically called and after some delay it will get the byte available on P1

motor control panel


remote control for AC
Drive
Traffic control
system
Wireless DC Motor
controller
Wireless Stepper
motor controller
remote controlled DC
drive

chngdir will change the direction of motor every time. It increments a count every time and checks even or odd.
If its even sets CW direction and vice versa
incspeed increase speed by one step. Actually it increases pulse width time by 1 ms. Total time is 10 ms and we
are varying the width of pulse from 1ms to 9ms. So speed of motor varies in 8 step. That is indicated on 8 LED
bar graph. Dec speed is similar to this but it will decreases pulse width by 1 ms
Shift up function is similar to rotate the content of port P2 left, once. It sends one more zero every time on P2
pins from P2.7 to P2.0 so bar graph is raised once. shiftdown function does the reverse thing. It will send one
more 1 on P2 pins from P2.0 to P2.7. So bargraph is reduced by once.
Delay function is a variable delay that varies the delay from 1 ms to the count you load into the function. T0
generates basic delay of 1ms and then this basic delay in a loop is repeated for number of times (like 2,3,4....) to
generate delay of 2ms, 3ms, 4 ms and likewise
Kodaly is fix delay and it is just used to settle down the data byte available on P1 from ST3049.
Here is complete program in C language written and compiled in KEIL (IDE)
#include<reg51.h>
unsigned char a;
bdata unsigned char byte=0x0F, databyt=0x00;
unsigned int d1=5,d2=5,c=0,f=0;
sbit b0 = byte^0;
sbit b1 = byte^1;
sbit b2 = byte^2;
sbit b3 = byte^3;
sbit b4 = byte^4;
sbit b5 = byte^5;
sbit b6 = byte^6;

sbit b7 = byte^7;
sbit led1=P3^0;
sbit led2=P3^1;
sbit led3=P3^4;
sbit led4=P3^5;
sbit op1=P3^6;
sbit op2=P3^7;

void keydely()
{
int x,y;
for(x=0;x<25;x++)
for(y=0;y<1000;y++);
}
void delay(int d)
{
int k;
TL0 = 0x17;
TH0 = 0xFC;
TR0 = 1;
for(k=0;k<d;k++)
{
while(TF0==0);
TF0 = 0;
TL0 = 0x17;
TH0 = 0xFC;
}
TR0 = 0;
}
void shiftup()
{
b0=b1;
b1=b2;
b2=b3;
b3=b4;
b4=b5;
b5=b6;
b6=b7;
b7=0;
}
void shiftdown()
{
b7=b6;
b6=b5;
b5=b4;
b4=b3;
b3=b2;
b2=b1;
b1=b0;
b0=1;
}
void incspeed()
{
if(d1<9)

{
d1++;
d2--;
shiftup();
P2=byte;
}
}
void decspeed()
{
if(d2<9)
{
d2++;
d1--;
shiftdown();
P2=byte;
}
}
void chngdir()
{
c++;
if((c%2)==1)
{
led3=0;
led4=1;
}
else
{
led3=1;
led4=0;
}
}
void start()
{
led2=0;
led1=1;
if((c%2)==0)
{
op2=0;
while(databyt==0x00)
{
op1=1;
delay(d1);
op2=0;
delay(d2);
}
}
else
{
op1=0;
while(databyt==0x00)
{
op2=1;
delay(d1);
op2=0;
delay(d2);
}
}
}
void intr() interrupt 0
{

{
keydely();
databyt=P1;
}
void main()
{
int tmp=0;
TMOD = 0x01;
P3=0x04;
P2=byte;
led2=1;
led3=1;
IE=0x81;
back: while(databyt==0x00);
check: switch(databyt)
{
case 0xD2:
tmp++;
if((tmp%2)==1)
{
f=1;
databyt=0x00;
start();
}
else
{
f=0;
led2=1;
led1=0;
databyt=0x00;
op1=0;
op2=0;
}
break;
case 0xD6:
incspeed();
databyt=0x00;
start();
break;
case 0xD7:
decspeed();
databyt=0x00;
start();
break;
case 0xD3:
chngdir();
databyt=0x00;
start();
break;
}
if(f==0)goto back;
else goto check;
}

All the projects are designed and developed by sight owner and they are thoroughly tested by him. Copyrights Ashutosh Bhatt 2010. All rights reserved.

You might also like