Microprocessor and Microcontroller Laboratory Manual
Microprocessor and Microcontroller Laboratory Manual
Microprocessor and Microcontroller Laboratory Manual
Prepared by:
Anand D
Anusha
Keerti N
Roopa P
COURSE LABORATORY MANUAL
A. LABORATORY OVERVIEW
Degree: BE Programme: CSE
Semester: 4 Academic Year: 2017-18
Microprocessors and
Laboratory Title: Laboratory Code: 15CSL48
Microcontroller Laboratory
L-T-P-S: 1-0-2-0 Duration of USE: 3 Hrs
Total Contact Hours: 42 Hrs USE Marks: 80
Credits: 2 IA Marks: 20
B. DESCRIPTION
1. PREREQUISITES:
• Microprocessors And ARM Processors(15CS44)
• Basic Electronics (15ELN15)
• Analog and Digital Electronics(15CS32)
• Computer programming laboratory (15CPL16)
• Programming in C and Data Structures (15PCDS13).
2. BASE COURSE:
• Microprocessors and Microcontrollers (15CS44)
3. COURSE OUTCOMES:
At the end of the course, the student will be able to
Apply the programming techniques in designing simple assembly language programs for solving
simple problems by using instruction set of 8086 microprocessor / ARM.
Gain hands-on experience in doing experiments on 8086 microprocessor / ARM by using
Assembler tool (MASM / MASM) in the laboratory and present the report.
Understand the hardware, software tradeoffs involved in the design and interface hardware
devices to x86/ARM family.
Assess processors for various kinds of applications.
4. GENERAL INSTRUCTIONS:
Start Run… cmd
MASM COMMANDS:
D:\ masm > edit filename.asm ; Write the program and save.
D:\ masm > masm filename.asm; If any errors, correct the same.
D:\ masm > link filename.obj
D:\ masm > debug filename.exe ; debugger command prompt
After the debugger command prompt the following commands are used;
a – assemble
d – dump (to view the contents of the data memory)
g – go (to execute the entire program at a time)
u – unassemble
t – trace (to execute the program in single step)
r – register (to see the contents of the register)
q – quit
? – to view all the options
5. CONTENTS:
Expt Blooms
Title of the Experiments CO
No. Level
Design and develop an assembly language program to search a key element
1 “X” in a L3 CO1,2,3,4
list of ‘n’ 16-bit numbers. Adopt Binary search algorithm in your program
for searching.
2 Design and develop an assembly program to sort a given set of ‘n’ 16-bit L3 CO1,2,3,4
numbers in ascending order. Adopt Bubble Sort algorithm to sort given
elements.
3 Develop an assembly language program to reverse a given string and L3 CO1,2,3,4
verify whether it is a palindrome or not. Display the appropriate message.
4 Develop an assembly language program to compute nCr using recursive L3 CO1,2,3,4
procedure. Assume that ‘n’ and ‘r’ are non-negative integers.
Design and develop an assembly language program to read the current time
5 and display. L3 CO1,2,3,4
To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable
6 program). L3 CO1,2,3,4
Theory: Binary search is a well-known method for searching for an item in a sorted array. In the beginning
the search range is the whole array. Then the search key is compared with the middle element of the
range. If they are equal, the wanted item has been found. If the key is smaller, the same procedure is
applied recursively to the left half of the search range, otherwise to the right half .
Program
.model small
.stack 20
.data
a dw 1112h,1234h,2356h,3478h,0ab88h,0bd90h,0ff93h
count equ ($-a)/2
key dw 0bd90h
msg1 db 0dh,0ah,"search successful, key present at position $"
msg2 db 0dh,0ah,"search unsuccessful$"
.code
start: mov ax,@data
mov ds,ax
mov bx,00
mov dx,count
mov cx,key
end start
Output:
sample input 1 :
list a : 0001h,0002h,0003h,0004h,0005h
key = 0002h
output :
search successful.
key element found at position 2.
sample input 2:
list a: 0001h,0002h,0003h,0004h,0005h
key = 0009h
output :
search unsuccessful.
2. Design and develop an assembly program to sort a given set of ‘n’ 16-bit numbers in ascending order.
Adopt Bubble Sort algorithm to sort given elements.
Theory
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps
through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the
wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the
list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements
"bubble" to the top of the list.
Program
.model small
.stack 20
.data
list dw 0c05h, 0120h, 0123h, 0004h
count equ 04h
.code
mov dx,count-1
ahead1:inc si
inc si
loop inner
dec dx
jnz outer
mov ah,4ch
int 21h
end start
Output:
The unsorted array input is
0c05h, 0120h, 0123h, 0004h
Sorted output is
0004h, 0120h, 0123h, 0c05h
3. Develop an assembly language program to reverse a given string and verify whether it is a palindrome
or not. Display the appropriate message.
Theory
PALINDROME CHECK: This program waits till it receives a string of characters from the standard input
device(keyboard),terminated by the carriage return, and stores the string in an array called str. The
reversed string is stored in another array called rev_str. The two strings are compared character wise; for
checking whether the original string is palindrome. Necessary messages are displayed using DOS function
calls.
Program
.model small
.stack 20
.data
msg1 db 0dh,0ah,"The givenstring is Palindrome.$"
msg2 db 0dh,0ah,"The givenstring is not a Palindrome.$"
givenstring db "liril"
n dw $-givenstring
reversedstring db 10 dup(0)
.code
start:
mov ax,@data
mov ds,ax
mov si,0
mov di,0
mov cx,n
add si,cx
dec si
loop3: inc si
loop loop2
lea dx,msg1
mov ah,09h
int 21h
mov ah,4ch
int 21h
end start
Output:
For string liril : The givenstring is Palindrome.
For string hello : The givenstring is not Palindrome.
4. Develop an assembly language program to compute nCr using recursive procedure. Assume that ‘n’
and ‘r’ are non-negative integers.
Theory
The ncr program computes nCr(no. of combinations of n, taken r at a time),using recursive procedure
where n and r are stored in wordwide memory locations.
Recursive definition for nCr:
Case1: If r=0 OR r=n, then nCr = 1 Case2: If r=1 OR r=n-1, then nCr = n
Program
//Calculating nCr value.
.MODEL SMALL
.DATA
N DB 4
R DB 2
NCR DB 0
.CODE
START: MOV AX,@DATA
MOV DS,AX
MOV AL,N
MOV BL,R
CALL NCRPRO
MOV AH,4CH
INT 21H
END START
Output:
n-4
r-2
ncr=6
5. Design and develop an assembly language program to read the current time and display.
Theory: The program for reading system time reads the system time ,using DOS ;function call number
2CH. The hour, minute and second are returned in CH, CL and DH registers (in HEX form) respectively, by
the DOS function. It is then converted into ASCII for display purpose.
Program
.model small
.data
hrs db ?
min db ?
sec db ?
.code
start:
mov ax,@data
mov ds,ax
mov ah,2ch
int 21h
mov hrs,ch
mov min,cl
mov sec,dh
mov al,hrs
call disp1
call disp2
mov al,min
call disp1
call disp2
mov al,sec
call disp1
mov ah,4ch
int 21h
disp1 proc
aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
ret
disp1 endp
disp2 proc
mov dl,':'
mov ah,02h
int 21h
ret
disp2 endp
end start
Output: 12:30:23
6.To write and simulate ARM assembly language programs for data transfer, arithmetic and logical
operations (Demonstrate with the help of a suitable program).
Theory
ARM processor is easy to program at the assembly level.
The state of an ARM system is determined by the content of visible registers and memory.
• A user-mode program can see 15 32-bit general purpose registers (R0-R14), program counter
(PC) and CPSR.
• Memory system of ARM is a linear array of bytes addressed from 0 to 232-1.
• ARM instructions are all 32-bit long (except for Thumb mode). There are 232 possible machine
instructions. Fortunately, they are structured.
Program
1.Area add, code, readonly
Ldr r1,=0x00000005
Ldr r2,=0x00000004
add r3,r1,r2
Nop
Nop
End
int main(void)
{
int a,b,c;
a=1;
b=1;
if(a==1 && b==1)
printf(“true”);
8a. Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99) on the Logic
Controller Interface.
model small
.stack 20
.data
base_address equ 0e880h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov dx,control
mov al,8ah
out dx,al
mov al,00h
up: mov dx,porta
out dx,al
call delay
cmp al,19h
jnz next
jmp stop
next: add al,01h
daa
jmp up
stop:mov ah,4ch
int 21h
b. Design and develop an assembly program to read the status of two 8-bit inputs (X & Y) from the Logic
Controller Interface and display X*Y.
.model small
.stack 20h
.data
msg1 db 'input x ',0dh,0ah,'$'
msg2 db 'input y ',0dh,0ah,'$'
msg3 db 'output the result on port a',0dh,0ah,'$'
base_address equ 0e880h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov al,8ah
mov dx,control
out dx,al
mov al,00
mov dx,porta
out dx,al
lea dx,msg1
mov ah,09h
int 21h
mov ah,01
int 21h
mov dx,portb
in al,dx
mov cl,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01
int 21h
mov dx,portb
in al,dx
mov ch,al
lea dx,msg3
mov ah,09h
int 21h
mov ah,01h
int 21h
mov al,ch
mul cl
mov dx,porta
out dx,al
mov al,ah
and al,0fh
mov dx,portc
out dx,al
mov ah,4ch
int 21h
end start
9.Design and develop an assembly program to display messages “FIRE” and “HELP” alternately with
flickering effects on a 7-segment display interface for a suitable period of time. Ensure a flashing rate
that makes it easy to read both the messages.
.model small
.stack 20
.data
base_address equ 20c0h
control equ base_address+03h ;control port
porta equ base_address+00h ;porta address
portb equ base_address+01h ;portb address
portc equ base_address+02h ;portc address
Blanks db 0,0,0,0,0,0
fire db 0,0,79h,50h,06h,71h
help db 73h,38h,79h,76h,0,0
.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
;----------display fire ---------------------------------------
up: mov di,150
fir: mov si,offset fire
call display
dec di
jnz fir
;----------display blank -------------------------------------
mov di,300
blnk: mov si,offset blanks
call display
dec di
jnz blnk
;----------display help ---------------------------------------
mov di,150
hlp: mov si,offset help
call display
dec di
jnz hlp
;----------display blank -------------------------------------
mov di,300
blnk1: mov si,offset blanks
call display
dec di
jnz blnk1
mov dx,porta
lodsb
out dx,al
call delay
inc bl
cmp bl,05
jle down
mov bl,00
down:
loop select
ret
display endp
delay proc
push bx
push cx
mov cx,0ffh
up1: mov bx,0fffh
up2: dec bx
jnz up2
loop up1
pop cx
pop bx
ret
delay endp
end start
10.Design and develop an assembly program to drive a Stepper Motor interface and rotate the motor in
specified direction (clockwise or counter-clockwise) by N steps (Direction and N are specified by the
examiner). Introduce suitable delay between successive steps.
.model small
.stack 20h
.data
base_address equ 20c0h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
again: mov cx,5
up:
mov al,077h
mov dx,portc
out dx,al
call delay
mov al,0bbh
out dx,al
call delay
mov al,0ddh
out dx,al
call delay
mov al,0eeh
out dx,al
call delay
loop up
mov cx,5
up1:
mov al,0eeh
mov dx,portc
out dx,al
call delay
mov al,0ddh
out dx,al
call delay
mov al,0bbh
out dx,al
call delay
mov al,077h
out dx,al
call delay
loop up1
mov ah,0bh
int 21h
or al,al
jz again
mov ah,4ch
int 21h
end start
void clock_wise(void) ;
void anti_clock_wise(void) ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
while(1)
{
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
IO1SET = var1 ;
}
}
b. Generate a Half Rectified Sine waveform using the DAC interface. (The output of the DAC is to be
displayed on the CRO).
.model small
.stack 20h
.data
base_address equ 20c0h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
table db 128,150,171,195,210,226,238,248,254,255,254,248,238,226,210,195,171,150
.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
up:
lea bx,table
mov cx,18
next:
mov al,[bx]
mov dx,portb
out dx,al
inc bx
call delay
loop next
mov cx,18
mov al,128
up1:
mov dx,portb
out dx,al
call delay
loop up1
mov ah,0bh
int 21h
or al,al
jz up
mov ah,4ch
int 21h
delay proc
push cx
push bx
mov cx,000fh
up3:
mov bx,000fh
up2:
dec bx
jnz up2
loop up3
pop bx
pop cx
ret
delay endp
end start
12.To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs in C
language for displaying text messages and numbers on LCD.
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]
} //end of main()
temp1 = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
lcd_com(); // 2 line and 5x7 matrix display
delay(3200);
temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
delay(800);
void lcd_com(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;
wr_cn();
delay(500); // some delay
}
13.To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to rotate
stepper motor
// A stepper motor direction is controlled by shifting the voltage across
// the coils. Port lines : P1.20 to P1.23
//-------------------------------------------------------------------
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
unsigned int var1 ;
unsigned long int i = 0 , j = 0 , k = 0 ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
while(1)
{
for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation clock_wise() ;
// rotate one round clockwise
for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation anti_clock_wise() ;
// rotate one round anticlockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation
}
}// End of main
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
IO1CLR =0x00F00000 ;
//clearing all 4 bits
IO1SET = var1 ;