0% found this document useful (0 votes)
17 views9 pages

Embedded System Hardware Exp

The document outlines several experiments involving interfacing various components with a microcontroller, including stepper motors, DACs for waveform generation, 7-segment displays, and switches. Each experiment includes a program code snippet, setup instructions, and expected results, such as motor rotation, waveform observation via oscilloscope, and display changes. The experiments demonstrate practical applications of GPIO and control mechanisms in embedded systems.

Uploaded by

prajwal24dsouza
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)
17 views9 pages

Embedded System Hardware Exp

The document outlines several experiments involving interfacing various components with a microcontroller, including stepper motors, DACs for waveform generation, 7-segment displays, and switches. Each experiment includes a program code snippet, setup instructions, and expected results, such as motor rotation, waveform observation via oscilloscope, and display changes. The experiments demonstrate practical applications of GPIO and control mechanisms in embedded systems.

Uploaded by

prajwal24dsouza
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/ 9

Experiment 9:

Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.

Program:

#include <LPC17xx.H>
void clock_wise(void);
void anti_clock_wise(void);
unsigned long int var1,var2;
unsigned int i=0,j=0,k=0;

int main(void)
{
LPC_PINCON->PINSEL4 = 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2->FIODIR = 0x0000000F; //P2.0 to P2.3 output
while(1)
{
for(j=0;j<50;j++) //50 times in Clock wise Rotation
clock_wise();

for(k=0;k<65000;k++); //Delay to show anti_clock


Rotation

for(j=0;j<50;j++) //50 times in Anti Clock


wise Rotation
anti_clock_wise();

for(k=0;k<65000;k++); //Delay to show clock Rotation


}
//End of while(1)
}
//End of main
void clock_wise(void)
{
var1 = 0x00000001; //For Clockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1<<1; //For Clockwise
for(k=0;k<15000;k++); //for step speed variation
}
}
void anti_clock_wise(void)
{
var1 = 0x0000008; //For
Anticlockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1>>1; //For
Anticlockwise
for(k=0;k<15000;k++); //for step speed variation
}
}

Result:
Observe the stepper motor rotation it should rotate Clockwise & Anti Clockwise direction.
This rotation of the motor will be continuously in loop.
Experiment 10:

Interface a DAC and generate Triangular and Square waveforms.

Triangular wave:

#include <LPC17xx.H>

int main ()

unsigned long int temp=0x00000000;

unsigned int i=0;

LPC_PINCON->PINSEL0 = 0x00000000; // Configure P0.4 to


P0.11 as GPIO

LPC_GPIO0->FIODIR = 0x00000FF0 ; // Configure P0.4 to


P0.11 as Outputs

LPC_GPIO0->FIOMASK = 0XFFFFF00F;

while(1)

/*output 0 to FE*/

for(i=0;i!=0xFF;i++)

temp=i;

temp = temp << 4;

LPC_GPIO0->FIOPIN = temp;

/* output FF to 1*/

for(i=0xFF; i!=0;i--)

temp=i;

temp = temp << 4;


LPC_GPIO0->FIOPIN = temp;

}
//End of
while(1)

Square Wave Generation

#include <LPC17xx.H>

void delay(void);

int main ()

LPC_PINCON->PINSEL0 = 0x00000000; //
Configure P0.4 to P0.11 as GPIO

LPC_GPIO0->FIODIR = 0x00000FF0 ; // Configure P0.4 to P0.11


as Output

LPC_GPIO0->FIOMASK = 0XFFFFF00F;

while(1)

LPC_GPIO0->FIOPIN = 0x00000FF0 ;

delay();

LPC_GPIO0->FIOCLR = 0x00000FF0 ;

delay();

void delay(void)

unsigned int i=0;

for(i=0;i<=9500;i++);
//3ms delay

}
A) Square Wave:
• Download the file “Square.hex” to trainer using Flash Magic 6.01 version.

• Jumper setting are same as sine wave.


Result:
Observe the Analog output waveform at the Pin-1 of RM3 using Oscilloscope (CRO) with respect to
GND pin-2 of RM3.
NOTE: POT3 is provided to control the Reference voltage for DAC output (Vref).User will get
maximum 2.5V peak to peak for uni-polar and 5V peak to peak for Bipolar.

B) Triangle Wave:
• Download the file “Triangle.hex” to trainer using Flash Magic 6.01 version.

• Jumper setting are same as sine wave.


Result:
Observe the Analog output waveform at the Pin-1 of RM3 using Oscilloscope (CRO) with respect
to GND pin-2 of RM3.

NOTE: POT3 is provided to control the Reference voltage for DAC output (Vref).User will get
maximum 2.5V peak to peak for uni-polar and 5V peak to peak for Bipolar
Experiment 11:

Display the Hex digits 0 to F on a 7-segment LED interface, with a suitable delay in between.

Program:

/* Description :\\\\\\\\\\\\\\\DISPLAY ARE CONNECTED IN COMMON CATHODE


MODE\\\\\\\\\\\\\\\\\\\\\

Port0 Connected to data lines of all 7 segement displays


a

----

f| g |b

|----|

e| |c

---- . dot

a = P0.04

b = P0.05

c = P0.06

d = P0.07

e = P0.08

f = P0.09

g = P0.10

dot = P0.11

*/

#include <LPC17xx.h>

unsigned int delay, count=0, Switchcount=0,j;

unsigned int Disp[16]={0x000003f0, 0x00000060, 0x000005b0, 0x000004f0,


0x00000660,0x000006d0,

0x000007d0, 0x00000070, 0x000007f0, 0x000006f0,


0x00000770,0x000007c0,

0x00000390, 0x000005e0, 0x00000790, 0x00000710 };


#define ALLDISP 0x00180000
//Select all display

#define DATAPORT 0x00000ff0


//P0.4 to P0.11 : Data lines connected to drive Seven Segments

int main (void)

LPC_PINCON->PINSEL0 = 0x00000000;

LPC_PINCON->PINSEL1 = 0x00000000;

LPC_GPIO0->FIODIR = 0x00180ff0;

while(1)

LPC_GPIO0->FIOSET |= ALLDISP;

LPC_GPIO0->FIOCLR = 0x00000ff0;
// clear the data lines to 7-segment displays

LPC_GPIO0->FIOSET = Disp[Switchcount]; // get the 7-


segment display value from the array

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

for(delay=0;delay<30000;delay++);
// delay

Switchcount++;

if(Switchcount == 0x10)
// 0 to F has been displayed ? go back to 0

Switchcount = 0;

LPC_GPIO0->FIOCLR = 0x00180ff0;

}
• Download the file “Seven_seg.hex” to trainer using Flash Magic 6.01 version.

• Both pins of SW5 should be in ON position. Switch off SW3, Un-short JP7. Press the reset
switch (SW1) to run the program.
Result:
Observe display changing from 00 to FF. This process is continuously in loop.
Experiment 12:

Interface a simple Switch and display its status through Relay, Buzzer and LED

Program:
#include <LPC17xx.H>
int main(void)
{
LPC_PINCON->PINSEL1 = 0x00000000; //P0.24,P0.25 GPIO
LPC_GPIO0->FIODIR = 0x03000000;
//P0.24 configured output for buzzer,P0.25 configured output for
Relay/Led

while(1)
{
if(!(LPC_GPIO2->FIOPIN & 0x00000800))
//Is GP_SW(SW4) is pressed??
{
LPC_GPIO0->FIOSET = 0x03000000;
//relay on
}
else
{
LPC_GPIO0->FIOCLR = 0x03000000;

//relay off
}
}
}

//end int main(void)

• Download the file “RELAY.hex” to trainer using Flash Magic 6.01 version.
• Short jumper JP12.
Result:
Press SW4 on the buzzer section, see that Relay RLY2, Led L4 and Buzzer BZ1 are On and
when user releases the push button the Relay RLY2, L4 and Buzzer should be in Off
condition. Relay Common and NO are brought out to CN5 connector.

You might also like