Microcontroller Laboratory (BCS402)
Bapuji Educational association®
BAPUJI INSTITUTE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
MICROCONTROLLER LABORATORY MANUAL
(BCS402) III SEMESTER
Vision and Mission of the Department
Vision
To provide a quality and holistic education in data science, data analytics, data visualization,
industry collaborations and research for empowering individuals to derive knowledge, thereby
transform the potentials in data for the betterment of society.
Mission
1. Educate and prepare students with a strong foundation in data science, equipping them
with the skills, knowledge, and ethical principles needed to excel in data-driven fields.
2. Foster collaborations with industries to adopt modern data science and visualization
tools which solves the real-world problems that have societal benefits.
3. Cultivate a culture of life-long learning with intellectual curiosity in data science and
nurturing individuals who are passionate about data-driven decision-making.
Laboratory Outcomes: The student should be able to:
1. Explain the ARM Architectural features and Instructions.
2. Develop programs using ARM instruction set for an ARM Microcontroller.
3. Explain C-Compiler Optimizations and portability issues in ARM Microcontroller.
4. Apply the concepts of Exceptions and Interrupt handling mechanisms in developing
applications.
5. Demonstrate the role of Cache management and Firmware in Microcontrollers.
Programme outcome (PO’s)
1. Engineering knowledge: Apply the knowledge of mathematics,
science, engineering fundamentals, and an engineering specialization to
the solution of complex engineeringproblems.
2. Problem analysis: Identify, formulate, research literature, and analyse
complex engineering problems reaching substantiated conclusions using
first principles of mathematics, natural sciences, and engineering sciences.
Prof. Usha C, BIET 1
Microcontroller Laboratory (BCS402)
3. Design/development of solutions: Design solutions for complex
engineering problems and design system components or processes that
meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments,
analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modernengineering and IT tools including prediction and
modelling to complex engineering activitieswith an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual
knowledge to assesssocietal, health, safety, legal, and cultural issues and
the consequent responsibilities relevant to the professional engineering
practice.
7. 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.
8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and
as a member or leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering
activities with the engineering community and with society at large, such
as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear
instructions.
11. Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply
these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. 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.
Prof. Usha C, BIET 2
Microcontroller Laboratory (BCS402)
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.
Prof. Usha C, BIET 3
Microcontroller Laboratory (BCS402)
INTRODUCTION
The µVision IDE combines project management, run-time environment, build
facilities, source code editing, and program debugging in a single powerful
environment. µVision is easy-to-use and accelerates your embedded software
development. µVision supports multiple screens and allows you to create individual
window layouts anywhere on the visual surface.
The µVision Debugger provides a single environment in which you may test, verify,
and optimize your application code. The debugger includes traditional features like
simple and complex breakpoints, watch windows, and execution control and provides
full visibility to device peripherals.
LPC2148 Microcontroller
LPC2148 is a 16-bit or 32-bit microcontroller based on ARM7 family.
ARM is an advanced reduced instruction set computer (RISC) machine.
The LPC2148 microcontroller has 512-kB on-chip FLASH memory as well as 32-kB
on-chip SRAM
STEPS TO BE FOLLOWED
Step1: Double click on Keil software. Window shown below opens
Prof. Usha C, BIET 4
Microcontroller Laboratory (BCS402)
Step2: Goto project - select - New µVision project
Step3: Create a new project, enter the file name
Prof. Usha C, BIET 5
Microcontroller Laboratory (BCS402)
Step4: Select the device for target
Step5: Type LPC2148 in search window and select NXP-LPC2148 as shown
Step6: After selecting LPC2148 a dialogue window is opened as shown in the snapshot.
Select -
“NO” for SOFTWARE PROGRAMS
“YES” for HARDWARE PROGRAMS
Note: Since we are working on software programs select “NO”
Prof. Usha C, BIET 6
Microcontroller Laboratory (BCS402)
Step7: Later the following window opens
Step8: Now go to file - select new
Prof. Usha C, BIET 7
Microcontroller Laboratory (BCS402)
Step9: A text file is opened then type program
Step10: save the text file
Step11: Save the file as “abc.s” as shown
Note: FOR SAVING THE SOFTWARE PROGRAM REQUIRES “.s” EXTENSION
EX : FILE_NAME.s
Prof. Usha C, BIET 8
Microcontroller Laboratory (BCS402)
Step12: Now go to Source Group1 – right click – select - Add Existing files to Group
‘Source Group1’ as shown
Prof. Usha C, BIET 9
Microcontroller Laboratory (BCS402)
Step13: A dialogue box opens from that select the file abc.s and click Add as shown
Step14:Now the file abc.s is added to source group1 as shown
Prof. Usha C, BIET 10
Microcontroller Laboratory (BCS402)
Step15: To compile the program click on the file abc.s – right click- select Build target
as shown
Step16: After compilation Build output is displayed wrt errors and warning as shown
Prof. Usha C, BIET 11
Microcontroller Laboratory (BCS402)
Step17: Select start/stop debug session
Step18: Select OK
Prof. Usha C, BIET 12
Microcontroller Laboratory (BCS402)
Step19: OUTPUT
Step20: Select RUN
Prof. Usha C, BIET 13
Microcontroller Laboratory (BCS402)
Step21: Go to Debug select-start/stop debug session
Prof. Usha C, BIET 14
Microcontroller Laboratory (BCS402)
END OF THE PROGRAM
Prof. Usha C, BIET 15
Microcontroller Laboratory (BCS402)
EXPERIMENT – 1
Using Keil software, observe the various Registers, Dump, CPSR (Current Program
Status Register), with a simple Assembly Language Programs (ALP).
AREA PROG,CODE,READONLY //created area called prog in memory
MOV R1,#10 //Instructions
MOV R2,#5
ADD R1,R2
END
OUTPUT
Prof. Usha C, BIET 16
Microcontroller Laboratory (BCS402)
EXPERIMENT – 2
Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
AREA PRG2, CODE, READONLY; defining logical area named prg2 and the code
ENTRY; the entry point where the code starts
LDR R0, =5; data transfer – R0=5
LDR R1, =3; R1=3
ADD R2, R0, R1; arithmetic ADD R2=8 (5+3)
SUB R3, R0, R1; SUB R3=2 (5-3)
MUL R4, R0, R1; MUL R4=F (5*3 = 15 = F)
AND R5, R0, R1; logical AND R5=1 (5&&3)
ORR R6, R0, R1 ; OR R6=7 (5||3)
EOR R7,R0,R1; XOR R7=6 (5^3)
END; end of the program
OUTPUT
Prof. Usha C, BIET 17
Microcontroller Laboratory (BCS402)
EXPERIMENT – 3
Develop an ALP to multiply two 16-bit binary numbers.
AREA MULTIPY,CODE,READONLY
ENTRY
MOV R1,#0002
MOV R2,#0004
MUL R3,R1,R2
REPEAT B REPEAT
END
OUTPUT
Prof. Usha C, BIET 18
Microcontroller Laboratory (BCS402)
EXPERIMENT – 4
Develop an ALP to find the sum of first 10 integer numbers.
AREA SUM1,CODE,READONLY
EXPORT__main
_main
MOV r1,#10; //counter of 10 numbers
MOV r2,#00; //OUTPUT gets stored
LOOP
ADDS R2,R2,R1; //r2=10
SUBS R1,R1,#01; // r1=9
CMP R1,#00
BNE LOOP; //checks r1=00
L BL
END
OUTPUT
Prof. Usha C, BIET 19
Microcontroller Laboratory (BCS402)
EXPERIMENT – 5
Develop an ALP to find the largest/smallest number in an array of 32 numbers.
AREA LARGEST,CODE,READONLY
ENTRY
START
MOV R5,#6
LDR R1,=VALUE1
LDR R2,[R1],#4
LOOP
LDR R4,[R1],#4
CMP R2,R4
BHI LOOP1
MOVR2,R4
LOOP1
SUBS R5,R5,$1
CMP R5,#0
BNE LOOP
LDR R4,=RESULT
STR R2,[R4]
NOP
NOP
NOP
VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
AREA DATA2,DATA,READWRITE;
RESULT DCD 0X0
END
OUTPUT
Prof. Usha C, BIET 20
Microcontroller Laboratory (BCS402)
EXPERIMENT – 6
Develop an ALP to count the number of ones and zeros in two consecutive memory
locations.
AREA ONEZERO,CODE,READONLY
ENTRY
START
MOV R2,#0
MOV R3,#0
MOV R7,#2
LDR R6,=VALUE
LOOP MOV R1,#32
LDR R0,[R6],#4
LOOP0 MOVS R0,R0,ROR #1
BHI ONES
ZEROS ADD R3,R3,#1
B LOOP1
ONES ADD R2,R2,#1
LOOP1 SUBS R1,R1,#1
BNE LOOP0
SUBS R7,R7,#1
;CMP R7,#0
BNE LOOP
BACK B BACK
VALUE DCD 0X11111111,0XAA55AA55
END
OUTPUT
Prof. Usha C, BIET 21
Microcontroller Laboratory (BCS402)
EXPERIMENT – 7
Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.
AREA ASCENDING,CODE,READONLY
ENTRY
START
MOV R8,#4
LDR R2,=CVALUE
LDR R3,=DVALUE
LOOP0 LDR R1,[R2],#4
STR R1,[R3],#4
SUBS R8,R8,#1
;CMP R8,#0
BNE LOOP0
START1 MOV R5,#3
MOV R7,#0
LDR R1,=DVALUE
LOOP LDR R2,[R1],#4
LDR R3,[R1]
CMP R2,R3
BLT LOOP2
STR R2,[R1],#4
STR R3,[R1]
MOV R7,#1
ADD R1,#4
LOOP2 SUBS R5,R5,#1
CMP R5,#0
BNE LOOP
CMP R7,#0
BNE START1
BACK B BACK
NOP
NOP
;ARRAY OF 32 BIT NUMBERS IN DATA REGION
CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1,DATA,READWRITE
Prof. Usha C, BIET 22
Microcontroller Laboratory (BCS402)
;ARRAY OF 32 BIT NUMBERS IN DATA REGION
DVALUE
DCD 0X00000000
END
OUTPUT
Prof. Usha C, BIET 23
Microcontroller Laboratory (BCS402)
EXPERIMENT – 8
Simulate a program in C for ARM microcontroller to find factorial of a number
TTL FACTORIAL OF A NUMBER
AREA PROG2,CODE,READONLY
ENTRY
START
LDR R0,NUM
SUB R1,R0,#1
TOP CMP R1,#0
BEQ DONE
MUL R0,R1,R0
SUB R1,R1,#1
B TOP
DONE
STOP B STOP
AREA DATA3,DATA,READONLY
NUM DCW 3
END
OUTPUT
Prof. Usha C, BIET 24
Microcontroller Laboratory (BCS402)
EXPERIMENT – 9
Simulate a program in C for ARM microcontroller to demonstrate case conversion of
characters from upper to lowercase and lower to uppercase.
Prof. Usha C, BIET 25