mc 2022 scheme lab manual
mc 2022 scheme lab manual
Laboratory Manual
MICROCONTROLLER(BCS402)
IV Semester (CBCS Scheme)
Prepared by
LALITHA M,
Asst. Prof, Dept. of CSE
VANISHREE,
Asst. Prof, Dept. of CSE
-
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.
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.
MICROCONTROLLER LABORATORY SEMESTER IV
Course Learning Objectives: This course (BCS402) will enable students to:
Programs List:
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.
Demonstrate enabling and disabling of Interrupts in ARM.
SL. EXP. PAGE
CONTENTS
NO No. NO.
Using Keil software, observe the various Registers, Dump, CPSR, with
1 - 1
a simple Assembly Language Programs (ALP).
2 1 Develop and simulate ARM ALP for Data Transfer, Arithmetic and 8
Logical operations (Demonstrate with the help of a suitable program).
Develop an ALP to multiply two 16-bit binary numbers.
3 2 9
Develop an ALP to find the sum of first 10 integer numbers.
4 3 10
Develop an ALP to find the largest/smallest number in an array of 32
5 4 11
Numbers.
Develop an ALP to count the number of ones and zeros in two consecutive
6 5 12
memory locations.
Simulate a program in C for ARM microcontroller using KEIL to
7 6 14
sort the numbers in ascending/descending order using bubble sort.
Simulate a program in C for ARM microcontroller to find factorial of a
8 7 16
number
Simulate a program in C for ARM microcontroller to demonstrate case
9 8 18
conversion of characters from upper to lowercase and lower to uppercase.
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 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:
The processors are designed to minimize 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.
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
onlyone 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
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.
These processors are application specific like for personal digital assistant computers.
They are designed according to proper specification.
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
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
-bit microcontroller, 8051
family. Quickly gained the position of the second generation world standard
microcontrollers.
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.
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 32-bit microcontroller uses the 32-bit instructions to perform the arithmetic and
logic operations. These are used in automatically controlled devices including
implantable medical devices, engine control systems, office machines, appliances and
other types of embedded systems. Some examples are Intel/Atmel 251 family, PIC3x.
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.
A) DATA TRANSFER
Output:
R1 0x00000012
R2 0x00000032
R3 0x00000012
R4 0xFFFFFFED
R5 0x00000032
R6 0xFFFFFFCD
B) ARITHMETIC OPERATIONS
Output:
R1 0x00000012
R2 0x00000032
R3 0x00000044
R4 0x00000044
R5 0x00000020
R6 0x0000001F
R7 0xFFFFFFE0
R8 0xFFFFFFDF
C) LOGICAL OPERATIONS
LABEL MNEMONIC FIELD COMMENTS FILED
FIELD
AREA MULTIPLY, CODE, READONLY
ENTRY ; Mark first instruction to execute
MOV R1,#0X12 ; STORE FIRST NUMBER IN R0
MOV R2,#0X32 ; STORE SECOND NUMBER IN R1
ORR R3,R2,R1 ;LOGICAL OR OPERATION
AND R4,R2,R1 ;LOGICAL AND OPERATION
EOR R5,R2,R1 ;LOGICAL EOR OPERATION
BIC R6,R2,R1 ;LOGICAL BIT CLEAR OPERATION
HERE B HERE
END ; MARK END OF FILE
Output:
R1 0x00000012
R2 0x00000032
R3 0x00000032
R4 0x00000012
R5 0x00000020
R6 0x00000020
2. ALP TO MULTIPLY TWO 16BIT NUMBERS
OUTPUT
3. ALP TO FIND THE SUM OF FIRST 10 INTEGER NUMBERS
OUTPUT
4. ALP TO FIND THE LARGEST/SMALLEST NUMBER IN AN ARRAY OF 32
NUMBERS.
#include<reg51.h>
Void main()
{
Unsigned long
array[]={0x22222222,0x99999999,0x33333333,0x55555555,0xAAAAAAAA,0x11111111}
Unsigned long temp,I,j;
For(I=0;I<5;I++)
{
For(j=0;j<5;j++)
{
If(array[j]>array[j+1])
{
Temp=array[j+1];
Array[j+1]=array[j];
Array[j]=temp;
}
}
}
Output=array
[0] 0x11111111
[1] 0x22222222
[2] 0x33333333
[3] 0x55555555
[4] 0x99999999
[5] 0xAAAAAAAA
DESCENDING ORDER USING BUBBLE SORT
#include<reg51.h>
Void main()
{
Unsigned long
array[]={0x22222222,0x99999999,0x33333333,0x55555555,0xAAAAAAAA,0x11111111}
Unsigned long temp,I,j;
For(I=0;I<5;I++)
{
For(j=0;j<5;j++)
{
If(array[j]<array[j+1])
{
Temp=array[j+1];
Array[j+1]=array[j];
Array[j]=temp;
}
}
}
Output=array
[0] 0xAAAAAAAA
[1] 0x99999999
[2] 0x55555555
[3] 0x33333333
[4] 0x22222222
[5] 0x11111111
7. SIMULATE A PROGRAM IN C FOR ARM MICROCONTROLLER TO FIND
FACTORIAL OF A NUMBER
#include<reg51.h>
Void main()
{
Unsigned int num=5,fact=1;
While (num>0)
{
fact=fact*num;
num--;
}
P1=fact;
While(1);
}
Output
LOCAL WINDOW
NUM 0x0000
FACT 0x0078
Port window
Parallel port
7 0
P1 0x78
pin 0x78
8. SIMULATE A PROGRAM IN C FOR ARM MICROCONTROLLER TO DEMONSTRATE
CASE CONVERSION OF CHARACTERS FROM UPPER TO LOWERCASE AND LOWER TO
UPPERCASE.
#include<LPC214x.H>
char toLower(char ch);
char toUpper(char ch);
void UART_Init(void){
PINSEL |=0x00000005;
V0LCR=0x83;
V0DLL=0x61;
V0DLM=0x00;
V0LCR=0x03;
}
void UART_sendChar(char c) {
while(|V0LSR & 0x20));
V0THR= c;
}
void UART0_ReceiveChar(void) {
while(|V0LSR & 0x01));
return V0RBR;
}
int main() {
char str[100];
UART0_Init();
UART0_receivestring(str, sizeof(str));
\r\
toLowerString(str);
UART0_SendString(str);
\r\
UART0_receivestring(str, sizeof(str));
\r\
ToUpperString(str);
UART0_SendString(str);
\r\
return 0;
}
-
} else {
return ch;
}
}
-
} else {
return ch;
}
}
9. DEMONSTRATE ENABLING AND DISABLING OF INTERRUPTS IN ARM..
#include<LPC214x.H>
Int i;
irq void Ext_ISR(void) // Interrupt Service Routine-ISR
//The _irq keyword tells the compiler that the function is an interrupt routine
{
IO1DIR |= 0x00010000;
IO1CLR |= 0x00010000;
For(i=0; i<3000000;i++);
IO1SET |= 0x00010000;
EXTINT |= 0x4; //clear interrupt
Vicvectaddr = 0; // End of interrupt execution
}
Void init_ext_interrupt() // Initialize Interrupt
{
EXTMODE = 0x4; //Edge sensitive mode on
EINT2 EXTPOLAR &= ~(0x4); //Falling Edge Sensitive
PINSEL0 = 0x80000000; //Select Pin function P0.15 as EINT2
/* initialize the interrupt vector */
Vicintselect &= ~ (1<<16); // EINT2 selected as
IRQ 16 Vicvectaddr5 = (unsigned int)Ext_ISR; //
address of the ISR Vicvectcntl5 = (1<<5) | 16;
// Basically Vector Address Register store the address of the function i.e. ISR and used to assign or
enable vector IRQ slot..Pointer Interrupt Function (ISR)
Vicintenable = (1<<16); // EINT2 interrupt
enabled EXTINT &= (0x4);
}
Int main (void)
{
Init_ext_interrupt(); // initialize the external
interrupt While(1);
}