18CSL48 Microcontroller and Embedded Systems Laboratory
18CSL48 Microcontroller and Embedded Systems Laboratory
S.NO PAGE
LIST OF THE EXPERIMENTS NO
SOFTWARE PART
1 Write a program to multiply two 16 bit binary numbers. 02
Write a program to find the sum of first 10 integer numbers.
2 03
Write a program to find factorial of a number.
3 04
Write a program to add an array of 16 bit numbers and store the 32 bit result in
4 internal RAM 05
Write a program to find the square of a number (1 to 10) using look-up table.
5 06
Write a Write program to find the largest number in an array of 32 numbers.
6a 07
Write a program to find the smallest number in an array of 32 numbers.
6.b 09
Write a program to arrange a series of 32 bit numbers in ascending order.
7.a) 11
Write a program to arrange a series of 32 bit numbers in descending order.
7.b) 13
Write a program to count the number of ones and zeros in two consecutive
8 memory locations. 15
HARDWARE PART
Display “Hello World” message using Internal UART.
1. 16
Determine Digital output for a given Analog input using Internal ADC of
4 21
ARM controller.
Experiment No 1:
Write a program to multiply two 16 bit binary numbers.
Output:
1st Input : Register R1 =6400
2nd Input : Register R2 =3200
Output:
Result can be viewed in Register R2 in hex decimal values.
Output:
Result can be viewed in Register R0
Output:
Result can be viewed in Memory location address specified in R4 and also in register R0
Output:
Enter Input number in memory location specified in Register R2
Result can be viewed in Register R3
NOP
NOP
NOP
; ARRAY OF 32 BIT NUMBERS (N=7)
VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
Output:
Result can be viewed in Memory location address specified in R4 and also in
register R2
Output:
Result can be viewed in Memory location address specified in R4 and also in
register R2
LOOP0
LDR R1, [R2], #4 ; LOADING VALUES FROM CODE REGION
STR R1, [R3], #4 ; STORING VALUES TO DATA REGION
SUBS R8, R8, #1 ; DECREMENT COUNTER
CMP R8, #0 ; COMPARE COUNTER TO 0
BNE LOOP0 ; LOOP BACK TILL ARRAY ENDS
START1 MOV R5, #3 ; INTIALISE COUNTER TO 3(i.e. N=4)
MOV R7, #0 ; FLAG TO DENOTE EXCHANGE HAS OCCURED
LDR R1, =DVALUE ; LOADS THE ADDRESS OF 1st VALUE
LOOP LDR R2, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R3, [R1] ; LOAD SECOND NUMBER
CMP R2, R3 ; COMPARE NUMBERS
BLT LOOP2 ; IF THE 1st NUMBER IS < THEN GOTO LOOP2
STR R2, [R1], #-4
STR R3, [R1]
MOV R7, #1 ; FLAG DENOTING EXCHANGE HAS TAKEN PLACE
ADD R1, #4 ; RESTORE THE PTR
LOOP2
SUBS R5, R5, #1 ; DECREMENT COUNTER
CMP R5, #0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
CMP R7, #0 ; COMPARING FLAG
BNE START1
; IF FLAG IS NOT ZERO THEN GO TO START1 LOOP
NOP
NOP
NOP
; ARRAY OF 32 BIT NUMBERS (N=4) IN CODE REGION
CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
Output:
Result can be viewed at location DVALUE (stored in R3)
LOOP0
LDR R1,[R2],#4 ; LOADING VALUES FROM CODE REGION
STR R1,[R3],#4 ; STORING VALUES TO DATA REGION
SUBS R8,R8,#1 ; DECREMENT COUNTER
CMP R8,#0 ; COMPARE COUNTER TO 0
BNE LOOP0 ; LOOP BACK TILL ARRAY ENDS
LOOP2
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
CMP R7,#0 ; COMPARING FLAG
BNE START1
; IF FLAG IS NOT ZERO THEN GO TO START1 LOOP
NOP
NOP
NOP
Output:
Result can be viewed at location DVALUE (stored in R3)
PROCEDURE:
Step 1: Give a double click on µvision 4 icon on the desk top, it will generate a window as shown below
Step 2: To create new project go to project select new micro vision project.
Step 3: select a drive where you would like to create your project.
Step 4: Create a new folder and name it with your project name.
Step 5: Open that project folder and give a name of your project executable and save it.
Step 6: After saving it will show some window there you select your microcontroller company i.e. NXP
from Phillips
Step 7: Select your chip as ARM DEVELOPMENT KIT
Step 8: After selecting chip click on OK then it will display some window asking to add STARTUP.
Select YES.
Step 9: A target is created and startup is added to your project target and is shown below.
Step 10: To write your project code select a new from menu bar.
Step 11: It will display some text editor, to save that select SAVE option from menu bar.
Step 12: By giving a name with extension .c and save it.
Step 13: Write the code of your project and save it.
Step 14: To add the c to target give a right click on Source Group, choose “ADD s to Group” option.
Step 15: It will display some window there select the file and click on ADD option.
Step 16: It will be added to our target and it shows in the project window.
Step 17: Select right click on target in the project window and select “Options for Target.”
Step 18: It will show some window, in that go to output option and choose Create Hex option by
selecting that box.
Step 20: Now to compile your project go to Project select Build Target option or press F7.
Step 21: Check the concern block of output and observe the results.
PROGRAM:
#include<lpc214x.h>
int main()
{
PINSEL0=0X0000005; //select TXD0 and RXD0 lines
U0LCR = 0X00000083; //enable baud rate divisor loading and
U0DLM = 0X00; //select the data format
U0DLL = 0x13; //select baud rate 9600 bps
U0LCR = 0X00000003;
while(1)
{
ptr = arr;
while(*ptr!='\0')
{
U0THR=*ptr++;
while(!(U0LSR & 0x20)== 0x20);
for(delay=0;delay<=600;delay++);
}
for(delay=0;delay<=60000;delay++);
}
}
int main()
{
IO0DIR= 0X00000900;
IO0SET= 0X00000100; //P0.8 should always high.
while(1)
{
//clock_wise
IO0CLR = 0x00000900; /stop motor and also turn
off relay
for(j=0;j<10000;j++); //small delay to
allow motor to turn off
IO0SET = 0X00000900; //Selecting the P0.11 line
for clockwise and turn on motor
for(j=0;j<400000;j++); //delay
//anti_clock_wise
IO0CLR = 0X00000900; //stop motor and also turn
off relay
for(j=0;j<10000;j++); //small delay to allow motor to turn off
IO0SET = 0X00000100; //not selecting the P0.11 line for Anti clockwise
for(j=0;j<400000;j++); //delay
} //End of
while(1)
} //End of Main
PROGRAM:
#include <LPC21xx.H>
void clock_wise(void);
void anti_clock_wise(void);
int main(void)
{
PINSEL0 = 0x00000000; //P0.12 to P0.15 GPIo
IO0DIR = 0x0000F000; //P0.12 to P0.15 output
while(1)
{
for(j=0;j<50;j++) // 50 times in Clock wise Rotation(360
degree)
clock_wise();
} // End of while(1)
} // End of main
void clock_wise(void)
{
var1 = 0x00001000; //For Clockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
IO0PIN = var1;
for(k=0;k<=30000;k++); //for step speed variation
var1 = var1<<1; //For Clockwise
}
}
void anti_clock_wise(void)
{
var1 = 0x00008000; //For Anticlockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
IO0PIN = var1;
for(k=0;k<=30000;k++); //for step speed variation
var1 = var1>>1; //For Anticlockwise
}
}
PROGRAM:
#include <lpc214x.h>
#include <Stdio.h>
#include "lcd_h.h"
int main()
{
PINSEL1 = 0X00040000; //AD0.4 pin is selected(P0.25)
IO0DIR = 0x000000FC; //configure o/p lines for lcd
ptr = dis;
temp1 = 0x80; //Display starting address of first line 1 th pos
lcd_com();
delay(800);
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
ptr1 = arr;
temp1 = 0xC0; //Display starting address of second line 4 th
pos
lcd_com();
delay(800);
while(*ptr1!='\0')
{
temp1 = *ptr1;
lcd_data();
ptr1 ++;
}
//infinite loop
while(1)
{
//CONTROL register for ADC
AD0CR = 0x01200010; //command register for ADC-AD0.4
temp1 = 0x89;
lcd_com();
delay(1200);
ptr = var1;
while(*ptr!='\0')
{
temp1=*ptr;
lcd_data();
ptr++;
}
temp1 = 0xc9;
lcd_com();
delay(1200);
ptr1 = var;
while(*ptr1!='\0')
{
temp1=*ptr1;
lcd_data();
ptr1++;
}
} // end of while(1)
} //end of main()
PROGRAM:
#include <LPC21xx.h>
unsigned long int temp=0x00000000;
int main ()
{
unsigned int i=0;
IO0DIR=0x00FF0000;
while(1)
{
// output 0 to FE
for(i=0;i!=0xFF;i++)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
// output FF to 1
for(i=0xFF; i!=0;i--)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
}//End of while(1)
}//End of main()
#include <lpc21xx.h>
int main ()
{
PINSEL1 = 0x00000000 ; //
Configure P0.16 to P0.31 as GPIO
IO0DIR = 0x00FF0000 ;
while(1)
{
IO0PIN = 0x00000000;
for(delay=0;delay<=950;delay++);
IO0PIN = 0x00FF0000;
for(delay=0;delay<=950;delay++);
}
}
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
while(1)
{
get_key();
}
} //end of main()
for(i=0;i<16;i++)
{
if(scan_code[i] == res1) //equate the scan_code with res1
{
result = ASCII_CODE[i]; //same position value
of ascii code
temp1 = 0xCE; //display address
for key value
lcd_com();
delay(3200); //delay
temp1 = result;
lcd_data();
delay(3200); //delay
break; //is assigned to
result
}
}
}// end of get_key();
void scan(void)
{
temp2 = IO1PIN; // status of port1
temp2 = temp2 & 0x000F0000; // Verifying column key
if(temp2 != 0x000F0000) // Check for Key Press or Not
{
delay(1000); //delay(100)//give debounce
delay check again
temp2 = IO1PIN;
temp2 = temp2 & 0x000F0000; //changed condition is same
#include<lpc214x.h>
int main(void)
{
IO1DIR = 0X02000000;
IO1SET = 0X02000000;
PINSEL1 =0X00000001; //Setup P0.16 to alternate
function EINT0
void Extint0_Isr(void)__irq
{ //whenever there is a low level on EINT0
EXTINT |= 0x01; //Clear interrupt
int_flag = 0x01;
VICVectAddr = 0; //Acknowledge
Interrupt
}
PROGRAM:
#include <LPC21xx.h>
while(1)
{
//Display values on Seven Segment
IO0SET = 0x10000000;
IO0CLR = 0x00FF0000;