0% found this document useful (0 votes)
99 views87 pages

Ec6513 Micorprocessor Lab Manual

This document describes an experiment on programming an 8086 microprocessor to perform arithmetic operations. It lists the objectives of writing assembly language programs for addition, subtraction, multiplication and division of 16-bit numbers. It provides the algorithms, flowcharts and assembly language codes to perform these arithmetic operations and store the results in memory locations. It also describes the test data used and verification of results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views87 pages

Ec6513 Micorprocessor Lab Manual

This document describes an experiment on programming an 8086 microprocessor to perform arithmetic operations. It lists the objectives of writing assembly language programs for addition, subtraction, multiplication and division of 16-bit numbers. It provides the algorithms, flowcharts and assembly language codes to perform these arithmetic operations and store the results in memory locations. It also describes the test data used and verification of results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

EC8681 MICROPROCESSORS AND MICROCONTROLLERS LABORATORY L T P C

0042
OBJECTIVES:

 To Introduce ALP concepts, features and Coding methods


 Write ALP for arithmetic and logical operations in 8086 and 8051
 Differentiate Serial and Parallel Interface
 Interface different I/Os with Microprocessors
 Be familiar with MASM

LIST OF EXPERIMENTS: 8086 Programs using kits and MASM


1. Basic arithmetic and Logical operations
2. Move a data block without overlap
3. Code conversion, decimal arithmetic and Matrix operations.
4. Floating point operations, string manipulations, sorting and searching
5. Password checking, Print RAM size and system date
6. Counters and Time Delay
Peripherals and Interfacing Experiments
7. Traffic light controller
8. Stepper motor control
9. Digital clock
10. Key board and Display
11. Printer status
12. Serial interface and Parallel interface
13. A/D and D/A interface and Waveform Generation
8051 Experiments using kits and MASM
14. Basic arithmetic and Logical operations
15. Square and Cube program, Find 2‘s complement of a number
16. Unpacked BCD to ASCII
TOTAL: 60 PERIODS
OUTCOMES:
At the end of the course, the student should be able to:

 Write ALP Programmes for fixed and Floating Point and Arithmetic
operations
 Interface different I/Os with processor
 Generate waveforms using Microprocessors
 Execute Programs in 8051
 Explain the difference between simulator and Emulator
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.1 8086 PROGRAMMING - ADDITION & SUBTRACTION

DATE:
AIM:

To write an Assembly Language Program (ALP) for performing the addition and subtraction
operation of two 2- byte (16) numbers.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 kit 1

2. Power Supply +5 V dc 1

PROBLEM STATEMENT:

Write an ALP in 8086 to add and subtract two byte numbers stored in the memory location
1000H to 1003H and store the result in the memory location 1004H to 1005H.Also provide an
instruction in the above program to consider the carry also and store the carry in the memory location
1006H.

ALGORITHM:

(i) 16-bit addition

h) Initialize the MSBs of sum to 0


i) Get the first number.
j) Add the second number to the first number.
k) If there is any carry, increment MSBs of sum by 1.
l) Store LSBs of sum.
m) Store MSBs of sum.

(ii) 16-bit subtraction

f) Initialize the MSBs of difference to 0


g) Get the first number
h) Subtract the second number from the first number.
i) If there is any borrow, increment MSBs of difference by 1.
j) Store LSBs of difference
k) Store MSBs of difference.

1
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOWCHART:

ADDITION SUBTRACTION
START
START

SET UP COUNTER (CY)


SET UP COUNTER (CARRY)

GET FIRST OPERAND


GET FIRST
OPERAND TO A

GET SECOND OPERAND TO


A SUBTRACT SECOND
OPERAND FROM
MEMORY A= A-B
A=A+B

YES
YES
IS THERE
IS THERE ANY CY
ANY
CARRY
COUNTER = NO COUNTER =
NO COUNTER + 1 COUNTER + 1

STORE THE STORE THE


SUM DIFFERENCE

STORE THE CARRY


STORE THE CARRY

STOP
STOP

2
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

ADDITION

PROGRAM COMMENTS

Start: MOV CX, 0000H Initialize counter CX

MOV AX,[1200] Get the first data in AX reg

MOV BX, [1202] Get the second data in BX reg

ADD AX,BX Add the contents of both the regs AX & BX

JNC Loop1 Check for carry

INC CX If carry exists, increment the CX

Loop1 : MOV [1206],CX Store the carry

MOV [1204], AX Store the sum

Stop: HLT Stop the program

SUBTRACTION

PROGRAM COMMENTS

Start: MOV CX, 0000H Initialize counter CX

MOV AX,[1200] Get the first data in AX reg

MOV BX, [1202] Get the second data in BX reg

SUB AX,BX Subtract the contents of BX from AX

JNC Loop1 Check for borrow

INC CX If borrow exists, increment the CX

Loop1: MOV [1206],CX Store the borrow

MOV [1204], AX Store the difference

Stop: HLT Stop the program

3
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

TEST DATA:

ADDITION

MEMORY

DATA

SUBTRACTION

MEMORY

DATA

MANUAL CALCULATION:

RESULT:

Thus an addition & subtraction of two 2-byte numbers are performed and the results are verified.

4
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.2 8086 PROGRAMMING - MULTIPLICATION & DIVISION

DATE:
AIM:

To write an Assembly Language Program (ALP) for performing the multiplication and division
operation of 16-bit numbers.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Power Supply +5 V dc 1

PROBLEM STATEMENT:

Write an ALP in 8086 MP to multiply two 16-bit binary numbers and store the result in the
memory location. Write instructions for dividing the data and store the result.

ALGORITHM:

Multiplication of 16-bit numbers:


a) Get the multiplier.
b) Get the multiplicand
c) Initialize the product to 0.
d) Product = product + multiplicand
e) Decrement the multiplier by 1
f) If multiplicand is not equal to 0,repeat from step (d) otherwise store the product.

Division of 16-bit numbers.


a) Get the dividend
b) Get the divisor
c) Initialize the quotient to 0.
d) Dividend = dividend – divisor
e) If the divisor is greater, store the quotient. Go to step g.
f) If dividend is greater, quotient = quotient + 1. Repeat from step (d)
g) Store the dividend value as remainder.

5
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

6
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOWCHART

MULTIPLICATION DIVISION
Start
Start

Load Divisor & Dividend


Get Multiplier & Multiplicand

REGISTER=00 Quotient = 0

REGISTER = REGISTER + DIVIDEND = DIVIDEND-DIVISOR


MULTIPLICAND

QUOTIENT = QUOTIENT+1

Multiplier=MULTIPLIER
–1

Is Dividend <
Divisor ?

NO
Is
Multiplier = Yes
0?

STORE QUOTIENT
YES STORE REMAINDER

STORE THE RESULTS = DIVIDEND NOW

Stop
STOP

7
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MULTIPLICATION

PROGRAM COMMENTS

Start: MOV AX,[1200] Get the first data

MOV BX, [1202] Get the second data

MUL BX Multiply both

MOV [1206],AX Store the lower order product

MOV AX,DX Copy the higher order product to AX

MOV [1208],AX Store the higher order product

Stop: HLT Stop the program

DIVISION

PROGRAM COMMENTS

Start: MOV AX,[1200] Get the first data

MOV DX, [1202] Get the second data

MOV BX, [1204] Divide the dividend by divisor

DIV BX Store the lower order product

MOV [1206],AX Copy the higher order product to AX

MOV AX,DX Store the higher order product

MOV [1208],AX Stop the program

Stop: HLT Get the first data

8
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

TEST DATA:

MULTIPLICATION

MEMORY

DATA

DIVISON

MEMORY

DATA

MANUAL CALCULATION

RESULT:

Thus the multiplication & division of two (16 bit) byte numbers are performed and the
results are verified

9
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.3 8086 PROGRAMMING – LOGICAL OPERATIONS (MASM)

DATE:
AIM:
To write an Assembly Language Program (ALP) for verifying logical operations using 16 bit
numbers.

APPARATUS REQUIRED:
S.NO ITEM SPECIFICATION QUANTITY
1. System with MASM 8086 bsased 1
package

Logic Operations 8086 Assembly Language program: LOGICAL AND:

CODE SEGMENT
ASSUME CS: CODE
ORG 1000H
START: MOV AL, 85H
MOV BL, 99H
AND AL, BL
MOV SI, 1200H
MOV [SI], AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

Logic Operations 8086 Assembly Language program: LOGICAL OR:

CODE SEGMENT
ASSUME CS: CODE
ORG 1000H
START: MOV AL, 85H
MOV BL, 99H
OR AL, BL
MOV SI, 1200H
MOV [SI], AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

10
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

Logic Operations 8086 Assembly Language program: LOGICAL XOR:


CODE SEGMENT
ASSUME CS: CODE
ORG 1000H
START: MOV AL, 85H
MOV BL, 99H
XOR AL, BL
MOV SI, 1200H
MOV [SI], AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

Logic Operations 8086 Assembly Language program: NOT OPERATION:


CODE SEGMENT
ASSUME CS: CODE
ORG 1000H
START: MOV AL, 85H
NOT AL
MOV SI, 1200H
MOV [SI], AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

Logic Operations 8086 Assembly Language program: NAND OPERATION:


CODE SEGMENT
ASSUME CS: CODE
ORG 1000H
START: MOV AL, 85H
MOV BL, 99H
AND AL, BL
NOT AL
MOV SI, 1200H
MOV [SI], AL
MOV AH,4CH
INT 21H
CODE ENDS
END START

11
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

Logic Operations 8086 Assembly Language program: SHL OPERATION:


The MUL (Multiplication) instruction. Example: Multiply AX by 19 (i.e., AX *(16 + 2 + 1))

PUSH BX
PUSH CX
MOV BX, AX
SHL BX, 1 ; BX: = AX * 2
ADD BX, AX ; BX: = AX * 3
MOV CL, 4
SHL AX, CL ; AX: = AX * 16
ADD AX, BX ; AX: = AX * 19
POP CX
POP BX
MOV SI,1200H
MOV [SI], AL
HLT

TEST DATA:

LOGICAL OPERATION

MEMORY

DATA

MEMORY

DATA

RESULT:.

Thus the logical operations of 8086 microprocessors are performed and the results are
verified.

12
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.4 8086 PROGRAMMING – SEARCHING OF LARGEST&

SMALLEST BYTE IN AN ARRAY

DATE:
AIM:

To write an Assembly Language Program (ALP) to find the largest and smallest number in a
given array.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Power Supply +5 V dc 1

PROBLEM STATEMENT:

An array of length 10 is given from the location. Find the largest and smallest number and store
the result.

ALGORITHM:

(i) Finding largest number:


a. Load the array count in a register C1.
b. Get the first two numbers.
c. Compare the numbers and exchange if the number is small.
d. Get the third number from the array and repeat the process until C1 is 0.

(ii) Finding smallest number:


e. Load the array count in a register C1.
f. Get the first two numbers.
g. Compare the numbers and exchange if the number is large.
h. Get the third number from the array and repeat the process until C1 is 0.

13
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

14
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOWCHART

LARGEST NUMBER IN AN ARRAY SMALLEST NUMBER IN AN ARRAY


START START

INITIALIZE COUNT
INITIALIZE COUNT
POINTER MAX = 0
POINTER MIN = 0
PONITER =
PONITER =
POINTER + 1
POINTER + 1
YES
YES
IS MAX 
POINTER ?
IS MIN 
NO POINTER ?

MAX = POINTER NO

MIN = POINTER
COUNT = COUNT-1

NO COUNT = COUNT-1

IS COUNT = 0
NO
?
YES IS COUNT = 0

STORE MAXIMUM ?
YES

STOP STORE MINIIMUM

STOP

15
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

LARGEST

PROGRAM COMMENTS

Start: MOV SI,1200H Initialize array size


MOV CL,[SI] Initialize the count
INC SI Go to next memory location
MOV AL,[SI] Move the first data in AL
DEC CL Reduce the count
L2 : INC SI Move the SI pointer to next data
CMP AL,[SI] Compare two data’s
JNB L1 If AL > [SI] then go to L1 ( no swap)
MOV AL,[SI] Else move the large number to AL
L1 : DEC CL Decrement the count
JNZ L2 If count is not zero go to L2
MOV DI,1300H Initialize DI with 1300H
MOV [DI],AL Else store the biggest number in 1300 location
Stop: HLT Stop

SMALLEST

PROGRAM COMMENTS

Start: MOV SI,1200H Initialize array size


MOV CL,[SI] Initialize the count
INC SI Go to next memory location
MOV AL,[SI] Move the first data in AL
DEC CL Reduce the count
L2 : INC SI Move the SI pointer to next data
CMP AL,[SI] Compare two data’s
JB L1 If AL < [SI] then go to L1 ( no swap)
MOV AL,[SI] Else move the large number to AL
L1 : DEC CL Decrement the count
JNZ L2 If count is not zero go to L2
MOV DI,1300H Initialize DI with 1300H
MOV [DI],AL Else store the biggest number in 1300 location
Stop: HLT Stop

16
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

TEST DATA:

LARGEST

MEMORY

DATA

SMALLEST

MEMORY

DATA

RESULT:.

Thus largest and smallest number is found in a given array.

17
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.5 8086 PROGRAMMING - ASCENDING & DESCENDING

DATE:
AIM:

To write an Assembly Language Program (ALP) to sort a given array in ascending and
descending order.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Power Supply +5 V dc 1

PROBLEM STATEMENT:

An array of length 10 is given from the location. Sort it into descending and ascending order and
store the result.

ALGORITHM:

(i) Sorting in ascending order:


a. Load the array count in two registers C1 and C2.
b. Get the first two numbers.
c. Compare the numbers and exchange if necessary so that the two numbers are in ascending order.
d. Decrement C2.
e. Get the third number from the array and repeat the process until C2 is 0.
f. Decrement C1 and repeat the process until C1 is 0.
(ii) Sorting in descending order:
a. Load the array count in two registers C1 and C2.
b. Get the first two numbers.
c. Compare the numbers and exchange if necessary so that the two numbers are in descending order.
d. Decrement C2.
e. Get the third number from the array and repeat the process until C2 is 0.
f. Decrement C1 and repeat the process until C1 is 0.

18
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOWCHART

ASCENDING ORDER DESCENDING ORDER


START
START

INITIALIZE POINTER
INITIALIZE POINTER
COUNT = COUNT – 1
COUNT = COUNT – 1

FLAG = 0 YES
FLAG = 0
YES IS POINTER 
POINTER + 1
IS POINTER
 POINTER + NO
1

NO TEMP = POINTER

POINTER = POINTER + 1
TEMP = POINTER
POINTER + 1 = TEMP
POINTER = POINTER + 1

POINTER + 1 = TEMP POINTER = POINTER +1


COUNT = COUNT + 1
POINTER = POINTER +1

COUNT = COUNT + 1

IS COUNT = 0
NO

IS COUNT YES
NO
=0
IS FLAG = 0

YES
NO YES

IS FLAG = 0 STOP

YES

19
STOP
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

ASCENDING ORDER:

PROGRAM COMMENTS

Start: MOV SI,1200H Initialize memory location for array size


MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two data’s
JNB L1 If AL < BL go to L1
DEC SI Else, Decrement the memory location
MOV [SI],AL Store the smallest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory location
MOV [SI],BL Store the greatest data in memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not reached zero
Stop: HLT Stop
Test data:

MEMORY

DATA

20
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

DESCENDING ORDER:

PROGRAM COMMENTS

Start: MOV SI,1200H Initialize memory location for array size


MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two data’s
JB L1 If AL > BL go to L1
DEC SI Else, Decrement the memory location
MOV [SI],AL Store the largest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory location
MOV [SI],BL Store the smallest data in memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not reached zero
Stop: HLT Stop
MEMORY

DATA

Result: Thus given array of numbers are sorted in ascending & descending order.

21
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.6 8086 PROGRAMMING - MOVE A DATA BLOCK

DATE: (COPYING A STRING)


AIM:

To move a string of length FF from source to destination.

ALGORITHM:

a. Initialize the data segment .(DS)


b. Initialize the extra data segment .(ES)
c. Initialize the start of string in the DS. (SI)
d. Initialize the start of string in the ES. (DI)
e. Move the length of the string (FF) in CX register.
f. Move the byte from DS TO ES, till CX=0.

22
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOW CHART:

23
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

COPYING A STRING

PROGRAM COMMENTS

Start: MOV SI,1200H Initialize destination address

MOV DI,1300H Initialize starting address

MOV CX,0006H Initialize array size

CLD Clear direction flag

REP MOVSB Copy the contents of source into destination until


count reaches zero
Stop: HLT Stop

INPUT

MEMORY

DATA

OUTPUT

MEMORY

DATA

RESULT:

Thus a string of a particular length is moved from source segment to destination segment.

24
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.7 8086 PROGRAMMING - SEARCHING A STRING

DATE:
AIM:

To search a given byte in the string and find the relative address of the byte from the starting
location of the string.

ALGORITHM:

a. Initialize the extra segment .(ES)


b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX register.
d. Move the byte to be searched in the AL register.
e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI to BX.

25
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOW CHART
START

Initialize DS,ES ,SI,DI

CX=length of the string,


DF=0.

NO

Scan for a particular character


specified in AL Register.

Check for ZF=1

Move DI to BX

STOP

26
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

SEARCHING FOR A CHARACTER IN THE STRING

PROGRAM COMMENTS

Start: MOV DI,1300H Initialize destination address

MOV SI, 1400H Initialize starting address

MOV CX, 0006H Initialize array size

CLD Clear direction flag

MOV AL, 08H Store the string to be searched

REPNE SCASB Scan until the string is found

DEC DI Decrement the destination address

MOV BL,[DI] Store the contents into BL reg

MOV [SI],BL Store content of BL in source address

Stop: HLT Stop

TEST DATA: INPUT

MEMORY

DATA

OUTPUT

MEMORY LOCATION

DATA

RESULT:

Thus a given byte or word in a string of a particular length in the extra segment(destination) is
found .

27
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

28
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.8 8086 PROGRAMMING - FIND AND REPLACE STRING

DATE:
AIM:

To find a character in the string and replace it with another character.

ALGORITHM:

a. Initialize the extra segment .(E S)


b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX register.
d. Move the byte to be searched in the AL register.
e. Store the ASCII code of the character that has to replace the scanned byte in BL register.
f. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning.
g. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
START

Initialize DS, ES, SI, DI

CX=length of the string in ES,


DF=0.

DF=0.

Scan for a particular character


specified in AL Register.

NO
Check for ZF=1

YES
Move the content of BL
to ES:DI

STOP

29
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FIND AND REPLACE A CHARACTER IN THE STRING

PROGRAM COMMENTS

Start: MOV DI,1300H Initialize destination address

MOV SI,1400H Initialize starting address

MOV CX, 0006H Initialize array size

CLD Clear direction flag

MOV AL, 08H Store the string to be searched

MOV BH,30H Store the string to be replaced

REPNE SCASB Scan until the string is found

DEC DI Decrement the destination address

MOV BL,[DI] Store the contents into BL reg

MOV [SI],BL Store content of BL in source address

MOV [DI],BH Replace the string

Stop: HLT Stop

RESULT: INPUT

MEMORY

DATA

OUTPUT
MEMORY

DATA

RESULT:
Thus a given byte or word in a string of a particular length in the extra segment(destination) is
found and is replaced with another character.

30
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.9 8086 PROGRAMMING - CODE CONVERSION

DATE: ASCII CODED DECIMAL FROM KEYBOARD TO ITS HEXA DECIMAL

AIM :
To Write an Assembly language program to convert ASCII coded decimal value into its
equivalent Hexa demical Value .

ALGORITHM
1. Save Contents of All Registers Which Are Used In The Routine.
2. Make binary result=0.
3. Subtract 30H from the character typed on the keyboard to convert it to BCD.
4. Multiply the result by 10, and then add the new BCD digit.
5. Repeat steps 2 and 3 until the character typed is not an ASCII coded number.
6. Restore register contents.

PROGRAM

LABEL PROGRAM COMMENTS

START: PUSH CX ; SAVE REGISTERS


PUSH BX
PUSH AX
MOV CX,10 ;LOAD 10 DECIMAL IN CX
MOV BX,0 ;CLEAR RESULT
BACK: MOV AH,01H [READ KEY
INT 21H ; WITH ECHO]
CMP AL,’0’
JB SKIP ;JUMP IF BELOW ‘0’
CMP AL,’9’
JA SKIP ;JUMP IF ABOVE ‘9’
SUB AL,30H ;CONVERT TO BCD
PUSH AX ;SAVE DIGIT
MOV AX,BX
MUL CX ;MULTIPLY PREVIOUS RESULT BY 10
MOV BX,AX ;GET THE RESULT IN BX
POP AX
MOV AH,00H
ADD BX,AX ;ADD DIGIT VALUE TO RESULT
JMP BACK ;REPEAT

31
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

SKIP: MOV NUMBER,BX ;SAVE THE RESULT IN NUMBER


POP AX ;RESTORE REGISTERS
POP BX
POP CX
RET
STOP: ENDP

RESULTS:

INPUT

MEMORY

DATA

OUTPUT
MEMORY

DATA

RESULT:

Thus the given byte or word is converted from ASCII coded decimal value into its equivalent
Hexa decimal Value and outputs are verified.

32
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.10 8086 PROGRAMMING

DATE: MATRIX ADDITION [3 X 3]


AIM:

To write an assembly language program to perform matrix addition of size 3x3 matrix.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Cable RS232C 1

3. System with MASM 8086 programmer 1

PROBLEM STATEMENT:

To perform a matrix addition whose data are present at the location of ------------- and store
at the location-------------.

.DATA
M1 DB 00H,01H,10H,12H,02H,03H,0F0H,0C0H,04H
M2 DB 00H,05H,01H,02H,50H,90H,03H,04H,0AAH
M3 DB 9 DUP (0)
M4 DB ' $'
MES1 DB "THE SUM OF TWO MATRIX IS $"
.CODE
.STARTUP
MOV DX, OFFSET MES1
MOV AH,09H
INT 21H
MOV CL,0
P1:
XOR BX,BX
MOV BL,CL
MOV AL,M1[BX]
MOV DL,M2[BX]
ADD AL,DL
MOV M3[BX],AL
INC CL
CMP CL,9
JNZ P1

33
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MOV DX,0AH
MOV AH,02H
INT 21H
MOV CL,0
MOV CH,0
PP:XOR BX,BX
MOV BL,CL
MOV AL,M3[BX]
MOV DL,AL
ROL DL,4
AND DL,0FH
ADD DL,30H
CMP DL,'9'
JBE F1
ADD DL,7H
F1:
MOV AH,02H
INT 21H
MOV AL,M3[BX]
AND AL,0FH
MOV DL,AL
ADD DL,30H
CMP DL,'9'
JBE F2
ADD DL,7
F2:
MOV AH,02H
INT 21H
MOV DX,OFFSET M4
MOV AH,09H
INT 21H
INC CH
CMP CH,3
JNZ L1
MOV DX,0AH
MOV AH,02H
INT 21H
MOV CH,0
L1:
INC CL
CMP CL,9
JNZ PP
MOV AH,4CH
INT 21H
END

34
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

OUTPUT:

THE SUM OF TWO MATRIX IS

00 06 11

14 52 93

F3 C4 AE

RESULTS:

INPUT

MEMORY

DATA

OUTPUT
MEMORY

DATA

RESULT:

Thus the given two 3x3 matrix A and B are added and the results are verified.

35
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.11 8086 PROGRAMMING

DATE: PROGRAMMING FOR PASSWORD CHECKING


AIM:

To write an assembly language program to Check Password.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Cable RS232C 1

3. System with MASM 8086 programmer 1

PROBLEM STATEMENT:

To write a program to perform the password checking.

.MODEL SMALL
.DATA
PASS DB ‘ABC’
MES1 DB 10,13,’ENTER 3 CHARACTER
PASSWORD $’
MES2 DB 10,13,’PASSWORD IS CORRECT $’
MES3 DB 10,13,’PASSWORD ID WRONG $ ‘
.CODE
START: MOV AX,@DATA
MOV DS,AX
MOV AH,09H
LEA DX,MES1
INT 21H
MOV CL,00
MOV DL,OOH
XOR DI,DI
.WHILE CL!=3
MOV AH,07H
INT 21H
LEA BX,PASS
MOV AH,[BX+DI]
.IF AL==AH

36
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

ADD DL,01
.ENDIF
INC DI
INC CL
.ENDW
.IF DL==3
MOV AH,09H
LEA DX,MES2
INT 21H
.ELSE
MOV AH,09H
LEA DX,MES3
INT 21H
.ENDIF
MOV AH,4CH
INT 21H
END START
END

INPUT:

OUTPUT:

RESULT:

Thus the given password is checked and the result is verified.

37
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 1.12 8086 PROGRAMMING

DATE: TO DISPLAY THE CURRENT SYSTEM TIME


AIM:

To write an assembly language program to Check Password.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Cable RS232C 1

3. System with MASM 8086 programmer 1

PROBLEM STATEMENT:

To write a program to fetch and display the current system time.

.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'Current System Time is : $'
TIME DB '00:00:00$' ; time format hr:min:sec
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA BX, TIME ; BX=offset address of string TIME
CALL GET_TIME ; call the procedure GET_TIME
LEA DX, PROMPT ; DX=offset address of string PROMPT
MOV AH, 09H ; print the string PROMPT
INT 21H

LEA DX, TIME ; DX=offset address of string TIME


MOV AH, 09H ; print the string TIME
INT 21H

MOV AH, 4CH ; return control to DOS


INT 21H
MAIN ENDP

38
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

GET_TIME PROC
; this procedure will get the current system time
; input : BX=offset address of the string TIME
; output : BX=current time

PUSH AX ; PUSH AX onto the STACK


PUSH CX ; PUSH CX onto the STACK
MOV AH, 2CH ; get the current system time
INT 21H
MOV AL, CH ; set AL=CH , CH=hours
CALL CONVERT ; call the procedure CONVERT
MOV [BX], AX ; set [BX]=hr , [BX] is pointing to hr
; in the string TIME
MOV AL, CL ; set AL=CL , CL=minutes
CALL CONVERT ; call the procedure CONVERT
MOV [BX+3], AX ; set [BX+3]=min , [BX] is pointing to min
; in the string TIME
MOV AL, DH ; set AL=DH , DH=seconds
CALL CONVERT ; call the procedure CONVERT
MOV [BX+6], AX ; set [BX+6]=min , [BX] is pointing to sec
; in the string TIME
POP CX ; POP a value from STACK into CX
POP AX ; POP a value from STACK into AX
RET ; return control to the calling procedure
GET_TIME ENDP ; end of procedure GET_TIME

OUTPUT:

RESULT:

Thus the systems current date is fetched, displayed and the result is verified.

39
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP. NO: 2.1 PARALLEL INTERFACING USING 8255 PPI


DATE:

AIM:
To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and mode 2.

APPARATUS REQUIRED:
8086 kit, 8255 interface kit.
ALGORITHM:

Mode 0
1. Initialize accumulator to hold control word
2. store control word in control word register
3. Read data port A.
4. Store data from port A in memory
5. Place contents in port B

Mode 1 & Mode 2


1. Initialize accumulator to hold control word (for port A)
2. Store control word in control word register
3. Initialize accumulator to hold control word (for port B)
4. Place contents in control word register.
5. Disable all maskable interrupts, enable RST 5.5
6. send interrupt mask for RST 6.5 & 7.5
7. Enable interrupt flag
8. Read data from port A, place contents in port B

FLOWCHART START

Mode 0 START Mode 1 & 2


Store control word in control register

Store control word in


control register Input to be read from port A

Input to be read from port A Disable all interrupts except RST 6.5

Store into accumulator


Store output to port B

Output written on port B


STOP

STOP 40
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

Control Word format:

I/O mode
D7 D6 D5 D4 D3 D2 D1 D0

1 (1=I/O) Group A mode select PA PCU Group B mode select PB PCL

 D6, D5: GA mode select:


o 00 = mode0
o 01 = mode1
o 1X = mode2
 D4(PA), D3(PCU): 1=input 0=output
 D2: GB mode select: 0=mode0, 1=mode1
 D1(PB), D0(PCL): 1=input 0=output

BSR mode
Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word:
D7 D6 D5 D4 D3 D2 D1 D0

0 (0=BSR) X X X B2 B1 B0 S/R (1=S,0=R)

Bit select: (Taking Don't care's as 0)


B2 B1 B0 PC bit Control word (Set) Control word (reset)

0 0 0 0 0000 0001 = 01h 0000 0000 = 00h

0 0 1 1 0000 0011 = 03h 0000 0010 = 02h

0 1 0 2 0000 0101 = 05h 0000 0100 = 04h

0 1 1 3 0000 0111 = 07h 0000 0110 = 06h

1 0 0 4 0000 1001 = 09h 0000 1000 = 08h

1 0 1 5 0000 1011 = 0Bh 0000 1010 = 0Ah

1 1 0 6 0000 1101 = 0Dh 0000 1100 = 0Ch

1 1 1 7 0000 1111 = 0Fh 0000 1110 = 0Eh

41
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MODE 0

PROGRAM COMMENTS
MOV AL,90H Set the control word
OUT C6,AL Send it to control port
IN AL,C0 Get the contents of port A in AL
OUT C2,AL Send the contents of port B to port address
HLT Stop

MODE 1

PROGRAM COMMENTS
MOV AL,0B0H Set the control word for mode 1
OUT C6,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT C6,AL Send it to control port
MOV AL,13H Interrupt generation
OUT 30,AL
MOV AL,0AH Through 8259
OUT 32,AL
MOV AL,0FH Using IR2 interrupt(lower order count)
OUT 32,AL
MOV AL,00H Higher order count
OUT 32,AL
STI Set trap flag
HLT Stop
ISR: Subroutine
IN AL,C0 Read from Port A
OUT C2,AL Send it to Port B
HLT Stop

42
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MODE 2

PROGRAM COMMENTS
MOV AL,0C0H Set the control word for mode 2
OUT C6,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT C6,AL Send it to control port
MOV AL,13H Interrupt generation
OUT 30,AL
MOV AL,0AH Through 8259
OUT 32,AL
MOV AL,0FH Using IR2 interrupt(lower order count)
OUT 32,AL
MOV AL,00H Higher order count
OUT 32,AL
STI Set trap flag
HLT Stop
ISR: Subroutine
IN AL,C0 Read from Port A
OUT C2,AL Send it to Port B
HLT Stop

Result:

Mode 0 Mode 1 Mode 2

Input Output Input Output Input Output

The programs for interfacing 8255 with 8085 are executed & the output is obtained for mode 0,1 & 2

43
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP. NO: 2.2 PROGRAMMABLE TIMER INTERFACING - 8253

DATE:
AIM :

To study different modes of operation of programmable timer 8253

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 Vi Microsystems 1

2. Power Supply +5V dc 1

3. 8253 interfacing kit - 1

4. CRO - 1

THEORY:

The main features of the timer are,

i. Three independent 16-bit counters


ii. Input clock from DC to 2 MHz
iii. Programmable counter modes
iv. Count binary or BCD
The control signals with which the 8253 interfaces with the CPU are CS, RD, WR, A1,
A2.The basic operations performed by 8253 are determined by these control signals. It
has six different modes of operation, viz, mode 0 to mode 5.

MODE 2 – RATE GENERATOR


It is a simple divide - by – N counter. The output will be low for one input clock period. The
period from one output pulse to the next equals the number of input counts in the count register. If the
count register is reloaded between output pulses, the present period will not be affected, but the
subsequent period will reflect the new value.

MODE 3 – SQUARE WAVE GENERATOR

44
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

It is similar to mode 2, except that the output will remain high until one half for even number
count, If the count is odd, the output will be high for (count+1)/2 counts and low for (count-1)/2 counts

ALGORITHM:

Mode 2-

1. Initialize channel 0 in mode 2


2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.

Mode 3-
1. Initialize channel 0 in mode 3
2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.

PORT ADDRESS :

1. CONTROL REGISTER –
2. COUNTER OF CHANNEL 0 -
3. COUNTER OF CHANNEL 1 -
4. COUNTER OF CHANNEL 2 -

CONTROL WORD FORMAT:

D7 D6 D5 D4 D3 D2 D1 D0

SC1 SC0 RL1 RL0 M2 M1 M0 BCD Mode 2 = 34 H


0 0 1 1 0 1 0 0 Mode 3 = 36 H
0 0 1 1 0 1 1 0

SC1 SC0 CHANNEL SELECT RL1 RL0 READ/LOAD

0 0 CHANNEL 0 0 0 LATCH
0 1 CHANNEL 1 0 1 LSB
1 0 CHANNEL 2 1 0 MSB
1 1 ----- 1 1 LSB FIRST, MSB NEXT

45
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

BCD --0 –BINARY COUNTER 1 --BCD COUNTER

M2 M1 M0 MODE
0 0 0 MODE 0
0 0 1 MODE 1
0 1 0 MODE 2
0 1 1 MODE 3
1 0 0 MODE 4
1 0 1 MODE 5
PORT PIN ARRANGEMENT DEBOUNCE CIRCUIT CONNECTION
1 CLK 0
2 GATE 0 * * *
3 OUT 0
4 CLK 1
5 GATE 1
6 OUT 1
7 CLK 2
8 GATE 2
9 OUT 2
10 GND

MODE 2 – RATE GENERATOR:


PROGRAM COMMENTS
Start: MOV AL, 34H Store the control word in accumulator
OUT 0BH Send through output port
MOV AL, 0AH Copy lower order count value in accumulator
OUT 08H Send through output port
MOV AL, 00H Copy higher order count value in accumulator
OUT 08H Send through output port
Stop: HLT Stop

MODE 3 – SQUARE WAVE GENERATOR:


PROGRAM COMMENTS
Start: MOV AL, 36H Store the control word in accumulator
OUT 0BH Send through output port
MOV AL, 0AH Copy lower order count value in accumulator
OUT 08H Send through output port
MOV AL, 00H Copy higher order count value in accumulator

46
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

OUT 08H Send through output port


Stop: HLT Stop

47
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MODEL GRAPH:

RATE GENERATOR SQUARE WAVE GENERATOR

FLOW CHART

START

INITIALIZE ACCUMULATOR
WITH MODE SET WORD

INITIALIZE LSB OF COUNT

INITIALIZE MSB OF COUNT

TRIGGER THE COUNT

STOP

RESULT:
Thus an ALP for rate generator and square wave generator are written and executed by
interfacing with timer ic8253.

48
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP. NO: 2.3 SERIAL INTERFACING - USART 8251

DATE:

AIM:
To study interfacing technique of 8251 (USART) with microprocessor 8086 and write an 8086
ALP to transmit and receive data between two serial ports with RS232 cable.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY


1. Microprocessor kit 8086 Vi Microsystems 1
2. Power Supply +5V dc 1
3. 8253 interfacing kit - 1
4. RS232 C Cable - 1

THEORY:
The 8251 is used as a peripheral device for serial communication and is programmed by the
CPU to operate using virtually any serial data transmission technique. The USART accepts data
characters from the CPU in parallel format and then converts them into a continuous serial data stream
for transmission. Simultaneously, it can receive serial data streams and convert them into parallel data
characters for the CPU. The CPU can read the status of the USART at any time. These include data
transmission errors and control signals. The control signals define the complete functional definition of
the 8251. Control words should be written into the control register of 8251.These control words are split
into two formats: 1) Mode instruction word & 2) Command instruction word. Status word format is used
to examine the error during functional operation.

1...transmit enable
1...data terminal ready
1... receive enable
1... send break character
1.... reset error flags (pe,oe,fe)
1..... request to send (rts)
1...... internal reset
1....... enter hunt mode (enable search for sync characters)

49
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

1 ransmitter ready
1. receiver ready
1.. transmitter empty
1... parity error (pe)
1.... overrun error (oe)
1..... framing error (fe), async only
1...... sync detect, sync only
1....... data set ready (dsr)

50
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

ALGORITHM:

1. Initialize 8253 and 8251 to check the transmission and reception of a character
2. Initialize8253 to give an output of 150Khz at channel 0 which will
give a 9600 baud rate of 8251.
3. The command word and mode word is written to the 8251 to set up for subsequent operations
4. The status word is read from the 8251 on completion of a serial I/O operation, or
when the host CPU is checking the status of the device before starting the next I/O operation

FLOW CHART:

START

Check TX/RX Ready

No

Is it High

Yes

Write Data into data register

STOP

51
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PROGRAM: TRANSMITTER END

PROGRAM COMMENTS
MOV AL,36 Initialize 8253 in mode 3 square wave generator
OUT CE,AL Send through port address
MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL Send through port address
MOV AL,00 Initialize AL with higher value of count
OUT C8,AL Send through port address
MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL Send through port address
MOV AL,37 Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL Send through port address
L1:IN AL,C2 Read status word
AND AL,04 Check whether transmitter ready
JZ L1 If not wait until transmitter becomes ready
MOV AL,41 Set the data as 41
OUT C0,AL Send through port address
INT 2 Restart the system

RECEIVER END

PROGRAM COMMENTS
MOV AL,36 Initialize 8253 in mode 3 square wave generator
OUT CE,AL Send through port address
MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL Send through port address
MOV AL,00 Initialize AL with higher value of count
OUT C8,AL Send through port address
MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL Send through port address
MOV AL,37 Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL Send through port address
L1: IN AL,C2 Read status word
AND AL,02 Check whether receiver ready
JZ L1 If not wait until receiver becomes ready
IN AL,C0 If it is ready, get the data
MOV BX,1500 Initialize BX register with memory location to store the data
MOV [BX],AL Store the data in the memory location
INT 2 Restart the system

RESULT: Thus ALP for serial data communication using USART 8251 is written and the equivalent
ASCII 41 for character ‘A’ is been transmitted & received.

52
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP.NO: 2.4 INTERFACING PRGRAMMABLE KEYBOARD AND

DATE: DISPLAY CONTROLLER - 8279


AIM :

To display the rolling message “ HELP US “ in the display.

APPARATUS REQUIRED:

8086 Microprocessor kit, Power supply, interfacing board 8279.

ALGORITHM :

Display of rolling message “ HELP US “

1. Initialize the counter


2. Set 8279 for 8 digit character display, right entry
3. Set 8279 for clearing the display
4. Write the command to display
5. Load the character into accumulator and display it
6. Introduce the delay
7. Repeat from step 1.

1. Display Mode Setup: Control word-10 H

0 0 1 0 0 0 0

0 0 0 D D K K K

DD

00- 8Bit character display left entry

01- 16Bit character display left entry

10- 8Bit character display right entry

11- 16Bit character display right entry

KKK- Key Board Mode

000-2Key lockout.

53
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

2. Clear Display: Control word-DC H

1 1 0 1 1 1 0 0

1 1 0 CD CD CD CF CA

1-Enables Clear display 11 A0-3; B0-3 =FF


0-Contents of RAM will be displayed
1-FIFO Status is cleared

1-Clear all bits

(Combined effect of CD)


3. Write Display: Control word-90H

1 0 0 1 0 0 0 0

1 0 0
AI A A A A

Selects one of the 16 rows of display.

Auto increment = 1, the row address selected will be incremented after each of read and
write operation of the display RAM.

54
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

START

FLOWCHART:
SET UP POINTER

INITIALIZE THE COUNTER

SET 8279 FOR 8-DIGIT CHARACTER DISPLAY

SET 8279 FOR CLEARING THE


DISPLAY

WRITE THE COMMAND TO DISPLAY

LOAD THE CHARACTER INTO ACCUMULATOR


AND DISPLAY

DELAY

PROGRAM TABLE

PROGRAM COMMENTS
Start : MOV SI,1200H Initialize array
MOV CX,000FH Initialize array size
MOV AL,10 Store the control word for display mode
OUT C2,AL Send through output port
MOV AL,CC Store the control word to clear display
OUT C2,AL Send through output port
MOV AL,90 Store the control word to write display
OUT C2,AL Send through output port
L1 : MOV AL,[SI] Get the first data
OUT C0,AL Send through output port
CALL DELAY Give delay
INC SI Go & get next data

55
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

LOOP L1 Loop until all the data’s have been taken


JMP Start Go to starting location

DELAY: MOV DX,0A0FFH Store 16bit count value


LOOP1: DEC DX Decrement count value
JNZ LOOP1 Loop until count values becomes zero
RET Return to main program

LOOK-UP TABLE:

1200 98 68 7C C8

1204 FF 1C 29 FF

MEMORY 7-SEGMENT LED FORMAT HEX Character


LOCATION DATA Displayed
d c b a dp g f e

1200H 1 0 0 1 1 0 0 0 98 H

1201H 0 1 1 0 1 0 0 0 68 E

1202H 0 1 1 1 1 1 0 0 7C L

1203H 1 1 0 0 1 0 0 0 C8 P

1204H 1 1 1 1 1 1 1 1 FF Space

1205H 0 0 0 0 1 1 0 0 1C U

1206H 0 0 1 0 1 0 0 1 29 S

1207H 1 1 1 1 1 1 1 1 FF Space

RESULT:

Thus the rolling message “HELP US” is displayed using 8279 interface kit.

56
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP.NO: 2.5 STEPPER MOTOR INTERFACING

DATE:
AIM:

To write an assembly language program in 8086 to rotate the motor at different speeds.
APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Power Supply +5 V, dc,+12 V dc 1

3. Stepper Motor Interface board - 1

4. Stepper Motor - 1

PROBLEM STATEMENT:

Write a code for achieving a specific angle of rotation in a given time and particular number of
rotations in a specific time.

THEORY:

A Stepper motor is a motor in which the rotation is in step by step manner with an angle of
rotation. The rotor in stepper motor has only discrete stationary angular. The rotary motion occurs in a
stepwise manner from one equilibrium position to the next. The stator has electromagnet with winding
on all the 4 poles. The rotor has permanent magnet with 3 pairs of poles having two poles of north and
south each. Two-phase scheme: Any two adjacent stator windings are energized. There are two magnetic
fields active in quadrature and none of the rotor pole faces can be in direct alignment with the stator
poles. A partial but symmetric alignment of the rotor poles is of course possible.

ALGORITHM:

For running stepper motor clockwise and anticlockwise directions

(i) Get the first data from the lookup table.


(ii) Initialize the counter and move data into accumulator.
(iii) Drive the stepper motor circuitry and introduce delay
(iv) Decrement the counter is not zero repeat from step(iii)
(v) Repeat the above procedure both for backward and forward directions.

57
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

SWITCHING SEQUENCE OF STEPPER MOTOR:

MEMORY A1 A2 B1 B2 HEX
LOCATION CODE

4500 1 0 0 1 09 H

4501 0 1 0 1 05 H

4502 0 1 1 0 06 H

4503 1 0 1 0 0A H

FLOWCHART:
START

INTIALIZE COUNTER FOR LOOK UP TABLE

GET THE FIRST DATA FROM THE ACCUMULATOR

MOVE DATA INTO THE ACCUMULATOR

DRIVE THE MOTOR CIRCUITARY

DELAY

DECREMENT COUNTER

YES
IS Count = 0

NO

GET THE DATA FROM LOOK UP TABLE

58
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PROGRAM TABLE

PROGRAM COMMENTS
Start: MOV DI, 1200H Initialize memory location to store the array of number
MOV CX, 0004H Initialize array size
Loop1: MOV AL,[DI] Copy the first data in AL
OUT 0C0,AL Send it through port address
MOV DX, 1010H
L1 : DEC DX Introduce delay
JNZ L1
INC DI Go to next memory location
LOOP Loop1 Loop until all the data’s have been sent
JMP Start Go to start location for continuous rotation
1200 : 09,05,06,0A Array of data’s

RESULT:

Thus the assembly language program for rotating stepper motor in both clockwise and
anticlockwise directions is written and verified.

59
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 2.6 8086 PROGRAMMING

DATE: THE TRAFFIC LIGHT CONTROL SYSTEM


AIM:

To write an assembly language program to control the Traffic light System by interfacing 8255
– Programmable Peripheral Interface using 8086 microprocessors.

APPARATUS REQUIRED:
SL.NO ITEM SPECIFICATION QUANTITY
1. Microprocessor kit 8086 1
3. System with MASM 8086 programmer 1
4. Traffic light system 1
interfacing card

PROBLEM STATEMENT:
To write a program to control traffic light setup using the interfacing 8255PPI, in which Port
A and Port B are used.

60
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

DESCRIPTION:
The board is a simple model of a traffic control system wherein the signaling lights are simulated
by the blinking ON-OFF of light emitting diodes. The signaling lights for the pedestrian crossing are
simulated by the ON-OFF control of dual color light emitting diodes.

A model of four road-four lane junctions, the board has green, yellow and red LEDs, which are
the green, orange and red signals of an actual system. Twelve LEDs are used in the board. In addition
eight dual color LEDs are used which can be made to change either to red or to orange.

The board communicates with the microprocessor trainer by means of a 26-core cable, which is
connected to the output pins of any parallel port of Vi range of trainers. The outputs are the inputs to the
buffers 7406 whose output drives the LEDs. The buffered output applied to the anode of the LEDs
decides whether it is ON or OFF.

ALGORITHM:

61
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

1. Initialize the system for the required situation


2. Generate the data accordingly
3. Out to particular port to make the Led glow
4. Call delay program
5. Repeat the sequence.

PORT ADDRESS:
Port A : 0CH
Port B : 0DH
Port C : 0EH
Control Reg.: 0FH

CONTROL WORD FORMAT of 8255H:

D7 -1 =I/O MODE

62
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

SAMPLE INPUTS:

CONTROL WORD TO INTERFACE 8255:


4100 80

INPUTS TO PORT A & PORT B-LOOK UP TABLE:

4101 1A A1 64
4104 A4 81 5A 64
4108 54 8A B1 A8
410C B4 88 DA 68
4110 D8 1A E8 46
4114 E8 83 78 86 74

ALGORITHM

PROGRAM
CONTRL EQU 026H
PORTA EQU 020H

63
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PORTB EQU 022H


PORTC EQU 024H
ORG 1000H
START: MOV BX,1100H
MOV CX,000CH
MOV AL,[BX]
OUT CONTRL,AL
INC BX
NEXT: MOV AL,[BX]
OUT PORTA,AL
INC BX
MOV AL,[BX]
OUT PORTB,AL
CALL DELAY
INC BX
LOOP2: JMP START

DELAY: PUSH CX
MOV CX,0005H
1020 REPEAT:
MOV DX,0FFFFH
LOOP2: DEC DX
FD JNZ LOOP2
LOOP REPEAT
POP CX
RET

ORG 1100H
DB 80H,1AH,0A1H,64H,0A4H
DB 81H,5AH,64H,54H,8AH
DB 0B1H,0A8H,0B4H,88H
DB 0DAH,68H,0D8H,1AH,0E8H
DB 46H,0E8H,83H,78H,86H,74H
CODE ENDS
END

RESULT:
Thus the traffic light controller interfacing with 8086 microprocessor using 8255PPI and
the traffic signals were tested and verified.

64
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 2.7 8086 INTERFACING

DATE: INTERFACING ANALOG TO DIGITAL CONVERTER


AIM:

To write an assembly language program to convert an analog signal into a digital signal using an
ADC interfacing.

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 1

2. Power Supply +5 V dc,+12 V dc 1

3. ADC Interface board - 1

PROBLEM STATEMENT:

The program is executed for various values of analog voltage which are set with the help of a
potentiometer. The LED display is verified with the digital value that is stored in a memory location.

THEORY:

An ADC usually has two additional control lines: the SOC input to tell the ADC when to start the
conversion and the EOC output to announce when the conversion is complete. The following program
initiates the conversion process, checks the EOC pin of ADC 0809 as to whether the conversion is over
and then inputs the data to the processor. It also instructs the processor to store the converted digital data
at RAM location.

ALGORITHM:

(i) Select the channel and latch the address.


(ii) Send the start conversion pulse.
(iii) Read EOC signal.
(iv) If EOC = 1 continue else go to step (iii)
(v) Read the digital output.
(vi) Store it in a memory location.

65
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

FLOW CHART:
START

SELECT THE CHANNEL AND LATCH ADDRESS

SEND THE START CONVERSION PULSE

NO
IS EOC = 1?

YES

READ THE DIGITALOUTPUT

STORE THE DIGITAL VALUE IN THE MEMORY


LOCATION SPECIFIED

STOP

PROGRAM TABLE

PROGRAM COMMENTS

Start:MOV AL,00 Load accumulator with value for ALE high


OUT 0C8H,AL Send through output port
MOV AL,08 Load accumulator with value for ALE low
OUT 0C8H,AL Send through output port
MOV AL,01 Store the value to make SOC high in the accumulator
OUT 0D0H,AL Send through output port
MOV AL,00
MOV AL,00 Introduce delay
MOV AL,00
MOV AL,00 Store the value to make SOC low the accumulator
OUT 0D0H,AL Send through output port
L1 : IN AL, 0D8H
AND AL,01 Read the EOC signal from port & check for end of
CMP AL,01 conversion

66
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

JNZ L1 If the conversion is not yet completed, read EOC signal


from port again
IN AL,0C0H Read data from port
MOV BX,1100 Initialize the memory location to store data
MOV [BX],AL Store the data
Stop: HLT Stop

RESULT:
ANALOG DIGITAL DATA ON LED HEX CODE IN MEMORY
VOLTAGE DISPLAY LOCATION

Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its
digital equivalent.

67
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 2.8 8086 INTERFACING

DATE: INTERFACING DIGITAL – TO – ANALOG CONVERTER


AIM:

1. To write an assembly language program for digital to analog conversion


2. To convert digital inputs into analog outputs & To generate different waveforms

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY

1. Microprocessor kit 8086 Vi Microsystems 1

2. Power Supply +5 V, dc,+12 V dc 1

3. DAC Interface board - 1

PROBLEM STATEMENT:

The program is executed for various digital values and equivalent analog voltages are measured
and also the waveforms are measured at the output ports using CRO.

THEORY:

Since DAC 0800 is an 8 bit DAC and the output voltage variation is between –5v and +5v. The
output voltage varies in steps of 10/256 = 0.04 (approximately). The digital data input and the
corresponding output voltages are presented in the table. The basic idea behind the generation of
waveforms is the continuous generation of analog output of DAC. With 00 (Hex) as input to DAC2 the
analog output is –5v. Similarly with FF H as input, the output is +5v. Outputting digital data 00 and FF
at regular intervals, to DAC2, results in a square wave of amplitude 5v.Output digital data from 00 to FF
in constant steps of 01 to DAC2. Repeat this sequence again and again. As a result a saw-tooth wave
will be generated at DAC2 output. Output digital data from 00 to FF in constant steps of 01 to DAC2.
Output digital data from FF to 00 in constant steps of 01 to DAC2. Repeat this sequence again and
again. As a result a triangular wave will be generated at DAC2 output.

ALGORITHM:
Measurement of analog voltage:

(i) Send the digital value of DAC.


(ii) Read the corresponding analog value of its output.

68
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

Waveform generation:

Square Waveform:

(i) Send low value (00) to the DAC.


(ii) Introduce suitable delay.
(iii) Send high value to DAC.
(iv) Introduce delay.
(v) Repeat the above procedure.
Saw-tooth waveform:

(i) Load low value (00) to accumulator.


(ii) Send this value to DAC.
(iii) Increment the accumulator.
(iv) Repeat step (ii) and (iii) until accumulator value reaches FF.
(v) Repeat the above procedure from step 1.
Triangular waveform:

(i) Load the low value (00) in accumulator.


(ii)Send this accumulator content to DAC.
(iii)
Increment the accumulator.
(iv)Repeat step 2 and 3 until the accumulator reaches FF, decrement the
accumulator and send the accumulator contents to DAC.
(v) Decrementing and sending the accumulator contents to DAC.
(vi) The above procedure is repeated from step (i)
FLOWCHART:

MEASUREMENT OF ANALOG VOLTAGE SQUARE WAVE FORM


START
START

INTIALISE THE ACCUMULATOR SEND


ACC CONTENT TO DAC
SEND THE DIGITALVALUE TO
ACCUMULATOR
DELAY

TRANSFER THE ACCUMULATOR LOAD THE ACC WITH MAX VALUE


CONTENTS TO DAC SEND ACC CONTENT TO DAC

READ THE CORRESPONDING DELAY


ANALOG VALUE

STOP

69
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

SAWTOOTH WAVE FORM TRIANGULAR WAVE FORM


START
START

INITIALIZE
INITIALIZE
ACCUMULATOR
ACCUMULATOR

SEND ACCUMULATOR
SEND ACCUMULATOR CONTENT TO DAC

CONTENT TO DAC
INCREMENT ACCUMULATOR INCREMENT ACCUMULATOR
CONTENT CONTENT

NO YES
YES
IS ACC  FF
IS ACC 
FF
NO

DECREMENT ACCUMULATOR
CONTENT

SEND ACCUMULATOR
CONTENT TO DAC

YES
NO
IS ACC  00

MEASUREMENT OF ANALOG VOLTAGE:

PROGRAM COMMENTS
MOV AL,7FH Load digital value 00 in accumulator
OUT C0,AL Send through output port
HLT Stop

DIGITAL DATA ANALOG VOLTAGE

70
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PROGRAM TABLE: Square Wave

PROGRAM COMMENTS
L2 : MOV AL,00H Load 00 in accumulator
OUT C0,AL Send through output port
CALL L1 Give a delay
MOV AL,FFH Load FF in accumulator
OUT C0,AL Send through output port
CALL L1 Give a delay
JMP L2 Go to starting location
L1 : MOV CX,05FFH Load count value in CX register
L3 : LOOP L3 Decrement until it reaches zero
RET Return to main program

Output waveform: X axis: Time in sec Y axis: Amplitude in volts

PROGRAM TABLE: Saw tooth Wave

PROGRAM COMMENTS

L2 : MOV AL,00H Load 00 in accumulator


L1 : OUT C0,AL Send through output port
INC AL Increment contents of accumulator
JNZ L1 Send through output port until it reaches FF
JMP L2 Go to starting location

Output waveform: X axis: Time in sec Y axis: Amplitude in volts

71
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PROGRAM TABLE:

Triangular Wave
PROGRAM COMMENTS

L3 : MOV AL,00H Load 00 in accumulator


L1 : OUT C0,AL Send through output port
INC AL Increment contents of accumulator
JNZ L1 Send through output port until it reaches FF
MOV AL,0FFH Load FF in accumulator
L2 : OUT C0,AL Send through output port
DEC AL Decrement contents of accumulator
JNZ L2 Send through output port until it reaches 00
JMP L3 Go to starting location

RESULT:WAVEFORM GENERATION:

WAVEFORMS AMPLITUDE TIMEPERIOD

Square Waveform
Saw-tooth waveform

Triangular waveform

MODEL GRAPH:

RESULT:

Thus the DAC was interfaced with 8086 and different waveforms have been generated.

72
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP. NO.2.9 8086 INTERFACING

PROGRAMS FOR DIGITAL CLOCK AND STOP WATCH


DATE:
AIM:

To Program the 8086microprrocessor that places a message on the screen every 10 seconds,
using INT 1A h.

APPARATUS REQUIRED:

8086 microprocessor kit

PROGRAM STATEMENT:

CODE SEGMENT
TIMEDELAY:
MOV SP,1000H
MOV DI,10XD
TIME OUT:
MOV AH,00H
INT 1AH
MOV BX,DX
TIMER:
MOV AH, 00H
INT 1AH
SUB DX, BX
CMP DX, 182XD
JC TIMER
MOV AH, 09H
CS MOV DX,MSG
INT 21H
DEC DI
JNZ TIMEOUT
MOV AX,4C00H
INT 21H
MSG:
DB 'TEN MORE SECONDS HAVE PASSED $'
CODE ENDS

RESULT:

Thus 8086microprocessor is programmed for digital clock and the outputs are verified.

73
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 3.1 8051 PROGRAMMING

DATE:
8 BIT Addition / Subtraction / Multiplication / Division – Basic Arithmetic Operations

AIM:

To write a program to add / Subtraction / Multiply and divide two 8-bit numbers using 8051
microcontroller.

ALGORITHM: Addition
1. Clear Program Status Word.
2. Select Register bank by giving proper values to RS1 & RS0 of PSW.
3. Load accumulator A with any desired 8-bit data.
4. Load the register R 0 with the second 8- bit data.
5. Add these two 8-bit numbers.
6. Store the result. START
7. Stop the program.
ALGORITHM:

1. Clear the carry flag. CLEAR CARRY


2. Initialize the register for borrow. FLAG
3. Get the first operand into the accumulator.
4. Subtract the second operand from the accumulator.
5. If a borrow results increment the carry register.
GET I’ST
6. Store the result in memory.
OPERAND IN
ACCR
FLOW CHART: Addition Subtraction
START SUBTRACT THE
2’ND OPERAND
FROM ACCR
Clear PSW

N
Select Register IS CF=1 o
Bank
Y
Load A and R 0
with 8- bit datas INCREMENT THE
BORROW
REGISTER
Add A & R 0

Store the sum STORE RESULT


IN MEMORY

STOP
74 STOP
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

8 Bit Addition (Immediate Addressing)

ADD LABEL MNEMONIC OPERAND HEX COMMENTS


RESS CODE

4100 Start: CLR C C3 Clear CY Flag

4101 MOV A, data1 74,data1 Get the data1 in


Accumulator
4103 ADDC A, # data 2 24,data2 Add the data1 with data2

4105 MOV DPTR, # 4500H 90,45,00 Initialize the memory


location
4108 MOVX @ DPTR, A F0 Store the result in
memory location
4109 L1: SJMP L1 80,FE Stop the program

8 Bit Subtraction (Immediate Addressing)

ADD LABEL MNEMONIC OPERAND HEX COMMENTS


RESS CODE
4100 Start: CLR C C3 Clear CY flag

4101 MOV A, # data1 74, data1 Store data1 in


accumulator
4103 SUBB A, # data2 94,data2 Subtract data2 from
data1
4105 MOV DPTR, # 4500 90,45,00 Initialize memory
location
4108 MOVX @ DPTR, A F0 Store the difference in
memory location
4109 L1: SJMP L1 80,FE Stop

OUTPUTS : Addition OUTPUTS : Subtraction


MEMORY DATA MEMORY DATA
LOCATION LOCATION

4500 4500

75
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

ALGORITHM: Multiplication

a. Get the multiplier in the accumulator.


b. Get the multiplicand in the B register.
c. Multiply A with B.
d. Store the product in memory.

ALGORITHM: Division

1. Get the Dividend in the accumulator.


2. Get the Divisor in the B register.
3. Divide A by B.
4. Store the Quotient and Remainder in memory.

FLOWCHART:

START START

GET MULTIPLIER GET DIVIDEND IN


IN ACCR ACCR

GET MULTIPLICAND GET DIVISOR IN B


IN B REG REG

MULTIPLY A WITH B DIVIDE A BY B

STORE
STORE RESULT QUOTIENT &
IN MEMORY REMAINDER IN
MEMORY

STOP STOP

76
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

8 Bit Multiplication

ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS


CODE
4100 MOV A ,#data1 74, data1 Store data1 in accumulator

4102 MOV B, #data2 75,data2 Store data2 in B reg

4104 MUL A,B F5,F0 Multiply both

4106 MOV DPTR, # 4500H 90,45,00 Initialize memory location

4109 MOVX @ DPTR, A F0 Store lower order result

401A INC DPTR A3 Go to next memory location

410B MOV A,B E5,F0


Store higher order result
410D MOV @ DPTR, A F0

410E STOP SJMP STOP 80,FE Stop

8 Bit Division

ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS


CODE
4100 MOV A, # data1 74,data1 Store data1 in
accumulator
4102 MOV B, # data2 75,data2 Store data2 in B reg

4104 DIV A,B 84 Divide

4015 MOV DPTR, # 4500H 90,45,00 Initialize memory


location
4018 MOVX @ DPTR, A F0 Store remainder

4109 INC DPTR A3 Go to next memory


location
410A MOV A,B E5,F0
Store quotient
410C MOV @ DPTR, A F0

410D STOP SJMP STOP 80,FE Stop

77
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

RESULT:

OUTPUT
MEMORY LOCATION DATA
4502
4503

OUTPUT

MEMORY LOCATION DATA

4502 (remainder)

4503 (quotient)

RESULT:

Thus the 8051 Assembly Language Program for addition / subtraction / multiplication and
division of two 8 bit numbers is executed and verified.

78
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 3.2 8051 PROGRAMMING

DATE:
8 BIT Logical and Bit Manipulation

AIM:

To write an Assembly Language Program to perform logical and bit manipulation operations
using 8051 microcontroller.

APPARATUS REQUIRED:

8051 microcontroller kit

ALGORITHM:

1. Initialize content of accumulator as FFH


2. Set carry flag (cy = 1).
3. AND bit 7 of accumulator with cy and store PSW format.
4. OR bit 6 of PSW and store the PSW format.
5. Set bit 5 of SCON.
6. Clear bit 1 of SCON.
7. Move SCON.1 to carry register.
8. Stop the execution of program.

FLOWCHART:

START

Set CY flag, AND CY with MSB of ACC

Store the PSW format, OR CY with bit 2 IE reg

Clear bit 6 of PSW, Store PSW

Set bit 5 of SCON , clear bit 1 and store


SCON

Move bit 1 of SCON to CY and store PSW

STOP 79
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

PROGRAM TABLE

ADDRESS HEX LABEL MNEMONICS OPERAND COMMENT


CODE
4100 90,45,00 Start: MOV DPTR,#4500 Initialize memory
location
4103 74,FF MOV A,#FF Get the data in
accumulator
4105 D3 SETB C Set CY bit

4016 82,EF ANL C, ACC.7 Perform AND with 7th


bit of accumulator
4018 E5,D0 MOV A,DOH
410A F0 MOVX @DPTR,A Store the result

410B A3 INC DPTR Go to next location

410C 72,AA ORL C, IE.2 OR CY bit with 2nd bit if


IE reg
410E C2,D6 CLR PSW.6 Clear 6th bit of PSW

4110 E5,D0 MOV A,DOH


4112 F0 MOVX @DPTR,A Store the result

4113 A3 INC DPTR Go to next location

4114 D2,90 SETB SCON.5 Set 5th of SCON reg


4116 C2,99 CLR SCON.1 Clear 1st bit of SCON
reg
4118 E5,98 MOV A,98H
411A F0 MOVX @DPTR,A Store the result

411B A3 INC DPTR Go to next location

411C A2,99 MOV C,SCON.1 Copy 1st bit of SCON


reg to CY flag
411E E5,D0 MOV A,D0H
Store the result
4120 F0 MOVX @DPTR,A

4122 80,FE L2 SJMP L2 Stop

80
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

OUTPUT:

MEMORY SPECIAL FUNCTION REGISTER FORMAT BEFORE AFTER


LOCATION EXECUTION EXECUTION
4500H (PSW) CY AC FO RS1 RS0 OV - P 00H 88H

4501H (PSW) CY AC FO RS1 RS0 OV - P 40H 88H

4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H

4503H (PSW) CY AC FO RS1 RS0 OV - P FFH 09H

RESULT:

Thus the bit manipulation operation is done and verified in 8051 microcontroller.

81
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 3.3 8051 PROGRAMMING

DATE:

2’s complements ,Square and Square root


AIM:

To write an ALP to find 2’s complement, square and square root of a byte using 8051
microcontroller.

APPARATUS REQUIRED:

8051 microcontroller kit

ALGORITHM: 2’s complement

1. Get the data in the accumulator.


2. Find complement of the data0.
3. Add 1 with the complemented data and find 2’s complement.
4. Store at one location and verify the result.
PROGRAM:

2’s complement
ORG 0000H
START: MOV A, # 05h
CPL A
ADD A, #01H
MOV DPTR,#4500h
MOV @DPTR, A
AGAIN: SJMP AGAIN

Square of a number

82
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

Square Root of A Number

RESULT:

2’s complement
INPUT OUTPUT
A=05H at memory location 4500h =FBH

Square of a number
8600H = 7AH 8700H=24H ; 8701 = 3AH

Square root of a number


8600H = 19H = (25)10 8700H=05H

Thus the 8051 Assembly Language Program for finding 2’ complement, square of a number and
square root of a number are executed and results are verified.

83
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

EXP NO: 3.4 8051 PROGRAMMING

DATE:

BCD to ASCII CONVERSION


AIM:

To convert packed BCD number to ASCII Code using 8051 microcontroller.

APPARATUS REQUIRED:

8051 microcontroller kit

PROGRAM STATEMENT:

Assume that register A has packed BCD. Write a program to convert packed BCD to two ASCII
numbers and place them in R2 and R6

Solution:

MOV A, #29H ; A=29H, packed BCD


MOV R2,A ;Keep a copy of BCD data in R2
ANL A,#0FH ;mask the upper nibble(A=09)

ORL A, #30H ;make it an ASCII, A=39H (‘9’)


MOV R6, A ;save it( R6=39H ASCII Char)
MOV A,R2 ;A=29H, get the original data
ANL A,)FH ;mask the lower nibble(A=20)
RR A ;Rotate right
RR A ;Rotate right
RR A ;Rotate right

RR A ;Rotate right
ORL A, #30H ;A=32H, ASCII Char’2’
MOV R2,A ;save ASCII Char in R2

After giving these instructions, you have to use the following instructions to verify the output at
memory location.

84
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

MOV DPTR,#4500H
MOV A, R6
MOV @DPTR,A
INC DPTR
MOV A,R2
MOV @DPTR,A
STOP: SJMP STOP

RESULT:
INPUT:29H (Packed BCD) OUTPUT: 4500 = 39H(ASCII) ; 4501 = 32H (ASCII).
Thus the given packed BCD is unpacked and packed ASCII number is found and verified.

85
EC6513 MICROPROCESSOR & MICROCONTROLLER LAB DEPT OF ECE / PEC

86

You might also like