You are on page 1of 157

1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY

Microprocessor and Microcontroller


Laboratory Manual

Prepared by
Mr.K.Aanandha saravanan, Assistant Professor, ECE
Mr.A.Yogaraj, Assistant Professor, ECE
Mr. A.Farithkhan, Assistant Professor, ECE
Mr. R.Sanmuga Sundaram, Assistant Professor, ECE
Mr.K.Sivachander, Assistant Professor, ECE
Ms.Shameli, Assistant Professor, ECE

On
02.04.2018

Department of ECE Veltech Rangarajan Dr.Sagunthala R&D Institute of Science and Technology
1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY

Table of Contents

Page
S.No Name of the Experiment
No.

Cycle -I

1 Program for 8-Bit ALU operations (8085) 1

2 Real time clock generation (8085) 25

3 Traffic light interfacing (8085) 39

4 Program for 16- Bit ALU operations (8086) 49

5 Program for square root and square of the given input(8086) 70

6 Interfacing of Stepper Motor using 8086 83

7 Program for ALU operation (8051) 89

8 Program for bit manipulation and masking for the given input (8051) 103

Cycle -I

9 ADC & DAC Interfacing with 8051 microcontroller 112

10 Keyboard and Display Interface with 8051 125

11 Interfacing DC motor with 8051 132

12 Timer programming using keil C compiler 138

13 Serial port programming using keil C compiler 144

14 Interrupt program using keil C compiler 149

15 Mini Project using microcontrollers. --

Department of ECE Veltech Rangarajan Dr.Sagunthala R&D Institute of Science and Technology
1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY

Department of ECE Veltech Rangarajan Dr.Sagunthala R&D Institute of Science and Technology
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 1

1. PROGRAM FOR ALU OPERATIONS (8085)


A) 8-BIT DATA ADDITION-8085
Aim:
To add two 8 bit numbers stored at consecutive memory locations.
.

Equipment and Components Required:

Power supply, 8085 kit

Algorithm:

 Initialize memory pointer to data location.

 Get the first number from memory in accumulator.

 Get the second number and subtract from the accumulator.

 If the result yields a borrow, the content of the acc. is complemented and 01H is

added to it (2’s complement). A register is cleared and the content of that reg. is

incremented in case there is a borrow. If there is no borrow the content of the acc. is

directly taken as the result.

 Store the answer at next memory location.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 2

Flow chart:
START

[C] 00H

[HL] 4500H

[A] [M]

[HL] [HL]+1

[A] [A]-[M]

If
Borrow?
N

Y
Complement [A]

Add 01H to [A]

[C] [C]+1

[HL] [HL]+1

[M] [A]

[HL] [HL]+1

[M] [C]

STOP

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 3

Program:

ADDRESS/LABEL MNEMONICS OPERAND OPCODE BYTES MACHINE CYCLES T-STATES EXECUTION TIME COMMENTS
4100 / START 0E
MVI C, 00 2 2 7T Clear C reg.
4101 00 3.5 µs
4102 21
4103 LXI H, 4500 00 3 10T 5 µs Initialize HL reg. to 4500
3
4104 45

4105 MOV A, M 7E 1 1 7T 3.5 µs Transfer first data to accumulator

3 µs Increment HL reg. to point next


4106 INX H 23 1 6T
1 memory Location.

4107 ADD M 86 1 2 7T 3.5 µs Add first number to acc. Content.

4108 D2 2/ 3 7T / 10T
Jump to location if result does not
4109 JNC L1 0C (if condition is not true (if condition is 3.5 µs / 5 µs
3 yield carry.
410A 41 / true) not true / true)
410B INR C 0C 1 1 4T 2 µs Increment C reg.
Increment HL reg. to point next
410C / L1 INX H 23 1 1 6T 3 µs
memory Location.
Transfer the result from acc. to
410D MOV M, A 77 1 2 7T 3.5 µs
memory.
Increment HL reg. to point next
410E INX H 23 1 1 6T 3 µs
memory Location.
410F MOV M, C 71 1 2 7T 3.5 µs Move carry to memory
4110 HLT 76 1 2 5T 2.5 µs Stop the program

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 4

Calculations :

Clock frequency F=2MHz


T-State =Clock Period (1/F) = 0.5µs
Execution time for Opcode Fetch: (4T)*0.5= 2 µs
Execution time for Memory Read: (3T)*0.5= 1.5 µs
Execution time for Instruction: (7T)*0.5= 3.5 µs

Total No. of T States:


If condition true:
If condition false:

Observation:

INPUT OUTPUT

4500 FF 4502 FE
4501 FF 4503 01

Conclusion:

Thus the 8 bit numbers stored at 4500 &4501 are added and the result stored at 4502 &
4503.

……………………………………………………………………………………………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 5

Questions:

1. What type of architecture used in 8085 microprocessor?

2. What is the function of accumulator?

3. What are the different types of flags in 8085 microprocessor?

4. What are the types of general purpose registers in 8085?

5. What is the length of stack pointer in 8085 microprocessor?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 6

B) 8 BIT DATA SUBTRACTION-8085


Aim:
To subtract two 8 bit numbers stored at consecutive memory locations.

Equipment and Components Required:

Power supply, 8085 kit

Algorithm:

 Initialize memory pointer to data location.

 Get the first number from memory in accumulator.

 Get the second number and subtract from the accumulator.

 If the result yields a borrow, the content of the acc. is complemented and 01H is

added to it (2’s complement). A register is cleared and the content of that reg. is

incremented in case there is a borrow. If there is no borrow the content of the

acc. is directly taken as the result.

 Store the answer at next memory location.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 7

Flow Chart:

START

[C] 00H

[HL] 4500H

[A] [M]

[HL] [HL]+1

[A] [A]-[M]

Is there a NO

Borrow ?
YES

Complement [A]

Add 01H to [A]

[C] [C]+1

[HL] [HL]+1

[M] [A]

[HL] [HL]+1

[M] [C]

STOP

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 8

Program:
ADDRESS/LABEL MNEMONICS OPERAND OPCODE BYTES MACHINE CYCLES T-STATES EXECUTION TIME COMMENTS
4100/START MVI C, 00 0E
2 2 7T 3.5 µs Clear C reg.
00
4102 21
LXI H, 4500
4103 00 3 3 10T 5 µs Initialize HL reg. to 4500
4104 45
4105 MOV A, M
7E 1 1 7T 3.5 µs Transfer first data to accumulator

Increment HL reg. to point next


4106 INX H 23 1 1 6T 3 µs
memory Location.
4107 SUB M 96
1 2 7T 3.5 µs Add first number to acc. Content.

4108 JNC L1 D2 2/ 3 7T / 10T


Jump to location if result does not
4109 0F 3 (if condition is not true (if condition is 3.5 µs / 5 µs
yield carry.
410A 71 / true) not true / true)
410B INR C OC 1 1 4T 2 µs Increment C reg.
410C CMA 2F 1 2 5T 2.5 µs Complement Accumulator
410D ADI 01H C6 3.5 µs
2 2 7T Add immediate to accumulator
410E 01
410F/L1 INX H 23 1 1 6T
Increment HL reg. to point next
3 µs memory Location.
4110 MOV M, A 77 1 2 7T 3.5 µs
Transfer the result from acc. to
memory.
4111 INX H 23 1 1 6T 3 µs
Increment HL reg. to point next
memory Location.
4112 MOV M, C 71 1 2 7T 3.5 µs Move carry to memory
4113 HLT 76 1 2 5T 2.5 µs Stop the program

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 9

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 10

Calculations:

Clock frequency F=2MHz

T-State =Clock Period (1/F) = 0.5µs

Execution time for Opcode Fetch: (4T)*0.5= 2 µs

Execution time for Memory Read: (3T)*0.5= 1.5 µs

Execution time for Instruction: (7T)*0.5= 3.5 µs

Total No. of T States:


If condition true:
If condition false:

Observation:

INPUT OUTPUT
4500 45 4502 4B
4501 90 4503 01

Conclusion:

Thus the 8 bit numbers stored at 4500 &4501 are subtracted and the result stored at
4502 & 4503.

……………………………………………………………………………………………………………………………………
…..

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 11

Questions:

1. What is the memory size of 8085 microprocessor?

2. How many bits is 8085 microprocessor?

3. What are the various interrupts in 8085 microprocessor? Which is the highest
priority interrupt?

4. Which type of cycle is used for fetch and execute instruction?

5. How many address lines are there in 8085 microprocessor?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 12

C) 8 BIT DATA MULTIPLICATION-8085


Aim:
To multiply two 8 bit numbers stored at consecutive memory locations and store
the result in memory.

Equipment and Components Required:

Power supply, 8085 kit

Algorithm:

LOGIC: Multiplication can be done by repeated addition.

 Initialize memory pointer to data location.

 Move multiplicand to a register.

 Move the multiplier to another register.

 Clear the accumulator.

 Add multiplicand to accumulator

 Decrement multiplier

 Repeat step 5 till multiplier comes to zero.

 The result, which is in the accumulator, is stored in a memory location.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 13

Flow Chart:
START

[C] 00H

[HL] 4500H

[A] [M]

[HL] [HL]+1

[A] [A]-[M]

Is there a NO

Borrow ?
YES

Complement [A]

Add 01H to [A]

[C] [C]+1

[HL] [HL]+1

[M] [A]

[HL] [HL]+1

[M] [C]

STOP

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 14

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15

Program:

ADDRESS/LABEL MNEMONICS OPERAND OPCODE BYTES MACHINE CYCLES T-STATES EXECUTION TIME COMMENTS
4100/START 21
4101 LXI H, 4500 00 3 3 10T 5 µs Initialize HL reg. to 4500
4102 45
4103 MOV B, M 46 1 1 7T 3.5 µs Move from reg M to Reg B
Increment HL reg. to point next
4104 23 1 1 6T 3 µs
INX H memory Location.
4105 3E
MVI A, 00H 2 2 7T 3.5 µs Clear accumulator
4106 00
4107 0E
MVI C, 00H 2 2 7T 3.5 µs Clear Reg C
4108 00

4109/L1 86 1 2 7T 3.5 µs Add first number to acc. Content.


ADD M
410A JNC NEXT D2 2/ 3 7T / 10T
Jump to location if result does not
410B 0E 3 (if condition is not true (if condition is 3.5 µs / 5 µs
yield carry.
410C 41 / true) not true / true)
410D INR C 0C 1 1 4T 2 µs Increment C reg.
410E DCR B 05 1 1 4T 2 µs Decrement B reg.
410F C2
4110 JNZ L1 09 3 3 10T 5 µs Jump to next iteration if counter
4111 41 not zero
Increment HL reg. to point next
4112 INX H 23 1 1 6T 3 µs
memory Location.
1 Transfer the result from acc. to
4113 MOV M, A 77 2 7T
3.5 µs memory.
Increment HL reg. to point next
4114 INX H 23 1 1 6T 3 µs
memory Location.
4115 MOV M, C 71 1 2 7T 3.5 µs Move carry to memory

4116 HLT 76 1 2 5T 2.5 µs


Stop the program

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 16

Calculations :

Clock frequency F=2MHz


T-State =Clock Period (1/F) = 0.5µs
Execution time for Opcode Fetch: (4T)*0.5= 2 µs
Execution time for Memory Read: (3T)*0.5= 1.5 µs
Execution time for Instruction: (7T)*0.5= 3.5 µs

Total No. of T States:


If condition true:
If condition false:

Observation:

INPUT OUTPUT
4500 05 4502 32
4501 0A 4503 00

Conclusion:

Thus the 8-bit multiplication was done in 8085 microprocessor using repeated
addition method.

……………………………………………………………………………………………………………………………………
….

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 17

Questions:

1. Why crystal is being preferred as a clock source?

2. Name High order / Low order register in 8085 microprocessor?

3. What is Tri-state logic?

4. What will happen if HLT instruction is executed in processor?

5. Which Stack is used in 8085?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 18

D) 8 BIT DIVISION-8085
Aim:
To divide two 8-bit numbers and store the result in memory.

Equipment and Components Required:

Power supply, 8085 kit

Algorithm:

LOGIC:
Division is done using the method Repeated subtraction.

 Load Divisor and Dividend

 Subtract divisor from dividend

 Count the number of times of subtraction which equals the quotient

 Stop subtraction when the dividend is less than the divisor .The dividend now

becomes the remainder. Otherwise go to step 2.

 Stop the program execution.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 19

Flow Chart:
START

B  00

[HL] 4500

A M

[HL]  [HL]+1

M  A-M

[B]  [B] +1

NO
IS A<0
YES
A  A+ M

B  B-1

[HL] [HL]+1

[M] [A]

[HL] [HL]+1

[M] [B]

STOP

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 20

Program:

ADDRESS/LABEL MNEMONICS OPERAND OPCODE BYTES MACHINE CYCLES T-STATES EXECUTION TIME COMMENTS
4100 MVI B,00 06
2 3.5 µs
2 7T Clear C reg.
4101 00

4102 LXI H,4500 21


4103 00 3 3 10T Initialize HL reg. to 4500
5 µs
4104 45

4105 MOV A,M 7E 1 1 7T 3.5 µs Transfer first data to accumulator

4106 INX H 23 1 6T 3 µs
Increment HL reg. to point next
memory Location.
1

4107 SUB M 96 1 2 7T 3.5 µs Sub first number to acc. Content.

4108 INR B 04 1 1 4T 2 µs Increment B reg.


4109 D2
JNC LOOP 2/ 3 7T / 10T
Jump to location if result does not
(if condition is not true (if condition is 3.5 µs / 5 µs
410A 07 3 / true) not true / true)
yield carry.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 21

410B 41

410C ADD M 86 1 2 7T 3.5 µs Add first number to acc. Content.

410D DCR B 05 1 1 4T 2 µs Decrement B reg.

410E INX H 23 1 1 6T 3 µs
Increment HL reg. to point next
memory Location.
410F MOV M,A 77 1 2 7T 3.5 µs
Transfer the result from acc. to
memory.
4110 INX H 23 1 1 6T 3 µs
Increment HL reg. to point next
memory Location.
4111 MOV M,B 70 1 2 7T 3.5 µs Move carry to memory
4112 HLT 76 1 2 5T 2.5 µs Stop the program

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 22

Calculations:

Clock frequency F=2MHz


T-State =Clock Period (1/F) = 0.5µs
Execution time for Opcode Fetch: (4T)*0.5= 2 µs
Execution time for Memory Read: (3T)*0.5= 1.5 µs
Execution time for Instruction: (7T)*0.5= 3.5 µs

Total No. of T States:


If condition true:
If condition false:

Observation:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4500 32 4502 05
4501 0A 4503 00
4500 05 4502 02
4501 02 4503 01

Conclusion:

Thus an ALP was written for 8-bit division using repeated subtraction method and
executed using 8085

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 23

Questions:

1. Define microprocessor.

2. Define micro controller.

3. Compare microprocessor and micro controller.

4. List some application of microprocessor and micro controller.

5. Define machine language and assembly language.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 24

Lab Exercises:

1. Write an Arithmetic logic program for repeated subtraction in 650000 data1 = AB H,


data2 = 12 H using in direct addressing mode of8085.

2. Write an Arithmetic logic program to store the repeated addition in memory


location 7000 of inputs AA & BB using indirect addressing mode of 8085.

3. Write an Arithmetic logic program to store the product in memory location 7000 of
inputs AB & BC using direct addressing mode of8085.

4. Write an Arithmetic logic program to store the debit value in memory location of the
inputs (2’s complement of data1=A3 H and data2 = 93 H ] Using 8085.

5. Write an Arithmetic logic program to store the debit value in memory location 6500
of the two immediate input data using 8085

6. Write an Arithmetic logic program to store the sum in memory location 4504 H &
carry in the subsequent memory location of the two immediate input data using
8085 and calculate the execution time total T states.

7. Write an Arithmetic logic program to store the sum in memory location 7503 H &
carry in the subsequent memory location of the two input data in 8085. Input 1 in
7401 and input 2 in 7408 using indirect addressing modes.

8. Write an Assembly language program to perform NOR operation on a 8 bit number


using 8085.

9. Write an Assembly language program to perform AND operation on 8 bit number


using 8085.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 25

2. REAL TIME CLOCK GENERATION (8085)

Aim:
To write the program that uses 8253 to generate delay od one second and runs a
digital clock using 8279..

Equipment and Components Required:

Power supply, 8085 kit

Algorithm:

 Initialize hours, minutes and seconds

 Provide one second delay routine.

 Display hours, minutes and seconds.

 Increment seconds.

 if seconds is reaches maximum of 60 , increment minutes else go to step 2.

 if minutes reaches maximum of 60 , increment hours else go to step 2.

 if hours reaches maximum of 24 , make hours, minutes and seconds zero else go

to step 2.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 26

Flow chart:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 27

Program:

BYTES EXECUTION COMMENTS


ADDRESS/LABEL MNEMONICS OPERAND OPCODE MACHINECYCLES T-STATES
TIME(us)
4100 06 Move the content 03 to B
MVI B,03 2 2 7 2.275
4101 03 register
4102 21
4103 LXI H,DATA 50 3 3 10 3.25 Load the value of DATA
4104 42
Move the contents of
4105/ L2 MOV A,M 7E 1 2 7 2.275
memory to accumulator
4106 32
4107 00 Load the contents of
STA BUFFER 3 13 4.225
4 buffer to accumulator
4108 43
4109 0E Move the contents OA to
MVI C,0A 2 2 7 2.275
410A 0A C register
410B E6 AND F0 with
ANI FO 2 2 7 2.275
410C F0 Accumulator
Rotate the contents
410D RLC 07 1 1 4 1.3 through left

Rotate the contents


410E RLC 07 1 1 4 1.3 through left

Rotate the contents


410F RLC 07 1 1 4 1.3 through left

Rotate the contents


4110 RLC 07 1 1 4 1.3 through left

Move the contents of A to


4111 MOV D,A 57 1 1 4 1.3
D register
Subtract the contents of A
4112 SUB A 97 1 1 4 1.3
by A
Add the contents of D
4113/ L1 ADD D 82 1 1 4 1.3
register with A
4114 DCR C 0D 1 1 4 1.3 Decrement the contents of
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 28

C register by 1
4115 C2 Jump if the contents is
4116 JNZ L1 13 3 2 10 3.25 non zero to the location
4117 41 L1
Move the contents of
4118 MOV D,A 57 1 1 4 1.3
accumulator to D register
4119 3A
Load the contents of
411A LDA BUFFER 00 3 4 13 4.225
buffer in accumulator
411B 43
411C E6
ANI 0F 2 2 7 2.275 AND accumulator and 0F
411D 0F
Add the contents of D and
411E ADD D 82 1 1 4 1.3
accumulator
Move the contents of
411F MOV M,A 77 1 2 7 2.275
accumulator to memory
Increment the memory
4120 INX H 23 1 1 6 1.95
location by one
Decrement the contents of
4121 DCR B 05 1 1 4 1.3
B register by 1
4122 C2 Jump if the contents is
4123 JNZ L2 05 3 2 10 3.25 non zero to the location
4124 41 L2
4125/START 3E Move the contents 90H to
MVI A,90 2 2 7 2.275
4126 90 A register
4127 D3 Move the contents of
OUT 01 2 3 10 3.25 accumulator to output
4128 01
port
4129 21
412A LXI H,DATA 50 3 3 10 3.25 Load the value of Data
412B 42
412C 06 Move the contents 03H to
MVI B,03 2 2 7 2.275
412D 03 B register
412E 0E Move the contents 18H to
MVI C,18 2 2 7 2.275
412F 18 C register
Move the contents of
4130/ L3 MOV A,M 7E 1 2 7 2.275
memory to accumulator
4131 CALL C1 CD 3 5 18 5.85 Call the subroutine C1

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 29

4132 47
4133 41
4134 CD
Call the subroutine
4135 CALL CONVERT 4C 3 5 18 5.85
Convert
4136 41
4137 CD
Call the subroutine
4138 CALL DISLAY 67 3 5 18 5.85
Display
4139 41
Increment the memory
413A INX H 23 1 1 6 1.95
location by 1
413B 3E Move the content 18H to
MVI A,18 2 2 7 2.275
413C 18 accumulator
413D C6 Add immediate the
ADI 24 2 2 7 2.275 contents of accumulator
413E 24
and 24
Move the contents of
413F MOV C,A 4F 1 1 4 1.3
accumulator to C register
Decrement the contents of
4140 DCR B 05 1 1 4 1.3
B register by 1
4141 C2 Jump if the contents is
4142 JNZ L3 30 3 3 10T 3.25 non zero to the location
4143 41 L3
4144 C3
4145 JMP DELAY 85 3 3 10 3.25 Jump to the delay location
4146 41
Compare the Accumulator
4147/C1 CMP C B9 1 1 4 1.3
contents with C register
Return to subroutine if the
4148 RNZ C0 1 3 10 3.25
contents is non zero
Subtract contents of C
4119 SUB C 91 1 1 4 1.3
register to accumulator
Move the contents of
414A MOV M,A 77 1 1 4 1.3
accumulator to Memory
414B RET C9 1 3 10 3.25 Return to the subroutine
414C/ CONVERT 16 Initialize D register with
MVI D,00 2 2 7 2.275
414D 00 00
414E/ LO1: SUI 0A D6 2 2 7 2.275 Subtract the contents of
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 30

414F 0A accumulator with OA


4150 DA
Jump if Carry flag is set
4151 JC LO2 57 3 3 10 3.25
to the location LO2
4152 41
Increment the contents of
4153 INR D 14 1 1 4 1.3
D register by 01
4154 C3
Jump to the location
4155 JMP LO1 4E 3 3 10 3.25
specified by LO1
4156 41
4157/ LO2 C6 AND accumulator and
ADI 0A 2 2 7 2.275
4158 0A OA
4159 32
Load the buffer contents
415A STA BUFFER 00 3 4 13 4.225
to accumulator
415B 43
Move the contents of D
415C MOV A,D 7A 1 1 4 1.3
register to accumulator
Rotate the contents
415D RRC 0F 1 1 4 1.3 through right

Rotate the contents


415E RRC 0F 1 1 4 1.3 through right

Rotate the contents


415F RRC 0F 1 1 4 1.3 through right

Rotate the contents


4160 RRC 0F 1 1 4 1.3
through right
Move the contents of
4161 MOV D,A 57 1 1 4 1.3
accumulator to D register
4162 3A
Load the buffer contents
4163 LDA BUFFER 00 3 4 13 4.225
to accumulator
4164 43
ADD the contents of
4165 ADD D 82 1 1 4 1.3
accumulator to D register
4166 RET C9 1 3 10 3.25 Return to call subroutine
4167/ DISLAY 32 Load the buffer contents
STA BUFFER 3 4 13 4.225
4168 00 to accumulator
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 31

4169 43
416A E6 AND operation with F0
ANI FO 2 2 7 2.275
416B F0 and accumulator
Rotate the contents
416C RLC 07 1 1 4 1.3 through left

Rotate the contents


416D RLC 07 1 1 4 1.3 through left

Rotate the contents


416E RLC 07 1 1 4 1.3 through left

Rotate the contents


416F RLC 07 1 1 4 1.3
through left
4170 CD
4171 CALL D1 7C 3 5 18 5.85 Call the subroutine D1
4172 41
4173 3A
Load the buffer contents
4174 LDA BUFFER 00 3 4 13 4.225
to accumulator
4175 43
4176 E6 AND operation with 0F
ANI 0F 2 2 7 2.275
4177 0F and accumulator
4178 CD
4179 CALL D1 7C 3 5 18 5.85 Call the subroutine D1
417A 41
417B RET C9 1 3 10 3.25 Return to call subroutine
417C/ D1 11
417D LXI D,TABLE C8 3 3 10 3.25 Load the look up table
417E 41
Add the contents of E and
417F ADD E 83 1 1 4 1.3
A and store in A
Move the contents of
4180 MOV E,A 5F 1 1 4 1.3
accumulator to E register
Load the content of reg
4181 LDAX D 1A 1 2 7 2.275
pair D to accumulator
4182 D3
OUT 00 2 3 10 3.25 Initialize output port as 00
4183 00
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 32

4184 RET C9 1 3 10 3.25 Return to call subroutine


4185 / DELAY OE Move the contents 02H
MVI C,02 2 2 7 2.275
4186 02 into C register
4187 3E Move the contents 30H
MVI A,30 2 2 7 2.275
4188 30 into accumulator
4189 D3 Initialize output port as
OUT 0B 2 3 10 3.25
418A 0B 0B
418B/ LO4: 3E Move the contents 90H
MVI A,90 2 2 7 2.275
418C 90 into accumulator
418D D3
OUT 08 2 3 10 3.25 Initialize output port as 08
418E 08
418F 3E Move the contents 80H
MVI A,80 2 2 7 2.275
4190 80 into accumulator
4191 D3
OUT 08 2 3 10 3.25 Initialize output port as 08
4192 08
4193/ LO3: 3E
MVI A,00 2 2 7 2.275 Initialize accumulator
4194 00
4195 D3
OUT 0B 2 3 10 3.25 Initialize output port as 08
4196 0B
4197 DB
IN 08 2 3 10 3.25 Initialize input port as 08
4198 08
Move the contents of
4199 MOV E,A 5F 1 1 4 1.3
accumulator to E register
419A DB
IN 08 2 3 10 3.25 Initialize input port as 08
419B 08
Or operation between
419C ORA E B3 1 1 4 1.3
accumulator and 0E
419D C2 If the accumulator
419E JNZ LO3 93 3 3 10 3.25 contents is zero jump to
419F 41 the LO3 subroutine
Decrement the contents of
41A0 DCR C OD 1 1 4 1.3
C register by 1
41A1 C2 If the accumulator
41A2 JNZ LO4 8B 3 3 10 3.25 contents is zero jump to
41A3 41 the LO4 subroutine
Decrement the memory
41A4 DCX H 2B 1 1 6 1.95
location by 1
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 33

Increment the contents of


41A5 INR M 34 1 3 10 3.25
memory by 1
Move the contents of
41A6 MOV A,M 7E 1 1 4 1.3
accumulator to memory
41A7 FE Compare the contents of
CPI 3C 2 2 7 2.275
41A8 3C accumulator with 3C
41A9 C2 If the accumulator
41AA JNZ START 25 3 3 10 3.25 contents is zero jump to
41AB 41 the START subroutine
41AC D6 Subtract the contents of
SUI 3C 2 2 7 2.275
41AD 3C accumulator by 3C
41AE MOV M,A 77 1 2 7 2.275
Decrement the memory
41AF DCX H 2B 1 1 6 1.95
location by 1
Increment the contents of
41B0 INR M 34 1 3 10 3.25
memory by 1
Move the contents of
41B1 MOV A,M 7E 1 2 7 2.275
accumulator to memory
41B2 FE Compare the contents of
CPI 3C 2 2 7 2.275
41B3 3C accumulator with 3C
41B4 C2 If the accumulator
41B5 JNZ START 25 3 3 10 3.25 contents is zero jump to
41B6 41 the START subroutine
41B7 D6 Subtract the contents of
SUI 3C 2 2 7 2.275
41B8 3C accumulator by 3C
Move the contents of
41B9 MOV M,A 77 1 1 4 1.3
accumulator to memory
Decrement the memory
41BA DCX H 2B 1 1 6 1.95
location by 1
Increment the contents of
41BB INR M 34 1 3 10 3.25
memory by 1
Move the contents of
41BC MOV A,M 7E 1 1 4 1.3
accumulator to memory
41BD FE Compare the contents of
CPI 18 2 2 7 2.275
41BE 18 accumulator with 18
41BF C2 If the accumulator
JNZ START 3 3 10 3.25
41C0 25 contents is zero jump to

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 34

41C1 41 the START subroutine


41C2 D6 Subtract the contents of
SUI 18 2 2 7 2.275
41C3 18 accumulator by 18
Move the contents of
41C4 MOV M,A 77 1 1 4 1.3
accumulator to memory
41C5 C3
Jump statement to the
41C6 JMP START 25 3 3 10 3.25
START subroutine
41C7 41
41C8/ TABLE: OA
41C9 9F
DB 0A,9F,49,0D Display codes for 0 to F
41CA 49
41CB 0D
41CC 9C
41CD 2C
DB 9C,2C,28,8F Display codes for 0 to F
41CE 28
41CF 8F
41D0 08
41D1 8C
DB 08,8C,88,38 Display codes for 0 to F
41D2 88
41D3 38
41D4 6A
41D5 19
DB 6A,19,68,E8 Display codes for 0 to F
41D6 68
41D7 E8
41D8 END

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 35

Calculations :

Clock frequency F=2MHz


T-State =Clock Period (1/F) = 0.325µs
Execution time for Opcode Fetch: (4T)* 0.325µs = 1.3 µs
Execution time for Memory Read: (3T)* 0.325µs = 0.975 µs
Execution time for Instruction: (7T)* 0.325µs = 2.275 µs

Total No. of T States: 904


If condition true:
If condition false:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 36

Observation:

INPUT OUTPUT

4250
4251
4252

Conclusion:

Thus an ALP was written for real time clock . Second in data field, minutes and hours in
address field was displayed using 8085p kits.

……………………………………………………………………………………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 37

Questions:

1. What type of architecture used in 8085 microprocessor?

2. What is the function of accumulator?

3. What are the different types of flags in 8085 microprocessor?

4. What are the types of general purpose registers in 8085?

5. What is the length of stack pointer in 8085 microprocessor?

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 38

Lab Exercises:

1. Write a program to convert decimal number to a hexadecimal number.

2. Write a program to convert hexadecimal number to decimal number.

3. Write a program to generate a clock for 10 min instead of 24 hours.

4. Write a program to generate a clock only for seconds

5. Write a program to generate a clock only for minutes

6. Write a program to generate a clock only for hours

7. Write a program to generate a clockin hexadecimal.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 39

3. TRAFFIC LIGHT INTERFACING (8085)


Aim:
To write an assembly language program to simulate the traffic light at an
intersection using a traffic light interface.
.
Equipment and Components Required:

8085 microprocessor kit, Traffic light interface kit, and Power Supply.

Algorithm:

 Initialize the ports.

 Initialize the memory content, with some address to the data.

 Read data for each sequence from the memory and display it through the ports.

 After completing all the sequences, repeat from step2.

A SAMPLE SEQUENCE:
1. (a) Vehicles from south can go to straight or left.
(b) Vehicles from west can cross the road.
(c) Each pedestrian can cross the road.
(d) Vehicles from east no movement.
(e) Vehicles from north can go only straight.

2. All ambers are ON, indicating the change of sequence.

3. (a) Vehicles from east can go straight and left.


(b) Vehicles from south can go only left.
(c) North pedestrian can cross the road.
(d) Vehicles from north, no movement.
(e) Vehicles from west can go only straight.

4. All ambers are ON, indicating the change of sequence.

5. (a) Vehicles from north can go straight and left.


(b) Vehicles from east can go only left.
(c) West pedestrian can cross the road.
(d) Vehicles from west, no movement.
(e) Vehicles from south can go only straight.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 40

Flow Chart:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 41

6. All ambers are ON, indicating the change of sequence.

7. (a) Vehicles from west can go straight and left.


(b) Vehicles from north can go only left.
(c) South pedestrian can cross the road.
(d) Vehicles from south, no movement.
(e) Vehicles from east can go only straight.

8. All ambers are ON, indicating the change of sequence.

9. (a) All vehicles from all directions no movement.


(b) All pedestrian can cross the road.

BIT LED BIT LED BIT LED

PA0 SOUTH LEFT PB0 NORTH LEFT PC0 WEST STRAIGHT

PA1 SOUTH RIGHT PB1 NORTH RIGHT PC1 NORTH STRAIGHT

PA2 SOUTH AMBER PB2 NORTH AMBER PC2 EAST STRAIGHT

PA3 SOUTH RED PB3 NORTH RED PC3 SOUTH STRAIGHT

PA4 EAST LEFT PB4 WEST LEFT PC4 NORTH PD

PA5 EAST RIGHT PB5 WEST RIGHT PC5 WEST PD

PA6 EAST AMBER PB6 WEST AMBER PC6 SOUTH PD

PA7 EAST RED PB7 WEST RED PC7 EAST PD

CONTROL ----- 0F (FOR 8255 PPI)

PORT A ----- 0C
PORT B ----- 0D
PORT C ----- 0E

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 42

Program:

EXECUTION
LABEL MNEMONICS BYTES MACHINE T-STATES
ADDRESS OPERAND OPCODE TIME(μs) COMMENTS
CYCLES
4100 START LXI H,DATA 21, 00, 45 3 3 10T 3.25 Initialize HL reg.to Data

4103 MVI C,04 0E 04 2 2 7T 2.275 Initialize C reg with no of


comparison

4105 MOV A,M 7E 1 1 7T 2.275 Move M content to


accumulator
OUT 2 2 10T 3.25 Load address 417B to HL
4106 CNT D3 0F
register

4108 INX H 23 1 1 10T 3.25 Increment H register


4109 LOOP 1: MOV A,M 7E 1 1 7T 2.275 Move M content to
accumulator
410A OUT APRT 2 2 10T 3.25 Output contents of
D3 0C
accumulator to OF port
410C INX H 1 1 10T 3.25
23 Increment H register
410D MOV A,M 7E 1 1 7T 2.275 Move M content to
accumulator
OUT BPRT 2 2 10T 3.25 Move M content to
410E D3 0D
accumulator

4110 CALL DELAY CD 1B 41 3 3 18T 5.85 Call DELAY address

4113 INX H 23 1 1 10T 3.25 Increment H register


4114 DCR C 0D 1 1 4T 1.3 Decrement C register

4115 JNZ LOOP 1 C2 09 41 3 3 7T/10T 2.275/3.25 Jump to LOOP 1 if no zero

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 43

4118 JMP START C3 00 41 3 3 10T 3.25 Jump to start

411B DELAY: PUSH B C5 1 3 12T 3.9 Push the register B

411C MVI C,05 0E 05 2 2 7T 2.275 Move 05 H immediately to

LOOP3: LXI 3 3 10T 3.25 Load FF FF in DE register


411E D,FFFF 7E,FF,FF pair

4121 LOOP2 DCX D D3 1 1 6T 1.95 Decrement D register

MOV 3 3 7T 2.275 Move D content to


4122 A,D CD,66,41
accumulator
ORA 1 1 4T 1.3 OR content of E with
4123 E EB
Accumulator

4124 JNZ LOOP2 13,42,41 3 2/3 7T/10T 2.275/3.25 Jump To L2 IF no zero

4127 DCR C 23 1 1 6T 1.95 Decrement C register

JNZ 3 2/3 7T/10T 2.275/3.25 Jump to LOOP 2 if no zero


4128 LOOP3 CD,1E,41

412B POP B EB 1 3 10T 3.25 POP the register B

412C RET 7E 1 1 10T 3.25 Return to subroutine

80 1A A1 DATA 80, 1A, A1, 4


4500 DB 1.3
64 64
A4 81 5A 4
4504 A4,81,5A,64 1.3
64
54 8A B1 54,8A,B1,A 4
4508 DB 1.3
A8 8

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 44

B4 88 DA B4,88,DA,6 4
450C 1.3
68 8
D8 1A E8 D8 1A E8 4
4510 1.3
46 46
E8 83 78 86 E8,83,78,86, 5
4514 74 74 1.3

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 45

Traffic Light Model:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 46

Calculations :

Clock frequency F=2MHz


T-State =Clock Period (1/F) = 0.325µs
Execution time for Opcode Fetch: (4T)* 0.325µs = 1.3 µs
Execution time for Memory Read: (3T)* 0.325µs = 0.975 µs
Execution time for Instruction: (7T)* 0.325µs = 2.275 µs

Total No. of T States: 232


If condition true:
If condition false:

Conclusion:
Thus an assembly language program to simulate the traffic light at an intersection using a
Traffic light interfaces was written and implemented
…………………………………………………………………………………….…………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 47

Questions:

1. Draw the control word register.

2. List the ports in 8255.

3. What are modes available in 8255?

4. How to initialize 8255?

5. Give the significance of SIM and RIM instruction available in 8085.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 48

Lab Exercises:

1. Write a subroutine program to exchange the content of BC-pair and DE-Pair.

2. Write a subroutine to clear the flag register and accumulator.

3. Write a program to split a hexa data into two nibbles and store in memory.

4. Write a simple program to find the smallest among the two data stored in memory.

5. Write an Assembly language program for controlling traffic in a three lane junction
using 8085.

6. Write an Assembly language program for controlling traffic in 4 lane junction with
green light on time 60 seconds and red light on time 180 seconds for each lane using
8085.

7. Write an Assembly language program to interface RTC with traffic control system
for effective control during the peak time.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 49

4. Programs for ALU operations (8086)


A) 16-BIT DATA ADDITION-8086
Aim:
To write a program to add two 16-bit numbers using 8086.
.

Equipment and Components Required:

8086 Microprocessor kit, Power Supply

Algorithm:

 Start the program.

 Initialize the memory locations with input data.

 Load the values from memory location to the registers..

 Add the two values stored in the registers.

 If carry occurs (CF=1) increment the carry storing register and store the sum and

carry in the memory location. Otherwise store the sum in the memory location.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 50

Flow chart:

Start

Clear CL Register

Get the content of


1100H &1101H in AX

Get the content of


1102H &1103H in BX

Perform Addition
[AX]=[AX]+[BX]

NO
Is
CF=1 ?

YES

Increment CL
Register

Store the Content of


CL register to 1106H

Store the Result


[1104]=[AL],[1105]=[AH]

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 51

BYTE MACHINE T- EXECUTION


ADDRESS LABEL MNEMONICS OPERAND OPCODE COMMENTS
S CYCLES STATES TIME
1000 START MOV CL,00H 2 2 4 Clear CL reg.
1001 0.84
1002
MOV Transfer first data byte
1003 AX, [1100] 4 2 14 2.94
to accumulator
1004
1005
MOV Transfer second data
1006 BX, [1102] 4 2 14 2.94
byte to BX Register pair
1007
Add the contents of AX
1008 ADD AX, BX 2 2 3 0.63 and BX and store in
Accumulator
1009 Jump to location if
100A JNC L1 2 3 16/4 3.36/0.84 result does not yield
100B carry.
100C INC CL 2 2 3 0.63 Increment CL reg.
100D
Transfer the result from
100E L1 MOV [1104], AX 4 3 15 3.15
acc. to memory.
100F
1010
MOV Move the CL register
1011 [1106], CL 3 3 15 3.15
content to memory.
1012
1013 HLT 1 1 2 0.42 Stop the program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 52

CALCULATION

Clock frequency F=4.77MHz


T-State =Clock Period (1/F) = 0.21µs
Execution time for Opcode Fetch: (4T)*0.5=0.84 µs
Execution time for Memory Read: (3T)*0.5=0.63 µs
Execution time for Instruction: (7T)*0.5=1.47 µs

Observation:

INPUT OUTPUT
ADDRESS 1100 1101 1102 1103 1104 1105 1106 1107
DATA1
DATA2

Conclusion:

Thus the 16 bit numbers stored in memory location are added and the result stored in
another memory location using 8086p kits.

………………………………………………………………………………………………………………………………………..

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 53

Questions:

1. What are the features of 8086 Microprocessor?

2. What is the function of accumulator?

3. What are the different types of flags available in 8086 microprocessor?

4. List the general purpose registers in 8086?

5. What type of architecture used in 8086 microprocessor?

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 54

B) 16-BIT DATA SUBTRACTION-8086


Aim:
To write a program to subtract two 16-bit numbers using 8086.
.

Equipment and Components Required:

8086 Microprocessor kit, Power Supply

Algorithm:

 Start the program.

 Initialize the memory locations with input data.

 Load the values from memory location to the registers..

 Subtract the two values stored in the registers.

 If carry occurs (CF=1) increment the carry storing register and store the difference

and borrow in the memory location. Otherwise store the difference in the memory

location.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 55

Flow chart:

Start

Clear CL Register

Get the content of


1100H &1101H in AX

Get the content of


1102H &1103H in BX

Perform Subtraction
[AX]=[AX]-[BX]

NO
Is
CF=1 ?

YES

Increment CL
Register

Store the Content of


CL register to 1106H

Store the Result


[1104]=[AL],[1105]=[AH]

End
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 56

MACHINE T- EXECUTION
ADDRESS LABEL MNEMONICS OPERAND OPCODE BYTES COMMENTS
CYCLES STATES TIME
1000 START MOV CL,00H 2 2 4 Clear CL reg.
1001 0.84
1002
MOV Transfer first data byte
1003 AX, [1100] 4 2 14 2.94
to accumulator
1004
1005
MOV Transfer second data
1006 BX, [1102] 4 2 14 2.94
byte to BX Register pair
1007
Subtract the contents
1008 SUB AX, BX 2 2 3 0.63 of AX and BX and store
in Accumulator
1009 Jump to location if
100A JNC L1 2 3 16/4 3.36/0.84 result does not yield
100B carry.
100C INC CL 2 2 3 0.63 Increment CL reg.
100D
Transfer the result from
100E L1 MOV [1104], AX 4 2 15 3.15
acc. to memory.
100F
1010
MOV Move the CL register
1011 [1106], CL 3 2 15 3.15
content to memory.
1012
1013 HLT 1 1 2 0.42 Stop the program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 57

CALCULATION

Clock frequency F=4.77MHz


T-State =Clock Period (1/F) = 0.21µs
Execution time for Opcode Fetch: (4T)*0.5=0.84 µs
Execution time for Memory Read: (3T)*0.5=0.63 µs
Execution time for Instruction: (7T)*0.5=1.47 µs

Observation:

INPUT OUTPUT
ADDRESS 1100 1101 1102 1103 1104 1105 1106 1107
DATA1
DATA2

Conclusion:

Thus the 16 bit numbers stored in memory location are subtracted and the result stored
in another memory location using 8086p kits.

………………………………………………………………………………………………………………………………………..

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 58

Questions:

1. What are the two types of conditional jumps?

2. Write short notes on Pointers and Index Group of Registers?

3. List the types of interrupts.

4. What happens when interrupt occurs?

5. Compare 8086 and 8088.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 59

D) 16-BIT DATA MULTIPLICATION-8086


Aim:
To write a program to perform multiplication of two 16 bit number using 8086.

Equipment and Components Required:

8086 Microprocessor kit, Power supply.

Algorithm:

 Start the program.

 Initialize the memory locations with multiplier and multiplicand.

 Load the values from memory locations to the registers.

 Multiply the two 16 bit data stored in the registers.

 Store the product in the memory location.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 60

Flow chart:

Start

Clear CL register

Store the Data1 in


AX register

Store the Data2 in


BX register

Perform
Multiplication
[AX]=[AX]*[BX]]
[DX]=R[[DX][AX]/[BX]]
Store the results in
to memory

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 61

ADDRESS/ MACHINE EXECUTION COMMENTS


LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES
LABEL CYCLES TIME(μs)
1000
START MOV CL, 00H 2 2 14 2.94 Clear CL reg.
1001
1002
MOV Transfer Multiplicand
1003 AX, [1100] 4 2 14 2.94
to accumulator
1004
1005
MOV BX, [1102] Transfer Multiplier to
1006 4 2 14 2.94
BX Register pair
1007
Multiply the contents of
MUL BX AX and BX register
1008 2 2 130 27.3
pairs and store in
Accumulator
1009
MOV Store the lower word to
100A [1104], AX 4 3 15 3.15
memory
100B
100C
MOV [1106], DX Store the higher word
100D 4 3 15 3.15
to memory
100E
1010 HLT 1 1 2 0.42 End of program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 62

CALCULATION

Clock frequency F=4.77MHz


T-State =Clock Period (1/F) = 0.21µs
Execution time for Opcode Fetch: (4T)*0.5=0.84 µs
Execution time for Memory Read: (3T)*0.5=0.63 µs
Execution time for Instruction: (7T)*0.5=1.47 µs

Observation:

INPUT OUTPUT
ADDRESS 1100 1101 1102 1103 1104 1105 1106 1107
DATA1
DATA2

Conclusion:

Thus the 16 bit numbers stored in memory location are multiplied and the result stored in
another memory location using 8086p kits.

………………………………………………………………………………………………………………………………………..

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 63

Questions:

1. List the various logical operations performed by the 8086?

2. How will you perform multiplication without using the MUL instruction?

3. What are the various jump instructions available in 8086 instruction set?

4. Write short notes on zero flag.

5. Define Program Counter.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 64

E) 32-BIT DATA DIVISION-8086


Aim:
To write a program to perform division of a 32 bit number by a 16 bit number using
8086.

Equipment and Components Required:

8086 Microprocessor kit, Power Supply

Algorithm:

 Start the program.

 Initialize the memory locations with divider and dividend.

 Load the values from memory locations to the registers..

 Divide the 32 bit data stored in the registers by the 16 bit data stored in the GP

register.

 Store the quotient and reminder in the memory location.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 65

Flow chart:

Start

Store the lower word


of Dividend in AX

Store the Higher word


of Dividend in DX

Store the Divider in BX

Perform Division
[AX]=Q[[DX][AX]/[BX]]
[DX]=R[[DX][AX]/[BX]]

Store the results in


to memory

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 66

ADDRESS/ MACHINE EXECUTION COMMENTS


LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES
LABEL CYCLES TIME(μs)
1000
START MOV AX, [1100] Store the lower word of
1001 4 3 14 2.94
Dividend in AX
1002
1003 Store the Higher word
MOV DX, [1102] 4 3 14 2.94 of Dividend in DX
1004
1005
1006 Store the Divider in BX
1007 MOV BX, [1104] 4 3 14 2.94
1008
DIV BX Perform Division
1009 2 4 156 31.2
100A
MOV Store the quotient to
100B [1106], AX 4 2 15 3.15
memory
100C
100D
MOV [1108], DX Store the reminder to
100E 4 2 15 3.15
memory
1010
1011 HLT 1 1 2 0.42 End the program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 67

CALCULATION

Clock frequency F=4.77MHz


T-State =Clock Period (1/F) = 0.21µs
Execution time for Opcode Fetch: (4T)*0.5=0.84 µs
Execution time for Memory Read: (3T)*0.5=0.63 µs
Execution time for Instruction: (7T)*0.5=1.47 µs

Observation:

INPUT OUTPUT
ADDRESS 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
DATA1
DATA2

Conclusion:

Thus the 16 bit numbers stored in memory location are divided and the result stored in
another memory location using 8086p kits.

………………………………………………………………………………………………………………………………………..

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 68

Questions:

1. Write short notes on parity flag.

2. List the general purpose registers in 8086?

3. What type of architecture used in 8086 microprocessor?

4. What are the various addressing modes of 8086?

5. Draw the Flag register of 8086.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 69

Lab Exercises:

1. Write an Assembly language program to perform 8-bit addition, subtraction,


multiplication and division using 8086.

2. Write an Assembly language program to add two 32 bit numbers stored as double
words in 8 consecutive memory locations are to be added and the result stored as a
double word in memory using 8086.

3. Write an Assembly language program to convert the number FFFFH to its decimal
equivalent and store the result in memory using 8086.

4. Write an Assembly language program to perform multiplication and division by


powers of 2 using the arithmetic shift instructions using 8086.

5. Write an Assembly language program to perform XOR operation on a 16 bit hexa


decimal number using 8086.

6. Write an Assembly language program to perform NAND operation on a 16 bit hexa


decimal number using 8086.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 70

5. PROGRAM FOR SQUARE ROOT AND SQUARE


OF THE GIVEN INPUT (8086)
Aim:
To write the program for find the square the root and square of given number using
8086.

Equipment and Components Required:

8086 Microprocessor kit, Power Supply

Algorithm: (square)

 Start the program.

 Initialize Source Index and Destination address.

 Load the values from source index to the registers.

 Multiply the two 16 bit data stored in the registers.

 Store the product in the destination address.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 71

Algorithm:(square root)

 Start the program.

 Initialize Source Index and Destination address.

 Load the values from source index to the registers.

 Initialize CX=0001 and BX=0000.

 Subtract CX from AX. If AX is greater than CX, increment CX by 02, and BL also

increment by 01 do the same process until Carry generate.

 Once carry generate, the data in the BL reg stored in Destination address.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 72

Flow chart: (square)

Start

Clear CL register

Store the Data1 in


AX register

Store the Data1 in


BX register

Perform
Multiplication
[AX]=[AX]*[BX]]
[DX]=R[[DX][AX]/[BX]]
Store the results in
to memory

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 73

Program:

EXECUTION COMMENTS
ADDRESS/ MACHINE TIME
LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES
LABEL CYCLES
(micro sec)
1000 MOV AX,[1100] A1 3 2 14 2.94 Move the content to AX
Register
1001 00
1002 11
1003 MUL AX,[1100] F7 4 2 130 27.3 Multiply the AX Register
with data in [1100]
1004 26
1005 00
1006 11
1007 MOV [1200],DX 87 4 2 15 3.15
1008 16
Move the result to
1009 00
memory
100A 12
100B MOV [1202],AX A3 3 2 15 3.15
100C 02
100D 12
100E HLT F4 1 1 2 0.42 End of execution
VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 74

Observation:

INPUT OUTPUT

1100 1104
1101 1106

V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 75

Flow chart: (square)

Start

Move the data to AX


reg

Move address of data to SI


Move address of result to DI

Initialize
CX=0001,BX=0000.

[AL]-[BL] [AL]
[CL]+02 [CL]

YES
IF
Increment the [AL]>[BL]
data in BL reg

NO

Move the data from


BL reg to DI

End

V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 76

V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 77

Program:

ADDRESS/ MACHINE EXECUTION COMMENTS


LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES
LABEL CYCLES TIME
2 14 Move the content to AX
1000 MOV AX,1100 8B 4 2.94
Register
1001 06
1002 00
1003 11
Move the data to B
1004 MOV BX,0FFFF C7 4 2 14 2.94
register
1005 C3
1006 FF
1007 FF
1008 MOV CX,0000 C7 4 2 14 2.94 Initialize C register
1009 C1
100A 00
100B 00
100C L1 INC CX 41 1 1 3 0.63 Increment C register
Add B register data with
100D ADD BX,02 81 4 1 4 0.84
02
100E C3
1010 02
1011 00
Subtract Data of BX register
1012 SUB AX,BX 29 2 1 3 0.63
from AX Register
1013 D8
1014 JNZ LI 75 2 2 4 0.84 Jump No Zero
1015 F7
Move data from C register
1016 MOV [1200],CX 89 4 2 15 3.15
to 1200
1017 0E
V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 78

1018 00
1019 12
1020 HLT F4 1 1 2 0.42 End of execution

V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 79

V VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 80

Observation:

INPUT OUTPUT

1100 1104
1101 1106

Conclusion:

Thus an ALP was written for 16-bit square the root and square of given number and
executed using 8086p kits

………………………………………………………………………………………………………………………………………..

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 81

Questions:

1. Give the significance of 8086.

2. Define STACK.

3. Compare 8085 And 8086

4. What is the maximum capacity of memory that can be identified with 8086?

5. What is the difference between RAR and RAL instructions in 8086?

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 82

Lab Exercise:

1. Write a program to find the square of a given number which is stored in memory
location 1102 and store the result in 1107 using 8086kit.

2. Write a program to find the square root of a given number which is stored in
memory location 1104 and store the result in 1108 using 8086kit.

3. Write a program to find the square of a given number which is stored in memory
location 1101 and store the result in 1107 using 8086kit.

4. Write a program to find the square and cube of a given number which is stored in
memory location 1101 and store the result in 1107, 1108 using 8086kit.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 83

6. INTERFACING OF STEPPER MOTOR USING 8086


Aim:
To write an assembly language program for running a stepper motor using 8086.

.
Equipment and Components Required:

8086 Microprocessor kit, Stepper motor, Driver circuit.

Theory

A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a step-wise manner from one
equilibrium position to the next. Stepper Motors are used very wisely in position control
systems like printers, disk drives, process control machine tools, etc.

The basic two-phase stepper motor consists of two pairs of stator poles. Each of
the four poles has its own winding. The excitation of any one winding generates a North
Pole. A South Pole gets induced at the diametrically opposite side. The rotor magnetic
system has two end faces. It is a permanent magnet with one face as South Pole and the
other as North Pole.

The Stepper Motor windings A1, A2, B1, and B2 are cyclically excited with a DC
current to run the motor in clockwise direction. By reversing the phase sequence as A1,
B2, A2, B1, anticlockwise stepping can be obtained. The commonly used switching
scheme is two – phase switching scheme which is shown below

CLOCKWISE ANTICLOCKWISE

STEP A1 A2 B1 B2 DATA STEP A1 A2 B1 B2 DATA


1 1 0 0 1 09H 1 1 0 1 0 0AH
2 0 1 0 1 05H 2 0 1 1 0 06H
3 0 1 1 0 06H 3 0 1 0 1 05H
4 1 0 1 0 0AH 4 1 0 0 1 09H

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 84

The step angle of the stepper motor available in the laboratory is 1.80

As per I/O decoding given by the manufacturer, the 8-bit address for sending data is
C0H

Look up Table:

Direction 1037 1038 1039 103A


Clockwise 09 05 06 0A
103B 103C 103D 103E
Anticlockwise 0A 06 05 09

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 85

ADDRES MACHIN T- EXECUTION


LABEL MNEMONICS OPERAND OPCODE BYTES COMMENTS
S E CYCLES STATES TIME
1 0 0 0 START M O V B L , 2 0 H B3, 20 2 2 7 T Move 20H to BL register
1 . 4 μ s
1 0 0 2 FORWD M O V DI, OFFSET FORW BF, 37, 10 3 3 1 0 T 2 μ s Move the input address to DI register to rotate in forward direction

1 0 0 5 C A L L R O T A T E E8, 18,00 3 3 1 0 T 2 μ s Call the loop address

1 0 0 8 D E C B L FE, CB 2 1 4 T 0 . 8 μ s Decrement the BL register by one


1 0 0 A J N
Z F O R W D 75, F6 2 2 / 3 7T/10T 1 . 4 μ s / 2 μ s Jump if no zero to loop address
1 0 0 C C A L L D E L A Y E8, 21, 00 3 3 1 0 T 2 μ s Call the loop address

1 0 0 F M O V B L , 2 0 H B3, 20 2 2 7 T 1 . 4 μ s / 2 μ s Move20HtoBLregister
1 0 1 1 REVER M O V DI, OFFSET REV BF, 3B, 10 3 3 1 0 T 2 μ s MovetheinputaddresstoDIregistertorotateinreverse direction
1 0 1 4 C A L L R O T A T E 2 μ s
E8, 09, 00 3 3 1 0 T Call loop address

1 0 1 7 D E C B L FE, CB 2 1 4 T 0 . 8 μ s DecrementtheBLregisterbyone
1 0 1 9 J N Z R E V E R 75, F6 2 2 / 3 7T/10T 1 . 4 μ s / 2 μ s Jumpifnozerotoloopaddress
1 0 1 B C A L L D E L A Y E8, 12, 00 3 3 1 0 T 2 μ s Call delay subroutine

1 0 1 E J M P S T A R T EB, E0 2 3 1 0 T 2 μ s Jump to starting address

1 0 2 0 ROTATE M O V C L , 0 4 B1, 04 2 2 7 T 1 . 4 μ s MovethecountvaluetoCL register


1 0 2 2 R E P T M O V A L , [ D I ] 8A, 05 2 2 7 T 1 . 4 μ s Move the DI value to AL regiater
1 0 2 4 O U T PORT1, AL E6, C0 2 2 7 T 1 . 4 μ s Transfer the AL value to out port address
1 0VTU
2 R62015 M O V DX, 1010H BA, 10, 10 3 3 1 0 T 2 μ s Move 1010 value to DX register

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 86

1 0 2 9 LOOP 1 D E C D X 4 A 1 1 4 T 0 . 8 μ s DecrementtheDXregisterbyone
1 0 2 A J N Z L O O P 1 75, FD 2 2 / 3 7T/10T 1 . 4 μ s / 2 μ s Jumpifnozerotoloopaddress
1 0 2 C I N C D I 4 7 1 1 4 T 0 . 8 μ s Increment DI register
1 0 2 D L O O P R E P T E2, F3 2 2 6 T 1 . 2 μ s Jump to loop address
1 0 2 F R E T C 3 1 1 4 T 0 . 8 μ s Return from subroutine
1 0 3 0 M O V DX, 0FFFFH BA, FF, FF 3 3 1 0 T 2 μ s Move FFFF to DX register

1 0 3 3 DELAY D E C D X 4 A 1 1 4 T 0 . 8 μ s Decrement DX register


1 0 3 4 J N Z D E L A Y 75, FD 2 2 / 3 7T/10T 1 . 4 μ s / 2 μ s Jump if no zero to loop address
1 0 3 6 R E T C 3 1 1 4 T 0 . 8 μ s Return from subroutine
1 0 3 7 FORW D B 09, 05,06,0AH 09, 05,06,0A Inputdataforforwarddirection
1 0 3 B R E V D B 0AH, 06, 05, 09 0A, 06, 05, 09 Inputdataforreverse direction

VTU R 2015

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 87

Conclusion:

Thus a stepper motor was interfaced with 8086 and run in forward and reverse directions
at various speeds.

………………………………………………………………………………………………………………………………………..

Questions:

1. In a two phase bipolar stepper motor, how many field coils are placed?

2. What is meant by Holding Torque?

3. In a stepper motor the speed is directly proportional to the frequency of input


electrical pulses?

4. Find the step angle of a three phase stepper motor which 12 rotor teeth in it?

5. The three phase stepper motor consists of 4 teeth in its rotor. How many steps are
required by the motor to complete one full revolution?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 88

Lab Exercises:

1. Write a program for a stepper motor to rotate it continuously.

2. Write a program to rotate a motor 700 in the clockwise direction. The motor has a
step angle of 70 .

3. Write a program in ALP to interface stepper motor to 8086 and rotate it in anti-
clockwise direction.

4. Write a program in ALP to interface stepper motor to 8086 and rotate it in


clockwise direction.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 89

7. PROGRAM FOR ALU OPERATION (8051)


Aim:
To write a program to do the arithmetic operations using 8051 microcontroller.

Equipment and Components Required:

Power supply, 8051 kit

Algorithm:

 Step 1 : Start the program

 Step 2 : Get the two values

 Step 3 : Add / subtract the values for multiply /Division(do the repeated
addition/subtraction)

 Step 4 : Store the result

 Step 5: Stop.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 90

Flow chart:

Start

Get the numbers

ADD/SUB/MUL/DIV
Numners

Store the result

Stop

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 91

Program:
8-bit Addition

Address/ Machine Execution


Mnemonics Operand Opcode Bytes T-states Comments
label cycles time

4100 CLR C C3 1 1 12T 12us Clear the carry flag


4101 MOV A1, #Data 1 74
4102 #Data 1 2 1 12 12us Move data 1 to accumulator
4103 ADD A1,# Data 2 24
Add the content of accumulator and
4104 # Data 2 2 1 12 12us
data2 and store in a accumulator
DPTR,
4105 MOV 96 3 2 24 24us Moves data 4500 to DPTR
#4500H

4106 45
4107 00

Moves the content of accumulator to


4108 MOVX @ DPTR, A F0 1 2 24 24us
location pointer

4109 L1 SJMP L1 80 2 2 24 24us Jump to 4109


410A FE

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 92

Calculation:
Crystal Oscillator frequency of 8051 = 12MHz
Clock period = (1/F) =1us
Clock frequency = 1MHZ

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 93

Program:
8-bit Subtraction

Bytes Machine Execution Comments


Address/label Mnemonics Operand Opcode T-states time
cycles
4100 CLR C C3 1 1 12 12us Clear the C register
A1, 2 12us
4101 MOV 74 1 12 Move the data 1 to accumulator
#Data 1
4102 Data 1
2 12us
Subtract the content of
A2,#Data
4103 SUBB 94 1 12 accumulator and data2 result
2
stored in acc

4104 #Data 2
4105 MOV DPTR 96 3 2 24 24us Moves data 4500 to DPTR
4106 #4800 45
4107 00
X@DTP 1 24us Moves content of accumulator
4108 MOV F0 2 24
R,A location pointer DPTR
4109 SJMP L1 80 2 2 24 24us Jump to 4109
410A FE

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 94

Execution:

Addition:

ML Input
ML Output
4102 03
4500 06
4104 03

Calculation:
Crystal Oscillator frequency of 8051 = 12MHz
Clock period = (1/F) =1us
Clock frequency = 1MHZ

Execution:
Subtraction:

ML Input ML Output

4102 08 4500 04

4104 04

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 95

Program:
8-bit Multiplication

4100 CLR C C3 1 1 12 12us Clear the C register


A1, 1 12us
4101 MOV 74 1 12 Move the data 1 to accumulator
#Data 1
4102 Data 1
A2,#Dat 3 12us
4103 MOV 75 1 12 Move the data 2 to register B
a2
4104 F0
4105 DATA 2 3 2 24 24us Moves data 4500 to DPTR
1 12us Multiply accumulator content and
4106 MUL A,B A4 1 12
store the result
4107 MOV DPTR 90 3 2 24 12us Moves data 4500 to DPTR
4108 #4500 H 45
4109 00
@DPTR, 1 12us
410A MOV X F0 1 12 Moves result by location pointer
A
410B INC DPTR A3 1 1 12 12us Increment data to DPTR
410C MOV A,B FF 2 1 12 12us Moves the content of B to A
410D F0
@DPTR, 1 24us
410E MOVX F0 2 24 Moves location by pointer DPTR
A
410F/ 2 24us
SJMP L1 80 2 24 Jump to410F
L1
4110 FE

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 96

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 97

Calculation:
Crystal Oscillator frequency of 8051 = 12MHz
Clock period = (1/F) =1us
Clock frequency = 1MHZ

Execution:
Multiplication:
ML Input
ML Output
4102 05
4500 0F
4104 03

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 98

Program:
8 – Bit Division

Operan Bytes Machine T- Execution Comments


Address/label Mnemonics Opcode
d cycles states time
4100 CLR C C3 1 1 12 12us Clear the C register
A1, 1 12us Move the data 1 to
4101 MOV 74 1 12
#Data 1 accumulator
4102 Data 1
A2,#Dat 3 12us Move the data 2 to
4103 MOV 75 1 12
a2 register B
4104 F0
3 24us Moves data 4500 to
4105 DATA 2 2 24
DPTR
1 12us Divide accumulator
4106 DIV A,B A4 1 12
content by reg B
3 12us Moves data 4500 to
4107 MOV DPTR 90 2 24
DPTR
4108 #4500 H 45
4109 00
@DPTR, 1 12us Moves result by
410A MOV X F0 1 12
A location pointer
1 12us Increment data to
410B INC DPTR A3 1 12
DPTR
2 12us Moves the content of
410C MOV A,B FF 1 12
B to A
410D F0
@DPTR, 1 24us Moves location by
410E MOVX F0 2 24
A pointer DPTR
410F/L1 SJMP L1 80 2 2 24 24us Jump to410F
4110 FE

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 99

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 100

Calculation:
Crystal Oscillator frequency of 8051 = 12MHz
Clock period = (1/F) =1us
Clock frequency = 1MHZ

Execution:
Divison:
ML Input
ML Output
4102 08
4500 02
4104 04

Conclusion:

Thus an ALP was written for arithmetic operations using 8051 microcontroller and
executed using 8051 controller kit.

……………………………………………………………………………………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 101

Questions:

1. Which control signals of 8051 are used to access external data memory and external
program memory

2. State any two applications of 8051

3. How does 8051 differentiate between external and internal program memory?

4. What is the use of DTPR?

5. What are the addressing modes supported by 8051.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 102

Lab Exercises:

1. Two numbers are stored in registers R0 and R1. Verify if their sum is greater than
FFH.

2. Write programs to add two 16-bit numbers, the numbers are FC45H and 02ECH.

3. Write programs to add two 32-bit numbers stored in RAM locations.

4. Assume that 5BCD data items are stored in RAM locations starting at 40H,as shown
below. Write a program to find the sum of the numbers. The result must be in BCD.
a. 40= (71)
b. 41= (11)
c. 42= (65)
d. 43= (59)
e. 44= (37)

5. In a semester, a student has to take six courses. The marks of the student (out of 25)
are stored in RAM locations 47H onwards. Find the average marks, and output it on
port 1.

6. Write a program to convert a Hexadecimal number to decimal.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 103

8. PROGRAM FOR BIT MANIPULATION AND MASKING


FOR THE GIVEN INPUT (8051)

Aim:
To write ALP for performing Bit manipulation and masking operations in 8051
.

Equipment and Components Required:

Power supply, 8051 kit

Algorithm:

Bit Manipulation

 Start the program


 Initialize the data
 Manipulate bit using OR operation
 Initialize the pointer
 Move the result to memory pointed by DPTR
 Stop the program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 104

Flow chart:

Start

Out 1H data in memory

By using Logical operator


OR on [data 1] &[data2]

Initialize DPTR

Move the result to


memory

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 105

Program for Bit Manipulation :

ADDRESS/ MACHINE EXECUTION


MNEMONICS OPERAND OPCODE BYTES T-STATES COMMENTS
LABEL CYCLES TIME

Move Ist data to Acc


4100 MOV A,#data1 74,2F 2 1 12T 12 μs
Perform OR operation of data 2
4102 ORL A,#data1 44,45 2 1 12T 12 μs with Acc

DPTR,# Move the result to DPTR


4103 MOV 90,45,00 3 2 24T 24 μs
4500
Move Acc content to DPTR
4104 MOVX @DPTR, A F0 1 2 24T 24μs
Short jump here
4105 SJMP HERE 80,FE 2 2 24T 24 μs
Stop the Program
4107 HLT 76 1 1 1T 1 μs

Observation:

INPUT OUTPUT

4101 03
4500 02
4103 02

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 106

Algorithm:

Masking

 Start the program


 Initialize the data
 Manipulate bit using AND operation
 Initialize the pointer
 Move the result to memory pointed by DPTR
 Stop the program

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 107

Flow chart:

Start

Out 1H data in memory

By using Logical operator


OR on [data 1] &[data2]

Initialize DPTR

Move the result to


memory

End

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 108

Program for masking:

ADDRESS MACHINE EXECUTION


MNEMONICS OPERAND OPCODE BYTES T-STATES COMMENTS
/LABEL CYCLES TIME

Move Ist data to Acc


4100 MOV A,#data1 74,2F 2 1 12T 12 μs
Perform AND
operation of data 2
4102 ANL A,#data1 44,45 2 1 12T 12 μs
with Acc

DPTR,# 90,45, Initialize the DPTR


4103 MOV 3 2 24T 24 μs
4500 00
Move Acc content to
@DPTR,
4104 MOVX F0 1 2 24T 24μs DPTR
A
Short jump here
4105 SJMP HERE 80,FE 2 2 24T 24 μs
Stop the Program
4107 HLT 76 1 1 1T 1 μs

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 109

Observation:

INPUT OUTPUT

4101 03
4500 05
4103 02

Calculations:

Crystal Oscillator frequency of 8051 = 11.0529MHz


With respect to clock cycle = 11.0529/12 = 921.6 KHz
For One Machine Cycle (Time) = (1/F) =1/ 921.6 = 1.085μs

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 110

Conclusion:

Thus an ALP was written for 8Bit manipulation and masking operations in 8051

……………………………………………………………………………………………………………………………

Questions:

1. What happens in power down mode of 8051 micro controller?

2. What is that register addressing mode in 8051 microcontroller?

3. Name the two external interrupt of 8051 microcontroller.

4. Specify any two applications of Microcontrollers.

5. What do you mean by Indirect Addressing Mode?

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 111

Lab Exercises:

1. Write a program to create a square wave of 50 % duty cycle on bit 0 of port 1.

2. Write a program to create a square wave of 66 % duty Cycle on bit 3 of port 1.

3. A switch is connected to pin P1.7.Write a program to check the status of SW and


perform the following:
If SW = 0, send letter ‘N’ to P2.
If SW = 1, send letter ‘Y’ to P2.

4. A switch is connected to pin P1.0 and an LED to Pin P2.7. Write a program to get the
status of the switch and send it to the LED.

5. Write a program to take in data through P1.0 and send it through P2.7.

6. Mask off the LN of memory location 4150 and place the result at 4151.

7. Mask off the 7th and 3rd bits of register H which contain B9. Store the result at 4150.
(Use AND instruction).

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 112

9. ADC AND DAC INTERFACING USING 8051


MICROCONTROLLER

Aim:
To write an assembly language program to interface ADC and DAC using 8051.

.
Equipment and Components Required:

8051 microcontroller kit, 8255 interface, DAC Kit, Power cord, RS232 cord.

Algorithm for ADC:

 Select the channel and latch the address

 Send the start conversion pulse.

 Read EOC signal.

 If EOC = 1 continue else go to pervious step i.e. read EOC signal.

 Read the digital output.

 Store in the memory location.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 113

ADC Circuit Diagram:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 114

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 115

MACHINE EXECUTION
ADDRESS LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES COMMENTS
CYCLES TIME
4100 MOV DPTR, #FFC8 90 FF C8 3 2 24T 24µsec Control Register
4103 MOV A, #10 74 10 2 1 12T 12 Select channel 0

4105 MOVX @DPTR, A F0 1 2 24T 24 Make ALE Low

4106 MOV A, #18 74 18 2 1 12T 12 Make ALE High

4108 MOVX @DPTR, A F0 1 2 24T 24

4109 MOV DPTR, #FFD0 90 FF D0 3 2 24T 24

410C MOV A, #01 74 01 2 1 12T 12 SOC Signal HIGH

410E MOVX @DPTR, A F0 1 2 24T 24

410F MOV A, #00 74 00 2 1 12T 12 SOC Signal LOW

4111 MOVX @DPTR, A F0 1 2 24T 24

4112 MOV DPTR, #FFD8 90 FF D8 3 2 24T 24

WAIT:
4115 MOVX A, @DPTR E0 1 2 24T 24

4116 JNB E0, WAIT 30 E0 FC 3 2 24T 24 Check for EOC

4119 MOV DPTR, #FFC0 90 FF C0 3 2 24T 24 Read ADC Data

411C MOVX A, @DPTR E0 1 2 24T 24

4110 MOV DPTR, #4150 90 4150 3 2 24T 24 Store the DATA IN

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 116

4120 MOVX @DPTR, A F0 1 2 24T 24 Memory Location

HERE:

4121 SJMP HERE 80 FE 2 2 24T 24

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 117

Calculations:
 Crystal Oscillator frequency of 8051 = 11.0529MHz
 With respect to clock cycle = 11.0529/12 = 921.6 KHz
 For One Machine Cycle (Time) = (1/F) =1/ 921.6 = 1.085 sec

Observation:

DIGITAL OUTPUT
SL.NO VOLTAGE INPUT
( IN HEXADECIMAL)
1

3
Algorithm for DAC:
 Inline ports
 Give low input
 Output data to port
 Give delay
 Give high
 Give high input
 Output data to ports
 Give delay

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 118

DAC Circuit Diagram:

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 119

Flow chart:

Program for DAC:


1. Square wave generation

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 120

LABEL BYTES MACHINE T-STATES EXECUTION


ADDRESS OPERAND OPCODE COMMENTS
MNEMONICS CYCLES TIME
MOV 3 2 24T 24µsec
4100 DPTR, #FFC8 90 FF C8 Control Register
MOV 2 1 12T 12
4103 A, #10 74 10 Select channel 0
MOVX 1 2 24T 24
4105 @DPTR, A F0 Make ALE Low
MOV 2 1 12T 12
4106 A, #18 74 18 Make ALE High
MOVX 1 2 24T 24
4108 @DPTR, A F0
MOV 3 2 24T 24
4109 DPTR, #FFD0 90 FF D0
MOV 2 1 12T 12
410C A, #01 74 01 SOC Signal HIGH
MOVX 1 2 24T 24
410E @DPTR, A F0
MOV 2 1 12T 12
410F A, #00 74 00 SOC Signal LOW
MOVX 1 2 24T 24
4111 @DPTR, A F0
MOV 3 2 24T 24
4112 DPTR, #FFD8 90 FF D8
WAIT:

MOVX 1 2 24T 24
4115 A, @DPTR E0
JNB 3 2 24T 24
4116 E0, WAIT 30 E0 FC Check for EOC
MOV 3 2 24T 24
4119 DPTR, #FFC0 90 FF C0 Read ADC Data
MOVX 1 2 24T 24
411C A, @DPTR E0
MOV 3 2 24T 24
4110 DPTR, #4150 90 4150 Store the DATA IN

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 121

MOVX 1 2 24T 24
4120 @DPTR, A F0 Memory Location
HERE:

SJMP 2 2 24T 24
4121 HERE 80 FE

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 122

2.

Observation:

Data Output Voltage

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 123

Conclusion:

Thus the assembly language program for interface ADC and DAC was written and verified
using 8051.

……………………………………………………………………………………………………………………………

Questions:

1. What are the internal devices of a typical DAC?

2. Why do we need relay interface?

3. What is settling or conversion time in DAC?

4 What are the different types of ADC?

5. Give the format of program clock word of 8279 and mention its purpose.

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 124

Lab Exercise:

1. Write an assembly language program for DAC that generates a saw tooth wave at
the output of the DAC at channel 0

2. Write an assembly language program for ADC that initializes the channel and read
the digital data.

3. Write an assembly language program to read the data from channel and display
the digital data in the seven segment display

VTU R 2015, Dept. of ECE, Vel Tech RangarajanDr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 125

11. KEYBOARD AND DISPLAY INTERFACE WITH


8051
Aim:
Write a ALP to initialize 8279 and to display the rolling message 'HELP US' in
the display. However, before sending codes to the display RAM, a write display RAM
control word should be sent. Then, write the data to be displayed, to the data register.

Equipment and Components Required:

8051 microcontroller kit,8279 interface board, Power cord

Algorithm:

 Start the program

 Initialize the lookup table pointer and counter.

 Initialize keyboard and display mode 8279.

 Initialize pre scalar count.

 Initialize 8279 in display RAM write mode.

 Get 7 segment code.

 Write 7 segment code in the display RAM

 Increment lookup table pointer.

 Decrement counter.

 Display value.

Flow chart:
VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 126

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 127

Program:

ADDRESS/ MACHINE T- EXECUTION


MNEMONICS OPERAND OPCODE BYTES COMMENTS
LABEL CYCLES STATES TIME
Write command word to the
4100/START MOV DPTR,#FFC2 90,FF,C2 3 2 24 26.04 µs
command word register
4103 MOV R0,#00 78,00 2 1 12 13.02 µs
To initialize Look up table at 4400
13.02 µs
4105 MOV R1,#44 79,44 2 1 12
13.02 µs
4107 MOV A,#10 74,10 2 1 12 Move the data 10H to accumulator
Move the content of accumulator to
4109 MOVX @DPTR,A F0 1 2 24 26.04 µs
the DPTR address
410A MOV A,#CC 74,CC 2 1 12 13.02 µs Move the data CCH to accumulator
Move the content of accumulator to
410C MOVX @DPTR,A FO 1 2 24 26.04 µs
the DPTR address
410D MOV A,#90 74,90 2 1 12 13.02 µs Move the data 90H to accumulator
Move the content of accumulator to
410F MOVX @DPTR,A F0 1 2 24 26.04 µs
the DPTR address
13.02 µs
4110/LOOP MOV DPH,R1 89,83 2 1 12 Move the content of R1 to the DPH
13.02 µs
4112 MOV DPL,R0 88,82 2 1 12 Move the content of R0 to the DPL
26.04 µs Move the content in DPTR address
4114 MOVX A,@DPTR E0 1 2 24
to accumulator
26.04 µs Write command word to the
4115 MOV DPTR,#FFC0 90,FF,C0 3 2 24
command word register
26.04 µs Move the content of accumulator to
4118 MOVX @DPTR,A F0 1 2 24
the DPTR address
26.04 µs
4119 LCALL DELAY 12,45,00 3 2 24 Call DELAY Subroutine

411C INC R0 08 1 1 12 13.02 µs Increment R0 register content


Compare and jump to LOOP if not
411D CJNE R0,#0F,LOOP B8,0F,F0 3 2 24 26.04 µs
equal
4120 LJMP START 02,81,00 3 2 24 26.04 µs Jump to Start

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 128

DELAY SUBROUTINE:

ADDRESS/LAB MACHINEC EXECUTION


MNEMONICS OPERAND OPCODE BYTES T-STATES COMMENTS
EL YCLES TIME
4500 MOV R4,#A0 7C,A0 2 1 12 13.02 µs Move the data A0H to R4

4502/LOOP2 MOV R5,#FF 7D,FF 2 1 12 13.02 µs Move the data FFH to R5

4504/LOOP1 NOP 00 1 1 12 13.02 µs No operation


Decrement and jump to
4505 DJNZ R5,LOOP1 DD,FD 2 2 24 26.04 µs
LOOP1 if not zero
Decrement and jump to
4507 DJNZ R4,LOOP2 DD,F9 2 2 24 26.04 µs
LOOP2 if not zero
4509 RET 22 1 2 24 26.04 µs Return to main routine

Look-Up Table:

4400 FFH FFH FFH FFH

4404 FFH FFH FFH FFH

4408 98H 68H 7CH C8H

440C FFH ICH 29H FFH

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 129

Calculations:

Crystal Oscillator frequency of 8051 =11.0529MHz


Clock Frequency =11.0529MHz/12
=921.6KHz
For one machine cycle (Time) =(1/F)=1/921.6 KHz
=1.085 µs

OUTPUT:

HELP US(in Scrolling)

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 130

Conclusion:

Thus an ALP program interface for keyboard and data was displayed using 8051.

……………………………………………………………………………………………………………………………………

Questions:

1. What are the tasks involved in keyboard interface?

2. How a keyboard matrix is formed in keyboard interface using 8279?

3. What is scanning in keyboard and what is scan time?

4What is scanning in display and what is the scan time?

5. Give the format of program clock word of 8279 and mention its purpose.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 131

Lab Exercise:

1. Write an ALP program to send letters `HELLO HELP US’ to the LCD using delays.

2. Write an ALP program to send letters `VELTECH’ to the LCD using busy flag method

3. Write an ALP program to send letters `WELCOME’ to the LCD.

4. Write an ALP program to send letters `MPMC LAB’ to the LCD and verify.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 132

12. INTERFACEING OF DC MOTOR WITH 8051


Aim:

To write an assembly language program for running a DC motor using 8051.

Equipment and Components Required:

8051 microcontroller kit, DC Motor Interface board, Power cord

Theory:

A DC motor is any of a class of rotary electrical machines that converts direct current
electrical energy into mechanical energy. The most common types rely on the forces produced by
magnetic fields. Nearly all types of DC motors have some internal mechanism, either
electromechanical or electronic; to periodically change the direction of current flow in part of the
motor.
DC motors were the first type widely used, since they could be powered from existing
direct-current lighting power distribution systems. A DC motor's speed can be controlled over a
wide range, using either a variable supply voltage or by changing the strength of current in its field
windings. Small DC motors are used in tools, toys, and appliances.
The universal motor can operate on direct current but is a lightweight motor used for
portable power tools and appliances. Larger DC motors are used in propulsion of electric vehicles,
elevator and hoists, or in drives for steel rolling mills. The advent of power electronics has made
replacement of DC motors with AC motors possible in many applications. The principle of working
of a DC motor is that "whenever a current carrying conductor is placed in a magnetic field, it
experiences a mechanical force".

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 133

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 134

Program:

MACHINE EXECUTION
ADDRESS LABEL MNEMONICS OPERAND OPCODE BYTES T-STATES COMMENTS
CYCLES TIME
4100 MOV A,#FF 74 FF 2 1 12 13.02 μs
4101
4102
4103 MOV DPTR,#FFC0 90 FF C0 3 2 24 26.04 μs
4104
4105 MOVX @DPTR,A F0 1 2 24 26.04 μs
4106 LOO SJMP
P LOOP 80 FE 2 2 24 26.04 μs
4107

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 135

Calculations :

Crystal Oscillator frequency of 8051 = 11.0529MHz


With respect to clock cycle = 11.0529/12 = 921.6 KHz
For One Machine Cycle (Time) = (1/F) =1/ 921.6 = 1.085 μs

Conclusion:

Thus an ALP for DC motor interfacing in 8051 microcontroller was written and executed.

…………………………………………………………………………………………………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 136

Questions:

1. List the ports in 8255.

2. What are modes available in 8255?

3. What is stall in a DC motor?

4. How do we change a DC motor’s rotation direction?

5. Why do we put a driver between the microcontroller and the DC motor?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 137

Lab Exercise:

1. A switch is connected to pin P2.7. Write a program to monitor the status of SW and
perform if SW=0, the DC motor moves clockwise.

2. A switch is connected to pin P2.5. Write a program to monitor the status of SW and
perform if SW=1, the DC motor moves counter clockwise.

3. A switch is connected to pin P1.5. Write a program to monitor the status of SW and
perform verify the speed limitations.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 138

13. TIMER PROGRAMMING USING KEIL C

Aim:
To write a C program to toggle all the bits of P0 and P2 Continuously with delay
using the inverting and Ex-OR operators in 8051.

Equipment and Components Required:

PC, Keil software

Algorithm:

 Start the program

 Declare the header file.

 Initializing port0 and port2 with an input value.

 Inverting the P0 value by a NOT operator.

 P2 input value is toggled by using EX-OR operation with 0xFF.

 Calling the delay of 250ms.

 The bits in P0 and P2 are toggled with the delay.

 Stop the program.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 139

Flowchart:
Start

Assign the values to


the ports
y

While (1)

Stop

Invert the port 0


variables

Ex-OR the port 1


variables

Call the delay


routine

Initialize the timer


register

While n
(TF0==0)

y
Toggle the values

Stop

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 140

Program:

#include <reg51.h>

void MSDelay();

void main()

P0=0x55;

P2=0x55;

while(1)

P0=~P0;

P2=P2^0xFF;

MSDelay();

void MSDelay()

TMOD=0x01;

TL0=0x00;

TH0=0x35;

TR0=1;

while (TF0==0);

TR0=0;

TF0=0;

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 141

Observation:

Port 0

√ √ √ √

√ √ √ √

Port 2

√ √ √ √

√ √ √ √

Conclusion:

Thus the C program to toggle all the bits of P0 and P2 continuously was written and
executed in 8051.

……………………………………………………………………………………………………………………
VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 142

Questions:

1. What is the clock source for the timers?

2. What is the function of the TMOD register?

3. What is the maximum delay that can be generated with the crystal frequency of 22MHz?

4. Auto reload mode is allowed in which mode of the timer?

5. Find out the roll over value for the timer in Mode 0, Mode 1 and Mode 2?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 143

Lab Exercises:

1. Develop an 8051 program using KEIL simulator to toggle the Port 0 1 st pin with a
timer delay 0f 5000μs using timer 0 mode 1.

2. Develop an 8051 C program to toggle only pin PI.7 continuously every 250 ms. Use
Timer 0, mode 2 (8-bit auto-reload) to create the delay.

3. Develop an 8051 C program to toggle only bit P3.5 continuously every 700 ms. Use
Timer 1, mode 1 (16-bit) to create the delay. Test the program on the AT89C51.

4. Developa 8051 C program to toggle all the bits of port P1 continuously with some
delay in between. Use Timer 0, 16-bit mode to generate the delay.

5. Write an 8051 C program to toggle all bits of P2 continuously every 500 ms. Use Timer
1. mode 1 to create the delay.

6. A switch is connected to pin PI.2. Write an 8051 C program to monitor SW and create
the following frequencies on pin PI.7: SW=0: 500 Hz SW=1: 750 Hz Use Timer 0, mode
1 for both of them.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 144

14. SERIAL PORT PROGRAMMING USING KEIL C

Aim:
To write a C program to transfer the letter “A” serially at 9600 baud continuously
in 8051.

on pin P2.5
Equipment .Use
and timer 0 toRequired:
Components create a square wave. Assume that XTAL=24 MHZ.

PC, Keil software

Algorithm:

 Start the program

 Declare the header file.

 Set the timer1 in mode 2.

 Set the baud rate to 9600.

 Set the SCON register to 50.

 Set the timers run bit.

 Start transferring the letter until timer interrupt becomes one.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 145

Flowchart:

Start

Initialize the timer


register

While (1)

No

Yes

Start transferring
the letter

Stop

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 146

rogram:

#include <reg51.h>

void main(void)

TMOD=0x20;

TH1=0XFD;

SCON=0x50;

TR1=1;

while(1)

SBUF ='A';

while(TI==0);

TI=0;

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 147

Observation:

UART#1:

AAAAAAAAAAA

Conclusion:

Thus the C program to transfer the letter “A” serially at 9600 baud continuously in 8051 is
written and executed.

…………………………………………………….…………………………………………………………………………………

Questions:

1. With fosc= 8 MHz, what will the count that has to filled in the UBRR register to account for
the 9600 baud rate?

2. The USART in AVR based micro controllers operate at which of the following modes?

3. Which of the following parameters should the transmitter and the receiver agree upon
before startinga serial transmission?

4. What is the use of the PE and the FE bits of the UCSRA register?

5. What does RI handshaking signal refer to according to the RS232 logic?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 148

Lab Exercises:

1. Develop an 8051 program using KEIL simulator to serially transmit the given
characters ‘INDIA’ with a baud rate of 9600 μs. Using timer 1 mode 1.

2. Develop an 8051 program using KEIL simulator to serially transmit the given
characters ‘ECE ROCKS’ with a baud rate of 4600 μs. Using timer 0 mode 1.

3. Develop an 8051 program using KEIL simulator to serially transmit the given
characters ‘WELCOME’ with a baud rate of 4600 μs. Using timer 1 mode 0.

4. Write an 8051 C program to send the two messages “Normal Speed” and “High Speed”
to the serial port. Assuming that SW is connected to pin P2.0, monitor its status and set
the baud rate as follows: SW = 0 28,800 baud rate SW = 1 56K baud rate Assume that
XTAL = 11.0592 MHz for both cases.

5. Write a C program that continuously gets a single bit of data from PI. 7 and sends it to
Pl.O in the main, while simultaneously (a) creating a square wave of 200 us period on
pin P2.5, and (b) sending letter ‘A’ to the serial port. Use Timer 0 to create the square
wave. Assume that XTAL = 11.0592 MHz. Use the 9600 baud rate.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 149

15. INTERRUPT PROGRAM USING KEIL C


Aim:
To write a C program to continuously get a single bit of data from P1.7 and sends it to P1.0
while simultaneously creating a square wave of 200micro sec period on pin P2.5 .Use timer 0
to create a square wave. Assume that XTAL=24 MHZ.

Equipment and Components Required:

PC, Keil software

Algorithm:

 Load IE register with respect to interrupts to be handled

 Load TMOD register with MOD and Timer information.

 Load timer registers

 Wait for an interrupt. If interrupt occurs, the control has to be passed to sub-

routine by calculating interrupt vector

 By executing RETI instruction the control will execute the main program.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 150

Flowchart:

Start

Set the switch


input

Set the timer

Enable the interrupt

While
===(1)
Yes No
Move the data

Stop

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 151

Program:

#include <reg51.h>

sbit SW =P1^7;

sbit IND =P1^0;

sbit WAVE =P2^5;

void timer0(void)interrupt 1

WAVE = ~ WAVE;

void main()

SW=1;

TMOD=0x02;

TH0=0xA4;

TR0=1;

IE=0x82;

while(1)

IND =SW;

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 152

Observation:

Port 1

√ √

√ √

Port 2

Conclusion:

Thus the C program to continuously get a single bit of data from P1.7 and sends it to P1.0 while
simultaneously creating a square wave of 200micro sec period on pin P2.5 written and executed.

………………………………………………………………………………….……………………………………………………

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 153

Questions

1. How many no. of interrupts available for 8051?

2. Which is the highest priority interrupt for 8051?

3. What are an ISR and IVT?

4. What is the difference between software and hardware interrupt?

5. What is the vector address for serial communication interrupt?

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.
Experiment No: …………….
Date: ……. /……. /…………… 1151EC303 MICROPROCESSOR AND MICROCONTROLLER LABORATORY 154

Lab Exercises:

1. Develop an 8051 program using KEIL simulator to generate the square wave in Port 1
5 th pin when interrupted and also when there is a change in Port 2 2nd pin the same
has to be affected in Port 35th pin with a timer delay 0f 3000μs using timer 0 mode 2.

2. Develop an 8051 program using KEIL simulator to generate the toggle input in Port 2
2 th pin when interrupted and also when there is a change in Port 2 5nd pin the same
has to be affected in Port 1 3th pin with a timer delay 0f 5000μs using timer 1 mode 1.

3. Develop an 8051 program using KEIL simulator to generate the toggle input in Port 1
5 th pin when interrupted and also when there is a change in Port 2 4nd pin the same
has to be affected inPort 31th pin with a timer delay 0f 4000μs using timer 1 mode 0.

4. Write a C program that continuously gets a single bit of data from PI. 7 and sends it to
Pl.O, while simultaneously creating a square wave of 200 (as period on pin P2.5. Use
timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz..

5. A switch is connected to pin PI.2. Write an 8051 C program to monitor SW and create
the following frequencies on pin PI.7:SW=0: 500 Hz SW=1: 750 Hz
Use Timer 0, mode 1 for both of them.

6. Program the DS89C4xO in C to receive bytes of data serially via the second serial port
and put them in PI. Set the baud rate at 9600, 8-bit data, and 1 stop bit. Use Timer 1 for
baud rate generation.

VTU R 2015, Dept. of ECE, Vel Tech Rangarajan Dr.Sagunthala R & D Institute of Science and Tech.

You might also like