[go: up one dir, main page]

0% found this document useful (0 votes)
142 views20 pages

Coarm Lab Manual Vtu 5th Sem 21 Scheme

Uploaded by

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

Coarm Lab Manual Vtu 5th Sem 21 Scheme

Uploaded by

ANU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

BANGALORE COLLEGE OF ENGINEERING AND TECHNOLOGY

CHANDAPURA, BANGALORE 560099

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

21EC52-COMPUTER ORGANIZATION AND ARM


MICROCONTROLLER
(REGULATION 2021 SCHEME)

SIXTH SEMESTER / ECE

LAB MANUAL
LIST OF EXPERIMENT

PART-A
Conduct the following experiments by writing Assembly Language Program (ALP) using ARM
Cortex M3 Registers using an evaluation board/simulator and the required software tool.
1. Write an ALP to i)multiply two 16 bit binary numbers ii) add two 64 bit Numbers.
2. Write an ALP to find the sum of first 10 integer numbers.
3. Write an ALP to find factorial of a number.
4. Write an ALP to add an array of 16 bit numbers and store the 32 bit result in internal RAM
5. Write an ALP to find the square of a number (1 to 10) using look-up table.
6. Write an ALP to find the largest/smallest number in an array of 32 numbers.
7. Write an ALP to arrange a series of 32 bit numbers in ascending/descending order.
8. i) Write an ALP to count the number of ones and zeros in two consecutive memory locations.
ii) Write an ALP to scan a series of 32 bit numbers to find how many are negative.

PART-B DEMONSTRATION EXPERIMENTS (FOR CIE ONLY NOT FOR SEE)

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


10. Interface a DAC and generate Triangular and Square waveforms.
11. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in
between.
12. Interface a simple Switch and display its status through Relay, Buzzer and LED.
Program No .1 (A) multiply two 16 bit binary numbers

Aim: Write an ALP program to multiply two 16 bit binary numbers

Tools:

Keil 5µvision

Program:
AREA DIS, CODE, READONLY
ENTRY
LDR R0,VALUE1 ; LOAD THE DATA PRESENT IN THE VALUE1 TO R0.
LDR R1,VALUE2 ; LOAD THE DATA PRESENT IN THE VALUE2 TO R1.
UMULL R4,R3,R1,R0 ; UNSIGNED MULTIPLY LONG R4, R3, R1, R0; [R3,R4] = R1*R0
STOP B STOP ; THIS LINE CAN BE IGNORED IF USING ONLY CODE.
VALUE1 DCD &11111111
VALUE2 DCD &11111111
END

OR (DIRECT LOADING OF 32 BIT DATA WILL ALSO WORK )


AREA DIS,CODE,READONLY
ENTRY
LDR R0, = 0X11111112
LDR R1, = 0X11111111
UMULL R3,R4,R1,R0
END
Program No .1 (B) ADD TWO 64 BIT NUMBERS
Aim: Write an ALP program to add two 64 bit binary numbers

Tools:

Keil 5µvision

Program:
AREA add64, CODE, READONLY
ENTRY
MAIN
LDR R0, =Value1 ;pointer to first value
LDR R1, [R0] ;load first part of value1
LDR R2, [R0, #4] ; load lower part of value1
LDR R0, =Value2 ;pointer to second value
LDR R3, [R0] ;load upper part of value2
LDR R4, [R0, #4] ; load lower part of value2
ADDS R6, R2, R4 ;add lower 4 bytes and set carry flag
ADC R5, R1, R3 ;add upper 4 bytes including carry
LDR R0, =Result ;pointer to result
STR R5, [R0] ;store upper part of result
STR R6, [R0, #4] ;store lower part of result
SWI &11
Value1 DCD &12A2E640, &F2100123
Value2 DCD &001019BF, &40023F51
Result DCD 0
END

(OR)
AREA ADDITION , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
LDR R0,=0X1234E640 ;LOAD THE FIRST VALUE IN R0,R1
LDR R1,=0X43210010
LDR R2,=0X12348900 ;LOAD THE SECOND VALUE IN R2,R3
LDR R3,=0X43212102
ADDS R4,R1,R3 ;RESULT IS STORED IN R4,R5
ADC R5,R0,R2
NOP
NOP
NOP
END ;Mark end of file

Program No .2 To find the sum of first 10 integer numbers


AIM: Write an ALP program to find the sum of first 10 integer numbers.
Program:
AREA INT, CODE, READONLY
ENTRY
MOV R5,#10
MOV R0,#0
MOV R1,#1
LOOP ADD R0,R0,R1
ADD R1,R1,#1
SUBS R5,R5,#1
CMP R5,#0
BNE LOOP
LDR R4,=RESULT
STR R0,[R4]
STOP B STOP
AREA INT1,DATA,READONLY
RESULT DCD 0X0
END

Result: 1+2+3+4+5+6+7+8+9+10= 55 in decimal The Hexa value of 55 is 37 is stored in R0 Register


Program No .3 To find factorial of a number
AIM: Write a program to find factorial of a number.
AREA factorial, CODE, readonly
ENTRY
MOV R0,#1 ;int c =1
MOV R1,#5 ;int fact=3
MOV R3,#1 ;int n=1
BL loop
BSTOP
loop
MUL R4,R3,R0
MOV R3,R4
ADD R0,R0,#1
CMP R0,R1
BLE loop
MOV PC,LR
STOP B STOP
END
Or
AREA FACT,CODE,READONLY
ENTRY
MOV R0,#4
MOV R1,#01
BACK MUL R2,R0,R1
MOV R1,R2
SUBS R0,R0,#01
CMP R0,#00
BNE BACK
STOP B STOP
END
The final result will be available in R1 register, It will be in Hexadecimal value
EX: The data given hers is 5: Factorial is 5*4*3*2*1= 120d, But result in R1 will be 78,
which is the hexadecimal value of 120.
For 4; 24 is Decimal and 18 in Hexa as shown in below output of Register R1.

Program No. 4 To add an array of 16 bit numbers and store the 32 bit result in internal
RAM
Aim: Write a program to add an array of 16 bit numbers and store the 32 bit result in internal
RAM
Program:
AREA PROG, CODE, READONLY
ENTRY
MOV R0, #04
MOV R1, #00
MOV R2, #0X40000000
MOV R3, #0X40000010
LOOP LDRH R4,[R2]
ADD R1,R4,R1
SUBS R0,R0,#01
ADD R2,#2
BNE LOOP
STR R1,[R3]
STOP B STOP
END
Program No. 5 to find the square of a number (1 to 10) using look-up table.

Aim: Write a program to find the square of a number (1 to 10) using look-up table.
Program:
AREA SQUARE, CODE, READONLY
ENTRY
LDR R0,=TABLE1
LDR R1, =5
SUB R1, #1
ADD R0,R1
LDRB R2, [R0]
STOP B STOP
AREA DATA1, DATA, READONLY
TABLE1 DCB 01,04,09,16,25,36,49,64,81,100
END
Result: The given number is 5, Square of 5 is 25 in decimal, It is 18 in Hexa, The value 18 is
found in R2.

Program No. 6 To find the largest/smallest number in an array of 32 bit numbers.


AIM: Write a program to find the largest/smallest number in an array of 32 bit numbers.
Program:
AREA PROG, CODE, READONLY
ENTRY
LDR R0,= DATA1
LDR R3,=0X40000000
LDR R4, = 0X05
LDR R1, [R0],#04
SUB R4,R4,#01
BACK LDR R2, [R0]
CMP R1,R2
BHS/BLO LESS
MOV R1,R2
LESS ADD R0,R0,#04
SUB R4,R4,#01
CMP R4,#00
BNE BACK
STR R1,[R3]
STOP B STOP
AREA DATA, CODE
; DATA1 DCD &64,&05,&96,&10,&65 ;(EITHER DATA CAN BE GIVEN IN
THIS FORMAT OR AS SHOWN IN THE NEXT LINE)
DATA1 DCD 0X70000000,0X80000000,0X90000000,0X10000000,0X50000000
END

Program no. 7 To arrange a series of 32 bit numbers in ascending/descending order.

AIM: Write a program to arrange a series of 32 bit numbers in ascending/descending order.


;/* PROGRAM TO sort in Descending order */
;/* ARRAY OF 4 NUMBERS 0X44444444
*/,0X11111111,0X33333333,0X22222222 */
;/* SET A BREAKPOINT AT START1 LABLE & RUN THE PROGRAM*/
;/* CHECK THE UNSORTED NUMBERS AT LOCATION 0X40000000 NEXT */
;/* SET A BREAKPOINT AT NOP INSTRUCTION,RUN THE PROGRAM & CHECK THE RESULT
*/
;/* RESULT CAN BE VIEWED AT LOCATION 0X40000000 */
AREA DESCENDING, CODE, READONLY
ENTRY ;Mark first instruction to execute
MOV R8,#4 ; INTIALISE COUNTER TO 4(i.e. N=4)
LDR R2,=CVALUE ; ADDRESS OF CODE REGION
LDR R3,=DVALUE ; ADDRESS OF DATA REGION
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 FIRST VALUE
LOOP LDR R2, [R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R3,[R1] ; LOAD SECOND NUMBER
CMP R2,R3 ; COMPARE NUMBERS
BGT/BLT LOOP2 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP2
STR R2,[R1],#-4 ; INTERCHANGE NUMBER R2 & R3
STR R3,[R1] ; INTERCHANGE NUMBER R2 & R3
MOV R7,#1 ; FLAG DENOTING EXCHANGE HAS TAKEN PLACE
ADD R1,#4 ; RESTORE THE PTR
LOOP2
NOP
NOP
NOP
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
; ARRAY OF 32 BIT NUMBERS(N=4) IN CODE REGION
CVALUE
DCD 0X44444444 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0X22222222 ;
AREA DATA1,DATA,READWRITE ;
; ARRAY OF 32 BIT NUMBERS IN DATA REGION
DVALUE
DCD 0X00000000 ;
END ; Mark end of file

Program No. 8 (i) To count the number of ones and zeros in two consecutive memory
locations.
Aim: Write a program to count the number of ones and zeros in two consecutive memory
locations.
Program:
AREA DATA1, CODE, READONLY
ENTRY
MOV R0, #0X40000000
MOV R1,#02
MOV R2,#00
MOV R3,#00
UP MOV R4,#08
LDRB R5,[R0]
TOP TST R5,#01
BEQ INCZERO
ADD R2,#01
B LOOP
INCZERO ADD R3,#01
LOOP LSR R5,#01
SUBS R4,#01
CMP R4,#0
BNE TOP
ADD R0,#1
SUBS R1,#01
CMP R1,#00
BNE UP
STOP B STOP
END

Program 8(ii) To Scan a series of 32 bit numbers to find how many are negative.
AIM: Write an ALP to Scan a series of 32 bit numbers to find how many are negative.
Program:
;/*ARRAY OF 7 NUMBERS
0X12345678,0X8D489867,0X11111111,0X33333333,0XAAAAAAAA */
;/*0XE605546C ,0X99999999 */
;/* RESULT CAN BE VIEWED IN R2 */
AREA NEGATIVE , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
MOV R5,#7 ; INTIALISE COUNTER TO 7(i.e. N=7)
MOV R2,#0 ; COUNTER
LDR R4,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE
LOOP
LDR R1,[R4],#4 ; WORD ALIGN T0 ARRAY ELEMENT
ANDS R1,R1,#1<<31 ; TO CHECK NEGATIVE NUMBER
BHI FOUND ; IF THE GIVEN NUMBER IS NEGATIVE GOTO FOUND
B LOOP1; IF THE GIVEN NUMBER IS NOT NEGATIVE GOTO LOOP1
FOUND
ADD R2,R2,#1 ; INCREMENT THE COUNTER
(NEGATIVE NUMBER)
B LOOP1 ; GOTO LOOP1
LOOP1
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
NOP
NOP
;ARRAY OF 32 BIT NUMBERS(N=7)
VALUE
DCD 0X12345678 ;
DCD 0X8D489867 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XE605546C ;
DCD0XAAAAAAAA;
DCD 0X99999999 ;
END ; Mark end of file
DEMONSTRATION EXPERIMENTS
Conduct the following experiments on an ARM CORTEX M3 evaluation board using evaluation version
of Embedded 'C' & Keil Uvision-4 tool/compiler.
9.Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
#include <LPC214X.h>
void delay();
void delay()
{
int i,j;
for (i=0; i<0xff; i++)
for (j=0; j<0xff; j++);
}
int main()
{
IO0DIR=0x000F0000; //Consider ARM port Pin from 16-19
//And set these pins
while (1)
{
//while (IO0PIN & 0x00008000);
//while (! (IO0PIN & 0x00008000));
IO0PIN=0x00010000;
delay ();
IO0PIN=0x00020000;
delay ();
IO0PIN=0x00040000;
delay ();
IO0PIN=0x00080000;
delay();
}
}
PROGRAM NO:10
Aim: Interface a DAC and generate Triangular and Square waveforms.
PROGRAM:
SQUARE WAVE PROGRAM
PROGRAM
#include "LPC214X.h"
unsigned int result=0x00000040,val;
int main()
{
PINSEL1|=0x00080000;
while(1)
{
while(1)
{
val =0xFFFFFFFF;
DACR=val;
{
break;
}
}
while(1)
{
val =0x00000000;
DACR=val;
{
break;
}
}
}
}

TRIANGLE WAVE PROGRAM


PROGRAM
#include "LPC214X.h"
unsigned int value;
int main()
{
PINSEL1|=0x00080000;
while(1)
{
value = 0;
while ( value != 1023 )
{
DACR = ( (1<<16) | (value<<6) );
value++;
}
while ( value != 0 )
{
DACR = ( (1<<16) | (value<<6) );
value--;
}
}
}
PROGRAM NO:11

AIM: Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay in between

PROGRAM:
#include <LPC214x.H>
void delay_led(unsigned long int);
int main(void)
{
IO0DIR = 0x000007FC;
while(1)
{
IO0CLR = 0x00000FFF;
IO0SET = 0x00000604;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000007E4;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000648;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000618;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000730;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000690;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000680;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x0000063C;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000600;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000630;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000620;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000780;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006C4;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000708;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006C0;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006E0;
delay_led(15000000);
IO0CLR = 0x00000FFF;
}
}
void delay_led(unsigned long int count1)
{
while(count1 > 0) {count1--;}
}

PROGRAM NO:12 Interface a simple Switch and display its status through Relay, Buzzer
and LED.
#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

You might also like