0% found this document useful (0 votes)
7 views4 pages

Interfacing Programs

The document contains code snippets for controlling a stepper motor in both anticlockwise and clockwise directions using an 8051 microcontroller. It also includes examples for generating square and sine wave signals using a Digital-to-Analog Converter (DAC). Each section features a delay function and utilizes port P2 for output control.

Uploaded by

apoorvanagraj315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Interfacing Programs

The document contains code snippets for controlling a stepper motor in both anticlockwise and clockwise directions using an 8051 microcontroller. It also includes examples for generating square and sine wave signals using a Digital-to-Analog Converter (DAC). Each section features a delay function and utilizes port P2 for output control.

Uploaded by

apoorvanagraj315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stepper Motor

a) Anticlockwise rotation
#include<reg51.h>
Void delay()
{
int i;
for(i=0;i<5000;i++)
{
}
}
Void main ()
{
While (1)
{
P2=0x01;
delay ();
P2=0x03;
delay ();
P2=0x02;
delay ();
P2=0x06;
delay();
P2=0x04;
delay();
P2=0x0C;
delay();
P2=0x08;
delay();
P2=0x09;
delay();
}

}
b)Clockwise rotation
#include<reg51.h>
Void delay()
{
int i;
for(i=0;i<5000;i++)
{
}
}
Void main ()
{
While (1)
{
P2=0x09;
delay ();
P2=0x08;
delay ();
P2=0x0C;
delay ();
P2=0x04;
delay();
P2=0x06;
delay();
P2=0x02;
delay();
P2=0x03;
delay();
P2=0x01;
delay();
}

}
DAC: Square wave

#include<reg51.h>

sbit DWR=P3^0;

Void delay()

int i;

for(i=0;i<5000;i++)

Void main ()

While (1)

P2=0XFF;

DWR=1;

DWR=0;

delay();

P2=0X00;

DWR=1;

DWR=0;

delay();

}
DAC: Sine wave

#include<reg51.h>

#include<math.h>

sbit DWR=P3^0;

void main()

Whie(1)

for(i=0; i<=360; i+=10)

P2=(5+(5*sin((x*3.14)/180)))*25.6;

DWR=1;

DWR=0;

You might also like