0% found this document useful (0 votes)
151 views41 pages

MC Lab Manual - RNSIT

The document outlines the evaluation criteria and structure for a Microcontrollers Laboratory course (BCS402), detailing internal assessments, lab evaluations, and rubrics for various components such as program execution and documentation. It includes a syllabus, course objectives, and a list of experiments focused on ARM microcontroller programming using Keil software. Additionally, it discusses the applications of microcontrollers, differences between microcontrollers and microprocessors, and career opportunities in embedded systems.

Uploaded by

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

MC Lab Manual - RNSIT

The document outlines the evaluation criteria and structure for a Microcontrollers Laboratory course (BCS402), detailing internal assessments, lab evaluations, and rubrics for various components such as program execution and documentation. It includes a syllabus, course objectives, and a list of experiments focused on ARM microcontroller programming using Keil software. Additionally, it discusses the applications of microcontrollers, differences between microcontrollers and microprocessors, and career opportunities in embedded systems.

Uploaded by

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

Microcontrollers Laboratory (BCS402)

MICROCNTROLLERS LABORATORY
INTERNAL EVALUATION SHEET

EVALUATION (MAX MARKS 25)


TEST REGULAR RECORD TOTAL MARKS
EVALUATION
A B C A+B+C
10 10 5 25

R1: REGULAR LAB EVALUATION WRITE UP RUBRIC (MAX MARKS 10)


Sl.
Parameters Good Average Needs improvement
No
a. Understanding of Clear understanding of Problem statement is Problem statement is
problem problem statement while understood clearly but few not clearly understood
(3 marks) designing and implementing mistakes while designing and while designing the
the program (3) implementing program (2) program (1)
b. Writing program(4 Program handles all Average condition is defined Program does not
marks) possible conditions (4) andverified. (3) handle possible
conditions (1)
c. Result and Meticulous documentation Acceptable documentation Documentation does
documentation(3 andall conditions are taken shown(2) not take care all
marks) care (3) conditions (1)

R2: REGULAR LAB EVALUATION VIVA RUBRIC (MAX MARKS 10)


Sl.
Parameter Excellent Good Average
No.
a. Conceptual Answers 80% of the viva Answers 60% of the viva Answers 30% of the
understanding(10 questions asked (10) questions asked (7) viva questions asked
marks) (4)

R3: REGULAR LAB PROGRAM EXECUTION RUBRIC (MAX MARKS 10)


Sl.
Parameters Excellent Good Needs Improvement
No.
a. Design, implementation Program follows syntax and Program has few logical Syntax and semantics
and demonstration semantics of ARM7 errors, moderately of programming is not
(5 marks) assembly instructions and demonstrates all possible clear (1)
Embedded C programming. concepts implemented in
Demonstrates the complete programs (3)
knowledge of the program
written (5)
b. Result and All expected results are Moderately debugs the Expected results are
documentation demonstrated successful, all program and Partial not demonstrated
(5 marks) errors are debugged with documentation properly, unable to
own practical knowledge (3) debug the errors and
and clear documentation no proper
according to the guidelines documentation (1)
(5)

R4: RECORD EVALUATION RUBRIC (MAX MARKS 20)


Sl.
Parameter Excellent Good Average
No.
a. Documentation(10 Meticulous record writing Write up contains program Write up contains only
marks) including program, comments and expected output, but program (15)
and expected output as per the comments are not included
guidelines mentioned (20) (18)
Microcontrollers Laboratory (BCS402)

A. TEST /LAB INTERNALS MARKS (MAX MARKS 10)

Write up Execution Viva Sign Total Avg. Final


TEST # 10 30 10 50 50 10

TEST-1

TEST-2 𝟒𝟎 10

B. REGULAR LAB EVALUATION (MAX MARKS 10)

Write
Date of Exen. Viva Total Teacher
Program # Lab programs up
Execution (10) (10) 30 Signature
(10)

10

11

Total
Marks 330 3𝟎 10
Microcontrollers Laboratory (BCS402)

FINAL MARKS OBTAINED


Signature Of Lab In Charge:
A : TEST (10) TOTAL
(A+B+C)
B : REGULAR EVALUATION (10)

C: RECORD (5) 25
Microcontrollers Laboratory (BCS402)

Lesson planning / Execution plan

Sl. No. WEEK OF REMARKS


CONTENTS EXECUTION

1. Introduction
Basic ARM Assembly Programs Week 1
2.
Using Keil software, observe the various Registers, Dump,
CPSR, with a simple Assembly Language Programs (ALP).
3. Develop and simulate ARM ALP for Data Transfer,
Arithmetic and Logical operations (Demonstrate with the
help of a suitable program).
4. Develop an ALP to multiply two 16-bit binary numbers.

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


6. Develop an ALP to find the largest/smallest number in an
array of 32 numbers.
7. Develop an ALP to count the number of ones and zeros in
two consecutive memory locations.
8. Introduction to Embedded C Programming and Basic
Additional Programs
9. Simulate a program in C for ARM microcontroller using
KEIL to sort the numbers in ascending/descending order
using bubble sort.
10. Simulate a program in C for ARM microcontroller to find
factorial of a number.
11. Simulate a program in C for ARM microcontroller to
demonstrate case conversion of characters from upper to
lowercase and lower to uppercase.
12. Demonstrate enabling and disabling of Interrupts in ARM.
13. Demonstrate the handling of divide by zero, Invalid
Operation and Overflow exceptions in ARM.

14.
Microcontrollers Laboratory (BCS402)

SYALLABUS
SEMESTER – IV
MICROCONTROLLERS LABORATORY
(Effective from the academic year 2023-2024)

Course Code – BCS402 CIE Marks - 50

Number of Contact Hours/Week -3:0:2:0 SEE Marks - 50

Total Number of Lab Contact Hours - 20 Exam Hours - 03

Course Objectives:
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.

Programs List:
Sl. Experiments
No IDE Used: Keil uVision 4 or 5
1. Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
Language Programs (ALP).
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.
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.
10.
Demonstrate enabling and disabling of Interrupts in ARM.
11. Demonstrate the handling of divide by zero, Invalid Operation and Overflow exceptions in
ARM.
Microcontrollers Laboratory (BCS402)

COs COURSE OUTCOMES


BCS402.1 Explain the ARM Architectural features and Instructions.
BCS402.2 Develop programs using ARM instruction set for an ARM Microcontroller.

BCS402.3 Explain C-Compiler Optimizations and portability issues in ARM Microcontroller.


BCS402.4 Apply the concepts of Exceptions and Interrupt handling mechanisms in developing
applications.
BCS402.5 Demonstrate the role of Cache management and Firmware in Microcontrollers.

Laboratory Outcomes: The student should be able to:


 Develop and test program using ARM7TDMI/LPC2148
 Conduct the experiments on an ARM7TDMI/LPC2148 evaluation board using evaluation version
of Embedded 'C' & Keil Uvision-4 tool/compiler.

CIE for the practical component of the IPCC

● 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.
● 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.
● 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.
● The laboratory test (duration 02 hours) after completion of all the experiments shall be conducted for 50
marks and scaled down to 10 marks.
● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory
component of IPCC for 25 marks.
● The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC.

CO-PO MATRIX

COURSE
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3 PSO4
OUTCOMES
CO1 3 3 3 3 1 3 1 2
CO2 3 3 3 3 1 3 1 2
CO3 3 3 3 2 1 2 1 2
CO4 3 3 3 2 1 3 1 2
CO5 3 3 3 1 2 1 2
Microcontrollers Laboratory (BCS402)

TABLE OF CONTENTS
SL. PAGE
CONTENTS
NO. NO.
1 INTRODUCTION
2 A SIMPLE GUIDE ON KEILUVISION 4
3 ARM PROGRAMMING
4 SAMPLE PROGRAMS
5 LABORATORY PROGRAMS
6 Using Keil software, observe the various Registers, Dump, CPSR, with a
simple Assembly Language Programs (ALP).
7 Develop and simulate ARM ALP for Data Transfer, Arithmetic and
Logical operations (Demonstrate with the help of a suitable program).
8 Develop an ALP to multiply two 16-bit binary numbers.
9 Develop an ALP to find the sum of first 10 integer numbers.
10 Develop an ALP to find the largest/smallest number in an array of 32
numbers.
11 Develop an ALP to count the number of ones and zeros in two consecutive
memory locations.
12 Simulate a program in C for ARM microcontroller using KEIL to sort the
numbers in ascending/descending order using bubble sort.
13 Simulate a program in C for ARM microcontroller to find factorial of a
number.
14 Simulate a program in C for ARM microcontroller to demonstrate case
conversion of characters from upper to lowercase and lower to uppercase.
15 Demonstrate enabling and disabling of Interrupts in ARM.
16 Demonstrate the handling of divide by zero, Invalid Operation and
Overflow exceptions in ARM.
17 VIVA QUESTIONS
18 LIST OF ADDITIONAL PROGRAMS
Microcontrollers Laboratory (BCS402)

MICROCONTOLLERS LABORATORY

INTRODUCTION
MICROCONTROLLER
 A small , low cost computer
 It is designed to do a specific Task
 A highly Integrated chip
 Part of Embedded System
 In addition to CPU, It includes RAM, ROM, I/O Ports and Timers also.
 I/O Ports are GPIO Pins

Difference between Microprocessor and Microcontroller

Microprocessor Microcontroller
Executes big application Executes a single task within an application
High Cost Low cost
Not easy to replace Easy to replace
More power consumption Less power consumption
It doesn’t consist of RAM, ROM, I/O Ports. It uses It consists of CPU, RAM, ROM, I/O Ports.
its pins to interface to peripheral devices.

Application of Microcontrollers:
 Light sensing & controlling devices
 Temperature sensing and controlling devices
 Fire detection & safety devices
 Industrial instrumentation devices
 Process control devices
 Power Tools
 Implantable medical devices
 Automobile Engine control systems
 Remote control appliances, Toys.
 Office Machines.

ARM
 Advanced RISC Machine
 The Project started in the year 1983
 Developed by ARM Holdings, a British company. They licensed the ARM architecture to other
companies, who design their own products using this architecture.
Microcontrollers Laboratory (BCS402)

 It is a 32-Bit Microcontroller.
 Uses RISC (Reduced Instruction Set Computing) Architecture.
 It has 32 Bit ALU, 32 Bit data bus.
 32 Bit Address bus. Hence 2 pow 32 = 4GB Memory
 It uses Von Newman Model in which Program and Data stored in common memory
 There are 37 Registers – 32 Bits each (16 Available at a time – R0 to R15)
 Based on Load – Store Model. (All RISC processor work on Registers and not not memory)
 It has 7 operating modes
 It has 7 Interrupts and 7 Addressing modes
 Data formats available in ARM are 8 Bit – Byte format, 16 Bit- Half word format and 32 Bit –
Word format
 In ARM everything is aligned.
 ARM instructions are 3 types
o ARM – When ARM state – 32 Bit instruction
o Thumb When in Thumb state – Purely 16 bit instruction
o Jazelle – For Java Byte code – 8 Bit instructions

Difference between Intel Processor and ARM Processor.


Intel ARM
It uses CISC Architecture Uses RISC Architecture
Needs more power Needs less power
High speed Low speed
More heat generated Less heat generated
High code density
It is heterogeneous computing

Applications:
ARM processor is widely found in

 LED TV
 Mobile phone, Tablets
 Multimedia devices, Gaming devices, ipods, Apple’s Mobile, Raspberry pi 3

Career Opportunities in Microcontroller, Embedded Systems and Arm


Programming
If you know how to make an embedded system then you can automate any task. Embedded system is an ocean.
There are huge products in Medical electronics, aerospace, Telecommunication, Automobiles etc. Every industry
needs an Artificial Intelligence System into it. Artificial Intelligence can be given by Embedded Systems only.
Microcontrollers Laboratory (BCS402)

Embedded system is the future. Lots of career opportunities available in Embedded System. Some of them are as
follows.
 Embedded Software Engineer(Firmware)
 System Software Engineer (Kernal and RTOs)
 Application Software Engineer (Device drivers)
 Embedded Hardware Engineer
 Software Test Engineer
 Embedded System Trainer

What skills you should have?


 Embedded C programming on Microcontroller
 Interfacing Microcontrollers with different sensors and peripherals
 Kernel Programming
 Device drivers
 Real Time operating Systems (RTOs)

LPC2148
 LPC means Linear Programming Control. 2148 is the version of LPC controller.
 It is one of the most commonly used ARM based Microcontroller.
 It is a product of NXP (A subsidiary of Philips Company).
 It is a 32-Bit microcontroller. It is based on ARM7 and uses RISC Technology.
 It has Two Input/output port namely P0, P1. Each port has 32 pins. These pins are called GPIO
Pins. Most of the pins are multifunctional.
 Its Features:
o 512 KB on-chip Flash Memory. 32 KB on-chip SRAM.
o Supports up to 2KB USB RAM.
o Speed - 60 MHz operation.
KEIL

KeilMicroVision is free software which solves many of the pain points for an embedded program
developer. This software is an integrated development environment (IDE), which integrated a text editor
to write programs, a compiler and it will convert your source code to hex files too. Keil can be used for
Writing programs in C/C++ or Assembly language

 Compiling and Assembling Programs


 Debugging program
 Creating Hex and Axf file
 Testing your program without Available real Hardware (Simulator Mode)
Microcontrollers Laboratory (BCS402)

A SIMPLE GUIDE ON KEILUVISION 4


Step 1: After opening Keil uV4, Go
to Project tab and
Create new uVision project
Now Select new folder and give name to
Project.

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.
For C programs – Add startup.s
file
For assembly programs – Not
necessary

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. Now come on
Project window.
Microcontrollers Laboratory (BCS402)

Step 6: Now Expand target and


you will see source group
Right click on group and click
on Add files to source group.

Now add your program file which


you have written in C/assembly.
You can see program file added
under source group.

Step 7 and 8 are for Hardware Demonstration Programs only. Omit these steps for Software
Assembly and Embedded C programs
Step 7:
Right click on target and click
on options for target

Step 8:
Output Tab: Check Create hex file
The various setting are as
follows: Linker Tab: Check Use Memory layout from Target Dialog

Debug Tab: Click Use Simulator Radio button.

Utilities Tab: Click Setting button. To the Flash download setup ,


Add “LPC2000 IAP2 512 KB Flash” and then Click OK button.

Step 9: Now Click on Build target. You can find it under Project tab or in toolbar. It can also be done by

pressing F7 key.

Step 10:
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]
Microcontrollers Laboratory (BCS402)

ARM PROGRAMMING
We do programming using
 Assembly Language
 Embedded C Programming Language

Assembly Language:
After machine level language, the next level of development in the evolution of computer languages was
the Assembly Language. Assembly language is a low-level programming language for a computer or
other programmable device. Programs written in assembly languages are compiled by an assembler.
Every assembler has its own assembly language, which is designed for one specific
computer architecture.
The Reasons to write computer instructions in assembly language:
01. To speed computer operation
02. To reduce the size of the program.
03. To write programs for special situations.
04. To save money
05. To better understand how computer operate.

Arm assembly programming consists of Symbols, Labels, Instructions Mnemonic, Directives


Symbols: The name given to identifier by programmer. It is case sensitive.
Labels: The label field is the first field in an assembly language instruction.
It is the symbol that represents memory address of an instruction or
data. The ARM assembler requires labels to start at the first
character of a line. Labels are most frequently used in branch
instruction. Examples for labels are START, LOOP, and MAIN
Instruction mnemonic: most of the arm instruction consists of three letters. For Example
sub, mov, str. usually instruction followed by one or more operands.
Some instructions have no operands.
Directives: These are instructions to assembler. It used at assembly time.
Example: AREA
Difference between instruction and directive.
Instruction carried out by processor at run time. Instructions are assembled into machine code.
They are linked to final executable. Instructions are part of program that will be executed when the
program is run. Instruction generates machine code, thus contributes towards the size of program.
Directive is instruction to assembler. It is not part of program. It is used at assembly time. It does
not create any machine code. Thus not contributes to program size. Directives are predefined
functions.
Microcontrollers Laboratory (BCS402)

ARM INSTRUCTIONS AND DIRECTIVES

Instruction Syntax Remark


Adds the value of op1 and Carry flag to Rn and
stores the result in Rd.
ADC ADC Rd Rn, op1
Add the most significant words (In ARM
word=32 bits)
Add the value of op1 to Rn and stores the result
ADD ADD Rd Rn, op1
in Rd
Add a 64-bit integer contained in r2 to another
ADDS ADDS r4, r0, r2 integer contained in r0 and stores the result in r4.
Least significant words are added.
Performa a bitwise AND of the value of register
AND AND Rd, Rn, op1 Rn with the value of op1 and stores the result in
Rd
B-Branch unconditionally to label,
B label
B,BL BL-Branch and link. Subroutine call to function
BL func
“func”
Compares a register value with another arithmetic
value. The condition flags are updated, based on
CMP CMP Rn, op1 the result of subtracting op1 from Rn, so that
subsequent instructions can be conditionally
executed.
Performs bitwise Exclusive OR of the value of
register Rn with the value of op1, and stores the
EOR EOR Rd,Rn, op1
result in the Rd. condition code flags are
optionally updated based on the result.
Loads a word from the memory address
LDR LDR Rd, op2
calculated by op2 and writes it to register Rd.

Instruction Syntax Remark


Loads a byte from memory address calculated by
LDRB LDRB Rd,op2
op2, zero extends the byte to a 32-bit word and
Microcontrollers Laboratory (BCS402)

writes the word to register Rd


MOV MOV Rd, op1 Moves the value of op1 to destination register Rd
Moves the logical one’s complement of the value
MVN MVN Rd,op1
of op1 to the destination Rd.
Performs a bitwise OR of the value of Register
ORR ORR Rd, Rn, op1 Rn with the value of op1 and stores the result in
Rd.
Subtracts the value of op1 and the value of
SBC SBC Rd, Rn, op1 NOT(Carry flag) from the value of Register Rn
and stores the result in Rd. Rd=Rn-op1-CPSR(C)
Stores a word from register Rd to the memory
STR STR Rd, op2
address calculated by op2
Stores a byte from the least significant byte of
STRB STRB Rd, op2 register Rd to the memory address calculated by
op2
Subtracts the value of op1 from the value of
SUB SUB Rd, Rn, op1 Register Rn and stores the result in the
destination register Rd

Swaps a word between registers and memory.


SWP loads a word from the memory address
given by the value of register Rn. The value of
register Rm is then stored to the memory address
SWP SWP Rd, Rm,[Rn] given by the value of Rn, and the original loaded
value is written to register Rd. If the same register
is specified for Rd and Rm, this instruction swaps
the value of the register and the value at the
memory address.
Swaps a byte between registers and memory.
SWPB loads a byte from the memory address
given by the value of register Rn. The value of
SWPB SWPB Rd, Rm, [Rn] least significant byte of Register Rm is stored to
the memory address given by the value of Rn,
and the original loaded value is zero-extended to
a 32-bit word and the word is written to register
Microcontrollers Laboratory (BCS402)

Rd. If the same register is specified for Rd and


Rm, this instruction swaps the value of the least
significant byte of register and the byte value at
the memory address

Directives

Directive Remark
The AREA directive allows the programmer to specify the memory locations where
AREA programs, subroutines,
or data will reside.
EQU The EQUATE directive allows the programmer to equate names with addresses or data.

ALIGN
DATA Indicates that the label points to the data rather than code.
ENTRY This directive specifies the program entry point for the linker.

HOUSE KEEPING DIRECTIVES

Directive Remark
TTL Title of the Program
END Marks the end of the assembly language source program.
INCLUDE Will include the contents of a named file into the current file.

DEFINE CONSTANT (DATA) DIRECTIVE

Directive Remark
Allocates one or more bytes of memory, aligned on 2-byte boundaries, and
DCB
defines the initial runtime contents of the memory
Allocates one or more words of memory, aligned on 2-byte boundaries, and
DCD
defines the initial runtime contents of the memory
Allocates one or more halfwords of memory, aligned on 2-byte boundaries, and
DCW
defines the initial runtime contents of the memory

Embedded C Programming Language


Embedded C Programming is the soul of the processor functioning inside each and every embedded system we
come across in our daily life, such as mobile phone, washing machine, and digital camera. Embedded C language
is most frequently used to program the microcontroller.
Microcontrollers Laboratory (BCS402)

Earlier, many embedded applications were developed using assembly level programming. However, they did not
provide portability. This disadvantage was overcome by the advent of various high level languages like C, Pascal,
and COBOL. However, it was the C language that got extensive acceptance for embedded systems, and it
continues to do so. The C code written is more reliable, scalable, and portable; and in fact, much easier to
understand.
Differences between C and Embedded C

C Programming Embedded C Programming

Possesses native development in nature Possesses cross development in nature

Independent of hardware architecture. Dependent on hardware architecture (


Microcontroller or other devices)

Used for desktop applications, OS and PC Used for limited resources like RAM, ROM
memories. and I/O peripherals on embedded controller.

Advantages of embedded C program:

 Its takes less time to develop application program.


 It reduces complexity of the program.
 It is easy to verify and understand.
 It is portable in nature from one controller to another.
Microcontrollers Laboratory (BCS402)

SAMPLE PROGRAMS
Data Processing Instructions
1. Mov Instruction
AREA ALP1, CODE, READONLY

ENTRY
MOV R5, #5
MOV R7,#8
MOV R7,R5
STOP B STOP
END

2. Logical Shift Left (LSL)


AREA ALP2, CODE, READONLY

ENTRY
MOV R5,#5
MOV R7, #8
MOV R7, R5, LSL #2
STOP B STOP
END

3. Arithmetic Operations
AREA ALP3, CODE, READONLY

ENTRY
LDR R0,=0x00000000
LDR R1,=0x00000002
LDR R2,=0x00000001
ADDr0,r1,r2
SUB r0,r1,r2
STOP B STOP
END

4. Reverse subtraction
AREA ALP4, CODE, READONLY

ENTRY
LDR R0,=0x00000000
Microcontrollers Laboratory (BCS402)

LDR R1, =0x00000077


RSB R0,R1,#0 ;RSB subtracts r1 from constant value #0 R0 = -R1
STOP B STOP
END
5. Addition with barrel shifter
AREA ALP5, CODE, READONLY

ENTRY
LDR R0,=0x00000000
LDR R1,=0x00000005
ADD R0, R1, R1, LSL#1
STOP B STOP
END

6. Logical Instructions
AREA ALP6 ,CODE, READONLY

ENTRY
LDR R0,=0x00000000
LDR R1,=0x02040608
LDR R2,=0x10305070
ORR R0, R1, R2
AND R0,R1,R2
EOR R0,R1,R2
STOP B STOP
END

7. MVN Instruction
AREA ALP7 ,CODE, READONLY

ENTRY
LDR R0,=0x0000000A
MVN R1,R0
STOP B STOP
END

8. Load and store instructions


AREA ALP8,CODE, READONLY

ENTRY
Microcontrollers Laboratory (BCS402)

LDR R0, =0x40000000


LDR R1,[R0]
LDR R2,=0x40000050
STR R1,[R2]
STOP B STOP
END

9. To check for carry flag C in CPSR


AREA ALP9,CODE,READONLY

ENTRY
LDR R0, =0x00000000
LDR R1, =0x80000004
MOVS R0,R1,LSL#1
STOP B STOP
END

10.Comparison instruction to check for C, Z flags in CPSR


AREA ALP10, CODE, READONLY ENTRY
LDR R0, =0x00000002
LDR R1, =0x00000002
CMP R0,R1
STOP B STOP
END

11. Instruction to check for C, Z in CPSR


AREA ALP11, CODE, READONLY

ENTRY
LDR R1,=0x00000001
SUBS R1,R1,#1
STOP B STOP
END

12. Logical bit clear


AREA ALP12, CODE, READONLY

ENTRY
LDR R1, = 0Xf
Microcontrollers Laboratory (BCS402)

LDR R2, =0x5


BIC R0,R1,R2 ; R0 = R1 AND (!R2)
STOP B STOP
END

13. MOVS and MOVCS instructions


AREA ALP13, CODE, READONLY

ENTRY
LDR R0, =0x00000000
LDR R1, =0x80000004
MOVS R0,R1,LSL#1
MOVCS R0, R1 ;if carry is set then R0:=R1
STOP B STOP
END

14. ADDCS instruction


AREA ALP14, CODE, READONLY

ENTRY
LDR R0, =0x00000000
LDR R1, =0x80000004
MOVS R0,R1,LSL #1
ADDCS R2, R0, R1
STOP B STOP
END

15. ADDEQ Instruction


AREA ALP15, CODE, READONLY

ENTRY
LDR R0, =0x00000004

LDR R1, =0x00000004

CMP R0,R1
ADDEQ R2, R0, R1
STOP B STOP
END
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
Get familiarize with KEIL SOFTWARE. In this program we are going to learn about the basic
structure of ARM assembly program and symbols, instructions, directives, variable. In the process we
will learn how to observe the register contents, memory dump, and CPSR.

NOTE:
 Users should create a working directory and in that directory project, programs should be stored.
 All user defined variables names, label names should be typed starting from Column 1.
 Example: Labels like MAIN, STOP, L1, L2, etc., variables like Value1, Value2 should start from
Column 1 (should not have a space before it)
 All directives like TTY, AREA, ENTRY, END and instructions like LDR, MOV, STR, ADDS,
SUB etc. should start after one tab space.
 Assembly program file should be stored with extension .asm or .s
 Always either type in uppercase or lower case but not in mixed case.

PROGRAM:

AREA PGM1, CODE, READONLY  Instructs the assembler to assemble a new code
section
ENTRY  Marks the beginning of the code section
MAIN  Label indicating the starting point (optional)
 Load the content of memory location VALUE1 to
LDR R1, VALUE1 register R1.
 Load the content of memory location VALUE2 to
LDR R2, VALUE2 register R2
ADDS R1, R2  R1 = R1 + R2 and update the carry flag. Check the
flag in CPSR
LDR R3, =DESTINATION  Load the address of DESTINATION memory
STR R1, [R3]
 Store the sum R1 to memory location pointed to by
R3.
STOP B STOP
VALUE1 DCD 0X71234567  Assign the value 0X71234567, and 0X9ABCDEF to
VALUE2 DCD 0X9ABCDEF0 memory location VALUE1 and VALUE2
 Create a data section to store the result with read-
AREA DATA1, DATA, READWRITE write permission.
DESTINATION DCD 0
END

OUTPUT:
Microcontrollers Laboratory (BCS402)

After Execution, observe the changes in contents of registers involved in the program, CPSR,
and memory contents.
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
Get familiarize with KEIL SOFTWARE. In this program we are going to learn about the basic
structure of ARM assembly program and symbols, instructions, directives, variable .In the process we
will learn how to declare variables, data transfer, arithmetic, logic operations.

NOTE:
 Users should create a working directory and in that directory project, programs should be stored.
 All user defined variables names, label names should be typed starting from Column 1.
 Example: Labels like MAIN, STOP, L1, L2, etc., variables like Value1, Value2 should start from
Column 1 (should not have a space before it)
 All directives like TTY, AREA, ENTRY, END and instructions like LDR, MOV, STR, ADDS,
SUB etc. should start after one tab space.
 Assembly program file should be stored with extension .asm or .s
 Always either type in uppercase or lower case but not in mixed case.

PROGRAM:

AREA PGM2, CODE, READONLY ; Assembler directive to indicate code segment


ENTRY ;Marks beginning of the program

LDR R1, Value1 ; Loads the contents of memory location Value1 to register R1
LDR R2, Value2
LDR R3, Value3
LDR R4, Value4
LDR R5, Value5

MOV R6, R1 ; Contents of R1 is moved to R6

ADD R7, R1, R2 ;R7=R1+R2


ADD R8, R3, #1 ;Add value #1 and R1 and store the result in R1

ADDS R9, R4, R5


ADC R10, R1, R2 ;add R1 and R2 with carry Bit from previous ADDS,
;store result to R10

SUB R11,R2,#1
MUL R12,R1,R2

AND R5, R1, R2 ; Logic AND operation


ORR R6, R1, R2 ; Logic OR operation
EOR R7, R1, R2 ; Logic Ex-OR operation STR R1, Result
ORR R6, R1, R2 ; Logic OR operation
EOR R7, R1,R2 ; Logic Ex-OR operation

STOP B STOP
;Memory Declarations

Value1 DCD 0x00000001


Value2 DCD 0x00000002
Value3 DCD 0x00000003
Microcontrollers Laboratory (BCS402)

Value4 DCD 0x00000004


Value5 DCD 0xFFFFFFFF

END

OUTPUT:
 Build the program and fix all the errors.
 Go to Debugging session to run the program and view the results.
 Perform single step execution and observe the changes in register contents.

Notes:
1. The semicolon indicates a user-supplied comment. Anything following a semicolon on the same
line is ignored by the assembler.
2. The first line is AREA PROGRAM, CODE, READONLY is an assembler directive and is required
to set up the program. It is a feature of the development system and not the ARM assembly
language. An assembler from a different company may have a different way of defining the start of
a program. In this case, AREA refers to the segment of code, PROGRAM is user defined name, and
CODE indicates executable code rather than data and READONLY state that it cannot be modified
at run time.
3. Anything starting in column 1 (in this case START) is a label that can be used to refer to that line.
4. The instruction STOP B STOP means ‘Branch to the line labeled STOP’ and is used to create an
infinite loop. This is a convenient way of ending programs in simple examples like these.
5. The last line END is an assemble directive that tells the assembler there is not more code to follow.
It ends the program.
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
To to learn about Bit Number format and MUL instruction. The bit number format is as follows.

Number of Bits Max. Hexadecimal value Binary


1 bit 1 1
2 bit 3 11
3 bit 7 111
4 bit F 1111
8 bit FF 1111 1111
16 bit FFFF 1111 1111 1111 1111
32 bit FFFF FFFF 1111 1111 1111 1111 1111 1111 1111 1111

PROGRAM:
; TO MULTIPLY TWO 16-BIT NUMBERS

AREA PGM3, CODE, READONLY  Instructs the assembler to assemble a new


code section
ENTRY  Marks the beginning of the code section
START  Label indicating the starting point (optional)
LDR R1, A  Load the content of memory location A to
register R1.
LDR R2, B
MUL R3, R1, R2  R3 = R1 * R2
STOP B STOP

A DCD 0X0000FFFF
 Assign the value 0X0000FFFF to memory
B DCD 0X0000FFFF location A
 Assign the value 0X0000FFFF to memory
END location

OUTPUT:
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
To learn about the loop and branching instructions.

Branching:

Branching instruction is used to change the control flow. The Branch instruction can be used in two ways,
conditionally and unconditionally. An unconditional branch will always branch no matter what the state of the
flags, For a conditional branch, one of the condition codes is given immediately after B.

BEQ instruction is used to branch on equal condition (the Z flag is set).


BNE Branch if not equal
BHI Branch if higher than
BHS Branch if higher or same
BLO Branch if lower
BLS Branch if lower or same
BGT Branch if greater than
BGE Branch if greater than or equal
BLT Branch if less than
BLE Branch if less than or equal

Example:

In this program we are going to add numbers from 10 to 1. The total we get will be 55. The total we get in
Hexadecimal format will be in R2 register.

PROGRAM:

AREA SUM, CODE, READONLY

ENTRY
START
MOV R1, #10  Load 10 to register R1. R1 is a counter
MOV R2, #0  Empty the register to store result
LOOP
ADD R2, R2, R1  Add the content of R1 with result at R2
SUBS R1, #0x01  Decrement R1 by 1 and update the flags
BNE LOOP  BNE results in true value as long as R1 contains non-
zero value in it and takes the control to a line labeled
LOOP. When R1 becomes zero, BNE results in false
value and the loop terminates
STOP B STOP
END

OUTPUT:
Microcontrollers Laboratory (BCS402)
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE: To learn about comparisons.


For comparisons in case of unsigned numbers we use HI, HS, LO, LS
For comparisons in case of signed numbers we use GT, GE, LT, LE
For generic we use EQ, NE

First Part – To find the Largest Number.

Example:
Input : Array containing 32 bit numbers
Output : Largest number is stored in location 0x40000000 and also in R2.
Check the result in R2 or memory location 0x40000000.
PROGRAM:

AREA LARGEST, CODE, READONLY

ENTRY  mark first instruction to execute


START
MOV R5, #6  initialize counter to 6(i.e. n=7)
LDR R1,=MYARRAY  loads the base address of the array MYARRAY to R1
LDR R4,=RESULT  loads the address of result to R4
LDR R2, [R1], #4  word align to array element. Load the content of memory
location pointed to by R1 to R2, then increment R1 by 4.

LOOP ; Load the next element to R3, and word align to array element
LDR R3, [R1], #4  compare numbers
 If R2 < R3, R3 is considered as highest and move to R2 –
CMP R2, R3 unsigned comparisons
MOVLO R2, R3
 decrement counter and update the status flag
 loop back till array ends
SUBS R5, R5, #1
 stores the result where R4 is pointed to
BNE LOOP
STR R2, [R4]
 ARRAY OF 32 BIT NUMBERS(N=7)
STOP B STOP
MYARRAY
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
 to store result in given address
AREA DATA2, DATA, READWRITE  Mark end of file
Microcontrollers Laboratory (BCS402)

RESULT DCD 0
END

OUTPUT:

Second Part – To find the Smallest Number.


PROGRAM:

AREA SMALLEST, CODE, READONLY


ENTRY
START  mark first instruction to execute
MOV R5, #6
LDR R1,=MYARRAY  initialize counter to 6(i.e. n=7)
LDR R4,=RESULT  loads the base address of the array MYARRAY to R1
LDR R2, [R1], #4  loads the address of result to R4
 word align to array element. Load the content of memory
LOOP location pointed to by R1 to R2, then increment R1 by 4.
LDR R3, [R1], #4

; Load the next element to R3, and word align to array element
CMP R2, R3  compare numbers
MOVHS R2, R3  If R2 >= R3, R3 is considered as highest and move to R2 -
unsigned comparisons
SUBS R5, R5, #1
 decrement counter and update the status flag
BNE LOOP
 loop back till array ends
STR R2, [R4]
 stores the result where R4 is pointed to
STOP B STOP
MYARRAY
 ARRAY OF 32 BIT NUMBERS(N=7)
Microcontrollers Laboratory (BCS402)

DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999  to store result in given address
 Mark end of file
AREA DATA2, DATA, READWRITE
RESULT DCD 0
END

OUTPUT:
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
 To learn about barrel shift instructions – LSR
 To understand how conditional execution simplifies the program development.
 To learnt new instructions ADDCS and ADDCC

LSR – LOGICAL SHIFT RIGHT: Right Shifts behave like dividing the contents of a register by 2 s
where s is the shift amount, if you assume the contents of the register are unsigned.

PROGRAM:

AREA COUNT, CODE, READONLY


ENTRY
START  mark first instruction to execute
LDR R5, MYVALUE ; Load the contents of memory location MYVALUE to R5
MOV R2, #16  Since we need to count 16 bits, load this counter to R2
LDR R6, =ONES  Load the address of memory location ‘ONES’ to R6
LDR R7, =ZEROS  Load the address of memory location ‘ZEROS’ to R7
LOOP
MOVS R5, R5, LSR #1  Logical shift Right the contents of R5 and move back the
shifted value to R5 also update the status. If the shifted bit
will be moved to carry flag. If the shifted bit is 1, CF
becomes 1, otherwise it becomes 0.
ADDCS R3, #1  R3 will be incremented by 1 if the CF = 1. ADDCS – add if
and only is carry flag is set
ADDCC R4, #1
 R4 will be incremented by 1 if the CF = 0 - ADDCC – add
if and only is carry flag is cleared
SUBS R2, #1
 Decrement the counter R2 and update the status flag.
BNE LOOP
 If R2 is not 0, process the next bit.
STRH R3, [R6]
 Store half-word: ONES and ZEROS are declared as DCW
STRH R4, [R7]
that allocates 16 bits (or half words). The contents of R3
and R4 are respectively stored where R6 and R7 are
pointing to.

STOP B STOP
MYVALUE DCW 0X5ADF
AREA DATA1, DATA, READWRITE
 Data section is created with read and write permission to
ONES DCW 0
store number of ones and zeros in memory locations ONES
ZEROS DCW
and ZEROS respectively.
END
Microcontrollers Laboratory (BCS402)

OUTPUT:
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
To gain hands-on experience in analyzing memory usage and register allocation, by observing how
values are assigned to registers and tracking changes in register contents during the sorting process,

PROGRAM:
#include <lpc21xx.h>

void swap(unsigned int* arr, unsigned int i, unsigned int j)


{
unsigned int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}

// function to implement bubble sort


void bubbleSort(unsigned int arr[], unsigned int n)
{
unsigned int i, j;
for (i = 0; i < n - 1; i++)

for (j = 0; j < n - i - 1; j++)


if (arr[j] > arr[j + 1])
swap(arr, j, j + 1);
}

int main()
{
unsigned int arr[] = { 5, 1, 4, 2, 8 };
unsigned int N = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, N);
return 0;
}

OUTPUT:
Step 1: Place a breakpoint for return statement. Place the cursor where breakpoint is needed and click
on Insert/Remove breakpoint as shown in the below snapshot.
Step 2: Build the program
Step 3: Start debugging session.
Step 4: View  Watch Windows  Watch 1
Step 5: In the watch window, enter the name of the variable and name of the array.
Step 6: Get the address of the required variable. Go to view  Memory Windows  Memory. Type
the address in memory window address bar.
Step 7: Run the program and observe the contents in the given location.
Microcontrollers Laboratory (BCS402)

Breakpoint:

Watch window

Go to view  Memory Windows  Memory. Type the address in memory window address bar.
Microcontrollers Laboratory (BCS402)
Microcontrollers Laboratory (BCS402)

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

OBJECTIVE:
To gain insight into the intricacies of register-level operations and memory management, by observing
how values are assigned to registers and tracking changes in register contents during program
execution.

PROGRAM:
#include <lpc21xx.h>
int main(){

unsigned int num = 5, i;


unsigned long fact = 1;
for(i = 1; i<=num; i++)
fact = fact * i;

return 0;
}

OUTPUT:
Microcontrollers Laboratory (BCS402)

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


characters from upper to lowercase and lower to uppercase.

OBJECTIVE:
To understand the process of memory dump analysis and ASCII representation.
In Keil uVision, when we perform a memory dump and the values are displayed in hexadecimal format,
we can easily see their equivalent ASCII characters by looking at the ASCII representation of each
hexadecimal value.
Typically, in the memory dump window, there will be two columns - one displaying the memory
address and the other displaying the memory contents in hexadecimal format. To see the ASCII
representation:
1. Locate the column displaying the hexadecimal values.
2. For each byte of memory content displayed in hexadecimal, you can refer to the ASCII
representation of that byte by right clicking on it and changing to “ASCII”

PROGRAM:

# include <lpc21xx.h>
char src[ ] = "Hello";
char dest[ ] = "";
void caseConvert(){
unsigned int i;
for (i = 0; src[i]!='\0'; i++){
if(src[i] >= 'a' && src[i] <= 'z') {
dest[i] = src[i] - 32;
}

if(src[i] >= 'A' && src[i] <= 'Z') {


dest[i] = src[i] + 32;
}
}
}

int main(){
caseConvert();
return 0;
}
Microcontrollers Laboratory (BCS402)

OUTPUT:

10. Demonstrate enabling and disabling of Interrupts in ARM.


11. Demonstrate the handling of divide by zero, Invalid Operation and Overflow exceptions in
ARM.
Microcontrollers Laboratory (BCS402)

VIVA QUESTIONS

1. What is the purpose of following assembler directives?


AREA CODE DATA ENTRY START STOP END
2. DEFINE: DCD, DCB,DCW
3. What is ARM (TDMI)?
4. Mention the design features of ARM.
5. Name different branch instructions used in our lab programs
6. What is the difference between SUB and SUBS?
7. How do we compile and run an assembly program?
8. What is the difference between ALL and HLL?
9. Difference between conditional and unconditional branch?
10. Name the status registers? What is difference between them?
11. Define all the bits of CPSR.
12. List the ARM processor modes.
13. How many registers are present in ARM microcontroller?
14. What is the register numbers of LR, SP, PC?
15. Explain the purpose of all the special purpose registers.
16. List the indexing methods in ARM. Explain each one of them.
17. What is size of each register in ARM?
18. Difference between LDR and STR.
19. Explain how masking is done in program 4?
20. What is a look up table?
21. What is a barrel shifter? Give example of a shifting operation.
22. Give examples of rotation instructions.
23. What is difference between shifting and rotating bits of a register?
24. Give an example to show how CMP instruction affects the status register.
25. Explain pipelining concept.
26. What is meant by flushing a pipeline?
27. List all arithmetic instructions
28. List all logical instructions
29. List all data processing instructions.
30. Explain how SP, LR, PC can be used in ARM programs.
Microcontrollers Laboratory (BCS402)

LIST OF ADDITIONAL PROGRAMS


1. Write an ALP to generate Fibonacci Series
2. Write an ALP to find the 1st and 2nd largest number in an array.
3. Write an ALP to find the 1st and 2nd smallest number in an array.
4. Write an ALP to search an element in an array (linear search)
5. Write an ALP to search an element in an array (binary search)
6. Write an ALP to find if the given number is prime or not.
7. Write an ALP to find factors of a given number
8. Write an ALP to count the occurrence of a given number in an array.
9. Write an ALP to find the position of a given number in an array
10. Write an ALP to generate multiplication table of 3 or 5
11. Write an ALP to find the trace of a matrix of the order 3x3
12. Write an ALP to find the transpose of 3x3 matrix
13. Write an ALP to add 2 matrices of order 3x3
14. Write an ALP to find the LCM of 2 32 bit numbers
15. Write an ALP to find the GCD of 2 32 bit numbers
16. Write an ALP to covert a BCD number to hex
17. Write an ALP to convert a hex number to BCD
18. Write an ALP to find factorial of a number.
19. Write an ALP to count leading 0’s
20. Write an ALP to Insert 0 in a given 32 bit data from bit 5 to bit 10
21. Write an ALP to Insert 1 in a given 32 bit number from bit 22 to bit 27
22. Write an ALP to convert a binary number into a gray number
23. Write an ALP to convert a gray number into a binary number
24. Write an ALP to exchange block of ten 32 bit numbers
25. Write an ALP to generate quotient and reminder
26. Write an ALP to find average of N words
27. Write an ALP to read and store 5 consecutive memory locations without using loop.
28. Write an ALP to generate odd/even series between x1 and x2 range
29. Write an ALP to perform subtraction of two 64 bit numbers
30. Write an ALP to perform multiplication of two 64 bit numbers
31. WAP to check if the given year is leap or not.
32. WAP to evaluate ΣXiYi where i ranges from 0 to 10.

You might also like