0% found this document useful (0 votes)
91 views54 pages

MP Lab

The document contains programs for 8-bit and 16-bit arithmetic operations - addition, subtraction, multiplication, and division - on a microprocessor. It includes the algorithms, memory address codes, instruction codes, inputs, outputs, and results of executing the programs to perform the arithmetic operations on 8-bit and 16-bit numbers in memory.

Uploaded by

ParthaSarathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views54 pages

MP Lab

The document contains programs for 8-bit and 16-bit arithmetic operations - addition, subtraction, multiplication, and division - on a microprocessor. It includes the algorithms, memory address codes, instruction codes, inputs, outputs, and results of executing the programs to perform the arithmetic operations on 8-bit and 16-bit numbers in memory.

Uploaded by

ParthaSarathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

CHERRAAN’S ARTS SCIENCE COLLEGE

(Affiliated to Bharathiar University, Coimbatore)


Kangayam – 638701

DEAPRTMENT OF
ELECTRONICS AND COMMUNICATION
SYSTEMS

III B.Sc., Electronics and Communication Systems

MICROPROCESSOR AND MICROCONTROLLER


LAB

2020-2021

NAME : ______________________________________________

Reg. No : ______________________________________________
CHERRAAN’S ARTS SCIENCE COLLEGE
(Affiliated to Bharathiar University, Coimbatore)
Kangayam – 638701

DEAPRTMENT OF
ELECTRONICS AND COMMUNICATION
SYSTEMS

MICROPROCESSOR AND MICROCONTROLLER


LAB

Certified that thus is a Bonafide Record of Work done by


_________________________________ (Reg. No.__________________________)
of III B.Sc., Electronics and communication systems, Cherraan’s Arts Science
College, Kangayam during the academic year 2020-2021.

Staff In-Charge Head of the Department

Submitted for the Practical Examination held on ___________________ in


Department of Electronics and communication systems, Cherraan’s Arts Science
College, Kangayam.

External Examiner Internal Examiner


INDEX
Page
Ex.No Date Name of the Experiment Remarks
No.
Ex.No:

Date:

8-BIT ADDITION

AIM:

T o add two 8-bit numbers in memory location and store the result in memory.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program


2. Load 1st data in register B
3. Load second data in accumulator
4. Add register B & Accumulator
5. Store the sum
6. Clear accumulator
7. Rotate the carry into accumulator
8. Store the result(carry)
9. Stop the program

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3

4100 3A 50 41 START LDA 4150 [A] [ 4150]


4103 47 MOV B,A [B]  [A]
4104 3A 51 41 LDA 4151 [A]  [4151]
4107 80 ADD B [A]  [A]+[B]
4108 32 53 41 STA 4153 [4153]  [A]
410B 3E 00 MVI A,00 [A]  00
410D 17 RAL LSB of [A]  [CS]
410E 32 52 41 STA 4152 [4152]  [A]
4111 76 END HLT Stop

INPUT:

OUTPUT:

Page |
RESULT:

The ALP for adding two 8-bit data was written and executed.

Page |
Ex.No:

DATE:

8-BIT SUBTRACTION

AIM:

To write ALP for subtracting two 8-bit data.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program


2. Load minuend in accumulator
3. Load subtrahend in register
4. Subtract subtrahend from minuend SUB r instruction
5. If borrow (carry)=0,store the result
6. If borrow=1, convert the result into 2’s complement and store
7. Stop the program

Page |
PROGRAM:

MEMORY 0P-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4100 21 00 42 START LXI H,4200 [H-L]  4200
4103 0E 00 MVI C,00 [C]  00
4105 7E MOV A,M [A]  [[H-L]]
4106 23 INX H [H-L]  [H-L]+1
4107 96 SUB M [A]  [A]-[[H-L]]
4108 D2 0F 41 JNC Loop If [CS]=0,jump to LOOP
410B 2F CMA [A]  [A]
410C C6 01 ADI 01 [A]  [A]+01
410E 0C INR C [C]  [C]+1
410F 23 Loop INX H [H-L]  [H-L]+1
4110 77 MOV M,A [[H-L]]  [A]
4111 23 INX H [H-L]  [H-L]+1
4112 71 MOV M,C [[H-L]]  [C]
4113 76 END HLT Stop

INPUT:

OUTPUT:

Page |
RESULT:

The ALP for 8-bit subtraction was written and executed.

Page |
Ex.No:

DATE:

16-BIT ADDITION

AIM:

To add two 16-bit numbers in memory location and store the result in
memory.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Get the 1st number in D-E pair.
3. Get 2nd number in H-L pair.
4. Add the register pairs using DAD D.
5. Store the sum.
6. Rotate the carry into the accumulator.
7. Store the carry.
8. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENT
ADDRESS B1 B2 B3
[L] [4150]
4100 2A 50 41 START LHLD 4150
[H]  [4151]
4103 EB XCHG [H-L]  [D-E]
[L]  [4152]
4104 2A 52 41 LHLD 4152
[H]  [4153]
4107 19 DAD D [H-L]  [D-E]+[H-L]
[4200]  [L]
4108 22 00 42 SHLD 4200
[4201]  [H]
410B 3E 00 MVI A,00 [A]  00
410D 17 RAL LSB OF [A]  [CS]
410E 32 02 42 STA 4202 [4202]  [A]
4111 76 END HLT Stop

INPUT:

OUTPUT:

Page |
RESULT:

The ALP for adding two 16-bit data was written and executed.

Page |
Ex.No:

DATE:

8-BIT MULTIPLICATION

AIM:

To write an ALP for multiplication of two 8-bit data.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program


2. Set the multiplier as counter
3. Load D-E pair with multiplicand
4. Clear H-L pair
5. Add multiplicand to H-L pair
6. Decrement counter
7. When count =0, store the result. Otherwise repeat the program.
8. Stop the program

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4100 3A 52 41 START LDA 4152 [A][4152]
[L]  [4150]
4103 2A 50 41 LHLD 4150
[H]  [4151]
4106 EB XCHG [H-L][D-E]
4107 21 00 00 LXI H,0000 [H-L] 0000
410A 19 Loop DAD D [H-L]  [H-L]+[D-E]
410B 3D DCR A [A]  [A]-1
410C C2 0A 41 JNZ Loop If [Z]=0 Jump to LOOP
410D 22 53 41 SHLD 4153 [4153]  [A]
4110 76 END HLT Stop

INPUT:

OUTPUT:

Page |
RESULT:

The ALP for 8-bit multiplication was written and executed.

Page |
Ex.No:

DATE:

8-BIT DIVISION

AIM:

To write an ALP for division of two 8-bit data.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Place divisor in register.
3. Place dividend in accumulator.
4. Initialize counter register.
5. Subtract register.
6. Increment counter for each subtraction.
7. Is [A] < [R], Store the remainder and get the quotient and store it.
Otherwise, repeat the program.
8. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3

4100 3A 51 41 START LDA 4151 [A] [4151]

4103 47 MOV B,A [B] V [A]

4104 3A 50 41 LDA 4150 [A]  [4150]

4107 0E 00 MVI C,00 [C]  00

4109 B8 CMP B [A] – [B]

If
410A DA 13 41 JC LOOP1
[CS]=1,Jump to LOOP1

410D 90 LOOP2 SUB B [A]  [A] – [B]

410E 0C INR C [C]  [C] + 1

410F B8 CMP B [A] – [B]

If
4110 D2 0D 41 JNC LOOP2
[CS]=0,Jump to LOOP2

4113 32 53 41 LOOP1 STA 4153 [4153]  [A]

4116 79 MOV A,C [A]  [C]

4117 32 52 41 STA 4152 [4152]  [A]

411A 76 END HLT Stop

Page |
INPUT:

OUTPUT:

Page |
RESULT:

The ALP for 8-bit division was written and executed.

Page |
Ex.No:

Date:

BIGGEST & SMALLEST NUMBER OF AN ARRAY

BIGGEST NUMBER OF AN ARRAY:

AIM:

To write an ALP to find the biggest number of an array.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Initialize memory, counter.
3. Get the 1st number in accumulator.
4. Is 1st number < next number, get next number in accumulator.
Otherwise, keep the 1st number in A.
5. Decrement counter.
6. Is counter=0, Store the result. Otherwise, repeat the program.
7. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3

4100 21 50 41 START LXI H,4150 [[H-L]] [ 4150]

4103 4E MOV C,M [C]  [[H-L]]

4104 23 INX H [[H-L]]  [H-L]+1

4105 7E MOV A,M [A]  [[H-L]]

4106 0D DCR C [C]  [C] – 1

4107 23 LOOP2 INX H [H-L]  [H-L]+1

4108 BE CMP M [A] – [[H-L]]

If
4109 D2 0D 41 JNC LOOP1 [CS]=0,Jump to
LOOP1

410C 7E MOV A,M [A]  [[H-L]]

410D 0D LOOP1 DCR C [C]  [C] – 1

If
410E C2 07 41 JNZ LOOP2
[Z]=0,Jump to LOOP2

4111 23 INX H [H-L]  [H-L]+1

4112 77 MOV M,A [[H-L]]  [A]

4113 76 END HLT Stop

Page |
INPUT:

OUTPUT:

Page |
SMALLEST NUMBER OF AN ARRAY:

AIM:

To write an ALP to find the smallest number of an array.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Initialize memory, counter.
3. Get the 1st number in accumulator.
4. Is 1st number > next number, get next number in accumulator.
Otherwise, keep the 1st number in A.
5. Decrement counter.
6. Is counter=0, Store the result. Otherwise, repeat the program.
7. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3

4100 21 50 41 START LXI H,4150 [[H-L]]  [4150]

4103 4E MOV C,M [C]  [[H-L]]

4104 23 INX H [H-L]  [H-L]+1

4105 7E MOV A,M [A]  [[H-L]]

4106 0D DCR C [C]  [C] – 1

4107 23 LOOP2 INX H [H-L]  [H-L]+1

4108 BE CMP M [A] – [[H-L]]

If
4109 DA 0D 41 JC LOOP1
[CS]=1,Jump to LOOP1

410C 7E MOV A,M [A]  [[H-L]]

410D 0D LOOP1 DCR C [C]  [C] – 1

If
410E C2 07 41 JNZ LOOP2
[Z]=0,Jump to LOOP2

4111 23 INX H [H-L]  [H-L]+1

4112 77 MOV M,A [[H-L]]  [A]

4113 76 END HLT Stop

Page |
INPUT:

OUTPUT:

RESULT:

The ALP for finding biggest & smallest number of an array were written and
executed.

Page |
Ex.No:

DATE:

ARRANGING DATA ARRAY IN ASCENDING & DESCENDING ORDER

ARRANGING IN ASCENDING ORDER:

AIM:

To write an ALP for arranging data array in ascending order.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Initialize memory, counter with length of array and the flag with 0.
3. Get the first two numbers from pt, pt+1 and compare them.
4. If pointer<pointer+1,
Pointer = pt+1
Counter = counter-1.
5. If pointer>pointer+1,
Temppt+1
Pt+1pt
Pt Temp
Counter = counter-1.
6. If count=0, check the flag. Otherwise repeat the program.
7. If flag=0, repeat the program. Otherwise stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3
4100 21 50 41 START LXI H,4150 [[H-L]]  [4150]

4103 4E MOV C,M [C]  [[H-L]]

4104 06 00 MVI B,00 [B]  00

4106 23 INX H [H-L]  [H-L] + 1

4107 0D DCR C [C]  [C] - 1

4108 7E LOOP2 MOV A,M [A]  [[H-L]]

4109 23 INX H [H-L]  [H-L] + 1

410A BE CMP M [A] – [[H-L]]


If
410B DA 14 41 JC LOOP1
[CS]=1,Jump to LOOP1
410E 56 MOV D,M [D]  [[H-L]]

410F 77 MOV M,A [[H-L]]  [A]

4110 2B DCX H [H-L]  [H-L] - 1

4111 72 MOV M,D [[H-L]]  [D]

4112 23 INX H [H-L]  [H-L] + 1

4113 04 INR B [B]  [B] + 1

4114 0D LOOP1 DCR C [C]  [C] - 1


If
4115 C2 08 41 JNZ LOOP2
[Z] = 0,Jump to LOOP2
4118 05 DCR B [B]  [B] - 1
If
4119 C2 00 41 JNZ START
[Z] = 0,Jump to START
411C 76 END HLT Stop

Page |
INPUT:

OUTPUT:

Page |
ARRANGING IN DESCENDING ORDER:

AIM:

To write an ALP for arranging data array in descending order.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program.


2. Initialize memory, counter with length of array and the flag with 0.
3. Get the first two numbers from pt, pt+1 and compare them.
4. If pointer>pointer+1,
Pointer = pt+1
Counter = counter-1.
5. If pointer<pointer+1,
Temppt+1
Pt+1pt
Pt Temp.
Counter = counter-1.
6. If count=0, check the flag. Otherwise repeat the program.
7. If flag=0, repeat the program. Otherwise stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3
4100 21 50 41 START LXI H,4150 [[H-L]]  [4150]

4103 4E MOV C,M [C]  [[H-L]]

4104 06 00 MVI B,00 [B]  00

4106 23 INX H [H-L]  [H-L]+1


4107 0D DCR C [C]  [C] - 1

4108 7E LOOP2 MOV A,M [A]  [[H-L]]

4109 23 INX H [H-L]  [H-L]+1

410A BE CMP M [A] – [[H-L]]

If [CS]=0,Jump to
410B D2 14 41 JNC LOOP1
LOOP1

410E 56 MOV D,M [D]  [[H-L]]

410F 77 MOV M,A [[H-L]]  [A]


4110 2B DCX H [H-L]  [H-L] – 1

4111 72 MOV M,D [[H-L]]  [D]

4112 23 INX H [H-L]  [H-L] + 1

4113 04 INR B [B]  [B] + 1

4114 0D LOOP1 DCR C [C]  [C] – 1


If
4115 C2 08 41 JNZ LOOP2 [Z] =0,Jump to
LOOP2
4118 05 DCR B [B]  [B] – 1
If
4119 C2 00 41 JNZ START [Z] =0,Jump to
START
411C 76 END HLT Stop

Page |
INPUT:

OUTPUT:

RESULT:

The ALP for arrange a data array in ascending and descending order were
written and executed.

Page |
Ex.No:

DATE:

1’S AND 2’S COMPLEMENT OF 8-BIT DATA

AIM

To write an ALP for 1’s and 2’s complement of 8-bit data.

APPARATUS REQUIRED:

Microprocessor 8085 kit

ALGORITHM:

1. Start the program


2. Complement the data using CMA instruction
3. Store 1’s complement
4. Add ‘01’ with 1’s complement
5. Store 2’s complement
6. End the program

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3

4100 3A 50 41 START LDA 4150 [A][4150]

4103 2F CMA [A]  A

4104 32 51 41 STA 4151 [4151]  [A]

4107 3C INR A [A][A]+01

4108 32 52 41 STA 4152 [4152]  [A]

410B 76 END HLT Stop

INPUT:

OUTPUT:

Page |
RESULT:

The ALP for 1’s and 2’s complement of 8-bit data was written and executed.

Page |
Ex.No:

DATE:

DATA TRANSFER PARALLEL PORTS OF 8255

AIM:

To write an ALP for transferring data between parallel ports of 8255.

APPARATUS REQUIERED:

Microprocessor 8085 kit

8255 interfacing kit

I/O PORT ADDRESS:

8255 port Address


Control register 0F
Port A [I/P] 0C
Port B[O/P] 0D

Page |
PROGRAM:

Read Operation:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4100 3E 90 START MVI A,90 [A]  90
[0F] [A] put the control
4102 D3 0F OUT 0F
word in control register
4104 DB 0C IN 0C [A] [0C] Read the input
4106 32 50 41 STA 4150 [4150]  [A]
4109 76 END HLT STOP

Write Operation:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4200 3E 90 START MVI A,90 [A]  90
[0F] [A] put the control
4202 D3 0F OUT 0F
word in control register
4204 3E 65 MVI A,65 [A]  65
[0D] [A] write the A
4206 D3 0D OUT 0D
content of the o/p port
4208 76 END HLT STOP

Read and Write Operation:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4300 3E 90 START MVI A,90 [A]  90
[0F] [A] put the control
4302 D3 0F OUT 0F
word in control register
4304 DB 0C IN 0C [A] [0C] Read the input
[0D] [A] write the A
4306 D3 0D OUT 0D
content of the o/p port
4308 76 END HLT STOP

Page |
RESULT:

The ALPs for data transfer between parallel ports of 8255 was written and
executed.

Page |
Ex.No:

DATE:

FUNCTION GENERATOR USING DAC

AIM:

To write an ALP for generating different waveforms using DAC.

APPARATUS REQUIERED:

Microprocessor 8085 kit

DAC

CRO

ALGORITHM:

SQUARE WAVE:

1. Start the program

2. Clear accumulator and out to DAC

3. Call delay

4. Set A with FF and out to DAC

5. Call Delay

6. Repeat the program

SAW TOOTH:

1. Start the program

2. Clear accumulator and out to DAC

3. Increment A and out to DAC until [A=00]

4. Repeat the program

Page |
TRIANGULAR WAVE:

1. Start the program

2. Clear the accumulator, out to DAC

3. Increment A and out to DAC

4. Decrement A and out to DAC

5. Repeat the program

PROGRAM:

SQUARE WAVE:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4100 3E 00 START MVI A,00 [A] 00
4102 D3 C0 OUT C0 Out to C0
4104 CD 00 44 CALL DELAY Call delay Subroutine
4107 3E FF MVI A,FF AFF
4109 D3 C0 OUT C0 Out to C0
410B CD 00 44 CALL DELAY Call delay Subroutine
410E C3 00 41 JMP START Jump to start

SAWTOOTH WAVE:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4200 3E 00 START MVI A,00 A00
4202 D3 C0 LOOP OUT C0 Out to C0
4204 3C INR A [A] [A]+1
4205 C2 02 42 JNZ LOOP If [Z]=0,Jump to LOOP
4208 C3 00 42 JMP START Jump to start

Page |
TRIANGULAR WAVE:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4300 3E 00 START MVI A,00 [A]  00
4302 D3 C0 LOOP1 OUT C0 Out to C0
4304 3C INR A [A]  [A]+1
4305 C2 02 43 JNZ LOOP1 If [Z]=0,Jump to LOOP1
4308 2F CMA [A][A]
4309 D3 C0 LOOP2 OUT C0 Out to C0
430B 3D DCR A [A]  [A]-1
430C C2 09 43 JNZ LOOP2 If [Z]=0,Jump to LOOP2
430F C3 00 43 JMP START Jump to start

DELAY SUBROUTINE:

MEMORY OP-CODE
LABEL MNEMONIC
ADDRESS B1 B2 B3
4400 16 05 DELAY MVI D,05
4402 1E FF LOOP2 MVI E,FF
4404 1D LOOP1 DCR E
4405 C2 04 44 JNZ LOOP1
4408 15 DCR D
4409 C2 02 44 JNZ LOOP2
440C C9 RET

RESULT:

The ALPs for generating different waveforms using DAC were written and
executed.

Page |
Ex.No:

DATE:

STEPPER MOTOR CONTROLLER

AIM:

To write an ALP for stepper motor controller.

APPARATUS REQUIRED:

Microprocessor 8085 kit

Stepper motor kit

ALGORITHM:

1. Start the program


2. Initialize memory, counter
3. Out data from memory to port
4. Call delay
5. Decrement the counter
6. When count =0, the program ends
7. The angle of rotation made for one step to known as step angle.

Page |
PROGRAM: CONTINOUS ROTATION

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4100 21 50 41 START LXI H,4150 [H-L]  [4150]
4103 06 04 MVI B,04 [B]  04
4105 7E LOOP1 MOV A,M [A]  [[H-L]]
4106 D3 C0 OUT C0 Out to C0(Step.mot.Address)
4108 CD 00 42 CALL DELAY Call the delay Subroutine
410B 23 INX H [H-L]  [H-L]+1
410C 05 DCR B [B]  [B]-1
410D C2 05 41 JNZ LOOP1 If [Z]=0,Jump to LOOP1
4110 C3 00 41 JMP START Jump to start

SUBROUTINE: DELAY

MEMORY OP-CODE
LABEL MNEMONIC
ADDRESS B1 B2 B3
4200 11 00 01 DELAY LXI D,0100
4203 1B LOOP DCX D
4204 7B MOV A,E
4205 B2 ORA D
4206 C2 03 42 JNZ LOOP
4209 C9 RET

180’ ROTATION:

MEMORY OP-CODE LABEL MNEMONICS


COMMENT
ADDRESS B1 B2 B3
5100 0E 19 START LXI H,4150 [H-L]  [4150]
5102 CD 00 52 LOOP CALL ROTATE Call Rotate Subroutine
5105 0D DCR C [C]  [C]-1
5106 C2 02 51 JNZ LOOP If [Z]=0,Jump to LOOP
5109 76 HLT Stop

Page |
SUBROUTINE: ROTATE (7.2’ rotation)

MEMORY OP-CODE LABEL MNEMONIC


ADDRESS B1 B2 B3
5200 21 50 41 ROTATE LXI H,4150
5203 06 04 MVI B,04
5205 7E LOOP MOV A,M
5206 D3 C0 OUT C0
5208 CD 00 42 CALL DELAY
520B 23 INX H
520C 05 DCR B
520D C2 05 52 JNZ LOOP
5210 C9 RET

INPUT:

MEMORY
CLOCKWISE ANTI-CLOCKWISE
ADDRESS
4150 0A 09
4151 06 05
4152 05 06

RESULT:

The ALP for stepper motor controller was written and executed.

Page |
Ex.No:

DATE:

8-BIT ADDITION USING 8051

AIM:

To add two 8-bit numbers using 8051.

APPARATUS REQUIRED:

Microcontroller 8051 kit

ALGORITHM:

1. Start the program


2. Initialize memory
3. Get the numbers in A and register Rn
4. Add the numbers using ADD A ,Rn instruction
5. Store the sum
6. Clear accumulator
7. Rotate carry into accumulator
8. Store the carry
9. Stop the program

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4200 90 43 00 START MOV DPTR,#4300 [DPTR]4300
4203 E0 MOVX A,@DPTR [A][[DPTR]]
4204 FF MOV R7,A [R7] [A]
4205 A3 INC DPTR [DPTR] [DPTR]+1
4206 E0 MOVX A,@DPTR [A]  [[DPTR]]
4207 2F ADD A,R7 [A]  [A]+[R7]
4208 A3 INC DPTR [DPTR]  [DPTR]+1
4209 F0 MOVX @DPTR,A [[DPTR]]  [A]
420A 74 00 MOV A,#00 [A] 00
420C 33 RLC A LSB of [A]  [CS]
420D A3 INC DPTR [DPTR]  [DPTR]+1
420E F0 MOVX @DPTR,A [[DPTR]]  [A]
420F 80 FE LOOP SJMP LOOP Stop

INPUT:

OUTPUT:

RESULT:

The ALP for 8-bit addition was written and executed.

Page |
Ex.No:

DATE:

8-BIT SUBTRACTION USING 8051

AIM:

To subtract two 8-bit numbers using 8051.

APPARATUS REQUIRED:

Microcontroller 8051

ALGORITHM:

1. Start the program


2. Initialize memory
3. Get the minuend in A and subtrahend in Register
4. Subtract the numbers using SUBB A, Rn instruction
5. Store result
6. End the program

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONIC COMMENT
ADDRESS B1 B2 B3
4100 90 43 00 START MOV DPTR,#4300 [[DPTR]]4300
4103 E0 MOVX A,@DPTR [A] [[DPTR]]
4104 FF MOV R7,A [R7]  [A]
4105 A3 INC DPTR [DPTR]  [DPTR]+1
4106 E0 MOVX A,@DPTR [A]  [[DPTR]]
4107 9F SUBB A,R7 [A]  [A]-[R7]
4108 A3 INC DPTR [DPTR]  [DPTR]+1
4109 F0 MOVX @DPTR,A [[DPTR]]  [A]
410A 80 FE LOOP SJMP LOOP Stop

INPUT:

OUTPUT:

RESULT:

The ALP for 8-bit subtraction program was written and executed.

Page |
Ex.No:

DATE:

8-BIT MULTIPLICATION USING 8051

AIM:

To multiply two 8-bit number using 8051.

APPARATUS REQUIRED:

8051 Microcontroller kit

ALGORITHM:

1. Initialize memory.
2. Get the two numbers in A & B registers.
3. Multiply the two numbers using MUL AB.
4. Store lower byte (LB) in A and higher byte (HB) in B.
5. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3
4100 90 43 00 START MOV DPTR,#4300 [[DPTR]]  4300
4103 E0 MOVX A,@DPTR [A]  [[DPTR]]
4104 F5 F0 MOV B,A [B]  [A]
4106 A3 INC DPTR [DPTR]  [DPTR] + 1
4107 E0 MOVX A,@DPTR [A]  [[DPTR]]
4108 A4 MUL AB [A]  [A].[B]
4109 A3 INC DPTR [DPTR]  [DPTR] + 1
410A F0 MOVX @DPTR,A [[DPTR]]  [A]
410B A3 INC DPTR [DPTR]  [DPTR] + 1
410C E5 F0 MOV A,B [A]  [B]
410E F0 MOVX @DPTR,A [[DPTR]]  [A]
410F 80 FE LOOP SJMP LOOP HALT

INPUT:

OUTPUT:

RESULT:

The ALP for 8-bit multiplication program was written and executed.

Page |
Ex.No:

DATE:

8-BIT DIVISION USING 8051

AIM:

To divide two 8-bit number using 8051.

APPARATUS REQUIRED:

8051 Microcontroller kit.

ALGORITHM:

1. Initialize memory.
2. Get the divisor in B and dividend in A registers.
3. Divide the two numbers using the instruction DIV AB.
4. Store the quotient from A and the remainder from B.
5. Stop the program.

Page |
PROGRAM:

MEMORY OP-CODE
LABEL MNEMONICS COMMENTS
ADDRESS B1 B2 B3
4100 90 43 00 START MOV DPTR,#4300 [[DPTR]]  4300
4103 E0 MOVX A,@DPTR [A]  [[DPTR]]
4104 F5 F0 MOV B,A [B]  [A]
4106 A3 INC DPTR [DPTR]  [DPTR] + 1
4107 E0 MOVX A,@DPTR [A]  [[DPTR]]
4108 A4 DIV AB [A]  [A]/[B]
4109 A3 INC DPTR [DPTR]  [DPTR] + 1
410A F0 MOVX @DPTR,A [[DPTR]]  [A]
410B A3 INC DPTR [DPTR]  [DPTR] + 1
410C E5 F0 MOV A,B [A]  [B]
410E F0 MOVX @DPTR,A [[DPTR]]  [A]
410F 80 FE LOOP SJMP LOOP HALT

INPUT:

OUTPUT:

RESULT:

The ALP for 8-bit division program was written and executed.

Page |
Ex.No:

DATE:

SQUARE WAVEFORM GENERATOR USING 8051

AIM:

To write an ALP for generating square wave with different frequencies using
8051.

APPARATUS REQUIERED:

Microcontroller 8051 kit

DAC

CRO

ALGORITHM:

1. Start the program

2. Load DAC address FFC0H to the DPTR.

3. Load accumulator with immediate data #00H.

4. Move the accumulator data to DPTR.

5. Call delay Subroutine.

6. Complement the accumulator data.

7. Move the accumulator data to DPTR.

8. Call delay subroutine.

9. Repeat the program.

Page |
PROGRAM:

SQUARE WAVE:

MEMORY OP-CODE LABEL MNEMONIC


COMMENT
ADDRESS B1 B2 B3
4100 90 FF C0 START MOV DPTR,#FFC0 [[DPTR]]  FFC0
4103 74 00 MOV A,#00 [A]  00
4105 F0 MOVX @DPTR,A [[DPTR]]  [A]
4106 12 42 00 LCALL DELAY Call delay Subroutine
4109 F4 CPL A Complement A
410A F0 MOVX @DPTR,A [[DPTR]]  [A]
410B 12 42 00 LCALL DELAY Call delay Subroutine
410E 80 F0 SJMP START Jump to start

DELAY SUBROUTINE:

MEMORY OP-CODE
LABEL MNEMONIC
ADDRESS B1 B2 B3
4200 7A FA DELAY MOV R3,# FA
4202 DA FE LOOP DJNZ R3,LOOP
4204 22 RET

Page |
DELAY ROUTINE IN 8051

In an 8051 microcontroller, it requires 12 cycles of the processor clock for executing a


single instruction cycle. For an 8051 microcontroller clocked by a 12MHz crystal, the
time taken for executing one instruction cycle is 1µS and it is according to the
equation

Time for 1 instruction cycle= 12 /12 MHz = 1µS.

The shortest instructions will execute in 1µS and other instructions will take 2 or more
micro seconds depending up on the size of the instruction. Thus a time delay of any
magnitude can be generated by looping suitable instructions a required number of
times. Anyway, the software delay is not very accurate because we cannot exactly
predict how much time it takes for executing a single instruction.

The above program roughly produces a delay of 1mS.The instruction DJNZ Rx,
LABEL is a two cycle instruction and it will take 2µS to execute. So repeating this
instruction 500 times will generate a delay of 500 x 2µS = 1mS. The program is
written as a subroutine and it works this way. When called the sub routine DELAY,
Registers R3 is loaded by 250D.

Square wave has ON and OFF period time delay = 0.5ms (Time delay = 500µs)

RESULT:

The ALPs for generating square wave with different frequencies using 8051
were written and executed.

Page |

You might also like