MPMC Lab Maual EXP 1,2s

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

Microprocessors and Microcontrollers Lab

SRI KRISHNA COLLEGE OF TECHNOLOGY


(Accredited by NAAC with A Grade)
Kovaipudur, Coimbatore - 641 042

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

21IT 503- MICROPROCESSORS AND


MICROCONTROLLERS
LAB MANUAL

LAB IN-CHARGE
Dr.K.Shanthi, Dr.S.Prema, Dr.N. Manikanda Prabu, Mr.M.Navin Kumar,
Mr.R.R.Thirunavukkarasu

Department of ECE, Sri Krishna College of Technology Page 1


Microprocessors and Microcontrollers Lab

OBJECTIVES

 To acquaint the students with the skills in Assembly Language


Programming (ALP) based on the microprocessors 8086 and
Microcontroller 8051.
 To be able to perform mathematical calculations and map out logical
operations by their own through ALP.
 Students should be able to set up an arrangement of Interfacing Units
and Program with 8086, 8051, Arduino and ARM Processor.

Department of ECE, Sri Krishna College of Technology Page 2


Microprocessors and Microcontrollers Lab

GENERAL INSTRUCTIONS FOR LABORATORY CLASSES

 Students should report to the concerned labs as per the time table schedule
 While entering into the LAB students should wear their ID cards, shoes and
proper uniform.
 Students should come with observation and record note book to the laboratory.
 Students are required to prepare thoroughly to perform the experiment before
coming to the Laboratory
 After completion of the experiment, certification of the concerned staff in-charge
in the observation book is necessary
 The record of observations along with the detailed experimental procedure of the
experiment performed in the immediate last session should be submitted and
certified by the staff in-charge

Department of ECE, Sri Krishna College of Technology Page 3


Microprocessors and Microcontrollers Lab

TABLE OF CONTENTS

Page
S.No Name of the experiment
No.

10

11

Department of ECE, Sri Krishna College of Technology Page 4


Microprocessors and Microcontrollers Lab

INTRODUCTION TO MICROPROCESSOR 8086

Objective
To study the microprocessor 8086
8086 MICROPROCESSOR
Features of 8086 microprocessor
 It is a 16 bit µp.
 8086 has a 20 bit address bus can access upto 220 memory locations (1 MB) .
 It can support upto 64K I/O ports.
 It provides 14, 16-bit registers.
 It has multiplexed address and data bus AD0- AD15 and A16 – A19.
 It requires single phase clock with 33% duty cycle to provide internal timing.
 8086 is designed to operate in two modes, Minimum and Maximum.
 It can prefetch upto 6 instruction bytes from memory and queues them in order to speed up
instruction execution.
 It requires +5V power supply.

Architecture of 8086

8086 has two blocks BIU and EU.

Department of ECE, Sri Krishna College of Technology Page 5


Microprocessors and Microcontrollers Lab

The BIU performs all bus operations such as instruction fetching, reading and
writing operands for memory and calculating the addresses of the memory operands. The
instruction bytes are transferred to the instruction queue.
•EU executes instructions from the instruction system byte queue.

GENERAL PURPOSE REGISTERS


8086 CPU has 8 general purpose registers, each register has its own name:
AX - the accumulator register (divided into AH / AL):
1. Generates shortest machine code 2. Arithmetic, logic and data transfer 3. One
number must be in AL or AX 4. Multiplication & Division 5. Input & Output
BX - the base address register (divided into BH / BL).
CX - the count register (divided into CH / CL):
1. Iterative code segments using the LOOP instruction 2. Repetitive operations on
strings with the REP command 3. Count (in CL) of bits to shift and rotate
DX - the data register (divided into DH / DL):
1. DX:AX concatenated into 32-bit register for some MUL and DIV operations 2.
Specifying ports in some IN and OUT operations
SI - source index register:
1. Can be used for pointer addressing of data 2. Used as source in some string
processing instructions 3. Offset address relative to DS
DI - destination index register:
1,Can be used for pointer addressing of data 2. Used as destination in some string
processing instructions 3. Offset address relative to ES
BP - base pointer:
1.Primarily used to access parameters passed via the stack 2. Offset address relative
to SS
SP - stack pointer:
1. Always points to top item on the stack 2. Offset address relative to SS 3. Always
points to word (byte at even address) 4. An empty stack will had SP = FFFEh

SEGMENT REGISTERS
CS - points at the segment containing the current program.
DS - generally points at segment where variables are defined.
ES - extra segment register, it's up to a coder to define its usage.
SS - points at the segment containing the stack.

8086 Pin Diagram

 AD15-AD0 : These are the time multiplexed memory I/O address and data lines.
 A19/S6,A18/S5,A17/S4,A16/S3 : These are the time multiplexed address and
status lines.
 BHE/S7 : The bus high enable is used to indicate the transfer of data over the
higher order ( D15-D8 ) data bus

Department of ECE, Sri Krishna College of Technology Page 6


Microprocessors and Microcontrollers Lab

 RD – Read : This signal on low indicates the peripheral that the processor is
performings emory or I/O read operation
 READY : This is the acknowledgement from the slow device or memory that
they have completed the data transfer
 INTR-Interrupt Request : This is a triggered input. This is sampled during
the last clock cycles of each instruction to determine the availability of the re-
quest
 TEST : This input is examined by a ‘WAIT’ instruction
 CLK- Clock Input : The clock input provides the basic timing for processor
operation and bus ontrol activity
 MN/MX : The logic level at this pin decides whether the processor is to operate in
either minimum or maximum mode.
 M/IO – Memory/IO : This is a status line logically equivalent to S2 in maxi-
mum mode. When it is low, it indicates the CPU is having an I/O operation,
and when it is high, it indicates that the CPU is having a memory operation

Result:
Thus 8086 Microprocessor was studied successfully.

Department of ECE, Sri Krishna College of Technology Page 7


Microprocessors and Microcontrollers Lab

PROGRAMS BASED ON 8086

Ex No: 1 a SIMPLE ARITHMETIC OPERATIONS USING 8086


Date: MICROPROCESSOR

OBJECTIVE:
To write the assembly language program to perform arithmetic operation
using 8086 microprocessors.

SYSTEM AND SOFTWARE TOOL REQUIRED:


1. 8086 Microprocessor kit
2. Keyboard

PRE LAB-WORK

ADDITION OF TWO NUMBERS

ALGORITHM:

1. Start the program


2. Load the 1st number to AX register.
3. Load the 2nd number to BX register.
4. Add both the numbers
5. Store the result in memory location
6. Halt the program.

Department of ECE, Sri Krishna College of Technology Page 8


Microprocessors and Microcontrollers Lab

FLOWCHART

IN LAB WORK

PROGRAM : ADDITION

Address Mnemonics Comments


1100 Move the 1st number to AX
MOV AX, 1212 register.
1103 Move the 2nd number to AX
MOV BX, 1313 register.
1106 ADD AX, BX Add both the numbers
1108 Store the result to memory
MOV [1200], AX location.
101A HLT Stop the program

POST LAB WORK

Input

Memory Input Data


Location

Output

Memory Output Data


Location

SUBTRACTION OF TWO NUMBERS

ALGORITHM:

1. Start the program


Department of ECE, Sri Krishna College of Technology Page 9
Microprocessors and Microcontrollers Lab

2. Load the 1st number to AX register.


3. Load the 2nd number to BX register.
4. Subtract both the numbers
5. Store the result in memory location
6. Halt the program.

FLOWCHART

IN LAB WORK

PROGRAM : SUBTRACTION

Address Mnemonics Comments


1100 Move the 1st number to AX
MOV AX, 1212 register.
1103 Move the 2nd number to AX
MOV BX, 1313 register.
1106 SUB AX, BX Subtract both the numbers
1108 Store the result to memory
MOV [1200], AX location.
101A HLT Stop the program

POST LAB WORK

Input

Memory Input Data


Location

Output

Memory Output Data


Location

MULTIPLICATION OF TWO NUMBERS

ALGORITHM:

1. Start the program

Department of ECE, Sri Krishna College of Technology Page 10


Microprocessors and Microcontrollers Lab

2. Load the 1st number to AX register.


3. Load the 2nd number to BX register.
4. Multiply both the numbers
5. Store the result in memory location
6. Halt the program.

FLOWCHART

IN LAB WORK

PROGRAM : MULTIPLICATION

Address Mnemonics Comments


1100 Move the 1st number to AX
MOV AX, 1212 register.
1103 Move the 2nd number to AX
MOV BX, 1313 register.
1106 MUL AX, BX Multiply the both the numbers
1108 Store the result to memory
MOV [1200], AX location.
101A HLT Stop the program

POST LAB WORK

Input

Memory Input Data


Location

Output

Memory Output Data


Location

Department of ECE, Sri Krishna College of Technology Page 11


Microprocessors and Microcontrollers Lab

DIVISION OF TWO NUMBERS

ALGORITHM:

1. Start the program


2. Load the 1st number to AX register.
3. Load the 2nd number to BX register.
4. Divide both the numbers
5. Store the result in memory location
6. Halt the program.

FLOWCHART

IN LAB WORK

PROGRAM : DIVISION

Address Mnemonics Comments


1100 Move the 1st number to AX
MOV AX, 1212 register.
1103 Move the 2nd number to AX
MOV BX, 1313 register.
1106 DIV AX, BX Divide the both the numbers
1108 Store the result to memory
MOV [1200], AX location.
101A HLT Stop the program

POST LAB WORK

Input

Memory Input Data


Location

Output

Department of ECE, Sri Krishna College of Technology Page 12


Microprocessors and Microcontrollers Lab

Memory Output Data


Location

Post‐Lab Questions:

1. Define microprocessor.
2. Write any 4 addressing modes used in 8086 microprocessors.
3. List the applications of microprocessor.
4. What is BIU and EU?
5. Mention any four types of instruction set used in 8086 microprocessors.

RESULT:

Department of ECE, Sri Krishna College of Technology Page 13


Microprocessors and Microcontrollers Lab

Thus the program for addition, subtraction, multiplication and division of given data was
executed and verified.

Ex No: 1 b ARRAY PROGRAMMING- FINDING LARGEST AND


Date: SMALLEST NUMBER

OBJECTIVE:
To write an Assembly Language Program for finding the smallest and largest
element in an array using 8086 trainer kit.

SYSTEM AND SOFTWARE TOOL REQUIRED:


1. 8086 Microprocessor kit
2. Keyboard

PRE LAB WORK

ALGORITHM:

i) Finding Largest Number

Step1: Load the array count in a register C1


Step2: Get the first two numbers
Step3: Compare the numbers and exchange if the number is small
Step4: Get the third number from the array and repeat the process until C1 is 0

ii) Finding smallest number:


Step1: Load the array count in a register C1
Step2: Get the first two numbers
Step3: Compare the numbers and exchange if the number is large
Step4: Get the third number from the array and repeat the process until C1 is 0

Department of ECE, Sri Krishna College of Technology Page 14


Microprocessors and Microcontrollers Lab

FLOWCHART

Fig: Finding the largest number Fig: Finding the smallest number

Department of ECE, Sri Krishna College of Technology Page 15


Microprocessors and Microcontrollers Lab

IN LAB WORK

PROGRAM

Address Label Mnemonics Opcode Comments


1000 MOV SI,2000 Initialize the pointer
1003 MOV CL, [SI] Initialize the count
1005 MOV CH,00 Initialize value in CH register
1007 INC SI Increment the address location
1008 MOV AL, [SI] Move the SI pointer to AL register
100A DEC CL Reduce the iteration count
100C INC SI Increment the address location
100D L2: CMP AL,[SI] Compare the array elements
100F For find largest number If AL >
[SI] then go to L1 ( no swap)
For find smallest number If AL <
JNC/JC , L1 [SI] then go to L1 ( no swap)
1011 Move the value in SI pointer to AL
MOV AL,[SI] register
1013 L1: INC SI Increment the address location
1014 Go to location L2(100D)and repeat
LOOP L2 the loop
1016 MOV Move the result in AL to a location
[2100],AL and store.
101A HLT Stop the program

POST LAB WORK


Input:
Memory Input Data
Location

Output (Smallest/Largest)

Memory Output Data


Location

Department of ECE, Sri Krishna College of Technology Page 16


Microprocessors and Microcontrollers Lab

Post‐Lab Questions:

1. What is the purpose of MOV DS, AX?


2. What will be the status of flags after executing the program?
3. What are the addressing modes are used in our program?
4. What is the difference between JUMP and LOOP instructions?

RESULT:
Thus the program for finding the largest and smallest data from a given array was
executed and verified

Department of ECE, Sri Krishna College of Technology Page 17


Microprocessors and Microcontrollers Lab

INTRODUCTION TO 8051 MICROCONTROLLER

Objective
To study the 8051 microcontroller
8051 MICROCONTROLLER
FEATURES:
 8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8-bit microcontroller
 8-bit data bus - It can access 8 bits of data in one operation
 16-bit address bus - It can access 216 memory locations - 64 KB (65536 locations) each
of RAM and ROM
 On-chip RAM - 128 bytes (data memory) and On-chip ROM - 4 kByte (program
memory)
 Four byte bi-directional input/output port
 UART (serial port)
 Two 16-bit Counter/timers
 Two-level interrupt priority
ARCHITECTURE OF 8051

Department of ECE, Sri Krishna College of Technology Page 18


Microprocessors and Microcontrollers Lab

1.ALU
All arithmetic and logical functions are carried out by the ALU.
2. Program Counter (PC)
A program counter is a 16-bit register and it has no internal address. The PC holds the
address of the next instruction residing in memory
3. Registers
Registers are usually known as data storage devices. 8051 microcontroller has 2
registers, namely Register A and Register B. Register A serves as an accumulator while
Register B functions as a general purpose register.
8051 microcontroller also has 7 Special Function Registers (SFRs). They are:
1. Serial Port Data Buffer (SBUF)
2. Timer/Counter Control (TCON)
3. Timer/Counter Mode Control (TMOD)
4. Serial Port Control (SCON)
5. Power Control (PCON)

Department of ECE, Sri Krishna College of Technology Page 19


Microprocessors and Microcontrollers Lab

6. Interrupt Priority (IP)


7. Interrupt Enable Control (IE)
4. Timers and Counters
Synchronization among internal operations can be achieved with the help of clock
circuits which are responsible for generating clock pulses
5. Internal RAM and ROM

6. Four General Purpose Parallel Input/output Ports


PORT P0: When there is no external memory present, this port acts as a general purpose
input/output port.. It performs a dual role.
PORT P1: This port is used for various interfacing activities. This 8-bit port is a normal I/O
port i.e. it does not perform dual functions.
PORT P2: Similar to PORT P0, this port can be used as a general purpose port . This is an 8-bit
port and performs dual functions.
PORT P3: PORT P3 behaves as a dedicated I/O port.
8. PSW (Program Status Word)
Program Status Word or PSW is a hardware register which is a memory location which
holds a program's information and also monitors the status of the program this is currently
being executed. PSW also has a pointer which points towards the address of the next
instruction to be executed.
9. Data Pointer (DPTR)
The data pointer or DPTR is a 16-bit register. These 8-bit registers are used for the
storing the memory addresses that can be used to access internal and external data/code.
10. Stack Pointer (SP)
The stack pointer (SP) in 8051 is an 8-bit register. The main purpose of SP is to access
the stack. Stack is a special area of data in memory. The SP acts as a pointer for an address that
Department of ECE, Sri Krishna College of Technology Page 20
Microprocessors and Microcontrollers Lab

point to the top of the stack.


11. Data and Address Bus
A bus is group of wires using which data transfer takes place from one location to
another within a system.
There are mainly two kinds of buses - Data Bus and Address Bus
Data Bus: The purpose of data bus is to transfer data. Wider the width of the bus, greater
will be the transmission of data.
Address Bus: The purpose of address bus is to transfer information but not data.

PIN DIAGRAM OF 8051

PIN DESCRIPTION

Pins 1 – 8:- Recognized as Port 1. Different from other ports, this port doesn’t provide any
other purpose. Port 1 is a domestically pulled up, quasi bi directional Input/output port.

Department of ECE, Sri Krishna College of Technology Page 21


Microprocessors and Microcontrollers Lab

Pin 9:- As made clear previously RESET pin is utilized to set the micro-controller 8051 to its
primary values, whereas the micro-controller is functioning or at the early beginning of
application. The RESET pin has to be set elevated for two machine rotations.

Pins 10 – 17:- Recognized as Port 3. This port also supplies a number of other functions such
as timer input, interrupts, serial communication indicators TxD & RxD, control indicators for
outside memory interfacing WR & RD, etc. This is a domestic pull up port with quasi bi
directional port within.

Pins 18 and 19:- These are employed for interfacing an outer crystal to give system clock.

Pin 20:- Titled as Vss – it symbolizes ground (0 V) association.

Pins- 21-28:- Recognized as Port 2 (P 2.0 – P 2.7) – other than serving as Input/output port,
senior order address bus indicators are multiplexed with this quasi bi directional port.

Pin- 29:- Program Store Enable or PSEN is employed to interpret sign from outer program
memory.

Pin-30:- External Access or EA input is employed to permit or prohibit outer memory


interfacing. If there is no outer memory need, this pin is dragged high by linking it to Vcc.

Pin-31:- Address Latch Enable or ALE is brought into play to de-multiplex the address data
indication of port 0 (for outer memory interfacing). Two ALE throbs are obtainable for every
machine rotation.

Pins 32-39: Recognized as Port 0 (P0.0 to P0.7) – other than serving as Input/output port,
low order data & address bus signals are multiplexed with this port (to provide the use of
outer memory interfacing). This pin is a bi directional Input/output port (the single one in
microcontroller 8051) and outer pull up resistors are necessary to utilize this port as
Input/output.

Pin-40: Termed as Vcc is the chief power supply. By and large it is +5V DC.

Department of ECE, Sri Krishna College of Technology Page 22


Microprocessors and Microcontrollers Lab

Result:
Thus the 8051 Microcontroller was studied successfully

Department of ECE, Sri Krishna College of Technology Page 23


Microprocessors and Microcontrollers Lab

PROGRAMMING WITH 8051

Ex No:2 CODE CONVERSION


Date: BCD TO BINARY & BINARY TO BCD CONVERSION

OBJECTIVE:
To write an assembly language program to convert BCD to Binary number and Binary
to BCD number using 8051 microcontroller kit.
SYSTEM AND SOFTWARE TOOL REQUIRED:
1. 8051 microcontroller kit
2. Keyboard

PRE LAB WORK

ALGORITHM:
a) BCD to Binary
Step 1: Start the program.
Step 2: Initialize the data pointer and Move it to A and R0
Step 3: Perform AND operation for value of A with 0FH
Step 4: Move the values of A to R1
Step 5: Move the value of R0 to A
Step 6: Perform AND operation for value of A with F0H.
Step 7: Rotate right the contents of A 4 times
Step 8: Move the value of 0AH to B and multiply the values of A and B
Step 10: Add the content of A and R1
Step 11: Increment DPTR and move the value of A to it.
Step 12: Stop the program.

b) BCD to Binary
Step 1: Start the program.
Step 2: Initialize the data pointer and Move it to A and R0
Step 3: Perform AND operation for value of A with 0FH
Step 4: Move the values of A to R1
Step 5: Move the value of R0 to A
Step 6: Perform AND operation for value of A with F0H.
Step 7: Rotate right the contents of A 4 times

Department of ECE, Sri Krishna College of Technology Page 24


Microprocessors and Microcontrollers Lab

Step 8: Move the value of 0AH to B and multiply the values of A and B
Step 9: Add the content of A and R1
Step 10: Increment DPTR and move the value of A to it.
Step 11: Stop the program.

FLOW CHART

START

INITIALIZE DPTR, MOVE THE CONTENT OF ADDRESS OF


DPTR TO A

MOVE THE VALUE OF 0AH TO B & DIVIDE THE


CONTENT OF A AND B

INCREMENT DPTR & MOVE THE VALUE OF A TO


ADDRESS OF DPTR

MOVE THE VALUE OF B TO A & 0AH TO B

DIVIDE THE CONTENT OF A AND B & INCREMENT DPTR

MOVE THE VALUE OF A TO ADDRESS OF DPTR & B TO A

INCREMENT DPTR & MOVE THE VALUE OF A TO


ADDRESS OF DPTR

STOP

Fig: BINARY TO BCD

Department of ECE, Sri Krishna College of Technology Page 25


Microprocessors and Microcontrollers Lab

START

INITIALIZE DPTR, MOVE THE CONTENT OF ADDRESS OF


DPTR TO A

MOVE THE VALUE OF 0AH TO B & DIVIDE THE


CONTENT OF A AND B

INCREMENT DPTR & MOVE THE VALUE OF A TO


ADDRESS OF DPTR

MOVE THE VALUE OF B TO A & 0AH TO B

DIVIDE THE CONTENT OF A AND B & INCREMENT DPTR

MOVE THE VALUE OF A TO ADDRESS OF DPTR & B TO A

INCREMENT DPTR & MOVE THE VALUE OF A TO


ADDRESS OF DPTR

STOP

Fig: BCD TO BINARY

Pre Lab Questions:

1. Upon reset, all ports of the 8051 are configured as _____________ (output, input).
2. Which ports of the 8051 have internal pull‐up resistors?
3. Which ports of the 8051 require the connection of external pull‐up resistors in order to be
used for I/O? Show the drawing for the connection

IN LAB WORK

Department of ECE, Sri Krishna College of Technology Page 26


Microprocessors and Microcontrollers Lab

PROGRAM

i) Binary to BCD
Memory Label Mnemonics Opcode Comment
MOV DPTR,#4500 Initialize DPTR as 4500
MOVX A,@DPTR Move the content of
DPTR to A
MOV B,#64 Move the value 64 to B
DIV AB Divide the content of A
by B
INC DPTR Increment the content of
DPTR
MOVX @DPTR,A Move the content of A to
DPTR
MOV A,B Move the content of B to
A
MOV B,#0A Move the 0AH to B
DIV AB Divide the content of B
by A
INC DPTR Increment the content of
DPTR
MOVX @DPTR,A Move the content of A to
DPTR
MOV A,B Move the content of B to
A
INC DPTR Increment the content of
DPTR
MOVX @DPTR,A Move the content of A to
DPTR
HERE SJMP HERE Short jump to HERE

ii) BCD to Binary


Memory Label Mnemonics Opcode Comment
MOV DPTR,#4550 Initialize DPTR as 4550
MOVX A,@DPTR Move the contents of
DPTR
To A
MOV R0,A Move the content of A to
R0
ANL A,#0F Perform AND for
content of A with 0FH
MOV R1,A Move the contyent of A
to R1
MOV A,R0 Move the content of R0
to A
ANL A,#0F0h Perform AND for the

Department of ECE, Sri Krishna College of Technology Page 27


Microprocessors and Microcontrollers Lab

content of A with F0H


RR A Rotate right the contents
of A
RR A Rotate right the contents
of A
RR A Rotate right the contents
of A
RR A Rotate right the contents
of A
MOV B,#0AH Move the content of A
MUL AB Multiply the content of
A
ADD A,R1 Add the Contents of A,
R1
INC DPTR Increment DPTR
MOVX @DPTR,A Move the content of A
into address specified in
DPTR
HERE SJMP HERE Short jump to HERE

POST LAB WORK

INPUT: BCD Number

Memory Input Data


Location

OUTPUT: Binary Number


Memory Output Data
Location

INPUT: Binary Number

Memory Input Data


Location

Department of ECE, Sri Krishna College of Technology Page 28


Microprocessors and Microcontrollers Lab

OUTPUT: BCD Number


Memory Output Data
Location

Post Lab Questions:

1. How the DPTR register is classified, explain its functions?


2. What is the function of EA pin in 8051?
3. List out the special function registers in 8051.
4. Find the number of times the following loop is performed
MOV R6, #200
BACK: MOV R5, #100
HERE: DJNZ R5, HERE
DJNZ R6, BACK

RESULT:
Thus an assembly language program to convert BCD to Binary number and Binary
to BCD number using 8051 microcontroller kit was executed and its output is verified.

Department of ECE, Sri Krishna College of Technology Page 29

You might also like