0% found this document useful (0 votes)
135 views50 pages

Microcontollers Lab Manual BCS402

The document is a lab manual for the Microcontrollers course (BCS402) at Dr. T. Thimmaiah Institute of Technology, detailing course objectives, outcomes, and practical experiments related to ARM microcontrollers. It outlines the evaluation criteria, including Continuous Internal Evaluation (CIE) and Semester End Examination (SEE), as well as the vision and mission of the college and department. The manual includes specific experiments to be conducted, focusing on ARM programming and microcontroller functionalities.

Uploaded by

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

Microcontollers Lab Manual BCS402

The document is a lab manual for the Microcontrollers course (BCS402) at Dr. T. Thimmaiah Institute of Technology, detailing course objectives, outcomes, and practical experiments related to ARM microcontrollers. It outlines the evaluation criteria, including Continuous Internal Evaluation (CIE) and Semester End Examination (SEE), as well as the vision and mission of the college and department. The manual includes specific experiments to be conducted, focusing on ARM programming and microcontroller functionalities.

Uploaded by

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

Dr. T.

THIMMAIAH INSTITUTE OF TECHNOLOGY


(Estd. 1986) Oorgaum, Kolar Gold Fields, Karnataka – 563120
(Affiliated to Visvesvaraya Technological University)
NAAC Accredited 'A' Grade, NBA Accredited (CSE, ECE, Mining Engg)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

IV Semester
MICROCONTROLLERS (BCS402)

LAB MANUAL

Name of the Student

Reg No. of the Student


Dr. T. THIMMAIAH INSTITUTE OF TECHNOLOGY
(Estd. 1986) Oorgaum, Kolar Gold Fields, Karnataka – 563120
(Affiliated to VTU, Belgaum, Approved by AICTE - New
Delhi) NAAC Accredited 'A' Grade, NBA Accredited (CSE, ECE, Mining
Engg)

Department of Computer Science & Engineering

Microcontrollers (BCS402)

Lab Manual

Name of the Student:

Reg No. of the Student:


Dr. T. THIMMAIAH INSTITUTE OF TECHNOLOGY
(Estd. 1986) Oorgaum, Kolar Gold Fields, Karnataka – 563120
(Affiliated to VTU, Belgaum, Approved by AICTE - New
Delhi) NAAC Accredited 'A' Grade

Laboratory
Certificate
This is to certify that....................................................................................bearing
USN ……………………….. has satisfactorily completed the experiments in
practical MICROCONTROLLERS prescribed by the Visvesvaraya Technological
University for the course with course code BCS402 in the Laboratory of this
college in the year 2023-24.

Signature of the faculty in-charge Head of the Department

Final Marks obtained.


College Vision and Mission

College Vision:
To produce technically competent engineers having innovative skills, positive attitude, leadership and
professional ethics, with a focus on developing sustainable and new technology

College- Mission:
 Create a conductive environment for teaching, learning and innovation by providing state of the
art infrastructure.
 Learn sustainable and new technologies through industry institute collaborations.
 Produce technically competent engineers with ethics, discipline and social consciousness
through holistic education.

Department of Computer Science and Engineering

Vision and Mission

Dept.-Vision

To produce highly competent and innovative Computer Science professionals through excellence in
teaching, training and research

Dept.- Mission

M1: To provide appropriate infrastructure to impart need-based technical education through effective
teaching and research.

M2: To involve the students in innovative projects on emerging technologies to fulfill the industrial
requirements

M3: To render leadership skills and ethical responsibilities in students that leads them to become
globally competent professionals
BE: Program Outcomes (POs)
At the end of the B.E program, students are expected to have developed the following outcomes.

1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.

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.
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 modern
engineering and IT tools including prediction and modelling to complex engineering activities
with an understanding of the limitations.
6. 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.
7. Environment and Sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of 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.
COURSE OBJECTIVES AND OUTCOMES

Course Objectives:

This course will enable students to:

CLO1 Understand the fundamentals of ARM-based systems and basic architecture of CISC and
RISC.
CLO2 Familiarize with ARM programming modules along with registers, CPSR and Flags

CLO3 Develop ALP using various instructions to program the ARM controller

CLO4 Understand the Exceptions and Interrupt handling mechanism in Microcontrollers

CLO5 Discuss the ARM Firmware packages and Cache memory polices

Course Outcomes:

At the end of the course the student will be able to:

CO1 Acquire the fundamental knowledge of ARM processor system and basic architecture of
CISC and RISC
CO2 Understand the various instructions for program of the ARM Miro-controller and develop
ALP

CO3 Summarize the optimization of C Compilers

CO4 Apply the concepts of exceptions, Interrupt handling and firmware mechanism in developing
applications

CO5 Demonstrate the role of Cache management in Microcontrollers


Conduction of Practical Examination:

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).
 The minimum passing mark for the SEE is 35% of the maximum marks (18 marks out of 50).
 A student shall be deemed to have satisfied the academic requirements and earned the credits
allotted to each subject/course if the student secures not less than 35% (18 Marks out of 50) in the
semester-end examination (SEE), and 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.

Continuous Internal Evaluation (CIE):

 The CIE marks for the theory component of the IC shall be 25 marks and for the laboratory
component 25 Marks.
Rubrics for Lab Performance Assessment

In Each Lab, students will be assessed on their participation and performance in the
lab. The marks obtained in each lab will be totaled and combined with Final Lab test
or Viva-voce. The students need to attend 85% of the labs to qualify to be eligible to
attend the university examination.

Lab Particiyu sddpation Rubric (Conduction)


=

Proficient(15-13) Good (12-10) Adequate(9-7) Substandard (6-4) Unacceptable(3-0)


Lab performance Lab performance Lab Lab performance is Lab performance is
is excellent. is good. At most, performance is fair. barely adequate.
The student has the student has adequate. The student may The student is
attended all labs. one lab absence. The student is have been absent irregular.
Student Student absent more than 3-4 times. Student was late to
demonstrates an demonstrates a 2 classes. Student lab or did not
accurate fair Student unpreparedness participate. There
understanding of the understanding of arrives on makes it was no attempt to
lab objectives and the lab objectives time to lab, impossible to fully make prior
concepts. The and concepts. but may be participate. If able arrangements to
student can The student can unprepared. to participate, make up the lab.
correctly answer answer Answers to student has
questions and if questions questions are difficulty
appropriate, can basic and explaining key lab
explain concepts to superficial concepts.
fellow classmates. suggesting that
Student is eager to concepts are
participate and not fully
assists when grasped
needed.
Dr. T.THIMMAIAH INSTITUTE OF
TECHNOLOGY
Department of Computer Science & Engineering

Microcontrollers
BCS402

Contents

Exp. Page
Title of the Experiment
No No
12-25
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 26-28
operations(Demonstrate with the help of a suitable program)
Develop an ALP to multiply two 16-bit binary numbers
3. 29
Develop an ALP to find the sum of first 10 integer numbers.
4. 30
5. Develop an ALP to find the largest/smallest number in an array of 32 numbers. 31-32
Develop an ALP to count the number of ones and zeros in two consecutive memory
6. locations 33-34

47. Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in 35-36
ascending/descending order using bubble sort
Simulate a program in C for ARM microcontroller to find factorial of a number
8. 37
9. Simulate a program in C for ARM microcontroller to demonstrate case conversion of 38-39
characters from upper to lowercase and lower to uppercase.
10. Demonstrate enabling and disabling of Interrupts in ARM. 40

11. Demonstrate the handling of divide by zero, Invalid Operation and Overflow 41-42
exceptions in ARM
12 Viva Questions 42-46
13 Additional programs 47-48
EVALVUATION SHEET

Faculty
Conduction
Sl. Date of Date of sign with
TITLE OF THE EXPERIMENT Record
No Conduction Submission Date
1
Using Keil software, observe the various Registers,
Dump, CPSR, with a simple Assembly Language
Programs (ALP).
Develop and simulate ARM ALP for Data Transfer,
2
Arithmetic and Logical operations(Demonstrate with
the help of a suitable program)
3 Develop an ALP to multiply two 16-bit binary
numbers
Develop an ALP to find the sum of first 10 integer
4 numbers.
Develop an ALP to find the largest/smallest number
5
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
Simulate a program in C for ARM microcontroller to
9
demonstrate case conversion of characters from
upper to lowercase and lower to uppercase.
Demonstrate enabling and disabling of Interrupts in
10
ARM.
Demonstrate the handling of divide by zero, Invalid
11
Operation and Overflow exceptions in ARM

Conduction Record Average Test Marks Total Signature of the faculty


marks marks with Date
Microcontrollers [ BCS402 ] 2023-
24
ARM7 based LPC2148 Microcontroller

The full form of an ARM is an advanced reduced instruction set computer


(RISC) machine, and it is a 32-bit processor architecture expanded by
ARM holdings. The applications of an ARM processor include several
microcontrollers as well as processors. The architecture of an ARM
processor was licensed by many corporations for designing ARM
processor-based SoC products and CPUs.

LPC2148 Microcontroller
The LPC2148microcontroller is designed by Philips(NXP Semiconductor) with
several in-built features & peripherals. Due to these reasons, it will make more
reliable as well as the efficient option for an application developer. LPC2148 is
a16-bit or 32-bit microcontroller based on ARM7 family.
Programmer's Model

ARM has a 32-bit data bus and a 32-bit address bus. The data types the
processor supports are Words (32 bits), where words must be aligned to four
byte boundaries. Instructions are exactly one word, and data operations (e.g.
ADD) are only performed on word quantities. Load and store operations can
transfer words.

Registers
The processor has a total of 37 registers made up of 31 general 32 bit registers
and 6 status registers. At any one time 16 general registers (R0 to R15) and one
or two status registers are visible to the programmer. The visible registers
depend on the processor mode and the other registers (the banked registers) are
switched in to support IRQ, FIQ, Supervisor, Abort and undefined mode
processing. The register bank organization is shown in below figure. The
banked registers are shaded in the diagram.
In all modes 16 registers, R0 toR15, are directly accessible. All registers
except R15 are general purpose and may be used to hold data or address values.
Register R15 holds the Program Counter (PC). When R15 is read, bits [1:0] are
zero and bits [31:2] contain the PC.A seventeenth register (the CPSR -Current
Program Status Register) is also accessible. It contains condition code flags
and the current mode bits and may be thought of as an extension to the PC.
R14 is used as the subroutine link register and receives a copy of R15 when a
Branch and Link instruction is executed. It may be treated as a general- purpose
register at all other times. R14_svc, R14_irq, R14_fiq, R14_abt and R14_und
are used similarly to hold the return values of R15 when interrupts and
exceptions arise, or when Branch and Link instructions are executed within
interrupt or exception routines.

Dept. of CSE, Dr. TTIT, Page 12


KGF
Microcontrollers [ BCS402 ] 2023-
24

ARM LPC 2148 FEATURES:

 16-bit/32-bit ARM7TDMI-S Microcontroller.


 40 kB of on-chip static RAM and 512 kB of on-chip flash memory.
 In-System Programming/In-Application Programming (ISP/IAP) via
on- chip boot loader software.
 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.
 Two 10-bit ADCs provide a total of 14 analog inputs
 Single 10-bit DAC provides variable analog output
 Two 32-bit timers/external event counters (with four capture and
four compare channels each)
 PWM unit (six outputs)
 Watchdog Timer.
 Low power Real-Time Clock (RTC) with independent power and 32
kHz clock input.

Dept. of CSE, Dr. TTIT, Page 13


KGF
Microcontrollers [ BCS402 ] 2023-
24
 Multiple serial interfaces including two UARTs, two Fast I²C-bus (400
kbit/s), SPI and SSP with buffering and variable data length
capabilities.
 Vectored Interrupt Controller (VIC) with configurable priorities and vector
addresses.
 60 MHz maximum CPU clock available from programmable on-chip PLL
with settling time of 100 us.
 On-chip integrated oscillator operates with an external crystal from 1 MHz
to 25 MHz
 Power saving modes include idle and Power-down.
 Individual enable/disable of peripheral functions as well as peripheral
clock scaling for additional power optimization.

Dept. of CSE, Dr. TTIT, Page 14


KGF
Microcontrollers [ BCS402 ] 2023-
24

HOW TO USE KEIL µVISION4


For ARM7 (LPC2148)
Step By Step
Step1: Click for KEIL µVISION4 Icon . Which appears after Installing
Keil KEIL µVISION4. This will open uvison IDE.

Step2: Click on Project Menu, Then New µVison Project.

Step3: Create New Project Folder named as “Keil Test”.

Dept. of CSE, Dr. TTIT, Page 15


KGF
Microcontrollers [ BCS402 ] 2023-
24

Step 4: Select Target

Step 5: Then select specific chip i.e. LPC2148.

For ALP program, CLICK “NO”, For “C” program click on “YES”

Step 6: Then you will see following window

Dept. of CSE, Dr. TTIT, Page 16


KGF
Microcontrollers [ BCS402 ] 2023-
24

Step 7: Now you see Startup.s is already added which is necessary for
running code for Keil.

Note: Code wills Not Run without Startup.s

Step 8: Now Click on File Menu and Click on New.

Step 09: Write Code for Blink LED in C OR ASM and FileName.c/ASM Save.

Note: Don’t forget to save .c/ASM Extension.

Dept. of CSE, Dr. TTIT, Page 17


KGF
Microcontrollers [ BCS402 ] 2023-
24

Step 10: Now you Window in C Syntax.

Step 11: Now you add LED.c file by adding Source Group 1 Add
files to Group ‘Source Group 1’.

Dept. of CSE, Dr. TTIT, Page 18


KGF
Microcontrollers [ BCS402 ] 2023-
24
Step 12: Add LED.C file.

Step 13: Now Click on Options for Target ‘Target 1’.

Step 14: Go to Options for Target ‘Target 1’. Click on Check Box
Create HEX File.

Step 15: Then go to Linker. Click on Use Memory Layout for Target
Dialog.

Dept. of CSE, Dr. TTIT, Page 19


KGF
Microcontrollers [ BCS402 ] 2023-
24

Step 16: Then Click on Rebuild All Target Files

Step 17: Now you see 0 Error(s), 0 Warning (s). Then Hex File will
create in Specific Folder. Now to download it for you target hardware.

Dept. of CSE, Dr. TTIT, Page 20


KGF
Microcontrollers [ BCS402 ] 2023-
24

Settings in Flash Magic


Click the start button, select the programs options and select the flash magic software.
The main screen appears

Go to options in the main menu and select advanced options the following screen displays.

Select hardware config tab and uncheck the use DTR and RTS option and press the OK button
Select the comm. Port (Check in device manager about UART bridge COM port).
Select the baud rate as 9600, select device as LPC2148, interface is None ISP, Oscillator is 12.000

Browse the appropriate hex file provided on the CD and click on the start Button. The
programs will the downloaded in the Kit,

Dept. of CSE, Dr. TTIT, Page 21


KGF
Microcontrollers [ BCS402 ] 2023-
24
Sample Programs using Keil Compiler:
Example 1: Additions

The problem: P = Q + R + S
Let Q = 2, R = 4, S = 5. Assume that r1 = Q, r2 = R, r3 = S. The
result Q will go in r0.

The Code

ADD r0, r1 ,r2 ; add Q to R and put in P


ADD r0 ,r0 ,r3 ; add S to P and put the result in P

The program

AREA Example1, CODE, READONLY


ENTRY
ADD r0, r1, r2
ADD r0, r3
Stop
B
Stop
END

Notes:

The semicolon indicates a user-supplied comment. Anything following a semicolon


on the same line is ignored by the assembler.

The first line is AREA Example1, 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, Example1 is the name we’ve given
it, CODE indicates executable code rather than data, and READONLY state that it
cannot be modified at run time.
Anything starting in column 1 (in this case Stop) is a label that can be used to refer to
that line.
The instruction Stop B Stop means ‘Branch to the line labelled Stop’ and is
used to create an infinite loop. This is a convenient way of ending programs in
simple examples like these.

The last line END is an assemble directive that tells the assembler there is not

Dept. of CSE, Dr. TTIT, Page 22


KGF
Microcontrollers [ BCS402 ] 2023-
24
more code to follow. It ends the program.

Figure 1: The state of the system after loading the code for Example 1

Note that the contents of r0 are 2 + 4 + 5 = 11 = 0x0B. This is the result we expected

Example 2: Additions

The problem once again is P = Q + R + S. As before, Q = 2, R = 4, S = 5


and we assume that r1 = Q, r2 = R, r3 = S.
In this case, we will put the data in memory as constants before the program
runs. We first use the load register,
LDR r1,Q instruction to load register r1 with the contents of memory
location Q. This instruction does not exist and is not part of the ARM’s
instruction set. However, the ARM assembler automatically changes it into
an actual instruction.
We call LDR r1,Q a pseudoinstruction because it behaves like a real
instruction. It is indented to make the life of a programmer happier by
providing a shortcut.

The Code
Dept. of CSE, Dr. TTIT, Page 23
KGF
Microcontrollers [ BCS402 ] 2023-
24

LDR r1,Q ;load r1 with Q


LDR r2,R ;load r2 with R
LDR r3,S ;load r3 with S
ADD r0,r1,r2 ;add Q to R
ADD r0,r0,r3 ;add in S
STR r0,Q ;store result in Q

The program

AREA Example 2, CODE, READWRITE


LDR r1,Q ;load r1 with Q
LDR r2,R ;load r2 with R
LDR r3,S ;load r3 with S
ADD r0,r1,r2 ;add Q to R
ADD r0,r3 ;add in S
STR r0, Q ;store result in Q
Stop B Stop

AREA Example2, CODE, READWRITE


P SPACE 4 ; save one word of storage
Q DCD 2 ; create variable Q with initial value 2
R DCD 4 ; create variable R with initial value 4
S DCD 5 ; create variable S with initial value 5 END

Note how we have to create a data area at the end of the program. We
have reserved spaces for P, Q, R, and S. We use the SPACE directive
for S to reserve 4 bytes of memory space for the variable S. After that
we reserve space for Q, R, and S. In each case we use a DCD assembler
directive to reserve a word location (4 bytes) and to initialize it. For
example, Q DCD 2 ;create variable Q with initial value 2 means ‘call the
current line Q and store the word 0x00000002 at that location.
Figure 2 shows the state of the program after it has been loaded. In this case
we’ve used the view memory command to show the memory space. We have
highlighted the three constants that have been pre- loaded into memory.

Take a look at the disassembled code. The pseudoinstruction LDR r1,Q was
Dept. of CSE, Dr. TTIT, Page 24
KGF
Microcontrollers [ BCS402 ] 2023-
24
actually translated into the real ARM instruction LDR r1,[PC,#0x0018].
This is still a load instruction but the addressing mode is register indirect. In
this case, the address is the contents of the program counter, PC, plus the
hexadecimal offset 0x18. Note also that the program counter is always 8
bytes beyond the address of the current instruction. This is a feature of the
ARM’s pipeline.
Consequently, the address of the operand is [PC] + 0x18 + 8 = 0 + 18 + 8
= 0x20.
If you look at the memory display area you will find that the contents
of 0x20 are indeed 0x00000002.

The code
generated by the

The address of the first These are the three data


data element on this line is values we’ve stored in memory
0x0000001C. The first at locations

0x00000020

Figure 2 : The state of the system after loading the program

2 Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
Dept. of CSE, Dr. TTIT, Page 25
KGF
Microcontrollers [ BCS402 ] 2023-
24
(Demonstrate with the help of a suitable program)

a) Data Transfer

Algorithm:

Step 1: Define Code segment


Step 2: Move the immediate 16 bit value into register r1
Step 3: Move the immediate 16 bit value into register r2
Step 4: copy the value of register r1 into register r3.
Step 5: copy the value of register r2 into register r4.
Step 6: branch to the stop label, effectively halting the program.
Step 7: End the program

Program

b) Arithmetic Operation

Dept. of CSE, Dr. TTIT, Page 26


KGF
Microcontrollers [ BCS402 ] 2023-
24

Algorithm:

Step 1: Define Code segment


Step 2: Move the immediate 16 bit value into register r0
Step 3: Move the immediate 16 bit value into register r1
Step 4: Add the content of r0 and r1 store in r2
Step 5: Subtract content of r0 and r1 store in r3
Step 6: Multiply content of r0 and r1 store in r4
Step 7: branch to the Loop label, effectively halting the program.
Step 8: End

Program

Dept. of CSE, Dr. TTIT, Page 27


KGF
Microcontrollers [ BCS402 ] 2023-
24
c) Logical operation

Algorithm:

Step 1: Define Code segment


Step 2: Move the immediate 16 bit value into register r0
Step 3: Move the immediate 16 bit value into register r1
Step 4: perform bitwise And operation to the content of r0 and r1 store result in
r2
Step 5: perform bitwise OR operation to the content of r0 and r1 store in r3
Step 6: branch to the Loop label, effectively halting the program.
Step 8: End

Program:

Dept. of CSE, Dr. TTIT, Page 28


KGF
Microcontrollers [ BCS402 ] 2023-
24

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

Algorithm:

Step 1: Define Code segment


Step 2: Store first 16 bit number into register r1
Step 3: Store second 16 bit number into register r2
Step 4: perform Multiplication of r1 and r2 store result in r3
Step 5: branch to the b label, effectively halting the program
Step 6: End

Program:

Dept. of CSE, Dr. TTIT, Page 29


KGF
Microcontrollers [ BCS402 ] 2023-
24

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

Algorithm:

Step 1: Define Code segment


Step 2: Initialize two registers:
- R1 to hold the current integer (starting from 10 and decrementing)
- R2 to accumulate the sum initially set to 0.
Step 3: Enter a loop:
a. Add the value in R1 to the accumulator in R2.
b. Decrement the value in R1 by 1.
c. Check if the result of the decrement is not zero:
- If not zero, repeat step a.
- If zero, exit the loop.
Step 4: Endless loop:
- Create an endless loop labeled 'back' to prevent the program from
terminating.
Step 5: End

Program:

Dept. of CSE, Dr. TTIT, Page 30


KGF
Microcontrollers [ BCS402 ] 2023-
24

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

Algorithm:
Step1: Define code segment and Data segment
Step 2: Initialize variables:
- Counter R5 to keep track of the number of iterations (initialized to 6,
representing N=7).
- Register R1 to hold the address of the array.
- Registers R2 and R4 to temporarily hold array elements for comparison.
- Register R3 to hold the largest number found.
- Register R4 to hold the address of the RESULT variable.
Step 3: Load the starting address of the array into register R1.
Step 4: Load the first two numbers of the array into registers R2 and R4.
Step 5: Compare the two numbers:
- If the first number is greater than the second number, store it in R3 (largest
number).
- If the second number is greater, store it in R3.
Or
- If the first number is smaller than the second number, store it in R3 (smallest
number).
- If the second number is smallest, store it in R3.
Step 6: Enter a loop:
- Decrement the counter R5.
- If the counter is not zero, loop back to step 4 to compare the next pair of
numbers.
- If the counter is zero, exit the loop.
Step 7: Store the largest number (in R3) in the RESULT variable.
Step 8: End

Dept. of CSE, Dr. TTIT, Page 31


KGF
Microcontrollers [ BCS402 ] 2023-
24

Program 5a:

Dept. of CSE, Dr. TTIT, Page 32


KGF
Microcontrollers [ BCS402 ] 2023-
24

Program 5b:

Dept. of CSE, Dr. TTIT, Page 33


KGF
Microcontrollers [ BCS402 ] 2023-
24

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

Algorithm:
Step1: Define Code segment and Data segment
Step 2: Initialize variables:
- R2 to count the number of ones.
- R3 to count the number of zeros.
- R7 as a loop counter initialized to 2 (for processing two 32-bit words).
- R6 to hold the address of the VALUE array.
- R1 as a loop counter initialized to 32 (to iterate through each bit of the word).
Step 3: Load the address of the VALUE array into register R6.
Step 4: Enter the outer loop:
- Load a 32-bit word from the VALUE array into register R0.
- Rotate R0 right by 1 bit position (ROR) to check each bit.
Step 5: Inside the outer loop:
- Check if the carry flag is set after rotation:
- If set, it indicates a one bit, so increment the ones count (R2).
- If not set, it indicates a zero bit, so increment the zeros count (R3).
Step 6: Continue looping through each bit until all 32 bits are processed.
Step 7: After processing one word:
- Decrement the loop counter (R7).
- If there are more words to process, repeat the outer loop.
- If not, exit the loop.

Step 8: At the end, R2 contains the count of ones and R3 contains the count of zeros.
Step 9: End

Dept. of CSE, Dr. TTIT, Page 34


KGF
Microcontrollers [ BCS402 ] 2023-
24

Program:

Dept. of CSE, Dr. TTIT, Page 35


KGF
Microcontrollers [ BCS402 ] 2023-
24

Dept. of CSE, Dr. TTIT, Page 36


KGF
Microcontrollers [ BCS402 ] 2023-
24

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

Algorithm: Ascending order

Step 1: Start with an array of numbers to be sorted.


Step 2: Loop through the array from the first element to the second to last element:
a. Within this loop, start another loop from the first element to the element before the last
element:
- Compare each pair of adjacent elements.
- If the current element is greater than the next element, swap them.
Step 3: Continue looping until the end of the array is reached.
Step 4: Repeat steps 2 and 3 until no more swaps are needed, indicating that the array is sorted in
ascending order.
Step 5: End

Algorithm: Descending order

Step 1: Start with an array of numbers to be sorted.


Step 2: Loop through the array from the first element to the second to last element:
a. Within this loop, start another loop from the first element to the element before the last
element:
- Compare each pair of adjacent elements.
- If the current element is smaller than the next element, swap them.
Step 3: Continue looping until the end of the array is reached.
Step 4: Repeat steps 2 and 3 until no more swaps are needed, indicating that the array is sorted in
descending order.
Step 5: End

Dept. of CSE, Dr. TTIT, Page 37


KGF
Microcontrollers [ BCS402 ] 2023-
24

Program

Dept. of CSE, Dr. TTIT, Page 38


KGF
Microcontrollers [ BCS402 ] 2023-
24

Dept. of CSE, Dr. TTIT, Page 39


KGF
Microcontrollers [ BCS402 ] 2023-
24

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


number.

Algorithm:
Step1: Start with a non-negative integer number for which factorial needs to be calculated.
Step 2: Check if the number is 0 or 1:
- If yes, return 1 (Factorial of 0 and 1 is 1).
Step 3: Otherwise, recursively calculate the factorial of (number - 1) and multiply it by the
number.
Step 4: Repeat step 3 until the number becomes 1.
Step 5: Return the factorial value.
Step 6 : End
Program:

Dept. of CSE, Dr. TTIT, Page 40


KGF
Microcontrollers [ BCS402 ] 2023-
24

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


characters from upper to lowercase and lower to uppercase.
Algorithm:
Step 1: Input a character
Step 2: If character is in the range 'A' to 'Z' (uppercase):
- Convert to lowercase by adding 32 to its ASCII value
- Output the converted character
Step 3: If character is in the range 'a' to 'z' (lowercase):
- Convert to uppercase by subtracting 32 from its ASCII value
- Output the converted character
Step 4: Otherwise, output "Not an alphabet character"
Program:

Dept. of CSE, Dr. TTIT, Page 41


KGF
Microcontrollers [ BCS402 ] 2023-
24

10.Demonstrate enabling and disabling of Interrupts in ARM.


Algorithm:
Step 1: Set up pin directions:.
Step 2 : Main loop:
-Clear the output pin P1.26 to turn off the relay.
- Wait for the button connected to pin P0.15 to be pressed.
-Wait until the button is released.
-Set the output pin P1.26 to turn on the relay.
-Wait for the button to be pressed again.
-Wait until the button is released again.
Step 3: Repeat steps 2 continuously in an infinite loop.

Program;

Dept. of CSE, Dr. TTIT, Page 42


KGF
Microcontrollers [ BCS402 ] 2023-
24

11. Demonstrate the handling of divide by zero, Invalid Operation and Overflow
exceptions in ARM
Algorithm;
Step 1: Define Exception Handlers:
-Define exception handler functions for divide by zero, invalid
operation, and overflow exceptions. These handlers will be responsible
for responding to the respective exceptions and taking appropriate
action.
Step 2: Set Exception Vector Addresses:
-Set the addresses of the exception handler functions in the exception
vector table.
Step 3: Generate Exceptions:
-In the main program, intentionally generate each type of exception to
demonstrate the handling:
- Divide by zero: Perform a division operation where the divisor is zero.
- Invalid operation: Use the builtin_nan("") function to generate an invalid
operation exception.
-Overflow: Perform an arithmetic operation that results in overflow, such
as adding a large positive number to the maximum integer value.

Dept. of CSE, Dr. TTIT, Page 43


KGF
Microcontrollers [ BCS402 ] 2023-
24

Program:

Dept. of CSE, Dr. TTIT, Page 44


KGF
Microcontrollers [ BCS402 ] 2023-
24

Viva Questions

1. What are the various criteria to choose the microcontroller?


The important criteria to be considered in choosing micro controllers are:
(1) Availability of software development tools like compilers, debuggers, assemblers
(2) Meeting the computing needs of the task at hand efficiently at low-cost.
(3) Wide availability
(4) Reliable sources/manufacturers
(5) The amount of RAM and ROM on chip
(6) The number of I/O pins and the timer on the chip
(7) Power consumption
(8) Speed of the device
(9) Packaging
(10) Cost per unit.

2. What is meant by micro controller?


Microcontroller is a small chip that has in-build Micro processor, memory, ports, timers and
converter. Micro controllers are designed for specific use. For instance, micro controller in
TV remote is mainly designed for controlling TV.

3. What is an interrupt?
Hardware or software can communicate to micro controller through interrupts. Interrupts are
external signal that controls the micro processor. Interrupt signals are generated by sources
like software programs or hardware controls.

4. What is an Interrupt service routine?


When micro controller is under sudden interrupt, it will call ISR (Interrupt service routine)
that will store the address of current memory address and takes the control to new interrupt
memory address. After the interrupt, the control will transfer back to its previous address.
5. What is meant by Register?
Registers are temporary storage area in micro controller. It can hold a value of 1- byte
memory space.

Dept. of CSE, Dr. TTIT, Page 45


KGF
Microcontrollers [ BCS402 ] 2023-
24
6. What is an Accumulator?
Accumulator has another name called Register 'A'. Accumulator is an important register in
8051, because it saves all arithmetic and logical values.
7. List some of the 8051 microcontroller manufacturers?
Intel
Philips
Infineon
Maxim/Dellas semiconductor
Atmel
8. What is difference between microprocessor and microcontroller?
The microprocessor has no ROM, RAM and no I/O ports on the chip itself.
Whereas the microcontroller has a CPU in addition to a fixed amount of RAM,ROM, I/O
ports and a timer all on a single chip.
9. List out some of the features of the 8051?
ROM – 4K bytes
RAM – 128 bytes
Timer – 2 no
I/O Pins – 32
Serial Port – 1
Interrupt sources – 6
10. What are the various types of memories used in microcontroller/microprocessor?
ROM – Read Only Memory
RAM – Random Access Memory
PROM – Programmable Read Only Memory
EPROM – Erasable Programmable Read Only Memory
EEROM – Electrically Erasable Programmable Read Only Memory
11. What are the different instruction sets ?
1. . Data transfer instruction.2.Arithmetic instruction.3.Logical Instruction.4.Boolean
variable manipulation instruction.5. Program branching instructions.

12. Compare Microprocessor and Microcontroller.


Dept. of CSE, Dr. TTIT, Page 46
KGF
Microcontrollers [ BCS402 ] 2023-
24

Microprocessor Microcontroller
Microprocessor contains ALU, general purpose Microcontroller obtains the circuitry of
registers, stack pointer, program counter, clock microprocessor and in addition it has built- in
timing circuit and interrupt circuit. ROM, RAM, I/O devices, timers and counters.
It has many instructions to
It has one or two instructions to move data
move data between memory
between memory and CPU.
and CPU.
It has one or two bit handling
It has many bit handling instructions.
instructions.
Access times for memory and I/O Less access times for built-in memory and I/O
devices are more. devices.
Microcontroller based system requires less
Microprocessor based system
hardware reducing PCB size and increasing the
requires more hardware.
reliability.

13. Name the five interrupt sources of 8051?


The interrupts are:

Vector address
 External interrupt 0 : IE0 : 0003H
 Timer interrupt 0 : TF0 : 000BH
 External interrupt 1 : IE1 : 0013H
 Timer Interrupt 1 : TF1 : 001BH
Serial Interrupt
 Receive interrupt : RI : 0023H
 Transmit interrupt: TI : 0023H

14. What is settling or conversion time in DAC?


The time taken by the DAC to convert a given digital data to corresponding analog signal is called
conversion time.

15. What are the different types of ADC?


The different types of ADC are successive approximation ADC, counter type ADC flash type
ADC, integrator converters and voltage- to-frequency converters.

16. What is interfacing?


An interface is a shared boundary between the devices which involves sharing information.
Interfacing is the process of making two different systems communicate with each other.

17. What is the use of stepper motor?


A stepper motor is a device used to obtain an accurate position control of rotating shafts. A stepper
Dept. of CSE, Dr. TTIT, Page 47
KGF
Microcontrollers [ BCS402 ] 2023-
24
motor employs rotation of its shaft in terms of steps, rather than continuous rotation as in case of
AC or DC motor.

18. Name the special functions registers available in 8051.


 Accumulator
 B Register
 Program Status Word
 Stack Pointer.
 Data Pointer.
 Port 0 , Port 1 , Port 2 & Port 3
 Interrupt priority control register.
 Interrupt enable control register.

19. What are input & output devices?

Keyboards, Floppy disk are the examples of input devices. Printer, LED / LCD
display, CRT Monitor are the examples of output devices.

20. Define A/D and D/A converters?


D/A converters transform a digital signal to an equivalent analog signal, and A/D
converters transform an analog signal o an equivalent digital signal.

Addition programs
Dept. of CSE, Dr. TTIT, Page 48
KGF
Microcontrollers [ BCS402 ] 2023-
24
1. Write an ALP to find square of a number (1 to 10 ) using look up table.

Algorithm:
Step 1: Define an array named TABLE1 with 12 elements.
Step 2: Define a variable named RESULT and initialize it to 0.
Step 3: Load the base address of TABLE1 into register R0.
Step 4: Load the value 9 into register R1.
Step 5: Multiply the value in R1 by 4 and store the result back in R1.
Step 6: Add the value in R1 to the base address in R0 and store the result back in R0.
Step 7: Load the value from the memory address pointed to by R0 into register R3.
Step 8: Load the address of the RESULT variable into register R5.
Step 9: Store the value from R3 into the memory location pointed to by R5.
Step 10: End

Program:

2. Write an ALP to find the largest/smallest number in an array of 32 bit numbers.


Dept. of CSE, Dr. TTIT, Page 49
KGF
Microcontrollers [ BCS402 ] 2023-
24

Algorithm:
Step 1: Set a variable, let's call it "largest", to an initial value. You can set it to the first
element of the array for simplicity.
Step 2: Iterate through each element of the array:
a. Compare the current element with the "largest" variable.
b. If the current element is greater than "largest", update the value of "largest" to the current
element.
Step 3: After iterating through all elements of the array, the "largest" variable will hold the
largest value.
Step 4: You can then use or display the value stored in the "largest" variable as needed.

Program;

Dept. of CSE, Dr. TTIT, Page 50


KGF

You might also like