Aim:
To write a C Program to interface DC motor with 8051 Microcontroller

Algorithm:
Step 1: Start the program.
Step 2: Initialize port A, port B and port C as output ports.
Step 3: Move the sequence of input to port A.
Step 4: Call the delay Routine
Step 5: Execute the above steps in a while loop
Step 6: Stop the program

Procedure:
Open the Keil software. Click on the project and create a new project.
Create a new C file and type the program.
Create the necessary header files add to the project. Compile the C file and debug the code.
Now the 8051 device is to be connected to PC.
Connect the ADC interface to 26 pin FRC connector of ECAMCB51.
Run the program.

Program:
#include <at89c51xd2.h>
#include <stdio.h>
unsigned char count;
unsigned char pedestal;
void delay()
{
unsigned int i = 0x00;
 for(i = 0; i <= 0x80; i ++);
}
void speed()
{ char i;
unsigned int value = 0x00;
printf("\nSPEED OF THE DC MOTOR AS ROTATIONS/SEC = ");
while(P1_1);
while(!P1_1);
count=0x00;
loop: while(!P1_0);
count += 1;
delay();
while(P1_0);
delay();
if(P1_1)
goto loop;
else
for(i=0;count>= 0x0a;i++)
{
count=(count-0x0a);
}
putchar((i+0x30));
putchar((count+0x30));
}
void main()
{
unsigned char c,input = 0;
SCON = 0x52;                      // Initialising serial port
TMOD |= 0x20;                 //with 9600 baud rate
TH1 = 0xfd;
TR1 = 1;
P0 = 0x00;
P1 = 0xff;
*a=0x7f
pedestal = vb hf&a;
P0=pedestal;
while((c = getchar())!='\n');
printf("\nPRESS 'i' TO INCREASE THE RPM OF THE DC MOTOR");
printf("\nPRESS 'd' TO DECREASE THE RPM OF THE DC MOTOR");
printf("\nPRESS 's' TO DISPLAY RGE SPEED IN ROTATIONS/SEC\n");
// P0 = 0x7f;
while(1)
{
loop: P0=pedestal;
take: input = getkey();
if(input == 0x69)
{
if(pedestal != 0x1f)
{
pedestal -= 1;
//putchar(('\n'));
putchar((0x08));
goto loop;
}
else
goto take;
}
else if(input == 0x64)
{
if(pedestal != 0xe0)
{
pedestal += 1;
//putchar(('\n'));
putchar((0x08));
goto loop;
}
else
goto take;
}
else if(input == 0x73)
speed();
else
goto take;
}}