18ecl66 - Embedded Systems Laboratory
18ecl66 - Embedded Systems Laboratory
18ECL66
FOR
NAME………………………….
USN……………………………
BATCH………………………..
Laboratory Experiments
Conduct the f o l l o w i n g experiments on a n ARM C O R T E X M3 evaluation board
t o learn ALP and u s i n g evaluation version of Embedded 'C' & Keil uVision-4
tool/compiler.
PART A:
1. ALP to multiply two 16-bit binary numbers.
2. ALP to find the sum of first 10 integer numbers.
3. ALP to find the number of 0’s and 1 ‘s in a 32- b i t data
4. ALP to find determine whether the given 16 bit is even or odd
5. ALP to write data to RAM
PART B:
6. Display ''Hello world" message using internal UART
7. Interface and Control the speed of a DC Motor.
8. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
9. Interface a DAC and generate Triangular and Square waveforms.
10. Interface a 4x4 keyboard and display the key code on an LCD.
11. Demonstrate the use of an external interrupt to toggle an LED On/Off.
12 Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay.
13. Measure Ambient temperature using a sensor and SPIADC IC.
Course outcomes: After studying this course, students will be able to:
1. Understand the instruction set of32 bit microcontroller ARM Cortex M3, and the
software tool required for programming in Assembly and C language.
2. Develop assembly language programs using ARM Cortex M3 for different
applications.
3. Interface external devices and1/0 with ARM Cortex M3.
4. Develop C language programs and library functions for embedded system
applications.
5. Analyze the functions of various peripherals, peripheral registers and power saving
modes of ARM Cortex M3
VK
18ECL66 Embedded Systems Laboratory
VK
18ECL66 Embedded Systems Laboratory
✓ Students are not allowed to touch any equipment, chemicals or other materials in
the laboratory area until you are instructed by Teacher or Technician.
✓ Before starting Laboratory work follow all written and verbal instructions
carefully. If you do not understand a direction or part of a procedure, ASK YOUR
CONCERN TEACHER BEFORE PROCEEDING WITH THE ACTIVITY.
✓ Before use equipment must be read carefully Labels and instructions. Set up and
use the equipment as directed by your teacher.
✓ If you do not understand how to use a piece of equipment, ASK THE TEACHER
FOR HELP!
✓ Perform only those experiments authorized by your teacher.
✓ Carefully follow all instructions, both written and oral.
✓ Unauthorized experiments are not allowed in the Laboratory.
✓ Students are not allowed to work in Laboratory alone or without presence of the
teacher.
✓ Any failure / break-down of equipment must be reported to the teacher.
✓ Protect yourself from getting electric shock.
VK
18ECL66 Embedded Systems Laboratory
VK
18ECL66 Embedded Systems Laboratory
Objectives:
ALGORITHM
__main
LDR R1,=0XFFFF
LDR R2,=0XFFFF
MUL R3,R1,R2
NOP
Stop
END
VK
18ECL66 Embedded Systems Laboratory
Aim: To determine the 1’s and 0’s in the given 32-bit data using assembly level
language.
Objectives:
Materials:
__main
VK
18ECL66 Embedded Systems Laboratory
Aim: To determine whether the given 16 bit is even or odd using assembly level
language.
Objectives:
Materials:
ALGORITHM
1. Start
2. Initialize the number to find it even or odd(0x91)
3. Load this number in R1 register.
4. Check the LSB of the number by logical shirt right by 1 time.
5. Move to branch if LSB= 1.
6. If the number if Even store 0xEEEE in R1 register.
7. If the number if Odd store Ox1111 in R1 register.
8. End
VK
18ECL66 Embedded Systems Laboratory
Objectives:
Materials:
ALGORITHM
1. Start
2. Initialize the data 0x12345678
3. Load this data to RO register.
4. Load R1 register with Address of Destination Location.
5. Write the contents of RO into RAM location.
6. Find the RAM location and its content.
7. End
__main
LDR R0, DATA
LDR R1, =RAMLOC
STR R0, [R1]
AREA RAM, DATA, READWRITE
RAMLOC DCD 0
END
VK
18ECL66 Embedded Systems Laboratory
AREA sum,CODE,READONLY
EXPORT __main
__main
MOV R0,#10 ; load 10 to register
MOV R1,#0 ; empty the register to store result
loop
ADD R1,R0 ; add the content of R1 with result at R0
SUBS R1,#1 ; Decrement R1 by 1
BNE loop ; repeat till r1 goes 0
LDR R0,=0x10000000 ; load the addrs of var into R0
STR R1,[R0] ; store the result into addrs location
NOP
NOP
end
VK
18ECL66 Embedded Systems Laboratory
unsigned int i;
unsigned char * ptr, arr[] = "Hello world\r";
#define THR_EMPTY 0x20 //U0THR is Empty
int main(void)
{
UART0_Init();
while (1)
{
ptr = arr;
while ( * ptr != '\0')
{
while ((LPC_UART0 -> LSR & THR_EMPTY) != THR_EMPTY); //Is U0THR is EMPTY??
LPC_UART0 -> THR = * ptr++;
}
for (i = 0; i <= 60000; i++);
}
}
void UART0_Init(void)
{
LPC_SC -> PCONP |= 0x00000008; //UART0 peripheral enable
LPC_PINCON -> PINSEL0 = 0x00000050;
LPC_UART0 -> LCR = 0x00000083;
//enable divisor latch, parity disable, 1 stop bit, 8bit word length
LPC_UART0 -> DLM = 0X00;
LPC_UART0 -> DLL = 0x1A; //select baud rate 9600 bps for 4Mhz
LPC_UART0 -> LCR = 0X00000003; //Disable divisor latch
LPC_UART0 -> FCR = 0x07; //FIFO enable,RX FIFO reset,TX FIFO reset
}
#include <LPC17xx.H>
void Clock_Wise(void);
void AClock_Wise(void);
unsigned long i;
int main(void)
{
LPC_PINCON -> PINSEL1 = 0x00000000; //P0.26 GPIO, P0.26 controls dir
LPC_PINCON -> PINSEL3 = 0x00000000; //P1.24 GPIO
LPC_GPIO0 -> FIODIR |= 0x04000000; //P0.26 output
LPC_GPIO1 -> FIODIR |= 0x01000000; //P1.24 output
while (1)
{
Clock_Wise();
for (i = 0; i < 300000; i++);
AClock_Wise();
for (i = 0; i < 300000; i++);
} //end while(1)
} //end main
void Clock_Wise(void)
{
LPC_GPIO1 -> FIOCLR = 0x01000000; //P1.24 Kept low to off DCM
for (i = 0; i < 10000; i++); //delay to componsate inertia
LPC_GPIO0 -> FIOSET = 0x04000000; //coil is on
LPC_GPIO1 -> FIOSET = 0x01000000; //motor in on
} //end void Clock_Wise(void)
void AClock_Wise(void)
{
LPC_GPIO1 -> FIOCLR = 0x01000000; //P1.24 Kept low to off DCM
for (i = 0; i < 10000; i++); //delay to componsate inertia
LPC_GPIO0 -> FIOCLR = 0x04000000; //coil is off
LPC_GPIO1 -> FIOSET = 0x01000000; //Motor is on
}
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 (j = 0; j < 50; j++) //50 times in Anti Clock wise Rotation
anti_clock_wise();
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
}
}
//TRIANGULAR WAVE
#include <LPC17xx.H>
int main()
{
unsigned long int temp = 0x00000000;
unsigned int i = 0;
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)
} //End of main()
//SQUARE WAVE
#include <LPC17xx.H>
void delay(void);
int main()
{
LPC_PINCON -> PINSEL0 &= 0xFF0000FF; // Configure P0.4 to P0.11 as GPIO
LPC_GPIO0 -> FIODIR |= 0x00000FF0;
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++);
}
#include <LPC17xx.h>
#include "lcd.h"
void scan(void);
0x87
};
int main(void)
{
LPC_PINCON -> PINSEL3 = 0x00000000; //P1.20 to P1.23 MADE GPIO
LPC_PINCON -> PINSEL0 = 0x00000000; //P0.15 as GPIO
LPC_PINCON -> PINSEL1 = 0x00000000; //P0.16 t0 P0.18 made GPIO
LPC_GPIO0 -> FIODIR &= ~0x00078000; //made INput P0.15 to P0.18 (cols)
LPC_GPIO1 -> FIODIR |= 0x00F00000; //made output P1.20 to P1.23 (rows)
LPC_GPIO1 -> FIOSET = 0x00F00000;
lcd_init();
while (1)
{
while (1)
{
for (row = 1; row < 5; row++)
{
if (row == 1)
var1 = 0x00100000;
else if (row == 2)
var1 = 0x00200000;
else if (row == 3)
var1 = 0x00400000;
else if (row == 4)
var1 = 0x00800000;
temp = var1;
flag = 0;
scan();
if (flag == 1)
break;
} //end for(row=1;row<5;row++)
if (flag == 1)
break;
} //2nd while(1)
} //end for(i=0;i<16;i++)
temp1 = 0xCC;
lcd_com();
delay_lcd(800);
lcd_puts( & key);
} //end while 1
} //end main
void scan(void)
{
void EINT3_IRQHandler(void);
int main(void)
{
LPC_PINCON -> PINSEL4 |= 0x04000000; //P2.13 as EINT3
LPC_PINCON -> PINSEL4 &= 0xFCFFFFFF; //P2.12 GPIO for LED
LPC_GPIO2 -> FIODIR = 0x00001000; //P2.12 is assigned output
LPC_GPIO2 -> FIOSET = 0x00001000; //Initiall LED is kept on
LPC_SC -> EXTINT = 0x00000008; //writing 1 cleares the interrupt, get set if there is
interrupt
LPC_SC -> EXTMODE = 0x00000008; //EINT3 is initiated as edge senitive, 0 for level
sensitive
LPC_SC -> EXTPOLAR = 0x00000000; //EINT3 is falling edge sensitive, 1 for rising edge
//above registers, bit0-EINT0, bit1-EINT1, bit2-EINT2,bit3-EINT3
NVIC_EnableIRQ(EINT3_IRQn); //core_cm3.h
while (1);
}
void EINT3_IRQHandler(void)
{
LPC_SC -> EXTINT = 0x00000008; //cleares the interrupt
7. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay.
/* Description :
\\\\\\\\\\\\\\\DISPLAY ARE CONNECTED IN COMMON CATHODE MODE\\\\\\\\\\\\\\\\\\\\\
Port0 Connected to data lines of all 7 segement displays
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>
0x00000070,
0x000007f0,
0x000006f0,
0x00000770,
0x000007c0,
0x00000390,
0x000005e0,
0x00000790,
0x00000710
};
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
Switchcount++;
if (Switchcount == 0x10) // 0 to F has been displayed ? go back to 0
{
Switchcount = 0;
LPC_GPIO0 -> FIOCLR = 0x00180ff0;
}
}
}
8. Measure Ambient temperature using a sensor and SPIADC IC. //Header file for SPI.c file
#include <LPC17xx.h>
#ifndef __SPI_H
#include "SPI.h" #define __SPI_H
extern unsigned char spi_flag,temp;
unsigned char spi_flag = 0, temp = 0; void SPI_Init(void); // SPI initialisation
void SPI_IRQHandler(void);//SPI Interrupt routine
void SPI_Init(void) #endif
{
LPC_PINCON -> PINSEL0 |= 0xC0000000; //P0.15 as SCK
LPC_PINCON -> PINSEL1 = 0x0000003C; //select MISO-P0.17,MOSI-P0.18
LPC_SPI -> SPCCR = 0x1E; // SPI CLOCK SELECTED AS 100KHZ
LPC_SPI -> SPCR = 0xA0; //8 bit data, actve high clk, master SPI mode,SPI Int enable
// Master mode and SCK line is active high
LPC_SPI -> SPINT = 0x01; //clear the interrupt flag
NVIC_EnableIRQ(SPI_IRQn);
}
void SPI_IRQHandler(void)
{
spi_flag = 1;
temp = LPC_SPI -> SPSR; // To clear SPIF bit we have to read status register.
temp = LPC_SPI -> SPDR; // Then read the data register(optional)
LPC_SPI -> SPINT = 0x01; // To clear the SPI interrupt
}