You are on page 1of 21

Microprocessor and Microcontroller LAB

YSPM’s
Yashoda Technical Campus,
Faculty of Engineering, Satara.

List of Experiments

Exp.No Title Page No

1 To Study of architecture of microprocessor 8085

Assembly language program for addition of 8 bit and 16 bit number


2 based on 8085 microprocessor

Assembly language program for Substraction of 8 bit and 16 bit


3 number based on 8085 microprocessor

Assembly language program for Multiplication of 8 bit based on 8085


4 microprocessor

Assembly language program for Division of 8 bit based on 8085


5 microprocessor

6 Program based on arithmetic instruction for 8051 microcontroller

7 Interfacing of stepper motor to 8051 microcontroller

assembly code program to generate a


8 delay of 10ms

10

Electrical Engg. DEPT ., YTC, Page 1


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 01
Study of architecture of microprocessor 8085

Aim:

Electrical Engg. DEPT ., YTC, Page 2


Microprocessor and Microcontroller LAB

1. To understand the architecture of microprocessor 8085

Objective:
Study of architecture of microprocessor 8085.
Apparatus Required

Theory:
Internal Architecture of 8085 Microprocessor

Fig1. Architecture of 8085 Microprocessor

8085 consists of various units as shown in Fig.1 and each unit


performs its own functions.
• The various units of a microprocessor are listed below
 Accumulator
 Arithmetic and logic Unit
 General purpose register
 Program counter
 Stack pointer
 Temporary register
 Flags
E. &T.C. DEPT ., YTC, SATARA Page 3
Microprocessor and Microcontroller LAB

 Instruction register and Decoder


 Timing and Control unit
 Interrupt control
 Address buffer and Address-Data buffer
 Address bus and Data bus
Accumulator
Accumulator is nothing but a register which can hold 8-bit data.
Accumulator aids in storing two quantities. The data to be processed by arithmetic and logic
unit is stored in accumulator. It also stores the result of the operation carried out by the
Arithmetic and Logic unit. The accumulator is also called an 8-bit register.
The accumulator is connected to Internal Data bus and
ALU (arithmetic and logic unit). The accumulator can be used to send or receive data from the
Internal Data bus
Arithmetic and logic Unit
There is always a need to perform arithmetic operations like +, -, *, / and to perform logical
operations like AND, OR, NOT etc. So, there is a necessity for creating a separate unit which
can perform such types of operations.These operations are performed by the Arithmetic and
Logic Unit (ALU).ALU performs these operations on 8-bit data. But these operations cannot be
performed unless we have an input (or) data on which the desired operation is to be
performed. So, from where do these inputs reach the ALU? For this purpose, accumulator is
used. ALU gets its Input from accumulator and temporary register. After processing the
necessary operations, the result is stored back in accumulator.
Flags
The ALU includes five flip-flops, which are set or reset after an operation according to data
conditions of the result in the accumulator and other registers. They are called Zero(Z), Carry
(CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags; they are listed in the Table and their bit
positions in the flag register are shown in the Figure below. The most commonly used flags
are Zero, Carry, and Sign. The microprocessor
uses these flags to test data conditions. For example, after an addition of two numbers, if the
sum in the accumulator id larger than eight bits, the flip-flop uses to indicate a carry - called
the Carry flag (CY) – is set to one. When an arithmetic operation results in zero, the flip-flop
called the Zero(Z) flag is set to one. The first Figure shows an 8-bit register, called the flag
register, adjacent to the accumulator. However, it is not used as a register; five bit positions
out of eight are used to store the outputs of the five flip-flops. The flags are stored in the 8-bit
register so that the programmer can examine these flags (data conditions) by accessing the
register through an instruction These flags have critical importance in the decision-making
process of the microprocessor. The conditions (set or reset) of the flags are tested through
the software instructions. For example, the instruction JC (Jump on Carry) is implemented to
change the sequence of a program when CY flag is set. The thorough understanding of flag is
essential in writing assembly language programs.
Instruction Register and Decoder
Instruction register is 8-bit register just like every other register of microprocessor.
Consider an instruction. The instruction may be anything like adding two data's, moving a
data, copying a data etc.
When such an instruction is fetched from memory, it is directed to Instruction register. So,
E. &T.C. DEPT ., YTC, SATARA Page 4
Microprocessor and Microcontroller LAB

the instruction registers are specifically to store the instructions that are fetched from
memory.
There is an Instruction decoder which decodes the information present in the Instruction
register for further processing.
Timing and Control Unit
Timing and control unit is a very important unit as it synchronizes the registers and flow of
data through various registers and other units.
This unit consists of an oscillator and controller sequencer which sends control signals
needed for internal and external control of data and other units.
The oscillator generates two-phase clock signals which aids in synchronizing all the registers
of 8085 microprocessor.
Program Counter and Stack Pointer
Program counter is a special purpose register . Program counter is a 16-bit register A
program counter stores the address of the next instruction to be executed.
In other words, the program counter keeps track of the memory address of the instructions
that are being executed by the microprocessor and the memory address of the next
instruction that is going to be executed.
Microprocessor increments the program whenever an instruction is being executed, so that
the program counter points to the memory address of the next instruction that is going to be
executed.
Stack pointer is also a 16-bit register which is used as a memory pointer . Stack pointer
maintains the address of the last byte that is entered into stack. Each time when the data is
loaded into stack, Stack pointer gets decremented. Conversely it is incremented when data is
retrieved from stack.
Interrupt control
Consider that a microprocessor is executing the main program. Now whenever the interrupt
signal is enabled or requested the microprocessor shifts the control from main program to
process the incoming request. after the completion of request, the control goes back to the main
program. 8085 has five Interrupt . INTR ,RST 7.5 , RST 6.5 ,RST 5.5 ,TRAP. INTR is maskable 8080A
compatible interrupt. RST5.5 is a maskable interrupt. RST6.5 is a maskable interrupt. RST7.5 is a
maskable interrupt. TRAP is a non-maskable interrupt.
Serial Input/output control
The input and output of serial data can be carried out using 2 instructions in 8085.
SID-Serial Input Data SOD-Serial Output Data . Two more instructions are used to perform
serial-parallel conversion needed for serial I/O devices. SIM (Set Interrupt Mask) RIM (Read
Interrupt Mask )
Address buffer and Address-Data buffer
The contents of the stack pointer and program counter are loaded into the address buffer and
address-data buffer. These buffers are then used to drive the external address bus and address-
data bus. As the memory and I/O chips are connected to these buses, the CPU can exchange
desired data to the memory and I/O chips. The address-data buffer is not only connected to the
external data bus but also to the internal data bus which consists of 8-bits. The address data
buffer can both send and receive data from internal data bus.
Address bus and Data Bus
Address bus

E. &T.C. DEPT ., YTC, SATARA Page 5


Microprocessor and Microcontroller LAB

8085 processor requires 16-bit address bus as the memory addresses are 16-bit wide. The 8 most
significant bits of the address are transmitted with the help of address bus and the 8 least
significant bits are transmitted with the help of multiplexed address/data bus.
The eight-bit data bus is multiplexed with the eight least significant bits of address bus. The
address/data bus is time multiplexed. for few microseconds, the 8 least significant bits of address
are generated, while for next few seconds the same pin generates the data. This is called Time
multiplexing.
Data Bus
The Data bus present in the microprocessor is also 8-bits wide .8-bits of data can be transmitted
from or to the microprocessor .

Conclusion :
In this experiment ,we have studied the Architecture of 8085 microprocessor is completed

E. &T.C. DEPT ., YTC, SATARA Page 6


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 02
Assembly language program for addition of 8 bit and 16 bit number
based on 8085 microprocessor
Aim:

Addition of 8 bit and 16 bit number based on 8085 microprocessor

Objective:

Write a Assembly language program for addition of 8 bit and 16 bit number based on 8085
microprocessor
Apparatus Required
1) 8085 Simulator 2) PC

PROGRAM 1
8 bit Decimal Addition:
Steps:
1 . Initialize HL Reg. pair with address where the first number is lying.
2. Store the number in accumulator.
3. Get the second number.
4. Add the two numbers and store the result in 200B.
5. Go back to Monitor
FLOWCHART:-

Start

st
Get the 1 no.

nd
Get the 2 no.

Add two no.

Adjust the decimal

Store the result

End
E. &T.C. DEPT ., YTC, SATARA Page 7
Microprocessor and Microcontroller LAB

PROGRAM:-

LXI H, 2009 ; Point 1st no.


MOV A, M ; Load the acc.
INX H ; Adv Pointer
ADD M ; ADD 2nd NO.
INX H ; Adv Pointer
MOV M, A ; Store Result
HLT
Observation:
Input: 3 (2009)
1 (200A)
Output: 04 (200B)

PROGRAM 1
16 bit Decimal Addition:

Steps:
1 . Initialize HL Reg. pair with address 2000H where the first number is lying.
2.Save first 16-bit number in DE.
3.Get the second number in HL pair .
4.Add DE and HE pair and store the result Store 16-bit result in memory locations 2004H and
2005H.
5.Go back to Monitor

PROGRAM:-

LHLD 2000H ; Get first 16-bit number in HL pair


XCHG ; Save first 16-bit number in DE
LHLD 2002H ; Get second 16-bit number in HL
DAD D ; Add DE and HE
SHLD 2004H ; Store 16-bit result in memory locations
2004H and 2005H
HLT
Observation:
Input: 12 (2000)
23 (2001)
43 (2002)
21 (2003)

Output: 55 (2004)
55 (2005)

REULTS:-
Thus the program to add two 8-bit & two 16-bit numbers was executed
E. &T.C. DEPT ., YTC, SATARA Page 8
Microprocessor and Microcontroller LAB

EXPERIMENT NO : 03
Assembly language program for subtraction of 8 bit and 16 bit number based on
8085 microprocessor

Aim:
Subtraction of 8 bit and 16 bit number based on 8085 microprocessor

Objective:

Write a Assembly language program for subtraction of 8 bit and 16 bit number based on
8085 microprocessor

Apparatus Required

1) 8085 Simulator 2) PC

PROGRAM 1
8 bit Decimal Addition:
Steps:
1 . Initialize HL Reg. pair with address where the first number is lying.
6. Store the number in accumulator.
7. Get the second number.
8. Subtract the two numbers and store the result in 200B.
9. Go back to Monitor
FLOWCHART:-

Start

st
Get the 1 no.

nd
Get the 2 no.

SUB two no.

Adjust the decimal

Store the result

End
E. &T.C. DEPT ., YTC, SATARA Page 9
Microprocessor and Microcontroller LAB

PROGRAM:-
8 bit Decimal Substraction

LXI H, 2009 ; Point 1st no.


MOV A, M ; Load the acc.
INX H ; Adv Pointer
SUB M ; SUB 2nd NO.
INX H ; Adv Pointer
MOV M, A ; Store Result
HLT
Observation:
Input: 4 (2009)
2 (200A)
Output: 02 (200B)
PROGRAM 1
16 bit Decimal Substraction:
Steps:
1 . Initialize HL Reg. pair with address 2000H where the first number is lying.
2.Save first 16-bit number in DE.
3.Get the second number in HL pair .
4.Add DE and HE pair and store the result Store 16-bit result in memory locations 2004H and
2005H.
5.Go back to Monitor
PROGRAM:-

LXI H, 9876H ; Load HL with 9876H data Save first load BC


LXI B ,5432H ; with 9876H data
MOV A, L ; Move the content of L reg. into Accumulator
SUB C ; Subtract the content of L reg. into Accumulator
STA 2000H ; Store the LSB into 2000H
MOV A H ; Move the content of H reg. into Accumulator
SUB B ; Subtract the content of H reg. into Accumulator
STA 2001H ; Store the LSB into 2000H
HLT

Observation:
Input: HL = 9876H BC = 5432H

Output: 44H (2000) 44H (2001)

REULTS:-

Thus the program for subtraction of two 8-bit & two 16-bit numbers was executed

E. &T.C. DEPT ., YTC, SATARA Page 10


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 04
Assembly language program for Multiplication of 8 bit based on 8085 microprocessor

Aim:

1. Multiplication of 8 bit based on 8085 microprocessor

Objective :

Write a Assembly language program for Multiplication of 8 bit based on 8085


microprocessor

Apparatus Required
1) 8085 Simulator 2) PC

PROGRAM
Steps:
1) Start the program by loading HL register pair with address of memory location.
2) Move the data to a register (B register).
3) Get the second data and load into Accumulator.
4) Add the two register contents.
5) Check for carry.
6) Increment the value of carry.
7) Check whether repeated addition is over and store the value of product and carry in
memory location.
8) Terminate the program.
MVI D, 00 Initialize register D to 00
MVI A, 00 Initialize Accumulator content to 00
LXI H, 4150H
MOV B, M Get the first number in B - reg
INX H
MOV C, M Get the second number in C- reg.
LOOP: ADD B Add content of A - reg to register B.
JNC NEXT Jump on no carry to NEXT.
INR D Increment content of register D
NEXT: DCR C Decrement content of register C.
JNZ LOOP Jump on no zero to address
STA 4152H Store the result in Memory
MOV A, D Move the content of D register to Accumulator
STA 4153H Store the MSB of result in Memory
HLT Terminate the program.

Observation:

Input: FF (4150)
FF (4151)

E. &T.C. DEPT ., YTC, SATARA Page 11


Microprocessor and Microcontroller LAB

Output: 01 (4152)
FE (4153)

REULTS:-

Thus the program to multiply two 8-bit numbers was executed.

E. &T.C. DEPT ., YTC, SATARA Page 12


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 05
Assembly language program for Division of 8 bit based on 8085 microprocessor

Aim:

1.Division of 8 bit based on 8085 microprocessor

Objective :

Write a Assembly language program for Division of 8 bit based on 8085


microprocessor

Apparatus Required
2) 8085 Simulator 2) PC

PROGRAM

Steps:-

1) Start the program by loading HL register pair with address of memory location.
2) Move the data to a register (B register).
3) Get the second data and load into Accumulator.
4) Compare the two numbers to check for carry.
5) Subtract the two numbers.
6) Increment the value of carry.
7) Check whether repeated subtraction is over and store the value of product and carry in memory
location.
8) Terminate the program.

LXI H, 4150
MOV B, M Get the dividend in B – reg.
MVI C, 00 Clear C – reg for quotient
INX H
MOV A, M Get the divisor in A – reg.
NEXT: CMP B Compare A - reg with register B.
JC LOOP Jump on carry to LOOP
SUB B Subtract A – reg from B- reg.
INR C Increment content of register C.
JMP NEXT Jump to NEXT
LOOP: STA 4152 Store the remainder in Memory
MOV A, C Move the Content of C register to Accumulator
STA 4153 Store the quotient in memory
HLT Terminate the program.

Observation:

Input: FF (4150)
FF (4151)

E. &T.C. DEPT ., YTC, SATARA Page 13


Microprocessor and Microcontroller LAB

Output: 01 (4152) Remainder


FE (4153) Quotient

RESULT

Thus the program to divide two 8-bit numbers was executed.

E. &T.C. DEPT ., YTC, SATARA Page 14


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 06

Program based on arithmetic instruction for 8051 microcontroller

Aim: To perform the arithmetic operation addition by using 8051 microcontroller

Apparatus Required

1) 8051 Simulator 2) PC

A) Addition Program:

ALGORITHM:

1. Start the program


2. Get the Input data at the accumulator.
3. Get the Input data at the another register
4. Add the adder data with the data which is already in accumulator.

5. Move the result to 20H memory location.


6. Stop the program

org 0000h ; Start the program from memory


location 0000H
MOV a,#02h ; Move 02 h data into accumulator
MOV b,#05h ; Move 05 h data into accumulator
add a,b ; Add a & b
MOV 20h,a ;
Move the contain of accumulator to
memory location 20h
End Stop the Program

Observation:
Input A = 02 H ; B=05H
Output D:20H =07H

E. &T.C. DEPT ., YTC, SATARA Page 15


Microprocessor and Microcontroller LAB

B) Subtraction Program

1. Start the program


2. Get the Input data at the accumulator.
3. Get the Input data at the another register
4. Subtract the data with the data which is already in accumulator.

5. Move the result to 20H memory location.


6. Stop the program

org 0000h ; Start the program from memory


location 0000H
MOV a,#07h ; Move 07 h data into accumulator
MOV b,#02h ; Move 02 h data into accumulator
SUBB a,b ; Subtract a & b
MOV 20h,a ;
Move the contain of accumulator to
memory location 20h
End Stop the Program

Observation:
Input A = 07 H ; B=02H
Output D:20H =05H

RESULT

Thus the program to for addition and subtraction using 8051 assemble language executed

E. &T.C. DEPT ., YTC, SATARA Page 16


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 07
Interfacing of stepper motor to 8051 microcontroller

Aim: Write an assembly language program for interfacing stepper motor with 8051
Apparatus Required

1) 8051 Simulator 2) PC 3) Proteus software

THEORY:
A Stepper Motor or a step motor is a brushless, synchronous motor which divides a full rotation
into a number of steps. Unlike a brushless DC motor which rotates continuously when a fixed DC
voltage is applied to it, a step motor rotates in discrete step angles. The Stepper Motors therefore
are manufactured with steps per revolution of 12, 24, 72, 144, 180, and 200, resulting in stepping
angles of 30, 15, 5, 2.5, 2, and 1.8 degrees per step.
The stepper motor can be controlled with or without feedback. Stepper motors work on the
principle of electromagnetism. There is a soft iron or magnetic rotor shaft surrounded by the
electromagnetic stators. The rotor and stator have poles which may be teethed or not depending
upon the type of stepper. When the stators are energized the rotor moves to align itself along with
the stator (in case of a permanent magnet type stepper) or moves to have a minimum gap with the
stator (in case of a variable reluctance stepper). This way the stators are energized in a sequence to
rotate the stepper motor.
PROGRAM:
ORG 0000H
MOV A,#66H
LOOP:MOV P2,A
ACALL DELAY
RR A
SJMP LOOP
DELAY:MOV R5,#0AH
AGAIN:MOV R3,#0FFH
BACK:DJNZ R3,BACK
DJNZ R5,AGAIN
RET
END

E. &T.C. DEPT ., YTC, SATARA Page 17


Microprocessor and Microcontroller LAB

E. &T.C. DEPT ., YTC, SATARA Page 18


Microprocessor and Microcontroller LAB

EXPERIMENT NO : 08
assembly code program to generate a delay of 10ms

Aim : -
Theory

Given: Time delay=10ms , Clock frequency= 11.0592 MHz


Step 1: Divide the desired time delay by 1.085 us
Count =10 ms/ 1.085 us=9216
Step 2: Perform 65536 – n
65536-9216=56320= DC00H
Step 3: Set TL = xx and TH = yy
Here xx=DC and yy=00,
Hence, TH0=DC and TL0=00.

Algorithm

1. Load the TMOD value register with mode and timer 0 or 1.


2. Load registers TLx and THx with initial count corresponding to delay.
3. Start the timer.
4. Continuously monitor the timer flag (TFx) with the “JNB TFx,target” instruction to see if it is
raised, if it is raised(TFx=1) then get out of the loop.
5. Stop the timer.
6. Clear the TFx flag for the next round.
7. Go back to Step 2 to load THx and TLx again

PROGRAM:

CLR P1.0
MOV TMOD,#01H
HERE:MOV TL0,#00H
MOV TH0,#0DCH
SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
END

E. &T.C. DEPT ., YTC, SATARA Page 19


Microprocessor and Microcontroller LAB

Observation:

RESULT

Thus the program to for generation of delay using 8051 assemble language executed

E. &T.C. DEPT ., YTC, SATARA Page 20


Microprocessor and Microcontroller LAB

E. &T.C. DEPT ., YTC, SATARA Page 21

You might also like