0% found this document useful (0 votes)
13 views

21BEC1010 - LAB11 - Embedded C

Uploaded by

rahulhmr868
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)
13 views

21BEC1010 - LAB11 - Embedded C

Uploaded by

rahulhmr868
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
You are on page 1/ 7

Embedded C LAB – 11

- SRI RAHUL RAGHAV


- 21BEC1010

1 Triangular wave generation

#include<reg51.h>

void main() // Start of main() function

P1 = 0x00; // Initialize Port 1 as Output Port

while(1) // Infinite Loop

do

P1 += 0x05;

while(P1<0xFF);

do

P1 -= 0x05;

while(P1>0x00);

}
2 Sawtooth wave generation

# include <reg51.h>

int main (void)

unsigned char i = 0; //Define a counter

P1 = 0x00; //make port P1 as output port

while (1) // Do forever

P1 = i; // copy i into port P2 to be converted

i++; // increment the counter

return 0;

}
3 Sawtooth wave generation

# include <reg51.h>

int main (void)

unsigned char i = 0; //Define a counter

P1 = 0x00; //make port P1 as output port

while (1) // Do forever

P1 = i; // copy i into port P2 to be converted

i++; // increment the counter

return 0;

}
4 Sine Wave Generation

#include<reg51.h>

void main(){

int sin_value[12] = {128,192,238,255,238,192,128,64,17,0,17,64};

int i;

while(1){

for(i = 0; i<12; i++){

P1 = sin_value[i];

}
Stepper motor
#include <reg52.h>

#define Stepper_Port P0 /* Define Stepper Motor Port */

/* Function to provide delay of 1ms at 11.0592 MHz */

void delay(unsigned int count)

int i,j;

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

for(j=0; j<112; j++);

int main(void)

int i,period;

period = 100; /* Set period in between two steps of Stepper Motor */

while (1)

/* Rotate Stepper Motor clockwise with Half step sequence */

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


{

Stepper_Port = 0x09;

delay(period);

Stepper_Port = 0x08;

delay(period);

Stepper_Port = 0x0C;

delay(period);

Stepper_Port = 0x04;

delay(period);

Stepper_Port = 0x06;

delay(period);

Stepper_Port = 0x02;

delay(period);

Stepper_Port = 0x03;

delay(period);

Stepper_Port = 0x01;

delay(period);

/* last one step to acquire initial position */

Stepper_Port = 0x09;

delay(period);

delay(1000);

/* Rotate Stepper Motor Anticlockwise with Full step sequence */

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

Stepper_Port = 0x09;

delay(period);
Stepper_Port = 0x03;

delay(period);

Stepper_Port = 0x06;

delay(period);

Stepper_Port = 0x0C;

delay(period);

Stepper_Port = 0x09;

delay(period);

delay(1000);

You might also like