You are on page 1of 35

Nagar Yuwak Shikshan Sanstha’s

Yeshwantrao Chavan College of Engineering


(An Autonomous Institution affiliated to Rashtrasant Tukadoji Maharaj Nagpur University)
Hingna Road, Wanadongri, Nagpur - 441 110

Department of Electronics Engineering

Microcontroller and its Applications


Lab
Manual
Prepared By
Dr. P.T. Karule
Prof. S.Y.Ambatkar
Dr. Y.A.Suryawanshi
Department of Electronics Engineering
Microcontroller / Embedded System Laboratory
Subject: Microcontroller & its Applications
Sem. /Branch: IV Sem. EE
List of Experiments
Objective: Outcomes:
 To understand the architecture,  Students will be able to understand the
programming and addressing modes concept of Controller, architecture of 8051
of Intel 8051  Students will demonstrate the ability to
 To study the instruction set and identify, formulate and design program for
programming of 8051 an assigned task.
 To understand various interfacing  Students will be able to interface & program
concepts and circuits necessary for peripheral devices.
various applications.
Expt. Name of Experiments Course
No. Outcomes
1. To Perform basic arithmetic (Addition , Subtraction, CO1,CO2
Multiplication, Division) and logical operations (AND,OR,X-OR)
using 8051 instructions.
i) Add 01 H with FF H And observe contents of Accumulator
and Program status word
ii) Subtract 01 H from FF H And observe contents of
Accumulator and Program status word
iii) AND 01 H with FF H And observe contents of Accumulator
and Program status word
iv) OR 01 H with FF H And observe contents of Accumulator
and Program status word
v) Ex-or 01 H with FF H And observe contents of Accumulator
and Program status word
vi) Multiply 10 H with 10 H And observe contents of
Accumulator and Register B
vii) Divide 26 H by 02 H And observe contents of Accumulator
and Register B
Add 05 data byte in a block , length of the block is at 40H. The
2. block starts at 41H. Place the sum at 30 H. CO1,CO2
3. Find the maximum data byte from a block of 05 data bytes. The
length of the block is at 40 H. The block starts at 41 H. Place CO1,CO2
maximum data byte at 30 H.
Transfer a block of 05 data bytes from a source block starting
4. at40H to destination block starting at 60 H. Length of the block CO1,CO2
is at 30 H.
Find the no of negative data bytes from a block of 05 data bytes.
5. The length of the block is at 40H. The block starts at 41H. Place CO1,CO2
no of negative data bytes at 30 H.
6. Convert single digit hex no. at 40H to its ASCII equivalent at
41H. CO1,CO2
CO1,CO2
7. Convert BCD no at 40H to its binary equivalent at 41H.
8. Glow led after every 1 ms /100 ms connected to port pin P0.4 of
8051. CO1,CO2,CO3
9. Generate square waveform of 2 ms using Timer #0 of 8051. CO1,CO2,CO3
10. Display 0-9 on seven segment display . CO1,CO2,CO3
11. To display string of characters on LCD display CO1,CO2,CO3
Procedure to write the program in μ Vision Keil:

• Create a New folder on the desktop for saving the contents of the program.
• Double click on the icon of Keil.
• Select the device for the target (Select Intel→ Select 8051 AH →Ok →No)
• Go in the project menu and click on μVision Project after this an edit window
will appear on desktop.
• Write the desired program in the editing window up to end.
• Right click on source group and select remove start up in project workspace.
• Go in the file menu and click on save as and save the program with the
extention .asm on desktop in the new folder.
• Right click on source group → Select add file to group → All file → Select file
.asm →
Select Add.
• Now go in the project menu and click on options for the target “Target1”.
• Update the frequency value (eg. 11.0592) and click on output and enable the
following.
• ®Create Executable
• √ or Ok –Debug info
• Select Create Hex file
• Select
Browse info
Now click on
Ok
• Go in the project menu and click on built target.
• Go in the project menu and click on Rebuild target.
• Go in the project menu and click on Run (or Ctrl +F5).
After this Hex file will be created in the New Folder
Experiment No.1
Aim: - To Perform basic arithmetic (Addition , Subtraction, Multiplication, Division)
and logical operations (AND,OR,X-OR) using 8051 instructions.

Objectives: -
i) Add 01 H with FF H And observe contents of Accumulator and Program
status word
ii) Subtract 01 H from FF H And observe contents of Accumulator and Program
status word
iii) AND 01 H with FF H And observe contents of Accumulator and Program
status word
iv) OR 01 H with FF H And observe contents of Accumulator and Program
status word
v) Ex-or 01 H with FF H And observe contents of Accumulator and Program
status word
vi) Multiply 10 H with 10 H And observe contents of Accumulator and Register
B
vii) Divide 26 H by 02 H And observe contents of Accumulator and Register B

Apparatus Required: - Keil Software /RIDE Software

Flowchart :

START

(A)=(A)+8BIT DATA

(A) =RESULT
(PSW)=RESULT

STOP

+ operator is changed with – (CY),AND,OR,XOR


Program:

1) Addition of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#01H ;move 10H in acc.
MOV R0,#FFH ;move 05H in R0
ADD A,R0 ;add R0 data with
L1: SJMP L1 acc.data

INPUT: - A=01H
R0=FFH
OUTPUT: - A= H PSW =

2) Subtraction of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#FFH ;move 10H in acc.
MOV R0,#01H ;move 05H in R0
SUBB A,R0 ;subtract R0 data
L1: SJMP L1 with acc. data

INPUT: - A=FFH, R0=01H


OUTPUT: - A= H PSW=

3) Multiplication of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#10H ;move 10H in acc.
MOV B,#10H ;move 05H in R0
MUL AB ;multiply R0 with
L1: SJMP L1 acc.
INPUT: - A=10H, B=10H
OUTPUT: - A= H, B= H

4) Division of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#26H ;move 10H in acc.
MOV B,#02H ;move 05H in R0
DIV AB ;divide R0 with acc.
L1: SJMP L1

INPUT: - A=26H
B=02H
OUTPUT: - A= H
B= H

5) ANDing of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#01H ;move 10H in acc.
MOV R0,#FFH ;move 05H in R0
ANL A,R0 ;logical ANDing R0
L1: SJMP L1 with acc.

INPUT: - A=01H
R0=FFH
OUTPUT: -A= H

6) ORing of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#01H ;move 10H in acc.
MOV R0,#FFH ;move 05H in R0
ORL A,R0 ;logical ORing R0
L1: SJMP L1 with acc.

INPUT: - A=01H
R0=FFH

OUTPUT: - A= H

7) XORing of two 8 bit data

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#01H ;move 10H in acc.
MOV R0,#FFH ;move 05H in R0
XRL A,R0 ;logical XORing R0
L1: SJMP L1 with acc.

INPUT: - A=01H
R0=FFH

OUTPUT:-A= H

Result: - Thus an assembly language program of 8 bit addition, subtraction,


Multiplication, division, AND, OR and XOR were written and Executed
Successfully.
Experiment No.2

Aim: - Add 05 data byte in a block , length of the block is at 40H. The block starts at
41H. Place the sum at 30 H.

Objectives: - To Perform addition of data bytes which are present in internal memory
Locations.

Apparatus Required: - Keil Software /RIDE Software.

Sample problem : (40H)=01H


(41H)=02H
(42H)=03H
(43H)=04H
(44H)=05H

Result :- (30H)=0FH

Sum =0
Sum 00H 01H 03H 06H 0AH
+01H + 02H +03H +04H +06H
-------- -------- -------- -------- --------
Sum 01H 03H 07H 0AH 0F H
Flowchart:

START

Count=(40H)
Pointer=41h
Sum=0

Sum =Sum+
(Pointer)

Pointer = Pointer +1

Count = Count-1

Is count No
=0

Yes

(30H)= Sum

End

End
Program:-

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV R0,#05 ;count = 05
MOV R1,#41H ;ptr =41h
CLR A ;sum = 0
L1: ADD A,@R1 Sum = Sum +( ptr)
INC R1 ;ptr =ptr+1
DJNZ R0,L1 ;count =count-1
MOV 30H,A ;Sum to 30H location
L2: SJMP L2

SOURCE MEMORY DESTINATION MEMEORY


MEMORY DATA
40H MEMORY DATA
41H 01 30H 0f
42H 02
43H 03
44H 04
45H 05

Result: - Addition OF 5 data bytes is oFH.


Experiment No.3

Aim: - Find the maximum data byte from a block of 05 data bytes. The length of the
block is at 40 H. The block starts at 41 H. Place maximum data byte at 30 H.

Objectives: - To perform searching of largest data bytes present in memory


Location

Apparatus Required: - Keil Software /RIDE Software


Flowchart:
start

Count = 05
Pointer = 41H
Max = 0

Max>(pointer) Yes

No

Max = (pointer)

Pointer = (Pointer)+1

Count = (Count-1)

No Count = 0

(30H) = Max

end

Program:-

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV R0,#41H ;ptr= 41h to r0
MOV R1,05H ;count =5, r1
MOV B,#00H ;max =0,move 00H
to B
BACK: MOV A,@R0 ;max >(ptr).
CJNEA,B,NOTEQUAL
NOTEQUAL: JC NOCHANGE ; nochange
MOV B,A ;max =( ptr)
NOCHANGE: INC R0 ;ptr =ptr+1
DJNZ R1,BACK ;count =count-1,if
MOV A,B count not equal to
MOV 30H,A 0,go back
SJMP $ ;Store the max at
END 30H

SOURCE MEMORY DESTINATION MEMEORY


MEMORY DATA
30H FFH

Result: - Maximum data bytes is stored in m.l.30H

Experiment No.4

Aim: - Transfer a block of 05 data bytes from a source block starting at40H to
destination block starting at 60 H. Length of the block is at 30 H.

Objectives: - To perform transfer of data bytes present in source memory to


Destination memory.

Apparatus Required: - Keil Software /RIDE Software


Flowchart:

start

Count = 05
Ptr1 = 40H
Ptr2 = 60H

(Ptr2) (Ptr1)

Count = Count-1

Yes
Count =
0

No

end

Program:-

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV R2,30H ;count = (30H) to R2
MOV R0,#40H ;ptr1= 40H to R0
MOV R1,#60H ;ptr2= 60H to R1
L1: MOV A,@R0 ;( ptr2) ( ptr1).
MOV @R1,A
INC R0 ; ptr1= ptr1+1 ,
INC R1 ptr2=ptr2+2
DJNZ R2,L1 ;Decrement R2 and
L2: SJMP L2 jump L1 if not zero
SOURCE MEMORY DESTINATION MEMEORY
MEMORY DATA
60H 1
61H 2
62H 3
63H 4
64H 5

Result: - Thus an assembly language program for transfer data bytes in a block
executed successfully.

Experiment No.5
Aim: - Find the no of negative data bytes from a block of 05 data bytes. The length
of the block is at 40H. The block starts at 41H. Place no of negative data bytes at 30 H.
Objectives: - To find number of negative data bytes present in source Memory.

Apparatus Required: - Keil Software /RIDE Software

Flowchart:
start

Count = 05H
Nneg = 0
Ptr = 40H
( Ptr) <
0

Yes

Nneg = Nneg+1

Ptr =Ptr +1

Count = (Count-1)

Yes Count =
0

NO

(30H) =Nneg

en
d
Program:-
Memory Hex. Label Assembly Codes Comments
address code
$MOD51
MOV R2,40H ;count =(40H)move
40H to R2
MOV R3,#00H ;nneg =0,move 00H
to R3
MOV R0,#41H ;ptr =41H,move 41H
to R0
UP: MOV A,@R0
CJNEA,#80H, NOTEQUAL ;(ptr)<0
JC POSITIVE ;yes, positive
NOTEQUAL: INC R3 ;nneg =nneg+1
POSITIVE: INC R0 ;ptr =ptr+1
DJNZ R2,UP ;Decrement R2 and
jump if Not Zero
SJMP $

SOURCE MEMORY DESTINATION MEMEORY


MEMORY DATA
30H 03,RESULT

Result: - Thus an assembly language program for find the number of Negative
Data bytes in a block Written and executed successfully.

Experiment No.6

Aim: -Convert Single digit Hex Number at 40H to its ASCII Equivalent at 41H.

Apparatus Required: - Keil Software /RIDE Software

Flowchart:

start

Num =(40H)
Yes
Num <
0AH

No
Num = Num+7
No

Num = Num+30H

(41H) = Num

en
d

Program:-
Memory Hex. Label Assembly Codes Comments
address code
$MOD51
MOV A,#40H ;Num =(40H).
CJNE ;Num<0AH
A,#0AH,NOTEQUAL ;yes add A with
NOTEQUAL: JC ASCII0 30H
ADD A,#07 ;Num =Num+07H
ASCII0: ADD A,#30H ;Num=Num+30H
MOV 41H,A ;(41H)=Num
SJMP $
L1:

SOURCE MEMORY DESTINATION MEMEORY


MEMORY DATA
41H ASCII Data

Result: - Thus an assembly language program for convert single digit Hex
Number to its ASCII equivalent Written and executed successfully.

Experiment No.7

Aim: - Convert BCD number at 40H to its Binary equivalent at 41H.

Apparatus Required: - Keil Software /RIDE Software

Flowchart:

START

NUM=(40H)
NUM1=NUM

A=A AND # 0FH

LSD= A

A=NUM1
AND#F0H
SWAP A

MSD
=MULTIPLY A
WITH 10

BINARY=MSD+LSD

Program:- END

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,40H ;move 40H to A.
ANL A,#0FH ;logical ANDing 0FH
MOV R7,A with A.
MOV A,40H
ANL A,#0F0H ;logical ANDing F0H
SWAP A with A.
MOV B,#0AH ;move 0AH to B
MUL AB ;multiply A with B.
ADD A,R7 ;add R7 with A.
MOV 41H,A ;move A content to
L1: SJMP L1 41H.
SOURCE MEMORY DESTINATION MEMEORY
MEMORY DATA
41H Binary Data

Result: - Thus an assembly language program for convert single digit BCD
Number to its Binary equivalent Written and executed successfully.

Experiment No.8

Aim: -Glow LED after every 1ms/100 ms connected to port of 8051

Apparatus required: - RIDE Software/Keil µ ( vision 4), Flash magic, 8051 trainer
kit

Flowchart:
P0.4 = 1

Program:- Assembly Programming

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
MOV A,#0FFH ;move FFH to A
AGAIN: MOV P0.4,A ; move A conent to
ACALL DELAY Port pin 0.4.
CPL A ; complement A
SJMP AGAIN content.

%DELAY PROGRAM ;delay program

DELAY: MOV R2,#07H ;move 07H to R2


HERE1: MOV R1,#255 ;move 255 to R1
HERE2: MOV R0,#255 ;move 255 to R0
HERE3: DJNZ R0,HERE3
DJNZ R1,HERE2
DJNZ R2,HERE1
RET

Result: - Thus an assembly language program for Glow LED after every 1ms
Connected to port 0, written and executed successfully.

C Programming
Re sult: Following windows shows that LED connected to P0.4 o f mic rocontroller
8051 toggles after a delay of 100ms .
Experiment No.9

Aim: - Generate Square waveform of 2ms using timer #0 of 8051

Apparatus required: - Keil Software /RIDE Software, Flash magic, 8051 trainer kit

Flowchart:

start

P0.4 = 1

TMOD = 01H
TH#0 = YY
TL#0 = XX

TR0 = 1
TF0 = 0

No
TF0 =
1

Yes

TR0 = 1
TF0 = 0

P0.4 ~ P0.4
Program:-

Memory Hex. Label Assembly Codes Comments


address code

$MOD51
BACK: MOV TMOD,#01H ; Initialize timer in
MOV TL0,#6FH MODE 1.
MOV TH0,#0FCH
CLR P0.4 ;clear pin 0.4
ACALL DELAY ;call delay
MOV TL0,#6FH ;move 6FH to TL0
MOV TH0,#0FCH ;move 0FCH to TH0
SETB P0.4 ;set BIT pin 0.4
ACALL DELAY ;call delay
SJMP BACK
DELAY: SETB TR0 ; set on TR0
AGAIN: JNB TF0,AGAIN
CLR TR0 ;clear TR0 flag
CLR TF0 ;clear TF0 flag
RET
END

Result: - Thus an assembly language program for Square waveform of 2ms using
Timer #0 of 8051 written and executed successfully.
Experiment No.10
Aim: - Display 0-9 on seven segment display.

Apparatus required: - RIDE Software/ Keil µ vision4, Flash magic, 8051 trainer kit

Flowchart:
Program:-

Memory Hex. Label Assembly Codes Comments


address code
$MOD51
ORG 0000H
START: MOV SP,#40H ;initialize stack
L5: MOV R1,#00H pointer at 40H
L1: MOV A,R1 ;move content of
MOV P0,A R1 to A
ACALL DELAY_2SEC ;call delay
INC R1 ;increment R1
CJNE R1,#0AH,L1 ;compare R1 with
SJMP L5 0AH

Subroutine for delay of


2sec ;move 10H to R2
MOV R2,#10H ;move 0FFH to R3
DELAY_2SEC: MOV R3,#0FFH ;move 0FFH to R4
L4: MOV R4,#0FFH
L3: DJNZ R4,L2
L2: DJNZ R3,L3
DJNZ R2,L4
RET
END

Result: - Thus an assembly language program for Display 0-9 on seven


Segment display written and executed successfully
C Programming :

Result: Following windows show that micro-controller 8051 sends a BCD no. to port 0
after a delay of 100ms, this data available at port 0 is used to display a BCD no. on seven
segment displays.
EXPERIMENT NO. 11

Aim: - To display string of characters on LCD display.


Apparatus required: - Keil µ vision4, Flash magic, 8051 trainer kit

Flowchart:
Program:-
PIN DESCRIPTION:
INTERFACING DIAGRAM:

Result : Characters Displayed

You might also like