Sie sind auf Seite 1von 9

PART-III 8051 MICROCONTROLLER PROGRAMMING

Lab 8
Ex.No.11: Addition, Subtraction, Multiplication and Division using 8051

11.1 Introduction:

The purpose of this experiment is to add, subtract, multiply and divide the given two 8
bit numbers and store them in a memory location. The student should also be able to design
the addition and subtraction with carry and borrow.

11.2 Hardware Requirement:

The 8051 Microcontroller kit , Power supply.

11.3 Program Logic:


To perform addition in 8051 one of the data should be in accumulator, another data
can be in any of the general purpose register or in memory or immediate data. After addition
the sum will be in accumulator. The sum of two 8-bit data can be either 8-bits(sum only) or 9-
bits(sum and carry). The accumulator can accumulate only the sum and there is a carry the
8051 will indicate by setting carry flag. Hence one of the register is used to account for carry.
The 8051 has MUL instruction unlike many other 8-bit processors. MUL instruction
multiplies the unsigned 8-bit integers in A and B. The lower order byte of the product is left
in A and the higher order byte in B.
The 8051 has DIV instruction unlike many other 8-bit processors. DIV instruction
divides the unsigned 8-bit integers in A and B. The accumulator receives the integer part of
the quotient and the register B receives the remainder.
11.4 Procedure:
i) Enter the opcodes from memory location 4200
ii) Execute the program
iii) Check for the result at 4100 and 4101
Using the accumulator, subtraction is performed and the result is stored. Immediate
addressing is employed. The SUBB instruction drives the result in the accumulator.
11.5 Program
Addition without carry:
MEMORY
LABEL MNEMONICS OP CODE
ADDRESS COMMENTS
CLR C
MOV A,#data1
ADD A, #data2
MOV DPTR, #4500H
MOVX @DPTR, A
LOOP SJMP LOOP
Observation
INPUT OUTPUT
Address Data Address Data

Subtraction
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
SUBB A, #data2
MOV DPTR, #4500H
MOVX @DPTR, A
LOOP SJMP LOOP

Observation
INPUT OUTPUT
Address Data Address Data

Multiplication
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
MOV B,#data2
MUL AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
LOOP SJMP LOOP

Observation
INPUT OUTPUT
Address Data Address Data
Division
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
CLR C
MOV A,#data1
MOV B,#data2
DIV AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
LOOP SJMP LOOP

Observation
INPUT OUTPUT
Address Data Address Data

11.6 Pre-Lab Questions:


1. Show the status of carry flag, auxiliary carry and parity flags after the addition of 38H
and 2FH in the following instructions
MOV A, #38H
ADD A, #2FH
2. A programmer puts the first opcode at address at 100H. What happens when the
microcontroller is powered up?
3. what is the result of the following code and where is it kept
MOV A, #15
MOV R5, #15
ADD A, R5
11.7 Post-Lab Questions:
1. Examine the following code then answer the following questions
A. Will it jump to NEXT?
B. What is in A after CJNE instruction is executed
MOV A, #55H
CJNE A, #99H, NEXT
….
NEXT: …
2. Assume that P1 is an input port connected to a temperature sensor. Write a program to
read the temperature and test it for the value 75. According to the test results place the
temperature value in to the registers indicated by the following.
If T = 75 then A = 75
If T < 75 then R1 = T
If T > 75 then R2 = T
3. Write a program to monitor P1 continuously for the value 63H. it should be get out of
monitoring only if P1 = 63H
4. Write an assembly language program to find one’s and two’s complement without using CPL
instruction.
5.In the absence of a SWAP instruction how would you exchange the nibbles?
Write a simple program to show the process.

Lab 9
One’s And Two’s Complement Using 8051
12.1 Introduction

To write an assembly language program to find the 1’s and 2’s complement of an 8-
bit number using microcontroller instruction set.
12.2 Hardware Requirement:

The 8051 Microcontroller kit , Power supply


12.3 Program Logic:

1. Move the data to Accumulator.


2. Complement the accumulator.
3. Move the one’s complement output to the memory 4500H.
4. Add 01H with accumulator.
5. Move the two’s complement output to the memory 4501H.
12.4 Program
MEMORY
LABEL MNEMONICS OP CODE
ADDRESS
MOV A, #data
CPL A
MOV DPTR, #4500H
MOVX @DPTR, A
INC A
INC DPTR
MOVX @DPTR, A
LOOP SJMP LOOP

12.5 Pre-Lab Questions:


1. Name the register banks of 8051.Which one is default register bank?
2. Mention any three applications of microcontroller?
3. Explain any two arithmetic instructions with examples.
4. What is the function of program counter in 8051?

12.6 Post-Lab Questions:


1. Find the contents of register A after executing the following instruction
CLR A
ORL A,#99H
CPL A
2. Write an ALP to mask D7 and D4 bit of an 8-bit number using 8051.

3. Write the program logic for LCM of two numbers in 8051.


4. Explain the bit level logical instructions of 8051.

5. Show the contents of PSW register after the execution of following instruction

MOV A, #0BH

ADD A,#1BH
Lab 10

BCD To Hexadecimal Conversion And Hexadecimal To BCD Conversion


13.1 Introduction:

The purpose of this experiment is to obtain the BCD to HEXADECIMAL and viceversa of a
given data using 8051 micro controller trainer kit.

13.2 Hardware Requirement:


The 8051 Microcontroller kit, Power supply.
13.3 Program Logic:

Binary coded decimal (BCD) is a system of writing numerals that assigns a


four-digit binary code to each digit 0 through 9 in a decimal (base-10) numeral. The
hexadecimal number system (also called base-16) is a number system that uses 16 unique
symbols to represent a particular value. Those symbols are 0-9 and A-F.

BCD number to be converted is brought to the accumulator. Mask the lower order
nibble using ANL instruction and swap their nibbles using SWAP instruction. Store the
resultant value in any registors. Then multiply the result with 10 Decimal. Mask the higher
order nibble and the result is added with the result obtained from above multiplication.
Finally, the result is stored in memory .

The hexadecimal number system (also called base-16) is a number system that uses
16 unique symbols to represent a particular value. Those symbols are 0-9 and A-F. In this
program, the hex number is converted to its equivalent BCD number. The hex number to be
converted is brought to the accumulator and is divided by 100 D i.e 64 . DIV instruction of
8051 is used in this program. The remainder is now divided by 10 D. Swap the quotient and
add the result with remainder obtained from above division. Finally, the result is stored in
memory .

13.4 Program:
BCD to HEXADECIMAL:
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
MOV DPTR,#4600
MOVX A,@DPTR
MOV R5,A
ANL A,#F0
SWAP A
MOV R1,A
MOV A,R5
ANL A,#0F
MOV R2,A
MOV A,R1
MOV B,#0A
MUL AB
ADD A,R2
INC DPTR
MOVX @DPTR,A
HERE SJMP HERE

Hexadecimal to BCD
MEMORY
LABEL MNEMONICS OP CODE COMMENTS
ADDRESS
MOV DPTR,#4600
MOVX A,@DPTR
MOV B,#64
DIV AB
INC DPTR
MOVX @DPTR,A
MOV A,B
MOV B,#0A
DIV AB
SWAP A
ADD A,B
INC DPTR
MOVX @DPTR,A
HERE SJMP HERE

13.5 Pre-Lab Questions:


1. Write the features of 8051 Microcontroller.
2. Upon reset, all ports of the 8051 are configured as _____________
(output, input).
3. Which ports of the 8051 require the connection of external pull-up
resistors in order to be used for I/O? Show the drawing for the
connection.
4. What happens in power down mode of 8051?

13.6 Post-Lab Questions:


1. How the DPTR register is classified, explain its functions?
2. Show the status of CY,AC, and P flags after the execution of following instructions
MOV A, # 9CH
ADD A, # 64H
3. What is the function of EA pin in 8051?
4. List out the special function registers in 8051.

Das könnte Ihnen auch gefallen