Microcontrollers Lab Manual - East Point
Microcontrollers Lab Manual - East Point
LABORATORY
MANUAL
SEMESTER : IV
SUBCO :
NAME :
USN :
SECTION:
PROGRAM OUTCOMES
PO2: Problem analysis: Identify, formulate, review research literature, and analyse complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex engineering
activitieswith an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and Team Work: Function effectively as an individual and as a member or
leader in diverse teams, and in multi – disciplinary settings.
PO12: Life-long learning: Recognize the need for and have the preparation and ability to
engage in independent and life -long learning in the broadest context of technological change.
Department of Computer Science and Engineering
VISION
MISSION
M2: To serve the technical, scientific, economic and societal developmental needs
of our communities
VISION
The department aspires to be a Centre of excellence in Computer Science & Engineering to develop
competent professionals through holistic development.
MISSION
M1: To create successful Computer Science Engineering graduates through effective pedagogies, the
M2: To augment experiential learning skills to serve technical, scientific, economic, and social
developmental needs.
M3: To instil integrity, critical thinking, personality development, and ethics in students for a
PEO 1: To produce graduates who can perform technical roles to contribute effectively in software
industries and R&D Centre
PEO 2: To produce graduates having the ability to adapt and contribute in key domains of computer
science and engineering to develop competent solutions.
PEO 3: To produce graduates who can provide socially and ethically responsible solutions while
adapting to new trends in the domain to carve a successful career in the industry
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO1: To conceptualize, model, design, simulate, analyse, develop, test, and validate computing
systems and solve technical problems arising in the field of computer science & engineering.
PSO2: To specialize in the sub-areas of computer science & engineering systems such as cloud
computing, Robotic Process Automation, cyber security, big data analytics, user interface design, and
IOT to meet industry requirements.
PSO3: To build innovative solutions to meet the demands of the industry using appropriate tools and
techniques.
CLO 1: Understand the fundamentals of ARM-based systems and basic architecture of CISC and RISC.
CLO 2: Familiarize with ARM programming modules along with registers, CPSR and Flags.
CLO 3: Develop ALP using various instructions to program the ARM controller.
CLO 4: Understand the Exceptions and Interrupt handling mechanism in Microcontrollers.
CLO 5: Discuss the ARM Firmware packages and Cache memory polices.
COURSE OUTCOMES
CO2: Develop programs using ARM instruction set for an ARM Microcontroller.
Teaching-Learning Process
These are sample Strategies, which teachers can use to accelerate the attainment of the various course
outcomes.
1. Lecturer method (L) needs not to be only a traditional lecture method, but alternative effective
teaching methods could be adopted to attain the outcomes.
2. Use of Video/Animation to explain functioning of various concepts.
3. Encourage collaborative (Group Learning) Learning in the class.
4. Ask at least three HOT (Higher order Thinking) questions in the class, which promotes critical
thinking.
5. Adopt Problem Based Learning (PBL), which fosters students’ Analytical skills, develop design
thinking skills such as the ability to design, evaluate, generalize, and analyze information rather than
simply recall it.
6. Introduce Topics in manifold representations.
7. Show the different ways to solve the same problem with different circuits/logic and encourage the
students to come up with their own creative ways to solve them.
8. Discuss how every concept can be applied to the real world - and when that's possible, it helps
improve the students understanding.
9. Use any of these methods: Chalk and board, Active Learning, Case Studies.
Module-1
ARM Embedded Systems: The RISC design philosophy, The ARM Design Philosophy, Embedded System
Hardware, Embedded System Software.
ARM Processor Fundamentals: Registers, Current Program Status Register, Pipeline, Exceptions, Interrupts,
and the Vector Table, Core Extensions
Textbook 1: Chapter 1 - 1.1 to 1.4, Chapter 2 - 2.1 to 2.5
RBT: L1, L2, L3
Module-2
Introduction to the ARM Instruction Set: Data Processing Instructions, Branch Instructions, Software
Interrupt Instructions, Program Status Register Instructions, Coprocessor Instructions, Loading Constants.
Module-4
Exception and Interrupt Handling: Exception handling, ARM processor exceptions and modes, vector table,
exception priorities, link register offsets, interrupts, assigning interrupts, interrupt latency, IRQ and FIQ
exceptions, basic interrupt stack design and implementation. Firmware: Firmware and bootloader, ARM
firmware suite, Red Hat redboot, Example: sandstone, sandstone directory layout, sandstone code structure.
Module-5
CACHES: The Memory Hierarchy and Cache Memory, Caches and Memory Management Units: CACHE
Architecture: Basic Architecture of a Cache Memory, Basic Operation of a Cache Controller, The
Relationship between Cache and Main Memory, Set Associativity, Write Buffers, Measuring Cache Efficiency,
CACHE POLICY: Write Policy—Writeback or Writethrough, Cache Line Replacement Policies, Allocation
Policy on a Cache Miss. Coprocessor 15 and caches.
Practical Sessions need to be assessed by appropriate rubrics and viva-voce method. This will contribute to 20 marks.
Rubrics for each Experiment taken average for all Lab components – 15 Marks.
Viva-Voce– 5 Marks (more emphasized on demonstration topics)
The sum of three tests, two assignments, and practical sessions will be out of 100 marks and will be
scaled down to 50 marks
(to have a less stressed CIE, the portion of the syllabus should not be common /repeated for any of the methods of the
CIE. Each method of CIE should have a different syllabus portion of the course).
CIE methods /question paper has to be designed to attain the different levels of Bloom’staxonomy as per the
outcome defined for the course.
The students have to answer 5 full questions, selecting one full question from each module
Suggested Learning Resources:
Textbooks
Andrew N Sloss, Dominic Symes and Chris Wright, ARM system developers guide, Elsevier,Morgan
Kaufman publishers, 2008.
Shibu K V, “Introduction to Embedded Systems”, Tata McGraw Hill Education, Private Limited,2nd Edition.
Reference Books
Raghunandan. G.H, Microcontroller (ARM) and Embedded System, Cengage learningPublication,2019
The Insider’s Guide to the ARM7 Based Microcontrollers, Hitex Ltd.,1st edition, 2005.
Steve Furber, ARM System-on-Chip Architecture, Second Edition, Pearson, 2015.
Raj Kamal, Embedded System, Tata McGraw-Hill Publishers, 2nd Edition, 2008.
Index
Sl. Pg.
Program List CO PO, PSO RBT
No. No
PART A
PO1, PO2,
Using Keil software, observe the various Registers, Dump, CPSR, PO3, PO4,
1 with a simple Assembly Language Programs (ALP). CO1 L3 1
PO5,
PSO1,2,3
PO1, PO2,
Develop and simulate ARM ALP for Data Transfer, Arithmetic and
PO3, PO4,
2 Logical operations (Demonstrate with the help of a suitable CO2 L3 2
program). PO5,
PSO1,2,3
PO1, PO2,
PO3, PO4,
3 Develop an ALP to multiply two 16-bit binary numbers. CO2 L3 3
PO5,
PSO1,2,3
PO1, PO2,
PO3, PO4,
4 Develop an ALP to find the sum of first 10 integer number CO2 L3 4
PO5,
PSO1,2,3
PO1, PO2,
Develop an ALP to find the largest/smallest number in an array of PO3, PO4,
5 CO2 L3 5
32 number PO5,
PSO1,2,3
PO1, PO2,
Develop an ALP to count the number of ones and zeros in two PO3, PO4,
6 consecutive memory locations CO2 L3 6
PO5,
PSO1,2,3
PO1, PO2,
Simulate a program in C for ARM microcontroller using KEIL to sort PO3, PO4,
7 CO3 L2 7
the numbers in ascending/descending order using bubble sort. PO5,
PSO1,2,3
PO1, PO2,
Simulate a program in C for ARM microcontroller to find factorial of PO3, PO4,
8 L2 8
a number. CO3 PO5,
PSO1,2,3
PO1, PO2,
Simulate a program in C for ARM microcontroller to demonstrate
PO3, PO4,
9 case conversion of characters from upper to lowercase and lower CO3 L2 9
to uppercase. PO5,
PSO1,2,3
PO1, PO2,
CO4, PO3, PO4,
10 Demonstrate enabling and disabling of Interrupts in ARM PO5, L3 10
CO5
PSO1,2,3
MC LAB BCS402
PO1, PO2,
Demonstrate the handling of divide by zero, Invalid Operation and PO3, PO4,
11 Overflow exceptions in ARM CO5 L3 10
PO5,
PSO1,2,3
Using Keil software, observe the various Registers, Dump, CPSR, with a simple
Assembly Language Programs (ALP).
1
Page
MC LAB BCS402
Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
2
MC LAB BCS402
multiply END
OUTPUT :
3
MC LAB BCS402
OUTPUT:
4
MC LAB BCS402
Write a program to find the largest/smallest number in an array of 32 numbers.
AREA LARGE,CODE,READONLY
ENTRY
MOV R5,#5 ;R5 = length of array - 1
LDR R1,=ARRAY ;load starting addressing of
array LDR R2,[R1],#4 ;load 1st element of array
LOOP LDR R4,[R1],#4 ;load next element of array
CMP R2,R4 ;compare 1st and 2nd
element BHI NEXT
MOV R2,R4 ;R2=largest value
NEXT SUBS R5,R5,#1 ;decrement the counter after every
comparison BNE LOOP ; repeat until R5=0
STOP B STOP
END
OUTPUT :
5
MCES LAB 21CS43
Write a program to count the number of ones and zeros in two consecutive memory
locations.
OUTPUT :
6
MCES LAB 21CS43
Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.
#include <stdio.h>
int main() {
int arr[] = {5, 1, 4, 2, 8}; // Your input array
int N = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, N);
return 0;
}
7
MCES LAB 21CS43
#include <stdio.h>
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 {
unsigned long long fact = factorial(num);
printf("Factorial of %d = %llu\n", num, fact);
}
return 0;
}
8
MCES LAB 21CS43
#include <stdio.h>
int main() {
char input[] = "Hello, World!"; // Your input string
int len = sizeof(input) - 1; // Exclude the null terminator
return 0;
}
9
MCES LAB 21CS43
10
MCES LAB 21CS43
11
MCES LAB 21CS43
The LPC2148 microcontrollers are based on a 32 bit ARM7TDMI-S CPU with real-time emulation
and embedded trace support, that combines the microcontroller with embedded high speed
flash memory of 512 kB FEATURES 32-bit ARM7TDMI-S microcontroller in a tiny LQFP64
package.8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program
memory.128 bit wide interface/accelerator enables high speed 60 MHz operation.
In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software. Single flash
sector or full chip erase in 400 ms and programming of 256 bytes in 1 ms.Embedded ICE RT and
Embedded Trace interfaces offer real-time debugging with the on-chip Real Monitor software
and high speed tracing of instruction execution. USB 2.0 Full Speed compliant Device Controller
with 2 kB of endpoint RAM. In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible
to USB by DMA.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14analog
inputs, with conversion times as low as 2.44 ms per channel. Single 10-bit D/A converter
provides variable analog output.
• Two 32-bit timers/external event counters (with four capture and four compare channels each),
PWM unit (six outputs) and watchdog.
• Low power real-time clock with independent power and dedicated 32 kHz clock input.
• Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus
(400 kbit/s), SPI and SSP with buffering and variable data length capabilities.
• Vectored interrupt controller with configurable priorities and vector addresses.
• Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.
• Up to nine edge or level sensitive external interrupt pins available.
12
MCES LAB 21CS43
13
MCES LAB 21CS43
14
MCES LAB 21CS43
15
MCES LAB 21CS43
5
Step 2: Now open Project –> New uVision Project
Step 3: Give Name to Project e.g. “LED blinking” and save it.
16
MCES LAB 21CS43
Step 4: then appears the popup box Select Device for Target “Target1”. Click the
drop down menu where you need to select Legacy Device Database [no RTE].
NOTE: If you need to install ARM7 packages this Legacy device database packages.
Step 5: Select our Device name LPC2148 under the NXP category and click OK
17
MCES LAB 21CS43
Step 6: A dialogue box appears to copy Startup.s to project folder, just click yes
18
MCES LAB 21CS43
Now go to File tab and add New file from the menu.
Save the file from the previous step with a specific name. Add .c
extension to the file name.Eg.(ledblinking.c)
19
MCES LAB 21CS43
20
MCES LAB 21CS43
Select the previously saved file from the window that pops up and add it to the Source Group1. In our
case, LED Blinking.c
Now click on the Options for Target ‘Target1’... symbol shown in red box in the image below or
press Alt+F7 or right click on Target1 and click on Options for Target ‘Target1’.... Options for
target window will open. Go to the Output tab in that window. Tick ‘√’ Create HEX File option.
Which will be burn into the microcontroller.
21
MCES LAB 21CS43
In the options for target window, go to the Linker tab. Select the Use
Memory Layout from Target Dialogue option.
22
MCES LAB 21CS43
Then click on OK. 12. Now Type the source code for LED Blinking 13. Once the code is typed,
Build the code by clicking on the button shown in red in the image below. You can also build
the project from the Build Target option in the Project tab or by pressing F7 on the keyboard.
You can see creating hex file ... in the Build Output window as shown in the image.
14. Once the project is built, a hex file is created in the Objects folder inside the folder of your
project.
Use Flash Magic software to burn this hex file in your microcontroller.
So open Flash Magic
23
MCES LAB 21CS43
Now you can see the that LED starts blinking on the development board
24
MCES LAB 21CS43
VIVA QUESTIONS:
4.What is embedded c?
The C standard doesn't care about embedded, but vendors of embedded systems usually provide
standalone implementations with whatever amount of libraries they're willing to provide. C is a
widely used general purpose high level programming language mainly intended for system
programming.
5, What is main difference between C and embedded C?
As, embedded C is generally an extension of the C language, they are more or less similar.
However, some differences do exist, such as: C is generally used for desktop computers, while
25
MCES LAB 21CS43
embedded C is for microcontroller based applications. C can use the resources of a desktop PC
like memory, OS, etc.
A watchdog timer is an electronic device or electronic cards that execute specific operation
after certain time period if something goes wrong with an electronic system.
7.What is the need for an infinite loop in embedded systems?
Embedded systems require infinite loops for repeatedly processing or monitoring the state of the
program. For instance, the case of a program state continuously being verified for any exceptional
errors that might just happen during run-time such as memory outage or divide by zero, etc.
8.What is semaphore?
A semaphore is an abstract data type or variable that is used for controlling access, by multiple
processes to a common resource in a concurrent system such as multiprogramming operating
system. Semaphores are commonly used for two purposes
· To share a common memory space
· To share access to files
The ARM7TDMI is a member of the Advanced RISC Machines (ARM) family of general purpose 32-
bit microprocessors, which offer high performance for very low power consumption and price.
It is used to to interface the digital input device like limit switch , digital sensors, keypad etc.,
It is used to interface the digital out put devices like LCD ,buzzer and etc.,
14.What is RTC
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on, and
optionally when it is off.
15.What is the Purpose of RTC
Measures the passage of time to maintain a calendar and clock. Provides Seconds, Minutes,
Hours, Day of Month, Month, Year, Day of Week, and Day of Year.
16.What is the UART Communication?
A universal asynchronous receiver/transmitter (UART) is a microchip that performs
serial-to-parallel conversion of data received from peripheral devices and parallel-to-serial
conversion of data coming from the CPU for transmission to peripheral devices
27
MCES LAB 21CS43
▶ The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link
between integrated circuits (ICs).
Standard I2C compliant bus interfaces that may be configured as Master, Slave, or Master/Slave.
Arbitration between simultaneously transmitting masters without corruption of serial data on the
bus.
Programmable clock to allow adjustment of I2C transfer rates.
Bidirectional data transfer between masters and slaves.
A real time operating system (RTOS) is an operating system that guarantees a certain capability
within a specified time constraint.
22.What is a Thread? What are the differences between process and thread?
28
MCES LAB 21CS43
A thread is a single sequence stream within in a process. Because threads have some of the
properties of processes, they are sometimes called lightweight processes. Threads are popular
way to improve application through parallelism. For example, in a browser, multiple tabs can be
different threads. MS word uses multiple threads, one thread to format the text, other thread to
process inputs, etc. A thread has its own program counter (PC), a register set, and a stack space.
Threads are not independent of one other like processes as a result threads shares with other
threads their code section, data section and OS resources like open files and signals.
23.What are the different scheduling algorithms
24.What is deadlock?
Deadlock is a situation when two or more processes wait for each other to finish and none of
them ever finish. Consider an example when two trains are coming toward each other on same
track and there is only one track, none of the trains can move once they are in front of each other.
Similar situation occurs in operating systems when there are two or more processes hold some
resources and wait for resources held by other(s).
A kernel, executive or nucleus is the smallest portion of the operating system that provides for
task scheduling, dispatching, and inter task communication.
27. What is meant by task?
A task is an independent thread of execution that can compete with other concurrent tasks for
processor execution time.
28.What is multitasking and its types?
Pre-emptive Multitasking
Non-preemptive Multitasking
Context switching is the process of saving and restoring sufficient information for a real-time task
so that it can be resumed after being interrupted.
Given a set of periodic tasks and preemptive priority scheduling, then assigning priorities such
that the tasks with shorter periods have higher priorities (rate-monotonic), yields an optimal
scheduling algorithm.
32. Mention the features of μc/os-II
The Real-Time Kernel is a portable, ROMable, scalable, preemptive real-time, multitasking kernel
for microprocessors and microcontrollers.
The functions to create task, suspend and resume, and time setting and time retrieving functions
• OSTaskCreate()
• OSTaskSuspend()
• OSTaskResume()
• OSTimeSet()
• OSTimeGet()
OSTimeDly()
OSTimeDlyHMSM()
30
MCES LAB 21CS43
OSTimeDlyResume()
31