Microcontroller Lab File - 72
Microcontroller Lab File - 72
LAB FILE
[ECE 314]
Submitted to: -
Mr.Lala Bhaskar
Submitted by: -
Arjun
Enrolment no. A2305119061
B.Tech 5ECE-1-Y
1
INDEX
S.No Category of Cod Exp Name of Experiment Date of Max Marks Signature of
Assignment e No. Allotment Marks Obtaine Faculty
of d
Experimen
t
1. Mandatory LR 1. Write a program to 26/07/2021 1
Experiment* (10) add and subtract two
8-bit numbers using
microcontroller 8051
2. Mandatory LR 2. Write a program to 09/08/2021 1
Experiment* (10) add a set of 5 nos.
stored in external
memory location
3. Mandatory LR 3. Write a program to 16/08/2021 1
Experiment* (10) multiply two 8-bit
numbers using
repeated additions in
microcontroller 8051
4. Mandatory LR 4. Write a program to 06/09/2021 1
Experiment* (10) multiply a16-bit
number with 8-bit
number using
microcontroller 8051
5. Mandatory LR 5. Write a program to 20/09/2021 1
Experiment* (10) count number of even
and odd numbers in a
set of 10 numbers.
6. Mandatory LR 6. Write a program to 27/09/2021 1
Experiment* (10) convert packed BCD
into two ASCII
numbers.
7. Mandatory LR 7. Write a program to 04/10/2021 1
Experiment* (10) generate Fibonacci
series and save the
result in external
memory location
8. Mandatory LR 8. Write a program to 11/08/2021 1
Experiment* (10) find the largest
number in an array of
numbers stored in
external memory
location.
9. Mandatory LR 9. Write a program to 18/08/2021 1
Experiment* (10) toggle the LEDs
connected at Port P1
2
of 8051.
10. Mandatory LR 10. Write a program to 25/08/2021 1
Experiment* (10) generate 1 sec delay
using Timer
EXPERIMENT 1
AIM :Write a program to add and subtract two 8-bit numbers using microcontroller 8051
ALGORITHM
ADDITION
3
2. Transfer the data to Register B
3. Move the second operand from 31h RAM location to register A
4. Perform the addition of two numbers
5. Store the result in 32h RAM location.
SUBTRACTION
CODE
ADDITION
org 0000h
0000| MOV R0,#30h
0002| MOV A,@R0
0003| MOV B,A
0005| INC R0
0006| MOV A,@R0
0007| ADD A,B
0009| INC R0
000A| MOV @R0,A
End
SUBTRACTION
org 0000h
0000| MOV R0,#30h
0002| MOV A,@R0
0003| MOV B,A
0005| INC R0
0006| MOV A,@R0
0007| SUBB A,B
0009| INC R0
000A| MOV @R0,A
End
OUTPUT
ADDITION
4
SUBTRACTION
RESULT
Thus, the program for Addition, subtraction of two 8 bit numbers are executed using 8051
simulator.
5
EXPERIMENT 2
AIM: Write a program to add a set of 5 nos. stored in external memory location.
ALGORITHM
1. Load the DPTR with external memory address 4000h.
2. Move the R2(loop variable R2=00h), R1 registers with 00h
3. Read the number from memory location and perform addition
6
4. Increment R2, and jump to lable BACK(point 3) if it not equal 05
5. Terminate the program.
CODE
org 0000h
0000| MOV DPTR, #4000h
0003| MOV R2,#00h
0005| MOV R0,#00h
0007| BACK:MOV A,R2
0008| MOVC A,@A+DPTR
0009| ADD A,R0
000A| MOV R0,A
000B| INC R2
000C| CJNE R2,#05,BACK
org 4000h
db 02,04,06,08,10;
end
OUTPUT
7
RESULT
Thus, the program for to add a set of 5 nos. stored in external memory location are executed
using 8051 simulator.
EXPERIMENT 3
8
AIM: Write a program to multiply two 8-bit numbers using repeated additions in microcontroller
8051.
SOFTWARE USED:EDSIM
ALGORITHM:
1. Read the 8 Bit number in R1 Register from 4000h memory location and read the second 8
bit number in R2 register from 4001h memory location.
2. For repeated addition R2 acting as loop counter.
3. Clean the accumulator.
4. Perform the addition of R1 accumulator.
5. If any carry comes increment the R0 register otherwise jump to label AHEAD.
6. Decrement the R2 and check if not ZERO then jump to label BACK.
7. Terminate the program.
CODE
org 0000h
0000| MOV DPTR, #4000h
0003| MOV A, #00h
0005| MOVC A, @A+DPTR
0006| MOV R1, A
0007| MOV A, #00h
0009| INC DPTR
000A| MOVC A, @A+DPTR
000B| MOV R2, A
000C| MOV A, #00h
000E| MOV R0, A
000F| BACK: ADD A,R1
0010| JNC AHEAD
0012| INC R0
0013| AHEAD: DJNZ R2, BACK
OUTPUT
9
RESULT
Thus, the program to multiply two 8-bit numbers using repeated additions is executed using 8051
simulator.
EXPERIMENT 4
AIM :Write a program to multiply a16-bit number with 8-bit number using microcontroller 8051.
CODE
org 0000h
MOV A,R0
MOV B,R2
MUL AB
MOV R3,A
MOV R4,B
MOV A,R1
MOV B,R2
MUL AB
MOV R5,A
MOV R6,B
ADD A,R4
JNC AHEAD
INC R6
AHEAD:MOV R5,A
MOV R6,B
END
OUTPUT
11
RESULT
Thus, the program to multiply a 16-bit number with 8-bit number is executed using 8051
simulator
EXPERIMENT 5
AIM :Write a program to count number of even and odd numbers in a set of 10 numbers.
12
SOFTWARE USED:EDSIM
ALGORITHM
1. Load the starting address of array into DPTR
2. Initialize the array length in R0 register
3. Read the number from array and rotate its contents to right through carry
4. Check the carry flag increment R2 (ODD) otherwise increment R1 (EVEN)
5. Repeat the step 3 & 4 till the R0 becomes zero
6. End Program
CODE
org 0000h
MOV DPTR,#4000h
MOV R1,#00h; Even
MOV R2,#00h; Odd
MOV R0,#00h
org 4000h
dB 04h,02h,05h,01h,02h,09h,FEh,06h,08h,FFh
END
OUTPUT
13
RESULT
Thus, the program to count number of even and odd numbers in a set of 10 numbers is executed
using 8051 simulator
EXPERIMENT 6
AIM:Write a program to convert packed BCD into two ASCII numbers.
14
SOFTWARE USED:EDSIM
ALGORITHM
1. Take any packed BCD in R0 register
2. Move the R0 to register A and mask its lower nibble (Logical AND with F0) and the add
with 30h (logical OR with 30) and store result in R1
3. Move the R0 to register A and mask its upper nibble (logical AND with 0F) and then add
with 30h (logicak OR with 30) and store result in R2
4. End the Program
CODE
org 0000h
MOV R0,#34h
MOV A,R0
ANL A, #0F0h
SWAP A
ADD A, #30h
MOV R1,A
MOV A,R0
ANL A,#0Fh
ADD A,#30h
MOV R2,A
OUTPUT
RESULT
Thus, the program to convert packed BCD into two ASCII numbers is executed using 8051
simulator
15
EXPERIMENT 7
AIM:Write a program to generate Fibonacci series and save the result in external memory
location.
SOFTWARE USED:EDSIM
ALGORITHM
1. Store the memory address in R0 and counter in R3
2. Store first two numbers that is 0 and 1 in memory space.
16
3. Add the previous two numbers and store in an memory space
4. Exchange the registers and store the previous two numbers
5. Repeat the steps 3 and 4 till the counter value R3 becomes zero.
CODE
org 0000h
MOV R0, #40h
MOV R3, #09
MOV R1, #00h
MOV @R0, #00h
INC R0
MOV @R0, #01h
MOV R2, #01H
AGAIN:
INC R0
MOV A, R1
ADD A, R2
MOV @R0, A
MOV B, R2
MOV R1, B
MOV R2, A
DJNZ R3, AGAIN
END
OUTPUT
17
RESULT
Thus, the program to generate Fibonacci series and save the result in external memory location is
executed using 8051 simulator
EXPERIMENT 8
AIM:Write a program to find the largest number in an array of numbers stored in external
memory location.
SOFTWARE USED:EDSIM
ALGORITHM
1. Load the DPTR with starting array address
2. Take the array length in R0 register
3. R3 register is used to keep the larger value for every compare operation
4. The program runs till the R0 register zero and finally R3 having largest number from the
array
18
CODE
org 0000h
MOV DPTR, #2000h
MOV R0, #05h
MOV R3, #00h
BACK : MOVC A, @A+DPTR
MOV B,A
SUBB A,R3
JC LOOP
MOV R3,B
LOOP:
MOV A, #00h
INC DPTR
DJNZ R0, BACK
org 2000h
db 01, 02, 05, 04, 03
END
OUTPUT
RESULT
Thus, the program to find the largest number in an array of numbers stored in external memory
location is executed using 8051 simulator
19
Criteria Total Marks Marks Obtained Comments
Concept (A) 2
Implementation (B) 2
Performance (C) 2
Total 6
EXPERIMENT 9
AIM:Write a program to toggle the LEDs connected at Port P1 of 8051.
SOFTWARE USED:EDSIM
ALGORITHM
1. This program displays the binary pattern from 0 to 255 (and back to 0) on the LEDs
interfaced with port 1.
2. A 1 in the pattern is represented by the LED on, while a 0 in the pattern is represented by
the LED off.
3. However, logic 0 on a port 1 pin turns on the LED, therefore it is necessary to write the
inverse of the pattern to the LEDs. The easiest way to do this is to send the data FFH to 0
(and back to FFH) to the LEDs.
4. Since port 1 is initially at FFH all we need to do is continuously decrement port 1
CODE
org 000h
20
MOV A, #00h
BACK: MOV P1, A
CPL A
SJMP BACK
OUTPUT
RESULT
Thus, the program to toggle the LEDs connected at Port P1 of 8051 is executed using 8051
simulator
21
EXPERIMENT 10
SOFTWARE USED:EDSIM
ALGORITHM
1. Make P1.0 pin as output mode
2. Initialize the TMOD register Timer 0 for mode 1 programming
3. Load the value in TL0, TH0 registers of Timer 0 with the count value to get the 1 second
delay.
4. Start the timer 0, monitor the TF0 flag.
5. Once the TF0 is set then stop the timer and clear the TF0 for next turn
22
CODE
CLR P1.0
MOV TMOD, #01h
MOV R2, #20
DELAY: MOV TH0, #048h
MOV TL0, #0FDH
CPL P1.0
SJMP DELAY
SETB TR0
HERE: JNB TF0, HERE
DJNZ R2, DELAY
CLR TR0
CLR TF0
OUTPUT
RESULT
23
Thus, the program for to add a set of 5 nos. stored in external memory location are executed
using 8051 simulator
24