Bcs402 Cse MC Lab Manual
Bcs402 Cse MC Lab Manual
IV Semester
2022 Scheme
Prepared By:
Mrs. Padmasree
Associate Professor,
Department of Computer Science and Engineering,
RVITM, Bengaluru – 560076
padmasree.rvitm@rvei.edu.in
RV Institute of Technology & Management®
Department of Computer Science & Engineering
Institute Vision
Strive to impart quality technical education with global competence and societal
commitment, leading to breakthrough innovations.
Department Vision
PEO 1: Impart strong foundation in solving hardware & software engineering problems and
adapt to the changes in technology through continuous-learning.
PEO 2: Inculcate innovation in new technologies and systems in their key domains thus
encouraging them to pursue higher education and research.
PEO 3: Disseminate their knowledge in advance areas of Computer science to become
industry ready graduates or entrepreneurs.
PEO 4: Exhibit professional ethics & values, effective communication and team work with
a multidisciplinary approach to meet the needs of the society.
PSO 1: Analyse the core concepts by Computer Science Engineering for building intensive
systems to improve efficiency with different algorithms and tools.
PSO 2: Able to use professional, managerial and interdisciplinary skills in identifying the
research gaps to develop cost effective and innovative solutions leading to
automation.
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.
Course outcomes (Course Skill Set): At the end of the course, the student will be able to:
● Explain the ARM Architectural features and Instructions.
● Develop programs using ARM instruction set for an ARM Microcontroller.
● Explain C-Compiler Optimizations and portability issues in ARM Microcontroller.
● Apply the concepts of Exceptions and Interrupt handling mechanisms in developing applications.
● Demonstrate the role of Cache management and Firmware in Microcontrollers.
Assessment Details (both CIE and SEE)
The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%. The
minimum passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum
passing mark is 35% of the maximum marks (18 out of 50 marks). A student shall be deemed to have satisfied the
IV-Semester, MICROCONTROLLERS Lab / IPCC (BCS402) P a g e 5 |32
RV Institute of Technology & Management®
Department of Computer Science & Engineering
academic requirements and earned the credits allotted to each subject/ course if the student secures a minimum of
40% (40 marks out of 100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester End
Examination) taken together.
CIE for the theory component of the IPCC (maximum marks 50)
● IPCC means practical portion integrated with the theory of the course.
● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.
● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests, each
of 15 Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods mentioned
in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second test after covering 85-
90% of the syllabus.
● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the theory
component of IPCC (that is for 25 marks).
● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.
CIE for the practical component of the IPCC
1. 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks for the test to
be conducted after the completion of all the laboratory sessions.
2. On completion of every experiment/program in the laboratory, the students shall be evaluated including viva-
voce and marks shall be awarded on the same day.
3. The CIE marks awarded in the case of the Practical component shall be based on the continuous evaluation of the
laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’ write-ups are
added and scaled down to 15 marks.
4. The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted for 50
marks and scaled down to 10 marks.
5. Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory component of
IPCC for 25 marks.
6. The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC.
SEE for IPCC
Theory SEE will be conducted by University as per the scheduled timetable, with common question papers for the
course (duration 03 hours)
1. The question paper will have ten questions. Each question is set for 20 marks.
2. There will be 2 questions from each module. Each of the two questions under a module (with a maximum of 3
sub-questions), should have a mix of topics under that module.
3. The students have to answer 5 full questions, selecting one full question from each module.
4. Marks scored by the student shall be proportionally scaled down to 50 Marks.
The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion will have a CIE component
only. Questions mentioned in the SEE paper may include questions from the practical component.
Suggested Learning Resources:
Text Books:
1. Andrew N Sloss, Dominic Symes and Chris Wright, ARM system developers guide, Elsevier, Morgan Kaufman
publishers, 2008.
Reference Books:
1. Raghunandan.G.H, Microcontroller (ARM) and Embedded System, Cengage learning Publication, 2019.
2. Insider’s Guide to the ARM7 based microcontrollers, Hitex Ltd.,1st edition, 2005
Activity Based Learning (Suggested Activities in Class)/ Practical Based Learning
Assign the group task to demonstrate the Installation and working of Keil Software.
Introduction to ARM7
Key Points:
1. Header File: Replace #include <LPC214x.h> with the header file appropriate for your
specific ARM microcontroller family.
2. Initialization: The initializeSystem() function is where you would configure system
clocks and other microcontroller-specific initializations. This function depends heavily
on the microcontroller and specific hardware configurations you are using.
3. Sorting Functionality: The bubbleSort() function is a straightforward implementation
of the bubble sort algorithm.
4. Swap Functionality: The swap() function simply swaps two integers in memory.
5. Execution Flow: In an embedded environment, main functions typically have an
infinite loop (while (1)) as they should continue running indefinitely.
To Run in KEIL:
1. Create a New Project: Open KEIL µVision and create a new project for your specific ARM Cortex
microcontroller.
2. Add Your Source File: Add a new .c file to your project and copy the code above into this file.
3. Configure Your Project: Set up your target CPU settings and configure any peripherals you are
using.
4. Compile and Debug: Compile the project and load it onto your microcontroller. Use debugging tools
to step through the code and ensure it's working correctly.
By following these steps, you should be able to implement and run a bubble sort algorithm on an ARM
microcontroller using KEIL. If you want to sort in descending order, adjust the comparison in the
bubbleSort() function from arr[j] >arr[j+1] to arr[j] <arr[j+1].
Step 1: After opening Keil uV4, Go to Project tab and click on close projectThen
Step 2: After Creating project now Select your device model. Example.NXP-LPC2148
Step 3: So now your project is created and Message window will appear to add start up file of
your Device click on Yes so it will be added to your project folder
Step 4: Now go to File and create new file and save it with .C extension if you will write
program in C language or save with .asm for assembly language.
Step 5: Now write your program and save it again. You can try example given at end of this
tutorial.
Step 6: After that on left you see project window [if it’s not there….go to View tab and click on
project window]
Click output tab here & check create Hex file if you want to generate hex file
Step 7: Now Expand target and you will see source group
Step 9: you can see Status of your program in Build output window
[If it’s not there go to view and click on Build output window]
EXPERIMENTS: 1 to 11
Conduct the following experiments by writing program using ARM7TDMI/LPC2148 usingan
evaluation board/simulator and the required software tool.
MODULE – 1 Experiment 1:
Using Keil software, observe the various Registers, Dump, CPSR, with a simple
Assembly Language Programs (ALP).
MODULE – 2 Experiment 2:
Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
Sample ALP Program to multiply two 16 bit binary numbers using Keil Microvision4
ENTRY
memory
END
MODULE – 2 Experiment 3:
Develop an ALP to multiply two 16-bit binary numbers.
START
MOV r1, #6400 ; STORE FIRST NUMBER INR0
MOV r2, #3200 ; STORE SECOND NUMBER INR1
MUL r3, r1, r2 ;
MULTIPLICATION
OUTPUT:
MODULE – 2 Experiment 4:
Develop an ALP to find the sum of first 10 integer numbers.
loop
END
OUTPUT:
START
MOVR2, R4; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4 TOR2
LOOP1
NOP
back B back; ARRAY OF 32-BIT NUMBERS (N=7) VALUE1
DCD0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;
Output:
Largest
LOOP
LDR R4, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2, R4 ; COMPARE NUMBERS
BLS LOOP1 ; IF THE FIRST NUMBER IS < THEN GOTO LOOP1
MOV R2, R4 ; IF THE FIRST NUMBER IS > THEN MOV CONTENT R4
TO R2
LOOP1
SUBS R5, R5, #1 ; DECREMENT COUNTER
CMP R5, #0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS LDR R4, =RESULT ; LOADS
THE ADDRESS OF RESULT STR R2, [R4] ; STORES THE RESULT IN R2
NOP
back B back
Output:
Smallest
MODULE – 2 Experiment 6:
Develop an ALP to count the number of ones and zeros in two consecutive memory locations.
ROTATE
RORS R1, #1 ; Rotate right by 1 bit, update
CPSR
BCS ONES ; is carry =1
ADD R3,R3,#1 ; increment 0 count
B NEXT ; Branch to next Rotation
ONES
ADD R2,R2,#1 ; increment 1 count
NEXT
ADD R4,R4,#-1 ; Decrement Rotation Count
CMP R4, #0 ; if Rotation EQ to 0
BNE ROTATE ; if No, goto Rotate
ADD R0,R0,#04 ; Add Address of no. of 1's
STRB R2,[R0] ; Store No. of 1's
ADD R0, R0, #1 ; Load address of no. of 0's
END
OUTPUT:
MODULE – 3 Experiment 7:
Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in ascending/descending
order using bubble sort.
// Function prototypes
void bubbleSort(int arr[], int n);
void swap(int *xp, int *yp);
void initializeSystem();
int main() {
initializeSystem();
// Example array
int data[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(data) / sizeof(data[0]);
// After sorting, you can add code here to do something with the sorted array
// For example, display it on an LCD connected to the microcontroller
while (1) {
// Typically, embedded programs have an infinite loop
}
Key Points:
6. Header File: Replace #include <LPC214x.h> with the header file appropriate for your specific
ARM microcontroller family.
7. Initialization: The initializeSystem() function is where you would configure system clocks and
other microcontroller-specific initializations. This function depends heavily on the microcontroller and
specific hardware configurations you are using.
8. Sorting Functionality: The bubbleSort() function is a straightforward implementation of the
bubble sort algorithm.
9. Swap Functionality: The swap() function simply swaps two integers in memory.
10. Execution Flow: In an embedded environment, main functions typically have an infinite loop (while
(1)) as they should continue running indefinitely.
To Run in KEIL:
5. Create a New Project: Open KEIL µVision and create a new project for your specific ARM Cortex
microcontroller.
6. Add Your Source File: Add a new .c file to your project and copy the code above into this file.
7. Configure Your Project: Set up your target CPU settings and configure any peripherals you are
using.
8. Compile and Debug: Compile the project and load it onto your microcontroller. Use debugging tools
to step through the code and ensure it's working correctly.
By following these steps, you should be able to implement and run a bubble sort algorithm on an ARM
microcontroller using KEIL. If you want to sort in descending order, adjust the comparison in the
bubbleSort() function from arr[j] >arr[j+1] to arr[j] <arr[j+1].
MODULE – 3 Experiment 8:
Simulate a program in C for ARM microcontroller to find factorial of a number.
#include <LPC214x.h> // Change this include according to your specific ARM MCU family
// Function prototypes
unsigned long longfactorial(unsigned int n);
void initializeSystem();
int main() {
initializeSystem();
// Calculate factorial
result = factorial(number);
// Now, you can use `result` to display on an LCD or debug through serial output
// As this is a simulation, you might set a breakpoint here and inspect `result`
while (1) {
// Embedded programs typically have an infinite loop
}
return 0;
}
MODULE – 3 Experiment 9:
Simulate a program in C for ARM microcontroller to demonstrate case conversion of characters from upper
to lowercase and lower to uppercase.
#include <LPC214x.h> // Specific header for the LPC1768; adjust for your ARM Cortex-M model
// Function prototypes
char toLowercase(char c);
char toUppercase(char c);
void initializeSystem();
int main() {
initializeSystem();
// Normally you would display these results or send them over a communication interface
// Use breakpoints or watch variables to check these conversions in KEIL's debugger
while (1) {
// Infinite loop to keep the microcontroller running
}
return 0;
}
// Converts uppercase letters to lowercase. If the input is not uppercase, it returns the input unchanged.
char toLowercase(char c) {
if (c >= 'A' && c <= 'Z') {
return c + ('a' - 'A');
}
return c;
}
// Converts lowercase letters to uppercase. If the input is not lowercase, it returns the input unchanged.
char toUppercase(char c) {
if (c >= 'a' && c <= 'z') {
return c - ('a' - 'A');
}
return c;
}
Basic Concepts
Enabling Interrupts: In ARM Cortex-M microcontrollers, interrupts are enabled using the
__enable_irq() function, which clears the PRIMASK register, allowing interrupts with configurable
priority.
Disabling Interrupts: Interrupts are disabled using the __disable_irq() function, which sets the
PRIMASK register, preventing the activation of all interrupts and exceptions with configurable priority.
Setting Up in KEIL:
1. New Project: Start a new project in KEIL for the specific ARM Cortex microcontroller you are using.
2. Add the Code: Copy the above C code into a new .c file in the project.
3. Configure the MCU Settings: Make sure you set up the microcontroller settings correctly, including
clock, memory, and peripherals.
4. Compile and Debug: Compile the project and upload it to your microcontroller. Use the debugger to
step through and observe the conversion functions at work.
void initializeSystem();
void criticalFunction();
int main() {
initializeSystem();
while (1) {
// Normal operation, where interrupts are enabled
}
return 0;
}
// System initialization
void initializeSystem() {
SystemInit(); // System specific initialization
// Additional initialization code like configuring system clocks,
// setting up GPIO, or other peripheral setups can be added here.
}
Key Points:
1. System Initialization: initializeSystem() typically configures the system clock, initializes
peripherals, and sets up any required hardware configurations specific to the application and
microcontroller.
2. Disabling/Enabling Interrupts: __disable_irq() and __enable_irq() are used to protect
the critical section, ensuring that the operations within criticalFunction() are not
interrupted. This is crucial for maintaining system integrity in scenarios involving shared data
or specific timing requirements.
3. Infinite Loop: The infinite loop in the main function signifies continuous operation common
in embedded systems, where the program must not terminate under normal operations.
Handling exceptions such as divide by zero, invalid operations, and overflow in ARM Cortex-M
microcontrollers requires a proper understanding of the ARM exception mechanism. ARM Cortex-M
processors use a fault mechanism called the Fault Exception to handle errors and exceptional
conditions that occur during execution. This includes:
Usage Fault: Caused by execution of an undefined instruction, illegal unaligned access, or other
erroneous operation codes, such as divide by zero.
Bus Fault: Caused by memory access errors.
Memory Management Fault: Typically, this occurs from an invalid access to a protected area of
memory (though not all Cortex-M processors have a Memory Protection Unit).
For the purposes of simplicity and clarity, I will focus on the Usage Fault handler, as it is typically
the one that deals with arithmetic exceptions such as divide by zero and overflow. Here’s how you
could set up handlers for these exceptions using a generic ARM Cortex-M microcontroller, such as
one from the LPC1768 series:
#include <LPC214x.h>
void SystemInit() {
// System Initialization code here
SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk; // Enable Divide by zero trap
}
void HardFault_Handler(void) {
// Handle Hard Fault exception
while(1);
}
void UsageFault_Handler(void) {
// Handle Usage Fault exception
uint32_t faultStatus = SCB->CFSR; // Collecting the fault status register
int main(void) {
SystemInit();
int a = 10;
int b = 0;
int c = a / b; // This will trigger a divide by zero if b is zero
return 0;
}
VIVA QUESTIONS