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

Microcontrollers Lab Manual

jk

Uploaded by

ddhineshkumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Microcontrollers Lab Manual

jk

Uploaded by

ddhineshkumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Microcontrolle Lab (BCSL403)

R. L. JALAPPA INSTITUTE OF TECHNOLOGY


Department of CS&E(DATA SCIENCE)

MICROCONTROLLERS LABORATORY MANUAL(BCSL402)


(2022 SCHEME)

SEMESTER : IV

FACULTY INCHARGE : Dr. KARTHIK B U,Incharge HOD,RLJIT

Ms .PRIYANKA.T.V, ASST.PROF,RLJIT

PROGRAMMER INCHARGE : Ms. NEHA. C. SHEKAR ,RLJIT

NAME
USN
Batch
Sem
Branch

Department of CSE(DS),RLJIT Page 1


Microcontrollers Lab (BCSL403)

DEPARTMENT OF CSE ( DATA SCIENCE)

Vision:

To Progress as a centre of Aptitude in Data Analytics and ripen clever professional as

data analytics and researchers.

Mission:

M1: To craft the students with novel and intellectual skills to capability in the field of

Data science.

M2: To consecrate to build professionals with social-virtuousness attitude and

implementing innovative Teaching and Learning methods

PROGRAMME EDUCATIONAL OBJECTIVES: (PEO)

PEO1: Graduates will have Prospective careers in the field of Data Science.

PEO2: Graduates will have good Leadership Qualities, Self Learning abilities and Zeal

for higher Studies and Research.

PEO3: Graduates will follow Ethical Practices and exhibit high level of Professionalism

by participating and addressing Technical, Business and environmental challenges.

Department ofCSE(DS),2023-24 Page 2


Microcontrollers Lab (BCSL403)

PROGRAMME SPECIFIC OUTCOMES: (PSO)

PSO 1: Students will able to solve the real life problems faced in the society, industry

and other areas by applying the skills of Data Science.

PSO 2: Students will have the knowledge of Software, Hardware, Algorithms, Modelling

Networking and Application Development.

PSO 3: Students will have the ability to develop computational knowledge and project

development skills Data Science Techniques.

Department ofCSE(DS),2023-24 Page 3


Microcontrollers Lab (BCSL403)

Sl.No. Experiments

Module – 1

1 Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
Language Programs (ALP).

Module – 2

2 Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).

3 Develop an ALP to multiply two 16-bit binary numbers.

4 Develop an ALP to find the sum of first 10 integer numbers.

5 Develop an ALP to find the largest/smallest number in an array of 32 numbers.

6 Develop an ALP to count the number of ones and zeros in two consecutive memory
locations.

Module – 3

7 Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.

8 Simulate a program in C for ARM microcontroller to find factorial of a number.

9 Simulate a program in C for ARM microcontroller to demonstrate case conversion of


characters
from upper to lowercase and lower to uppercase.

Module – 4 and 5

10 Demonstrate enabling and disabling of Interrupts in ARM.

11 Demonstrate the handling of divide by zero, Invalid Operation and Overflow exceptions in
ARM.

Department ofCSE(DS),2023-24 Page 4


Microcontrollers Lab (BCSL403)

INDEX

Sl. C PO, PSO RB


No. Program List O T
PART A
1 Using Keil software, observe the various Registers, Dump, CO PO1, PO2, L3
CPSR, with a simple Assembly Language Programs (ALP). 1 PO3, PO4,
PO5,
PSO1,2,3
2 Develop and simulate ARM ALP for Data Transfer, CO PO1, PO2, L3
Arithmetic and Logical operations (Demonstrate with the 2 PO3, PO4,
help of a suitable program). PO5,
PSO1,2,3
3 Develop an ALP to multiply two 16-bit binary numbers. CO PO1, PO2, L3
2 PO3, PO4,
PO5,
PSO1,2,3
4 Develop an ALP to find the sum of first 10 integer number CO PO1, PO2, L3
2 PO3, PO4,
PO5,
PSO1,2,3
5 Develop an ALP to find the largest/smallest number in an CO PO1, PO2, L3
array of 32 number 2 PO3, PO4,
PO5,
PSO1,2,3
6 Develop an ALP to count the number of ones and zeros in CO PO1, PO2, L3
two consecutive memory locations 2 PO3, PO4,
PO5,
PSO1,2,3
7 Simulate a program in C for ARM microcontroller using CO PO1, PO2, L2
KEIL to sort the numbers in ascending/descending order 3 PO3, PO4,
using bubble sort. PO5,
PSO1,2,3
8 Simulate a program in C for ARM microcontroller to find CO PO1, PO2, L2
factorial of a number. 3 PO3, PO4,
PO5,
PSO1,2,3

Department ofCSE(DS),2023-24 Page 5


Microcontrollers Lab (BCSL403)

9 Simulate a program in C for ARM microcontroller to CO PO1, PO2, L2


demonstrate case conversion of characters from upper to 3 PO3, PO4,
lowercase and lower to uppercase. PO5,
PSO1,2,3
10 Demonstrate enabling and disabling of Interrupts in ARM CO PO1, PO2, L3
4 PO3, PO4,
CO PO5,
5 PSO1,2,3
11 Demonstrate the handling of divide by zero, Invalid CO PO1, PO2, L3
Operation and Overflow exceptions in ARM 5 PO3, PO4,
PO5,
PSO1,2,3

Department ofCSE(DS),2023-24 Page 6


Microcontrollers Lab (BCSL403)

Course Articulation Matrix

COs POs PSOs


PO PO PO PO PO PO PO PO PO PO1 PO1 PO1 PSO PSO PSO
1 2 3 4 5 6 7 8 9 0 1 2 1 2 3
CO1 3 3 2 1 3 - - - - - - - 3 2 1

CO2 3 3 3 1 3 - - - - - - - 3 2 1

CO3 3 3 3 1 3 - - - - - - - 3 2 1

CO4 3 3 3 1 3 - - - - - - - 3 2 1

CO5 3 3 3 1 3 - - - - - - - 3 2 1

3 - High Correlation 2 - Medium Correlation 1 – Low Correlation

Department ofCSE(DS),2023-24 Page 7


Microcontrollers Lab (BCSL403)

1) Using Keil software, observe the various Registers, Dump, CPSR, with
a simple Assembly Language Programs (ALP).

AREA SimpleALP, CODE, READONLY


ENTRY

START
MOV R0, #10
MOV R1, #20
ADD R2, R0, R1

END

OUTPUT:

Department ofCSE(DS),2023-24 Page 8


Microcontrollers Lab (BCSL403)

2)Develop and simulate ARM ALP for Data Transfer, Arithmetic and
Logical operations
(Demonstrate with the help of a suitable program).
AREA PRG6, CODE, READONLY
ENTRY

LDR R0, =5
LDR R1, =3
ADD R2, R0, R1
SUB R3, R0, R1
MUL R4, R0, R1
AND R5, R0, R1
ORR R6, R0, R1
EOR R7, R0, R1
END

OUTPUT:

Department ofCSE(DS),2023-24 Page 9


Microcontrollers Lab (BCSL403)

3)Develop an ALP to multiply two 16-bit binary numbers.


AIM: To write a program to multiply two 16 bit binary numbers using ARM7TDMI/LPC2148 using an
evaluation board/simulator and the required software tool.

AREA MULTIPLY, CODE, READONLY


ENTRY
MOV R1, #6400
MOV R2, #3200

MUL R3, R1, R2

HERE B HERE
END

OUTPUT:

Department ofCSE(DS),2023-24 Page 10


Microcontrollers Lab (BCSL403)

4)Develop an ALP to find the sum of first 10 integer numbers.


AIM: To write a program to find the sum of first 10 integer numbers using ARM7TDMI/LPC2148
using an evaluation board/simulator and the required software tool.

AREA SUM,CODE,READONLY
ENTRY
MOV R1,#10
MOV R2,#0
LOOP ADD R2,R2,R1
SUBS R2,#0X01
BNE LOOP
HERE B HERE
END

OUTPUT:

Department ofCSE(DS),2023-24 Page 11


Microcontrollers Lab (BCSL403)

5)Develop an ALP to find the largest/smallest number in an array of 32


numbers.
AIM: To write a program to find the largest/smallest number in an array of 32 numbers using
ARM7TDMI/LPC2148 using an evaluation board/simulator and the required software tool.

AREA LARGE,CODE,READONLY
ENTRY
MOV R5,#5
LDR R1,=ARRAY
R2,[R1],#4
LOOP LDR R4,[R1],#4
MOV R2,R4
NEXT SUBS R5,R5,#1
LOOP
STOP B STOP
ARRAY DCD 0X23,0X45,0X65,0X76,0X12,0X99
END

OUTPUT:

Department ofCSE(DS),2023-24 Page 12


Microcontrollers Lab (BCSL403)

6)Develop an ALP to count the number of ones and zeros in two


consecutive memory locations.
AREA ONEZERO, CODE, READONLY
ENTRY
MOV R2,#0
MOV R3,#0
MOV R7,#2
LDR R6,=LOOKUP
LOOP MOV R1,#32
LDR R0,[R6]
MOVS R0,R0,ROR #1
BHI ONES
ZEROS ADD R3,R3,#1
B REPEAT
ONES ADD R2,R2,#1
REPEAT SUBS R1,R1,#1
NEXTBIT
ADD R6,R6,#4
SUBS R7,R7,#1
LOOP
STOP B STOP
LOOKUP DCD
0X5,0X7
END

OUTPUT:

Department ofCSE(DS),2023-24 Page 13


Microcontrollers Lab (BCSL403)

7)Simulate a program in C for ARM microcontroller using KEIL to sort


the numbers in
ascending/descending order using bubble sort.
#include <stdio.h>

#define ARRAY_SIZE 10

void bubbleSort(int arr[], int n) {


int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
// Swap arr[j] and arr[j+1]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

int main() {
int arr[ARRAY_SIZE] = {64, 34, 25, 12, 22, 11, 90, 32, 45, 70};
int i;

printf("Original array: \n");


for (i = 0; i < ARRAY_SIZE; i++) {
printf("%d ", arr[i]);
}
printf("\n");

bubbleSort(arr, ARRAY_SIZE);

printf("Array sorted in ascending order: \n");


for (i = 0; i < ARRAY_SIZE; i++) {
Department ofCSE(DS),2023-24 Page 14
Microcontrollers Lab (BCSL403)

printf("%d ", arr[i]);


}
printf("\n");

return 0;
}

OUTPUT:
Original array:
64 34 25 12 22 11 90 32 45 70
Array sorted in ascending order:
11 12 22 25 32 34 45 64 70 90

Department ofCSE(DS),2023-24 Page 15


Microcontrollers Lab (BCSL403)

8)Simulate a program in C for ARM microcontroller to find factorial of a


number.
AIM: To write a program to find factorial of a number using ARM7TDMI/LPC2148 using anevaluation
board/simulator and the required software tool.
.
#include <stdio.h>

unsigned long long factorial(int n)


{
if (n == 0 || n == 1)
{
return 1;
} else
{
unsigned long long result = 1;
for (int i = 2; i <= n; ++i)
{
result *= i;
}
return result;
}
}

int main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);

if (num < 0)
{
printf("Error! Factorial of a negative number doesn't exist.\n");
} else

Department ofCSE(DS),2023-24 Page 16


Microcontrollers Lab (BCSL403)

{
unsigned long long fact = factorial(num); printf("Factorial of %d = %llu\n",
num, fact);
}

return 0;
}

Department ofCSE(DS),2023-24 Page 17


Microcontrollers Lab (BCSL403)

9)Simulate a program in C for ARM microcontroller to demonstrate case


conversion of characters from upper to lowercase and lower to uppercase.

#include <stdio.h>

void toLowercase(char *str) {


while (*str != '\0') {
if (*str >= 'A' && *str <= 'Z') {
*str = *str + 32;
}
str++;
}
}

void toUppercase(char *str) {


while (*str != '\0') {
if (*str >= 'a' && *str <= 'z') {
*str = *str - 32; }
str++;
}
}

int main() {
char str1[] = "Hello World!";
char str2[] = "HeLLo WorLD!";

toLowercase(str1);
printf("String in lowercase: %s\n", str1);

toUppercase(str2);
printf("String in uppercase: %s\n", str2);

return 0;
}

Department ofCSE(DS),2023-24 Page 18


Microcontrollers Lab (BCSL403)

OUTPUT:
String in lowercase: hello world!
String in uppercase: HELLO WORLD!

Department ofCSE(DS),2023-24 Page 19


Microcontrollers Lab (BCSL403)

10)Demonstrate enabling and disabling of Interrupts in ARM.


AREA InterruptDemo, CODE, READONLY
ENTRY

INTERRUPT_ENABLE equ 0xE000E100


INTERRUPT_DISABLE equ 0xE000E180
INTERRUPT_BIT_POSITION equ 0
ENABLE_INTERRUPT MACRO
LDR r0, =INTERRUPT_ENABLE
LDR r1, [r0]
ORR r1, r1, #(1 << INTERRUPT_BIT_POSITION)
STR r1, [r0]
ENDM

DISABLE_INTERRUPT MACRO
LDR r0, =INTERRUPT_DISABLE
LDR r1, [r0]
ORR r1, r1, #(1 << INTERRUPT_BIT_POSITION) ;
STR r1, [r0]
ENDM

START
ENABLE_INTERRUPT

DISABLE_INTERRUPT

END

explanation:

In this code, we define memory-mapped addresses for the Interrupt Enable Register
(INTERRUPT_ENABLE) and the Interrupt Disable Register (INTERRUPT_DISABLE). These registers
control the enabling and disabling of interrupts in ARM microcontrollers.
We also define a bit position (INTERRUPT_BIT_POSITION) corresponding to the specific interrupt we
want to enable or disable. This allows us to manipulate individual interrupts.
Two macros are defined: ENABLE_INTERRUPT and DISABLE_INTERRUPT. These macros use
assembly instructions to modify the values of the Interrupt Enable and Disable Registers to enable or
disable the specific interrupt.
In the example usage within the START section, we first enable interrupts using the
ENABLE_INTERRUPT macro, then execute the interrupt service routine or main program code, and

Department ofCSE(DS),2023-24 Page 20


Microcontrollers Lab (BCSL403)

finally disable interrupts using the DISABLE_INTERRUPT macro to prevent further interrupts from being
serviced.

11)Demonstrate the handling of divide by zero, Invalid Operation and


Overflow exceptions in ARM.
AREA ExceptionHandling, CODE, READONLY
ENTRY

CPSR equ 0xE000EDC0


VEC_BASE equ 0xE000ED08

DCD ExceptionHandler
DCD ExceptionHandler
DCD ExceptionHandler
MRS R0, CPSR
TST R0, #0x1F
BNE HandlerNotARM

LDR R1, =VEC_BASE


MOV R2, #0x10
STR R1, [R1, R2]
MOV R2, #0x14
STR R1, [R1, R2]
MOV R2, #0x18
STR R1, [R1, R2]

BX LR
END

Explanation:

In this code, we define memory-mapped addresses for the Current Program Status Register (CPSR) and
the Vector Base Register (VICBASE), which are used for exception handling.
We define an exception vector table with entries for each type of exception: divide by zero, invalid
operation, overflow, etc.
Each entry in the exception vector table points to the ExceptionHandler label, where the actual exception
handling code resides.
In the ExceptionHandler, we check if the processor is in ARM state and interrupts are enabled. If not, we
handle the exception accordingly.
If the processor is in ARM state and interrupts are enabled, we set the appropriate vector base address for
each exception using the Vector Base Register.
After setting up the exception handling, you can add your custom exception handling code where indicated.

Department ofCSE(DS),2023-24 Page 21


Microcontrollers Lab (BCSL403)

Department ofCSE(DS),2023-24 Page 22

You might also like