Microcontroller Lab Manual - MIT
Microcontroller Lab Manual - MIT
MICROCONTROLLERS
LABORATORY
(BCS402)
LAB MANUAL
For
IV SEMESTER
⮚ Exhibit relevant professional skills and learned involvement to match the requirements
of technological trends.
PROGRAM SPECIFIC OUTCOME:
DONT’S:-
Don't touch open wires unless you are sure that there is no voltage. Always disconnect
the plug by pulling on the connector body not by the cable. Switch off the supply while
you make changes to the experiment.
Don’t leave the experiment table unattended when the experimental setup supply is on.
Students are not allowed to work in laboratory alone or without presence of the teaching
staff/ instructor.
No additional material should be carried by the students during regular labs.
Avoid stepping on electrical wires or any other computer cables.
MICROCONTROLLERS
(Effective from the academic year 2023 -2025)
SEMESTER – IV
Course Learning Objectives: This course (BCS402) will enable students to:
Develop and test Assembly Language Program (ALP) using ARM7TDMI/LPC2148.
Conduct the experiments on an ARM7TDMI/LPC2148 evaluation board using evaluation
version of Embedded 'C' & Keil Uvision-4 tool/compiler.
Programs List:
2. Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
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.
INTRODUCTION
Evolution of Microprocessor:
The microprocessor forms the brain of the Central Processing Unit (CPU). Microprocessor
is an engine which can compute various operations fabricated on a single chip. The internal
architecture of microprocessor determines what operations can be performed on a
microprocessor and how it can be performed.
The first microprocessor was introduced in the year 1971. It was introduced by Intel and was
named Intel 4004.Intel 4004 is a 4 bit microprocessor and it was not a powerful microprocessor.
It can perform addition and subtraction operation on 4 bits at a time.
However it was Intel’s 8080 was the first microprocessor to make it to Home computers. It was
introduced during the year 1974 and it can perform 8 bit operations. Then during the year 1976,
Intel introduced 8085 processors which is nothing but an update of 8080 processors.8080
processors are updated by adding two Enable/Disable Instructions, Three added interrupt pins
and serial I/O pins.
Intel introduced 8086 pins during the year 1976. The major difference between 8085 and 8086
processor is that 8085 is an 8 bit processor, but 8086 processor is a 16 bit processor. The
greatest advantage of the above processors are that it do not contain Floating point instructions.
Here floating point refers to the radix point or decimal point. For example: 123.456 is a floating
point representation. Processors such as 8085 and 8086 do not support such representations
and instructions.
Intel later introduced 8087 processor which was the first math co-processor and later the 8088
processor which was incorporated into IBM personal computers.
As the years progressed lots of processors from 8088,80286,80386,80486,Pentium II, Pentium III,
Pentium IV and now Core2Duo,Dual Core and Quad core processors are the latest in the market.
Types of microprocessors:
Complex instruction set microprocessor
The processors are designed to minimise the number of instructions per program and
ignore the number of cycles per instructions. The compiler is used to translate a high level
language to assembly level language because the length of code is relatively short and an
extra RAM is used to store the instructions. These processors can do tasks like
downloading, uploading and recalling data from memory. Apart from these tasks these
microprocessor can perform complex mathematical calculation in a single command.
Example: IBM 370/168, VAX 11/780.
Reduced instruction set microprocessor
These processor are made according to function. They are designed to reduce the
execution time by using the simplified instruction set. They can carry out small things in
specific commands. These processors complete commands at faster rate. They require only
one clock cycle to implement a result at uniform execution time. There are number of
registers and less number of transistors. To access the memory location LOAD and STORE
instructions are used. Example: Power PC 601, 604, 615, 620
Super scalar microprocessor
These processors can perform many tasks at a time. They can be used for ALUs and
multiplier like array. They have multiple operation unit and perform tasts my executing
multiple commands.
Application specific integrated circuit
These processors are application specific like for personal digital assistant computers. They
are designed according to proper specification.
Digital signal multiprocessor
These processors are used to convert signals like analog to digital or digital to analog. The
chips of these processors are used in many devices such as RADAR SONAR home theatres
etc.
Advantages of microprocessor –
1. High processing speed
2. Compact size
3. Easy maintenance
4. Can perform complex mathematics
5. Flexible
6. Can be improved according to requirement
Disadvantages of microprocessors –
1. Overheating occurs due to overuse
2. Performance depends on size of data
3. Large board size than microcontrollers
4. Most microprocessors do not support floating point operations
Intel has introduced standard 8-bit microcontroller 8048 in 1976. The same company has
continued to drive the evolution of single chip microcontrollers. In the year 1980, Intel has
introduced the 8051 microcontroller, with higher performance than 8048. With the advantages
of 8051, the microcontroller’s applications took a peak level. The 8-bit microcontroller, 8051
family. Quickly gained the position of the second generation world standard microcontrollers.
Because of the advanced semiconductor technology, it has become possible to integrate more
than 1.00.000 transistors onto a single silicon chip. Intel has made use of this advanced process
technology and developed a new generation of single chip 16 bit microcontrollers called the
MCS-96 (8096 family). The 8096 family offers the highest level of system integration ever
achieved on a single chip microcontroller with l,20,000 transistors. This 8096 microcontroller has
16 bit CPU, 8K bytes of program memory. 232 bytes of data memory and both analog and digital
type of 1/ O features.
The Motorola Microcontroller family was first introduced to the market in 1978 and is built in
the same pattern of the microprocessor 6800. Even though the Microcontroller 6801 family was
designed similar to the microprocessor 6800, its design and instruction set have been modified
to suit the control applications.
The microcontroller 6801 family includes on-chip Input/output ports, an Asynchronous serial
communication device and 16 bit timer modules. The Microcontrollers 6801. 6803, 6805. 6811
are available from Motorola Company. The 6811 microcontroller family have different version
with ROM, RAM, EPROM, and EEPROM. These versions are denoted by suffix characters and
numbers.
RISC: The RISC is stands for Reduced Instruction set Computer, this type of instruction
sets reduces the design of microprocessor for industry standards. It allows each
instruction to operate on any register or use any addressing mode and simultaneous
access of program and data.
The ARM processor is a 32-bit RISC processor, meaning it is built using the RISC (reduced
instruction set computer) ISA (instruction set architecture). ARM processors are microprocessors
and are widely used in many of the mobile phones sold each year, as many as 98% of mobile
phones. They are also used in PDAs (personal digital assistants), digital media and music layers,
hand-held gaming systems, calculators, and even computer drives. The first ARM processor-
based computer was the Acorn Archimedes, released in 1987. Apple Computer became involved
with helping to improve the ARM technology in the late 1980s, with their work resulting in the
ARM6 technology in 1992. Later, Acorn used the ARM6-based ARM 610 processor in their RISC
PC's in 1994. Today, the ARM architecture is licensed to many companies, including Apple, Cirrus
Logic, Intel, LG, Microsoft, NEC, Nintendo, Nvidia, Sony, Samsung, Texas Instruments, and many
more. The latest developed ARM processor families include ARM11 and Cortex. ARM processors
capable of 64-bit processing are currently in development.
Load/store architecture.
An orthogonal instruction set.
Mostly single-cycle execution.
Enhanced power-saving design.
64 and 32-bit execution states for scalable high performance.
Hardware virtualization support.
• Open Keil uVision4 IDE software by double clicking on “Keil Uvision4” icon.
• Go to “Project” then to “New uVision Project” and save it with a name in the respective
project folder, already you created.
• Select the device as “NXP” In that “LPC2148” then press OK and then press “YES” Button to add
“startup.s” file.
• In startup file go to Configuration Wizard. In Configuration Wizard window uncheck PLL Setup
and check VPBDIV Setup.
• Go to “File” In that “New” to open an editor window. Create your source file and use the
header file “lpc21xx.h” in the source file and save the file. Colour syntax highlighting will be
enabled once the file is saved with a extension such as “.C “.
• Right click on “Source Group 1” and select the option “Add Existing Files to Group
• Source Group 1“add the *.C source file(s) to the group. After adding the source file you can see
the file in Project Window. Then go to “Project” in that “Translate” to compile the File (s).
Check out the Build output window.
Right click on Target1 and select options for Target Target1.
Then go to option “Target” in that
• Xtal 12.0MHz
• Select “Use MicroLIB”.
• Select IROM1 (starting 0x0 size 0x80000).
• Select IRAM1 (starting 0x40000000 size 0x8000).
Then go to option “Output”
• Select “Create Hex file”
Then go to option “Linker”
• Select “Use Memory Layout for Target Dialog”.
To come out of this window press OK.
Go to “Project” in that “Build Target” for building all source files such as “.C”,”.ASM”,
“.h”, files, etc…This will create the *.HEX file if no warnings & no Errors. Check out the
Build output window.
4. ALP TO ADD AN ARRAY OF 16BIT NUMBERS AND STORE THE 32BIT RESULT IN
INTERNAL RAM.
LABEL MNEMONIC FIELD COMMENTS FILED
FIELD
AREA FACTORIAL,CODE, READONLY
ENTRY ; MARK FIRST INSTRUCTION TO EXECUTE
MOV R1,#05 ; COUNTER BIT FOR 5 16BIT ADDITION
SUB R1,#01 ; DECREMENTED BY 1 BECAUSE WE ADD ONLY 4 TIME
MOV R0,#0X40000000 R0 POINTING TO 0X40000000 MEMORY LOCATION
LDRH R2,[R0] ; LODING HALF WORD POINTED BT RO TO R2
UP ADD R0,R0,#2 ; MEMORY POINTER INCREMENTED BY 2
LDRH R3,[R0] ; SECOND 16BIT NUMBER IS LOADED TO R3
ADD R2,R2,R3 ; ADDITION IS DONE
SUBS R1,#01 ; DECREMENTS COUNTER BIT FOR NUMBER OF ADDITION
BNE UP ; IF COUNTER≠0 THE EXECUTION JUMPS TO THE LABEL 'UP'
MOV R0,#0X40000020 ; MEMORY LOCATION WHERE RESULT SHOULD BE SAVED
STR R2,[R0] ; STORING OF RESULT
HERE B HERE
END ; MARK END OF FILE
7. ALP TO COUNT THE NUMBER OF ONES AND ZEROS IN TWO CONSECUTIVE MEMORY
LOCATIONS.
LABEL FIELD MNEMONIC FIELD COMMENT FIELD
AREA ONEZERO , CODE, READONLY
ENTRY ;MARK FIRST INSTRUCTION TO EXECUTE
MOV R2,#0 ; COUNTER FOR ONES
MOV R3,#0 ; COUNTER FOR ZEROS
MOV ; LOADS THE VALUE
R6,#0X00000002
MOV R1,#32 ; 32 BITS COUNTER
MOV R0,R6 ; GET THE 32 BIT VALUE
MOV R0,R6 ; GET THE 32 BIT VALUE
LOOP0 MOVS R0,R0,ROR #1 ; RIGHT SHIFT TO CHECK CARRY BIT (1'S/0'S)
BHI ONES ; IF C=1 GOTO ONES BRANCH OTHERWISE NEXT
ZEROS ADD R3,R3,#1 ; IF C= 0 THEN INCREMENT THE COUNTER BY 1(R3)
B LOOP1 ; BRANCH TO LOOP1
ONES ADD R2,R2,#1 ; IF C=1 THEN INCREMENT THE COUNTER BY 1(R2)
LOOP1 SUBS R1,R1,#1 ; COUNTER VALUE DECREMENTED BY 1
BNE LOOP0 ; IF NOT EQUAL GOTO TO LOOP0 CHECKS 32BIT
STOP B STOP
END
#include<lpc21xx.h>
int temp (int temp)
{
int i,j;
int arr[5]={3,2,7,1,5};
for(i=0;i<5;i++)
{
for(j=0;j<4-I;j++)
{
if(arr[j]>arr[j+1])
{
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;
}
}
}
}
Before Execution :
After Execution:
#include<lpc21xx.h>
int temp (int temp)
{
int i,j;
int arr[5]={3,2,7,1,5};
for(i=0;i<5;i++)
{
for(j=0;j<4-I;j++)
{
if(arr[j]<arr[j+1])
{
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;
}
}
}
}
Before Execution :
After Execution:
#include<lpc21xx.h>
Int tmp(int temp)
{
Unsigned int num=5,fact=1;
While(num>0)
{
Fact=fact*num;
Num--;
}
While(0);
Return 1;
}
Before Execution :
After Execution: