You are on page 1of 111

P a g e |1

PROGRAMMING WITH 8085

ADDITION OF TWO 8-BIT NUMBERS.

Ex. No.1a

AIM:
To write an Assembly Language Program (ALP) for performing the addition operations of 8-bit
numbers with and without carry.

APPARATUS REQUIRED:
Microprocessor kit, Power supply.

PROBLEM STATEMENT:
Write an ALP in 8085 P to add two 8-bit binary numbers stored in the memory location 5500H
and 5501H and store the result in the memory location 5502H.Also provide an instruction in the above
program to consider the carry also and store the carry in the memory location 5503H.

ALGORITHM:

a) Initialize the MSBs of sum to 0


b) Get the first number from the location 5500H
c) Add the second number which is in the location 5501H to the first number.
d) If there is any carry, increment MSBs of sum by 1.
e) Store LSBs of sum in the location 5502H
f) Store MSBs of sum in the location 5503H.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |2

PROGRAM:
ADDRESS LABEL MNEMONICS HEX CODE
4100 MV1 C,00

4102 LDA 5500


4105
MOV B,A

4106
LDA 5501

4109
ADD B

410A
JNC L1

410D
INR C

410E
L1 STA 5502

4111
MOV A,C

4112
STA 5503

4115
HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |3

SUBTRACTION OF TWO 8-BIT NUMBERS.


Ex. No.1b

AIM:
To write an Assembly Language Program (ALP) for performing the subtraction operations of 8-
bit numbers with and without carry.

APPARATUS REQUIRED:
Microprocessor kit, Power supply.

PROBLEM STATEMENT:
Write an ALP in 8085 P to subtract two 8-bit binary numbers stored in the memory location
5500H and 5501H and store the result in the memory location 5502H.Also provide an instruction in the
above program to consider the carry also and store the carry in the memory location 5503H.

ALGORITHM:

a) Initialize the MSBs of difference to 0


b) Get the first number from the location 55000H
c) Subtract the second number which is in the location 5501H from the first number.
d) If there is any carry, increment MSBs of difference by 1.
e) Store LSBs of difference in the location 5502H
g) Store MSBs of difference in the location 55003H.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |4

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE


4100 MV1 C,00

4102 LDA 5500

4105
MOV B,A

4106
LDA 5501

4109
SUB B

410A
JNC L1

410D
INR C

410E
L1 STA 5502

4111
MOV A,C

4112
STA 5503

4115
HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |5

ADDITION OF TWO 16-BIT NUMBERS.


Ex.No.1c

AIM:
To write an Assembly Language Program (ALP) for performing the addition operations of 16-bit
numbers with and without carry.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
PROBLEM STATEMENT:
Write an ALP in 8085 P to add two 16-bit binary numbers stored in the memory location
5500H and 5503H (in the order of lower byte in the first location, higher byte in the second location) and
store the result in the memory location 5504H and 5505H.Also provide an instruction in the above
program to consider the carry also and store the carry in the memory location 5506H.
ALGORITHM:
1. Clear the contents of B register
2. Load HL pair with the first 16 bit number,
3. Move this number to the DE pair using Exchange instruction
4. Load the HL Pair with second 16 bit number
5. Add the content of DE pair with contents of HL pair and store the result in HL pair
6. If a carry occurs increment the value of B register
7. Store the sum in memory

PROGRAM:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |6

ADDRESS LABEL MNEMONICS HEX CODE


4100 MVI C,00
4102
LHLD 5500
4105
XCHG
4106
LHLD 5502
4109
DAD D
410A
JNC L1
410D
INR C
410E L1
SHLD 5504
4111
MOV A,C
4112
STA 5506
4115
HLT

INPUT & OUTPUT:

RESULT:

SUBTRACTION OF 16-BIT NUMBERS.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |7

Ex.No.1d

AIM:
To write an Assembly Language Program (ALP) for performing the subtraction operations of 16-
bit numbers with and without carry.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
PROBLEM STATEMENT:
Write an ALP in 8085 P to subtract two 16-bit binary numbers stored in the memory location
5500H and 5503H (in the order of lower byte in the first location, higher byte in the second location) and
store the result in the memory location 5504H and 5505H.Also provide an instruction in the above
program to consider the carry also and store the carry in the memory location 5506H.
ALGORITHM:
1. Initialize the MSBs of difference to 0
2. Get the first low byte of data-1in the accumulator.
3. Subtract the low byte of data-2 from that of data-1.
4. Store the low byte of the result.
5. Get the high byte of data-1 in the accumulator
6. Subtract the high byte of data-2 and also the carry from the high byte of data-1.
7. Store the high byte of the result.
8. If there is any carry, increment the contents MSBs by 1.
9. Store MSBs of result.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |8

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE


4100
MVI C,00
4102
LHLD 5500
4105
XCHG
4106
LHLD 5502
4109
MOV A,L
410A
SUB E
410B
MOV L,A
410C
MOV A,H
410D
SBB D
410E
MOV H,A
410F
JNC L1
4112
INR C
4113 L1
SHLD 5504
4116
MOV A ,C
4117
STA 5506
411A
HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e |9

VIVA QUESTIONS:

1.What is an Opcode?
The part of the instruction that specifies the operation to be performed is called the operation
code or opcode.

2.What is an Operand?
The data on which the operation is to be performed is called as an Operand.

3.List out the five categories of the 8085 instructions. Give examples of the
instructions for each group.
• Data transfer group – MOV, MVI, LXI.
• Arithmetic group – ADD, SUB, INR.
• Logical group –ANA, XRA, CMP.
• Branch group – JMP, JNZ, CALL.
• Stack I/O and Machine control group – PUSH, POP, IN, HLT.

4.Name 5 different addressing modes?


Immediate, Direct, Register, Register indirect, Implied addressing modes

5.What happens when HLT instruction is executed in processor?


The Micro Processor enters into Halt-State and the buses are tri-stated.

6.What is the use of JMP instruction?


A JMP instruction permanently changes the program counter.

7.Difference between ADD and DAD?


ADD - Add the contents of register to the contents of the accumulator.
DAD - The instruction DAD is an exception; it adds 16-bit data directly in register pairs.

8.Subtraction concept:
Any 8-bit number, or the contents of a register, or the contents of a memory location can be
subtracted from the contents of the accumulator and the results stored in the accumulator. The
subtraction is performed in 2's compliment, and the results if negative, are expressed in 2's complement.
No two other registers can be subtracted directly.

9.What is the use of SBB?


SBB---Subtract from Accumulator Using Borrow (Carry) Flag

10.Explain the instructions used in this exercise:


XCHG---Exchange H & L with D & E
LDA----Load Accumulator Directly from Memory
STA----Store Accumulator Directly in Memory
LHLD----Load H & L Registers Directly from Memory
SHLD------Store H & L Registers Directly in Memory

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 10

MULTIPLICATION OF TWO 8-BIT NUMBERS.


Ex.No.2a

AIM:
To write an Assembly Language Program (ALP) for performing the multiplication operation of
8-bit numbers.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
PROBLEM STATEMENT:
Write an ALP in 8085 P to multiply two 8-bit binary numbers stored in the registers B and C
and store the result in the memory location 5502H.
ALGORITHM:
1. Get the multiplier.
2. Get the multiplicand
3. Initialize the product to 0.
4. Product = product + multiplier
5. Decrement the multiplicand by 1
6. If multiplicand is not equal to 0, repeat from step (d) otherwise store the product.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 11

PROGRAM:
ADDRESS LABEL MNEMONICS HEX CODE
4100
MV1 D,00
4102
LDA 5500
4105
MOV B,A
4106
LDA 5501
4109
MOV C,A
410A
XRA A
410B L2
ADD B
410C
JNC L1
410F
INR D
4110 L1
DCR C
4111
JNZ L2
4114
STA 5502
4117
MOV A,D
4118
STA 5503
411B
HLT

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 12

DIVISION OF TWO 8-BIT NUMBERS.

Ex.No.2b

AIM:
To write an Assembly Language Program (ALP) for performing the division operation of 8-bit
numbers.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
PROBLEM STATEMENT:
Write an ALP in 8085 P to multiply two 8-bit binary numbers stored in the registers B and C
and store the result in the memory location 5502H.
ALGORITHM:
1. Get the dividend
2. Get the divisor
3. Initialize the quotient to 0.
4. Dividend = dividend – divisor
5. If the divisor is greater, store the quotient.
6. If dividend is greater, quotient = quotient + 1. Repeat from step (d)

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 13

PROGRAM:
ADDRESS LABEL MNEMONICS HEX CODE
4100 MV1 D,00
4102
LDA 5500
4105
MOV B,A
4106
LDA 5501
4109 L1
SUB B
410A
INR D
410B L2
JNC L1
410E
ADD B
410F
DCR D
4110
STA 5502
4113
MOV A,D
4114
STA 5503
4117
HLT

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 14

MULTIPLICATION OF TWO 16-BIT NUMBERS.

Ex.No.2c

AIM:
To write an Assembly Language Program (ALP) for performing the multiplication operation of
16-bit numbers.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
PROBLEM STATEMENT:
Write an ALP in 8085 P to multiply two 16-bit binary numbers stored in the register pairs BC
and DE and store the result in the memory location 5504H & 5506H.
ALGORITHM:
1. Get the multiplier.
2. Get the multiplicand
3. Initialize the MSBs and LSBs of product to 0.
4. LSBs of Product = LSBs of product + multiplier
5. If there is a carry, increment MSBs of product.
6. Decrement the multiplicand by 1
7. If multiplicand is not equal to 0, repeat from step (d) otherwise store the LSBs MSBs of product.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 15

PROGRAM

ADDRESS LABEL MNEMONICS HEX CODE


4100 LHLD 5500
4103
XCHG
4104
LHLD 5502
4107
SPHL
4108
LXI B,0000
410B
LXI H,0000
410E L2
DAD SP
410F
JNC L1
4112
INX B
4113 L1
DCX D
4114
MOV A,E
4115
ORA D
4116
JNZ L2
4119
SHLD 5504
411C
MOV H,B
411D
MOV L,C
411E
SHLD 5506
4121
HLT
OUTPUT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 16

RESULT:

DIVISION OF TWO 16-BIT NUMBERS.

Ex.No.2d

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

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 17

APPARATUS REQUIRED:
Microprocessor kit, Power supply.

PROBLEM STATEMENT:
Write an ALP in 8085 P to divide two 16-bit binary numbers stored in the register pairs BC and
DE and store the result in the memory location 5506H & 5508H.
ALGORITHM:

1. Get the lower order byte of the dividend


2. Get the lower order byte of the divisor
3. Initialize the quotient to 0.
4. Dividend = dividend – divisor
5. If the divisor is greater, store the quotient.
6. If dividend is greater, quotient = quotient + 1. Repeat from step (d)
7. If there is borrow, add with higher order byte of the divisor.
8. Get the higher order byte of the dividend
9. Get the higher order byte of the divisor.
10. Dividend = dividend – divisor
11. If the divisor is greater, store the quotient.
12. If dividend is greater, quotient = quotient + 1. Repeat from step (d)

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 18

PROGRAM
ADDRESS LABEL MNEMONICS HEX CODE
4100 LHLD 5500
4103
XCHG
4104
LHLD 5502
4107
LXI B,0000
410A L2
MOV A,L
410B
SUB E
410C
MOV L,A
410D
MOV A.H
410E
SBB D
410F
MOV H,A
4110
JC L1
4113
INX B
4114
JMP L2
4117 L1
MOV A,L
4118
ADD E
4119
MOV L,A
411A MOV A,H
411B ADC D
411C MOV H,A
411D SHLD 5506
4120 MOV L,C
4121 MOV H,B
4122 SHLD 5508
4125
HLT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 19

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 20

VIVA QUESTIONS:
1. Multiplication is repeated addition & division is repeated subtraction.

2. What is the use of XRA?


XRA -- Exclusive Logical OR with Accumulator

3. what is the use DAD?


DAD-- Double Register Add; Add Content of Register Pair to H & L Register
Pair Used in 16-bit multiplication

4. Compare the instruction DCR B and DCX B


DCX B Decrement register pair BC to HL
DCR B Decrement register C

5. What is the use of ADC instruction?


Add register with carry. Used in case of 16- bit arthimetic operations

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 21

FINDING THE SMALLEST & LARGEST NUMBER IN A GIVEN ARRAY

Ex.No.3a
AIM:
To write an Assembly Language Program (ALP) for finding the smallest & largest number in a
given array.
APPARATUS REQUIRED:
Microprocessor kit, Power supply.
ALGORITHM:

To Find The Smallest Element In An Array:


1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next element).
7. If the accumulator content is smaller, then move the memory content (largest
element) to the accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.

To Find The Largest Element In An Array.


1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next element).
7. If the accumulator content is smaller, then move the memory content (largest element) to the
accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 22

PROGRAM(Smallest):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LDA 5500
4103
MOV B,A
4104 LXI H,5501

4107
DCR B
4108
MOV C,M
4109 L1
INX H
410A
MOV A,M
410B
CMP C
410C
JZ L2
410F
JNC L2
4112
MOV C,A
4113 L2
DCR B
4114
JNZ L1
4117
MOV A,C
4118
STA 6000
411B
HLT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 23

PROGRAM(LARGEST):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LDA 5500
4103
MOV B,A
4104
LXI H,5501
4107
DCR B
4108
MOV C,M
4109 L1
INX H
410A
MOV A,M
410B
CMP C
410C
JZ L2
410F
JC L2
4112
MOV C,A
4113 L2
DCR B
4114
JNZ L1
4117
MOV A,C
4118
STA 6000
411B
HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 24

SORTING ‘n ‘NUMBERS

Ex. No.3b

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

APPARATUS REQUIRED:
Microprocessor kit, Power supply.

PROBLEM STATEMENT:
An array of length n is given from the location starting from 5200.Sort it into ascending order
and descending order and store the result starting from 5200H.

ALGORITHM:

i) Sorting in ascending order:

1. Load the array count in two registers C1 & C2.


2. Get the first 2 numbers.
3. Compare the numbers and exchange if they are in ascending order.
4. Decrement C2.
5. Decrement C1 and repeat the process until C1 is zero.

ii) Sorting in descending order:

1. Load the array count in two registers C1 & C2.


2. Get the first 2 numbers.
3. Compare the numbers and exchange if they are in descending order.
4. Decrement C2.
5. Get the third number from the array and repeat the process.
6. Decrement C1 and repeat the process until C1 is zero.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 25

PROGRAM(ASCENDING):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LX1 H,5200
4103
MOV B,M
4104 L4
MOV D,M
4105
INX H
4106 L1
MOV A,M
4107 L2
DCR D
4108
JZ L3
410B
INX H
410C
CMP M
410D
JC L1
4110
MOV E,M
4111
MOV M,A
4112
DCX H
4113
MOV M,E
4114
INX H
4115
JMP L2
4118 L3
LXI H,5200
411B
DCR B
411C
JNZ L4
411F
HLT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 26

PROGRAM (DESCENDING):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LX1 H,5200
4103
MOV B,M
4104 L4
MOV D,M
4105
INX H
4106 L1
MOV A,M
4107 L2
DCR D
4108
JZ L3
410B
INX H
410C
CMP M
410D
JNC L1
4110
MOV E,M
4111
MOV M,A
4112
DCX H
4113
MOV M,E
4114
INX H
4115
JMP L2
4118 L3
LXI H,5200
411B
DCR B
411C
JNZ L4
411F
HLT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 27

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 28

VIVA QUESTIONS:
1. What is the use of Label?

A label is any sequence of alphabetic or numeric characters starting with an alphabetic. A label is
permitted on any line except a line where the opcode is IF, ELSE, or ENDIF. The label is
assigned the value of the assembly program counter before any of the rest of the line is
processed except when the opcode is EQU, ORG, PAGE, or SET.

2. What is the use of CMP?

CMP is a compare instruction. Used to compare register with that of the accumulator

3. Difference between LXI and LDA?


The data transfer instructions move data between registers or between memory and registers.
LDA Load Accumulator Directly from Memory.
An X in the name of a data transfer instruction implies that it deals with a register pair 16-
bits;LXI

4. What are the different JUMP instructions?

JNZ Addr Conditional Jump (Not Zero Flag)

JMP Addr Jump to Direct Address

JZ Addr Conditional Jump (Zero Flag)

JNC Addr Conditional Jump (Not Carry Flag)

JC Addr Conditional Jump (Carry Flag)

JPO Addr Conditional Jump (Parity Odd, Not Parity Flag)

PCHL Jump Indirect HL

JPE Addr Conditional Jump (Parity Even, Parity Flag)

JP Addr Conditional Jump (Positive, Not Sign Flag)

JM Addr Conditional Jump (Minus, Sign Flag)

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 29

CODE CONVERSION –DECIMAL TO HEX


Ex.No.4a

AIM:

To convert a given decimal number to hexadecimal.

APPARATUS REQUIRED:
8085 microprocessor kit. Power supply.
ALGORITHM:

1. Initialize the memory location to the data pointer.


2. Increment B register.
3. Increment accumulator by 1 and adjust it to decimal every time.
4. Compare the given decimal number with accumulator value.
5. When both matches, the equivalent hexadecimal value is in B register.
6. Store the resultant in memory location.

PROGRAM:

ADDRESS LABEL OPCODE OPERAND COMMENTS


Initialize HL reg. to
8000 LXI H,8100
8100H
8003 MVI A,00 Initialize A register.
8005 MVI B,00 Initialize B register..
8007 LOOP INR B Increment B reg.
8008 ADI 01 Increment A reg
800A DAA Decimal Adjust Accumulator
800B CMP M Compare M & A
If acc and given number are not
800C JNZ LOOP
equal, then go to LOOP
800F MOV A,B Transfer B reg to acc.
Store the result in a memory
8010 STA 8101
location.
8013 HLT Stop the program

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 30

CODE CONVERSION –HEXADECIMAL TO DECIMAL


Ex.No.4b

AIM:

To convert a given hexadecimal number to decimal.

APPARATUS REQUIRED:
8085 microprocessor kit. Power supply.

ALGORITHM:

1. Initialize the memory location to the data pointer.


2. Increment B register.
3. Increment accumulator by 1 and adjust it to decimal every time.
4. Compare the given hexadecimal number with B register value.
5. When both match, the equivalent decimal value is in A register.
6. Store the resultant in memory location.

PROGRAM:

ADDRESS LABEL OPCODE OPERAND COMMENTS


8000 LXI H,8100 Initialize HL reg. to8100H
8003 MVI A,00 Initialize A register.
8005 MVI B,00 Initialize B register.
8007 MVI C,00 Initialize C register for carry.
8009 LOOP INR B Increment B reg.
800A ADI 01 Increment A reg
800C DAA Decimal Adjust Accumulator
800D JNC NEXT If there is no carry go to NEXT.
8010 INR C Increment c register.
8011 NEXT MOV D,A Transfer A to D
8012 MOV A,B Transfer B to A
8013 CMP M Compare M & A
8014 MOV A,D Transfer D to A
8015 JNZ LOOP If acc and given number are not equal,
then go to LOOP
8018 STA 8101 Store the result in a memory location.
801B MOV A,C Transfer C to A
801C STA 8102 Store the carry in another memory
location.
801F HLT Stop the program

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 31

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 32

CODE CONVERSION –HEXADECIMAL TO ASCII

Ex.No.4c

AIM:

To convert a given hexadecimal number to ASCII..

APPARATUS REQUIRED:
8085 microprocessor kit. Power supply.
ALGORITHM:
1. Load the data in A-register and then to B-register
2. Mask the upper nibble of the hexadecimal number in A register.
3. Call subroutine to get ASCII of lower nibble.
4. Store it in memory.
5. Move B to A and mask the lower nibble.
6. Rotate the value
7. Call subroutine to get ASCII of upper nibble.
8. Store it in memory

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE


8000 LDA 4500 3A,00,45
8003 MOV B,A 47
8004 ANI 0FH E6,0F
8006 CALL SUB CD,1A,42
8009 STA 4502 32,02,45
800C MOV A,B 78
800D ANI F0H E6,F0
800F RRC 0F
8010 RRC 0F
8011 RRC 0F
8012 RRC 0F
8013 CALL SUB CD,1A,42
8016 STA 4503 32,03,45
8019 HLT 76

SUBROUTINE SUB:
ADDRESS LABEL MNEMONICS HEX CODE
801A CPI 0AH FE ,0A
801C JC L1 DA,21,42
801F ADI 07H C6,07
8021 L1 ADI 30H C6,30
8023 RET C9

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 33

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 34

CODE CONVERSION –ASCII TO HEXADECIMAL

Ex.No.4d

AIM:

To convert a given ASCII to hexadecimal number..

APPARATUS REQUIRED:
8085 microprocessor kit. Power supply.
ALGORITHM:
1. Load the data in A-register.
2. Subtract 30H from A register.
3. Compare the content of A register with 0AH.
4. If A<0A H, jump to step 6. Else proceed to next step.
5. Subtract 07H from A register
6. Store it in memory

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE


8000 LDA 4500 3A,00,45
8003 SUI 30 D6,30
8005 CPI 0A FE,0A
8007 JC L1 DA,21,42
8010 SUI 07 D6,07
800A L1 STA 4501 32,01,45
800D HLT 76

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 35

VIVA QUESTIONS:
1. Explain the difference between a JMP instruction and CALL instruction.
A JMP instruction permanently changes the program counter. A CALL
instruction leaves information on the stack so that the original program execution
sequence can be resumed.
2. What is the difference between the shift and rotate instructions?
A rotate instruction is a closed loop instruction. That is, the data moved
out at one end is put back in at the other end. The shift instruction loses the data
that is moved out of the last bit locations.
3. Explain LDA, STA and DAA instructions
LDA copies the data byte into accumulator from the memory location
specified by the 16-bit address. STA copies the data byte from the accumulator in
the memory location specified by 16-bit address. DAA changes the contents of
the accumulator from binary to 4-bit BCD digits.
4. Why is ANI used?
It is ANDed immediately. Here it is used to clear the accumulator (ie) ANI 0f

5. What are the different Rotate instructions?


 RRC Rotate Right
 RAL Rotate Left with Carry
 RAR Rotate Right with Carry
 RLC Rotate Left

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 36

2 X 2 MATRIX MULTIPLICATION

Ex.No.5

AIM:

To perform the 2 x 2 matrix multiplication.

APPARATUS REQUIRED:
8085 microprocessor kit. Power supply.

ALGORITHM:

1. Load the 2 input matrices in the separate address and initialize the HL and the DE register pair
with the starting address respectively.
2. Call a subroutine for performing the multiplication of one element of a matrix with the other
element of the other matrix.
3. Call a subroutine to store the resultant values in a separate matrix.

PROGRAM:

ADDRESS LABEL OPCODE O COMMENT


8100 MVI C, 00 Clear C reg.
8102 LXI H, 4500 Initialize HL reg. to4500
8105 LOOP2 LXI D, 4600 Load DE register pair
8108 CALL MUL Call subroutine MUL
810B MOV B,A Move A to B reg.
810C INX H Increment HL register pair .
810D INX D Increment DE register pair
810E INX D Increment DE register pair
810F CALL MUL Call subroutine MUL
8112 ADD B Add [B] with [A]
8113 CALL STORE Call subroutine STORE
8116 DCX H Decrement HL register pair
8117 DCX D Decrement DE register pair
8118 CALL MUL Call subroutine MUL
811B MOV B,A Transfer A reg content to B reg.
811C INX H Increment HL register pair
811D INX D Increment DE register pair
811E INX D Increment DE register pair
811F CALL MUL Call subroutine MUL
8122 ADD B Add A with B
8123 CALL STORE Call subroutine MUL
8126 MOV A,C Transfer C register cont to Acc.
8127 CPI 04 Compare with 04 to check
whether all elements are
multiplied.
8129 JZ LOOP1 If completed, go to loop1
812C INX H Increment HL register Pair.
812D JMP LOOP2 Jump to LOOP2.
8130 LOOP1 HLT Stop the program.
CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 37

8131 MUL LDAX D Load acc from the memory


location pointed by DE pair.
8132 MOV D,A Transfer acc content to D
register.
8133 MOV H,M Transfer from memory to H
register.
8134 DCR H Decrement H register.
8135 JZ LOOP3 If H is zero go to LOOP3.
8138 LOOP4 ADD D Add Acc with D reg
8139 DCR H Decrement H register.
813A JNZ LOOP4 If H is not zero go to LOOP4.
813D LOOP3 MVI H,85 Transfer 85 TO H register.
813F MVI D,86 Transfer 86 to D register.
8141 RET Return to main program.
8142 STORE MVI B,87 Transfer 87 to B register.
8144 STAX B Load A from memory location
pointed by BC pair.
8145 INR C Increment C register.
8146 RET Return to main program.

OUTPUT

RESULT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 38

VIVA QUESTIONS:
1. Why CPI used?

CPI- Compare with immediate data. Compare with the given data to check whether all
elements are multiplied.

2. What is a subroutine?

In 8085 microprocessor a subroutine is a separate program written aside from main


program ,this program is basically the program which requires to be executed several times in
the main program.
3. What is the difference between CALL and RET
The microprocessor can call subroutine any time using CALL instruction .
After the subroutine is executed the subroutine hands over the program to main program using
RET instruction.
4. diference between STAX andLDAX

LDAX--Load Accumulator from Address in Register Pair


STAX--Store Accumulator in Address in Register Pair
An 'X' in the name of a data transfer instruction implies that it deals with a register pair (16-bits);

PROGRAMMING WITH 8086


CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 39

16 – BIT ADDITION AND SUBTRACTION

Ex.No.6a

AIM:
To add/ subtract two 16 bit numbers residing in memory and to store the result in memory.
APPARATUS REQUIRED:
8086 microprocessor kit. Power supply.
PROBLEM STATEMENT:
The program is to start from memory location 1000 H onwards. Input is to be stored
from 1200 H and output is to be stored from 1400 H onwards.

ALGORITHM:

1. Move the content in the memory to the AX register


2. Increment the memory location
3. Add the content in the memory to the AX register
4. Move the result to a memory location
5. Halt

The add instruction requires either the addend or the augend to be in a register, unless the source operand
is immediate since the addressing modes permitted for the source and destination are register-register,
memory to register, register to memory, register to immediate, and finally memory to immediate.
Hence one of the operands is initially moved to AX. Then using the add instruction, 16- bit addition is
performed.
The next arithmetic primitive is SUB. As discussed in ADD it permits the same modes of addressing.
Hence moving the minuend to a register pair is necessary. Then the result is moved to a location in
memory.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 40

ADDITION
PROGRAM COMMENTS

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 L1 Check for carry

INC CX If carry exists, increment the CX

L1 : MOV [1206],CX Store the carry

MOV [1204], AX Store the sum

HLT Stop the program

SUBTRACTION

PROGRAM COMMENTS

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 L1 Check for borrow

INC CX If borrow exists, increment the CX

L1 : MOV [1206],CX Store the borrow

MOV [1204], AX Store the difference

HLT Stop the program

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 41

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 42

16 BIT MULTIPLICATION/DIVISION

Ex.No.6b

AIM:
To multiply two 16 bit numbers in memory and store the result in memory and to perform
division of a 16 bit number by a 16 bit number and to store quotient and remainder in memory.
APPARATUS REQUIRED:
8086 Microprocessor kit, Power supply.
ALGORITHAM:
(i)16 BIT MULTIPLICATION:
1.Start the program.
2.Get the multiplicand and multiplier.
3.Find the product.
4.Store the result.
5.Terminate the program.

(ii)16 bit Division:


1.Start the program.
2.Get the Dividend and Devisor.
3.Find the Quotient and Reminder.
4.Store the result.
5.Terminate the program.

The 8086 Processor provides both signed and unsigned multiply in their instruction set to overcome the
loss of efficiency in performing the repeated addition.
The MUL instruction can have both 16 and 8 bit operands and the multiplicand is AX or AL, accordingly
the result for a byte multiply is a 16 bit number in AX while that for a word multiply is a 32 bit number,
the lower word of which is in AX and the higher word in DX.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 43

MULTIPLICATION

PROGRAM COMMENTS

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

HLT Stop the program

DIVISION

PROGRAM COMMENTS

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

HLT Get the first data

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 44

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 45

VIVA QUESTIONS:

1.8086 Registers:
AX (= AH + AL)
BX (= BH + BL)
CX (= CH + CL)
DX (= DH + DL)
SI (source index)
DI (destination index)
SP (stack pointer)
BP (base pointer)

2. Explain the process control instructions


STC – It sets the carry flag & does not affect any other flag
CLC – it resets the carry flag to zero &does not affect any other flag
CMC – It complements the carry flag & does not affect any other flag
STD – It sets the direction flag to 1 so that SI and/or DI can be decremented
automatically after execution of string instruction & does not affect other flags
CLD – It resets the direction flag to 0 so that SI and/or DI can be incremented
automatically after execution of string instruction & does not affect other flags
STI – Sets the interrupt flag to 1. Enables INTR of 8086.
CLI – Resets the interrupt flagto0. 8086 will not respond to INTR.

3. Explain REPEAT-UNTIL statements


REPEAT-UNTIL statements allow executing a series of instructions repeatedly
until some condition occurs. The REPEAT defines the start of the loop & UNTIL the end of
the loop. UNTIL has a condition when the condition is true the loop is terminated

4. What are the different forms of multiplication?

There are two forms of the multiply instruction: an unsigned multiplication (mul) and a signed
multiplication (imul). Unlike addition and subtraction, you need separate instructions for these two
operations.

The multiply instructions take the following forms:

Unsigned Multiplication:

mul reg
mul mem

Signed (Integer) Multiplication:

imul reg
imul mem
imul reg, reg, immediate (2)
imul reg, mem, immediate (2)
imul reg, immediate (2)
imul reg, reg (3)
imul reg, mem (3)
AAM Instruction - ASCII adjust after Multiplication

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 46

5.What are the different forms of Division?

The 80x86 divide instructions perform a 64/32 division (80386 and later only), a 32/16 division or
a 16/8 division. These instructions take the form:

div reg For unsigned division


div mem

idiv reg For signed division


idiv mem

aad ASCII adjust for division

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 47

STRING MANIPULATION
Ex.No.7

AIM:
To write 8086 program
5A) To copy a string of data words from one location to the other.
5B) To search a word from a string.
5C) To find and replace a word from a string.

APPARATUS REQUIRED:
8086 Microprocessor kit, power supply.

ALGORITHM:
5A)Copying a String
1.Initialise DS, S1, DS, ES.
2.Move the length of the strin in CX register.
3.Move the byte from DS to ES till CX =0.

5B)Search
1.Initialise ES and DI.
2. Move the no. Of characters in the string to CX.
3. Move the byte to be searched to AL.
4. Store the ASCII code of character in BL.
5. Scan for the byte in ES. If the byte is not found ZF ≠ 1 and repeat scanning.
6. If the byte is found ZF=1,display 01 in destination address. Otherwise, display 00 in destination
address.

5C) Find & Replace


1.Initialise ES and DI.
2. Move the no. Of characters in the string to CX.
3. Move the byte to be searched to AL.
4. Store the ASCII code of character in BL.
5. Scan for the byte in ES. If the byte is not found ZF ≠ 1 and repeat scanning.
6. If the byte is found ZF=1, move the content of BC register ES, D1.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 48

COPYING A STRING
PROGRAM COMMENTS

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
HLT Stop

SEARCHING FOR A CHARACTER IN THE STRING


PROGRAM COMMENTS

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

HLT Stop

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 49

FIND AND REPLACE A CHARACTER IN THE STRING


PROGRAM COMMENTS

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

HLT Stop

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 50

BIOS/DOS CALLS – DISPLAY


Ex.No.8a

AIM:
To display a message on the CRT screen of a microcomputer using DOS calls.

ALGORITHM:
1. Initialize the data segment and the message to be displayed.
2. Set function value for display.
3. Point to the message and run the interrupt to display the message in the CRT.

PROGRAM:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
MSG DB 0DH, 0AH, “GOOD MORNING” , ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:MOV AX, DATA
MOV DS, AX
MOV AH, 09H
MOV DX, OFFSET MSG
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 51

BIOS/DOS CALLS – FILE MANIPULATION


Ex.No.8b

AIM:
To open a file using DOS calls.
ALGORITHM:
1. Initialize the data segment, file name and the message to be displayed.
2. Set the file attribute to create a file using a DOS call.
3. If the file is unable t o create a file display the message
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
FILENAME DB “SAMPLE.DAT”, “$”
MSG DB 0DH, 0AH, “FILE NOT CREATED”, ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET FILENAME
MOV CX, 00H
MOV AH, 3CH
INT 21H
JNC LOOP1
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET MSG
MOV AH, 09H
INT 21H
LOOP1 MOV AH, 4CH
INT 21H
CODE ENDS
END START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 52

BIOS/DOS CALLS – DISK INFORMATION


Ex.No.8c

AIM:
To display the disk information.

ALGORITHM:
1. Initialize the data segment and the message to be displayed.
2. Set function value for disk information.
3. Point to the message and run the interrupt to display the message in the CRT.

PROGRAM:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
MSG DB 0DH, 0AH, “GOOD MORNING” , ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:MOV AX, DATA
MOV DS, AX
MOV AH, 36H
MOV DX, OFFSET MSG
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 53

INTERFACING WITH 8086

INTERFACING PROGRAMMABLE PERIPHERAL INTERFACE 8255

Ex.No.9a

AIM:
To initialize port A as i/p and to i/p the data set by SPDT switches through port A and store the data. The
avove is done in mode 0, 1, 2 of 8255.
APPARATUS REQUIRED:
Microprocessor kit, power supply, 8255 interface board.
THEORY:
The 8255 is called as a PPI (Programmable Peripheral Interface), which is used as a
mediator between processor and input/output devices. It has three 8-bit port i.e.
Port A (PA) and Port B (PB) & Port C (PC). Port C can be configure in two 4-bit port
i.e. Pcupper & Pclower. It has different controlling signals ie. RD, WR, CS are low-
level active signals and A0, A1 & Reset are high-level active signal.
MODES OF OPERATION OF 8255
 These are two basic modes of operation of 8255.
 I/O mode and Bit Set-Reset mode (BSR).
 In I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode only port C
(PC0-PC7) can be used to set or reset its individual port bits.
 Under the I/O mode of operation, further there are three modes of operation of 8255, so as to
support different types of applications, mode 0, mode 1 and mode 2.
 Two 8-bit ports ( port A and port B )and two 4-bit ports (port C upper and lower ) are available.
The two 4-bit ports can be combined used as a third 8-bit port.
 Any port can be used as an input or output port.
 Output ports are latched. Input ports are not latched.
 A maximum of four ports are available so that overall 16 I/O configurations are possible.
 All these modes can be selected by programming a register internal to 8255 known as CWR.
 The control word register has two formats. The first format is valid for I/O modes of operation,
i.e. modes 0, mode 1 and mode 2 while the second format is valid for bit
 set/reset (BSR) mode of operation.
 These formats are shown in following fig.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 54

I/O MODES:
Control Word:

MODE 0 – SIMPLE I/O MODE:


This mode provides simple I/O operations for each of the three ports and is suitable for
synchronous data transfer. In this mode all the ports can be configured either as input or output port.
Let us initialize port A as input port and port B as output port
MODE 1 STROBED INPUT/OUTPUT :
This mode is called strobed i/o mode. The hand shaking signals controls i/o action of the specified port.
The Port C lines PC0 –PC3 provides hand shaking signals for port B in group B. The Port C lines PC4 –
PC7 provides hand shaking signals for port A in group A.

MODE 2 STROBED BIDIRECTIONAL :


In this mode 8-bit port A and 5 bits of port C (PC3 – PC7) are available.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 55

MODE 0
PROGRAM COMMENTS
MOV DX, CNT1(106) Initialize DX reg with port address for control word
MOV AL,90H Control word
OUT DX,AL Send it to control port
MOV DX, Set DX reg with port A address
PORTA(100)
IN AL,DX Get the contents of port A in AL
MOV DX, Set DX reg with port A address
PORTB(102)
OUT DX,AL Send the contents of port B to port address
HLT Stop

MODE 1
PROGRAM COMMENTS
MOV DX, CNT1 Initialize DX reg with port address for control word
MOV AL,0B0H Control word
OUT DX,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT DX,AL Send it to control port
MOV DX,PORTC(104) Set DX reg with port C address
L1 : IN AL,DX Get the contents of port C in AL
AND AL,20H Mask RST 6.5
JZ L1 Check whether it is enabled
MOV DX, PORTA Set DX reg with port A address
IN AL,DX Get the contents of port A in AL
MOV DX,PORTB Set DX reg with port B address
OUT DX,AL Send the contents of AL to port B address
HLT Stop

MODE 2
PROGRAM COMMENTS
MOV DX, CNT1 Initialize DX reg with port address for control word
MOV AL,0C0H Control word
OUT DX,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT DX,AL Send it to control port
MOV DX,PORTC Set DX reg with port C address
L1 : IN AL,DX Get the contents of port C in AL
AND AL,20H Mask RST 6.5

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 56

JZ L1 Check whether it is enabled


MOV DX, PORTA Set DX reg with port A address
IN AL,DX Get the contents of port A in AL
MOV DX,PORTB Set DX reg with port B address
OUT DX,AL Send the contents of AL to port B address
HLT Stop

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 57

VIVA QUESTIONS:

1. What are the basic modes of operation of 8255?


There are two basic modes of operation of 8255, viz.
1. I/O mode.
3. BSR mode.
In I/O mode, the 8255 ports work as programmable I/O ports, while
In BSR mode only port C (PC0-PC7) can be used to set or reset its individual
port bits. Under the IO mode of operation, further there are three modes of operation of 8
255, So as to support different types of applications, viz. mode 0, mode 1 and mode 2.
Mode 0 - Basic I/O mode
Mode 1 - Strobed I/O mode
Mode 2 - Strobed bi-directional I/O

2. Write the features of mode 0 in 8255?


1. Two 8-bit ports (port A and port B) and two 4-bit ports (port C upper and lower)
are available. The two 4-bit ports can be combined used as a third 8-bit port.
2. Any port can be used as an input or output port.
3.Output ports are latched. Input ports are not latched.
4. A maximum of four ports are available so that overall 16 I/O configurations are
possible.

3. What are the features used mode 1 in 8255?


Two groups – group A and group B are available for strobed data transfer.
1. Each group contains one 8-bit data I/O port and one 4-bit control/data port.
2. The 8-bit data port can be either used as input or output port. The inputs and
outputs both are latched.
3. Out of 8-bit port C, PC0-PC2 is used to generate control signals for port B and
PC3=PC5 are used to generate control signals for port A. The lines PC6, PC7 may
be used as independent data lines.

4. What are the signals used in input control signal & output control signal?
Input control signal
STB (Strobe input)
IBF (Input buffer full)
INTR(Interrupt request)
Output control signal
OBF (Output buffer full)
ACK (Acknowledge input)
INTR(Interrupt request)

5. What are the features used mode 2 in 8255?


The single 8-bit port in-group A is available.
1. The 8-bit port is bi-directional and additionally a 5-bit control port is available.
2. Three I/O lines are available at port C, viz PC2-PC0.
3. Inputs and outputs are both latched.
4. The 5-bit control port C (PC3=PC7) is used for generating/accepting handshake
signals for the 8-bit data transfer on port A.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 58

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 59

INTERFACING PROGRAMMABLE KEYBOARD AND DISPLAY


CONTROLLER 8279

Ex.No.9b

AIM:
To display rolling message “CAROLINE” in the display (or) to accept a key and display it.
APPARATUS REQUIRED:
8086 microprocessor key, power supply of interfacing board.
PROBLEM STATEMENT:
The program starts from memory location 4100H. The input data is displayed at 8279 interfacing kit.
ALGORITHM:
Display:
1. Initialise the count.
2. Set 8279 for 8 digit character display, right entry.
3. Set 8279 for clearing to display.
4. Write the command to display.
5. Load the character into display and accumulator kit.
6. Introduce the delay.
7. Repeat from step 1.

Accepting a key and to display it.:


1. Initialise 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. Key in the character and load it into the acc.
6. Repeat step 5.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 60

1. Display Mode Setup: Control word-10 H

0 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.

2.Clear Display: Control word-DC H

1 1 0 1 1 1 0 0
1 1 0 CD CD CD CF CA

11 A0-3; B0-3 =FF

1-Enables Clear display


0-Contents of RAM will be displayed

1-FIFO Status is cleared

3. Write Display: Control word-90H 1-Clear all bits


(Combined effect of CD)
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.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 61

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
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

RESULT:

MEMORY 7-SEGMENT LED FORMAT HEX DATA


LOCATION d c b a dp e g f
1200H
1201H
1202H
1203H
1204H
1205H
1206H
1207H

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 62

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 63

VIVA QUESTIONS:

1. What is the output modes used in 8279?


8279 provides two output modes for selecting the display options.
1.Display Scan
In this mode, 8279 provides 8 or 16 character-multiplexed displays those can be
organized as dual 4-bit or single 8-bit display units.
2.Display Entry
8279 allows options for data entry on the displays. The display data is entered for
display from the right side or from the left side.

2. What are the modes used in keyboard modes?


1. Scanned Keyboard mode with 2 Key Lockout.
2. Scanned Keyboard with N-key Rollover.
3. Scanned Keyboard special Error Mode.
4. Sensor Matrix Mode.

3. What are the modes used in display modes?


1. Left Entry mode
In the left entry mode, the data is entered from the left side of the display
unit..
2. Right Entry Mode
In the right entry mode, the first entry to be displayed is entered on the
rightmost display.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 64

INTERFACING WITH 8085

INTERFACING PROGRAMMABLE TIMER – 8253

Ex.No.10a

AIM:
To Interface 8253 with 8085 and to verify the operation of 8253 in different modes.
APPARATUS REQUIRED:
Microprocessor Kit, Powersupply, 8253 Interfaceing kit, CRO
PROBLEM STATEMENT:
The program starts from memory location 4100H onwards. Output waveform can be observed by
properly connecting CRO at the output port.

Mode 0 – Interrupt on terminal count:


The output will be initially low after mode set operations. After loading the counter, the output will be
remaining low while counting and on terminal count; the output will become high, until reloaded
again.Let us set the channel 0 in mode 0. Connect the CLK 0 to the debounce circuit by changing the
jumper J3 and then execute the following program.

PROGRAM:

Address Label Operand Operands Comments


4100 START: MVI A, 30 Channel 0 in mode 0
4102 OUT CE Send Mode Control word
4104 MVI A, 05 LSB of count
4106 OUT C8 Write count to register
4108 MVI A, 00 MSB of count
410A OUT C8 Write count to register
410C HLT

It is observed in CRO that the output of Channel 0 is initially LOW. After giving six clock pulses, the
output goes HIGH.

Mode 1 – Programmable ONE-SHOT:


After loading the counter, the output will remain low following the rising edge of the gate input. The
output will go high on the terminal count. It is retriggerable; hence the output will remain low for the
full count, after any rising edge of the gate input.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 65

Example:
The following program initializes channel 0 of 8253 in Mode 1 and also initiates triggering of Gate 0.
OUT 0 goes low, as clock pulse after triggering the goes back to high level after 5 clock pulses. Execute
the program, give clock pulses through the debounce logic and verify using CRO.

Address Label Mnemonic Operands Comments


4100 START: MVI A, 32 Channel 0 in mode 1
4102 OUT CE Send Mode Control word
4104 MVI A, 05 LSB of count
4106 OUT C8 Write count to register
4108 MVI A, 00 MSB of count
410A OUT C8 Write count to register
410C OUT D0 Trigger Gate0
4100 HLT

Mode 2 – Rate Generator:


It is a simple divide by N counter. The output will be low for one period of the input clock. 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.

Example:
Using Mode 2, Let us divide the clock present at Channel 1 by 10. Connect the CLK1 to

Address Opcodes Label Mnemonic Comments


4100 3E 74 START: MVI A, 74 Channel 1 in mode 2
4102 D3 CE OUT CE Send Mode Control word
4104 3E 0A MVI A, 0A LSB of count
4106 D3 CA OUT CA Write count to register
4108 3E 00 MVI A, 00 MSB of count
410A D3 CA OUT CA Write count to register
410C 76 HLT

PCLK.In CRO observe simultaneously the input clock to channel 1 and the output at Out1.

Mode 3 Square wave generator:


It is similar to Mode 2 except that the output will remain high until one half of count and go low for the

other half for even number count. If the count is odd, the output will be high for (count + 1)/2 counts.

This mode is used of generating Baud rate for 8251A (USART).

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 66

Example:

We utilize Mode 0 to generate a square wave of frequency 150 KHz at channel 0.


Address Opcodes Label Mnemonic Operands Comments
4100 3E 36 START: MVI A, 36 Channel 0 in mode 3
4102 D3 CE OUT CE Send Mode Control word
4104 3E 0A MVI A, 0A LSB of count
4106 D3 C8 OUT C8 Write count to register
4108 3E 00 MVI A, 00 MSB of count
410A D3 C8 OUT C8 Write count to register
410C 76 HLT
Set the jumper, so that the clock 0 of 8253 is given a square wave of frequency 1.5 MHz. This program
divides this PCLK by 10 and thus the output at channel 0 is 150 KHz.

Vary the frequency by varying the count. Here the maximum count is FFFF H. So, the square
wave will remain high for 7FFF H counts and remain low for 7FFF H counts. Thus with the input clock
frequency of 1.5 MHz, which corresponds to a period of 0.067 microseconds, the resulting square wave
has an ON time of 0.02184 microseconds and an OFF time of 0.02184 microseconds.

To increase the time period of square wave, set the jumpers such that CLK2 of 8253 is
connected to OUT 0. Using the above-mentioned program, output a square wave of frequency 150 KHz
at channel 0. Now this is the clock to channel 2.

Mode 4: Software Triggered Strobe:


The output is high after mode is set and also during counting. On terminal count, the output will
go low for one clock period and becomes high again. This mode can be used for interrupt generation.
The following program initializes channel 2 of 8253 in mode 4.

Example:
Connect OUT 0 to CLK 2 (jumper J1). Execute the program and observe the output OUT 2.
Counter 2 will generate a pulse after 1 second.

Address Label Mnemonic Operands Comments


4100 START: MVI A, 36 Channel 0 in mode 0
4102 OUT CE Send Mode Control word
4104 MVI A, 0A LSB of count
4106 OUT C8 Write count to register
4108 MVI A, 00 MSB of count
410A OUT C8 Write count to register
410C MVI A, B8 Channel 2 in Mode 4
410E OUT CE Send Mode control Word
4110 MVI A, 98 LSB of Count
4112 OUT CC Write Count to register
4114 MVI A, 3A MSB of Count
4116 OUT CC Write Count to register
4118 HLT

Mode 5 Hardware triggered strobe:


Counter starts counting after rising edge of trigger input and output goes low for one clock
period when terminal count is reached. The counter is retriggerable.
Example:
The program that follows initializes channel 0 in mode 5 and also triggers Gate 0. Connect CLK 0 to
debounce circuit.
Execute the program. After giving Six clock pulses, you can see using CRO, the initially HIGH
output goes LOW. The output ( OUT 0 pin) goes high on the next clock pulse.
CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 67

Address Label Mnemonic Operands Comments


4100 START: MVI A, 1A Channel 0 in mode 5
4102 OUT CE Send Mode Control word
4104 MVI A, 05 LSB of count
4106 OUT C8 Write count to register
4108 MVI A, 00 MSB of count
410A OUT D0 Trigger Gate 0
410C HLT
OUTPUT:

RESULT:

VIVA QUESTIONS:
CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 68

1.What are the modes of operations used in 8253?


Each of the three counters of 8253 can be operated in one of the following
six modes of operation.
1. Mode 0 (Interrupt on terminal count)
2. Mode 1 (Programmable monoshot)
3. Mode 2 (Rate generator)
4. Mode 3 (Square wave generator)
5. Mode 4 (Software triggered strobe)
6. Mode 5 (Hardware triggered strobe)

2.. What are the different types of write operations used in 8253?
There are two types of write operations in 8253
(1) Writing a control word register
(2) Writing a count value into a count register
The control word register accepts data from the data buffer and initializes
the counters, as required. The control word register contents are used for
(a) Initializing the operating modes (mode 0-mode4)
(b) Selection of counters (counter 0- counter 2)
(c) Choosing binary /BCD counters
(d) Loading of the counter registers.
The mode control register is a write only register and the CPU cannot read
its contents.

3. Explain the purpose of the I/O instructions IN and OUT.


The IN instruction is used to move data from an I/O port into the
accumulator.
The OUT instruction is used to move data from the accumulator to an I/O
port.
The IN & OUT instructions are used only on microprocessor, which use a
separate address space for interfacing.

4.What is meant by interrupt?


Interrupt is an ex ternal signal that causes a microprocessor to jump to a
specific subroutine.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 69

INTERFACING USART 8251

Ex.No.10b

AIM :
To study interfacing technique of 8251(USART) with microprocessor 8085 and write an 8085 ALP to
transmit and receive data between two serial ports with Rs 232 cable.
APPARATUS REQUIRED:
8085 Kit, Rs232 cable
ALGORITHM:
1. Initialise 8253 and 8251 to check the transmission and reception of character
2. Initialise 8253 to give output of 150 Khz at channel 0 which give 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 staus 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.
THEORY:
The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data
communication. As a peripheral device of a microcomputer system, the 8251 receives parallel data from
the CPU and transmits serial data after conversion. This device also receives serial data from the outside
and transmits parallel data to the CPU after conversion.
Control Words There are two types of control word.

1. Mode instruction (setting of function)

2. Command (setting of operation)

1) Mode Instruction
Mode instruction is used for setting the function of the 8251. Mode instruction will be in "wait for write"
at either internal reset or external reset. That is, the writing of a control word after resetting will be
recognized as a "mode instruction."
Items set by mode instruction are as follows:
• Synchronous/asynchronous mode
• Stop bit length (asynchronous mode)
• Character length
• Parity bit
• Baud rate factor (asynchronous mode)
• Internal/external synchronization (synchronous mode)
• Number of synchronous characters (Synchronous mode)

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 70

2) Command
Command is used for setting the operation of the 8251. It is possible to write a command whenever
necessary after writing a mode instruction and sync characters.
Items to be set by command are as follows:
• Transmit Enable/Disable
• Receive Enable/Disable
• DTR, RTS Output of data.
• Resetting of error flag.
• Sending to break characters
• Internal resetting
• Hunt mode (synchronous mode)
COMMAND WORD

MODE WORD

STATUS WORD

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 71

PROGRAM (Transmitter):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LXI H,4500
4103
MVI A,36
4105
OUT 0B
4107
MVI A,40
4109
OUT 08
410B
MVI A,01
410D
OUT 08
410F L2
MVI C,05
4111 L1
IN 05
4113
ANI 04
4115
JZ L1
4118
MOV A,M
4119
OUT 04
411B
INX H
411C
CPI 3F
411E
JNZ L2
4121
DCR C
4122
JNZ L1
4125
RST 1

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 72

PROGRAM (Receiver):

ADDRESS LABEL MNEMONICS HEX CODE


4100 LXI H,4500
4103
MVI A,36
4105
OUT 0B
4107
MVI A,40
4109
OUT 08
410B
MVI A,01
410D
OUT 08
410F L2
MVI C,05
4111 L1
IN 05
4113
ANI 02
4115
JZ L1
4118
IN 04
411A
MOV M,A
411B
INX H
411C
CPI 3F
411E
JNZ L2
4121
DCR C
4122
JNZ L1
4125
RST 1

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 73

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 74

VIVA QUESTIONS:
1.What is an USART?
USART stands for universal synchronous/Asynchronous Receiver/
Transmitter. It is a programmable communication interface that can communicate by
using either synchronous or asynchronous serial data.

2.What is the use of 8251 chip?


8251 chip is mainly used as the asynchronous serial interface between the
processor and the external equipment.

3. What is the use of modem control unit in 8251?


The modem control unit handles the modem handshake signals to coordinate the
communication between the modem and the USART.

4.Format for Character Framing:


Character framing

5. Explain receiver and transmitter


Receiver

The receiver tests the state of the incoming signal on each clock pulse, looking for the
beginning of the start bit. If the apparent start bit lasts at least one-half of the bit time, it is valid
and signals the start of a new character. If not, the spurious pulse is ignored. After waiting a
further bit time, the state of the line is again sampled and the resulting level clocked into a shift
register.

Transmitter

Transmission operation is simpler since it is under the control of the transmitting system. As
soon as data is deposited in the shift register after completion of the previous character, the
USART hardware generates a start bit, shifts the required number of data bits out to the line,
generates and appends the parity bit (if used), and appends the stop bits. Since transmission of a
single character may take a long time relative to CPU speeds, the USART will maintain a flag
showing busy status so that the host system does not deposit a new character for transmission
until the previous one has been completed; this may also be done with an interrupt. Since full-
duplex operation requires characters to be sent and received at the same time, practical USARTs
use two different shift registers for transmitted characters and received characters.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 75

8051 PROGRAMS

8 BIT ADDITION/SUBTRACTION
Ex.No.11a

AIM:
To write an ALP to perform 8 bit addition/subtraction in 8051.
Apparatus required:
8051 microcontroller kit, power supply.
ALGORITHM:
8 bit addition:
1. Clear the program status word.
2. Load the first number in the accumulator.
3. Load the second reg. in the register R0.
4. Load the destination address in the DPTR.
5. Add te 2 numbers.
6. Store the sum and carry in the destination address.
7. Terminate the program.
8 bit subtraction:
1. Clear PSW.
2. Select the register by giving proper values.
3. Lolad the accumulator with 1st data & reg with 2nd data.
4. Subtract 2nd data from 1st data.
5. Store the diff and borrow and terminate the program.

8 Bit Addition (Immediate Addressing)


ADDRESS LABEL MNEMONIC OPERAND HEX
CODE
4100 CLR C

4101 MOV A, data1

4103 ADDC A, # data 2

4105 MOV DPTR, #


4500H
4108 MOVX @ DPTR, A

4109 L1 SJMP L1

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 76

8 Bit Subtraction (Immediate Addressing)

ADDRESS LABEL MNEMONIC OPERAND HEX


CODE
4100 CLR C

4101 MOV A, # data1

4103 SUBB A, # data2

4105 MOV DPTR, # 4500

4108 MOVX @ DPTR, A

4109 L1 SJMP L1

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 77

MULTIPLICATION/DIVISION OF 8 BIT NUMBERS

Ex.No.11b

AIM:
To write a program for 8 bit multiplication & 8 bit division using 8051 microcontroller.
Apparatus required:
8051 microcontroller kit, power supply.
ALGORITHM:
8 bit multiplication:
1. Clear PSW.
2. Select register bank by giving proper values.
3. Load accumulator A with any derived 8 bit data.
4. Load registers B with 2nd data.
5. Multiply there 2 nods.
6. Store the result
7. Terminate the program.

8 BIT DIVISION:
1. Clear PSW.
2. Select register bank by giving proper values.
3. Load A with 1st data dividend.
4. Load B wit 8 bit divisor.
5. Divide A/B.
6. Store the quotient & remainder.
7. Terminate the program.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 78

8 Bit Multiplication
ADDRESS LABEL OPCODE OPERAND HEX CODE
4100 MOV A ,#data1

4102 MOV B, #data2

4104 MUL A,B

4106 MOV DPTR, # 4500H

4109 MOVX @ DPTR, A

401A INC DPTR

410B MOV A,B

410D MOV @ DPTR, A


STOP
410E SJMP STOP

8 Bit Division
ADDRESS LABEL OPCODE OPERAND HEX CODE
4100 MOV A, # data1

4102 MOV B, # data2

4104 DIV A,B

4015 MOV DPTR, # 4500H

4018 MOVX @ DPTR, A

4109 INC DPTR

410A MOV A,B

410C MOV @ DPTR, A


STOP
410D SJMP STOP

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 79

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 80

STEPPER MOTOR CONTROLLER

Ex.No:12a

AIM:
To write an ALP in 8051 to rotate the motor at different speeds in clockwise and in anticlockwise
directions with delay.
APPARATUS REQUIRED:
1. Microcontroller kit
2. Power supply
3. Stepper motor interface board
PROBLEM STATEMENT
The Program starts from memory location 4100H.The input data should be available at 4300H.
The output is sent through ports to run the stepper motor.

THEORY
A motor in which a rotor is able to assume only discrete stationary angular position is a stepper
motor.The rotary motion occurs in a stepwise manner from one equilibrium position to the next.The
stepper motor windings A1,B1,A2,B2 can be cyclically excited with a DC current to run the motor in a
clockwise direction.By reversing the phase sequence A1,B2,A2,B1, we can obtain anticlockwise
stepping.
ALGORITHM
1. Get the first data from the look-up table.
2. Initialize the counter and move data into accumulator.
3. Drive the stepper motor circuitry and introduce delay
4. Decrement the counter
5. Repeat the above procedure both for backward and forward directions.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 81

PROGRAM :

ADDRESS LABEL OPCODE OPERAND

ORG

4100 START: MOV

4103 MOV
4105 LOOP: MOVX
4106 PUSH
4108 PUSH
410A MOV

410D MOVX

410E MOV
4110 DELAY: MOV
4112 DELAY1: DJNZ
4114 DJNZ
4116 POP
4118 POP

411A INC

411B DJNZ

411D SJMP

411F TABLE: DB

PROCEDURE:
Enter the above program starting from location 4100.and execute the same. The stepper motor rotates.
Varying the count at R4 and R5 can vary the speed. Entering the data in the look-up TABLE in the
reverse order can vary direction of rotation.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 82

SWITCHING SEQUENCE OF STEPPER MOTOR

CLOCKWISE DIRECTION
Memory Location A1 A2 B1 B2 Hex Code

ANTICLOCKWISE DIRECTION

Memory Location A1 A2 B1 B2 Hex Code

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 83

ANALOG-TO- DIGITAL CONVERTER

Ex.No.12b

AIM: -
To Interface Analog-to-Digital converter to 8051 and write Assembly Language Program to read Digital
value from ADC.
APPARATUS:-
Microprocessor trainer kit, ADC kit, power supply, data cable etc
THEORY:
ANALOG TO DIGITAL CONVERTER
Resolution 8 bits
1. Conversion time 100 micro sec.
2. Single supply 5V
3. 8 channel multiplexed with latched control logic
4. easy interface to all microprocessor
5. 0 to 5V analog input voltage range with single 5V supply
6. low power consumption 15mW
7. latched tristate output
WORKING:-
ADC interface consists of a NAND gate oscillator witch feeds 50 KHz as the input clock to ADC, input
to channel is given through terminal blocks provided on the card. Channel selection is done using port
lines PC0, PC1 & PC2, START OF CONVERSION and ALE is controlled by port line PC7. Converted
digital output is read by ADC through PORTA lines by enabling OE.
In this method of interfacing microprocessor is continuously monitoring EOC line (which is connected
to port line PA7). When this goes high, make OE (PC6) high & then low, this will put the digital
equivalent of analog voltage of the given channel on data lines of ADC. Read the digital data through
port lines PA0 to PA7 and display the same data.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 84

PROGRAM

ADDRESS LABEL MNEMONICS


HEXCODE
4100 MOV DPTR, #add1
4103 MOV A, #data1
4105 MOVX @DPTR,A
4106 MOV A,#data2
4108 MOVX @DPTR,A
4109 MOV DPTR,#add2
410C MOV A,#data3
410E MOVX @DPTR,A
410F MOV A,#data4
4111 MOVX @DPTR,A
4112 HERE SJMP HERE

Add1 - address to select the channel, send ALE & OE signals


Add2 - address to send the SOC signal
Data1 - data to select the channel, ALE low & OE high
Data2 - data to select the channel, ALE high & OE high
Data3 -send SOC high D0 - high
Data4 -send SOC low D0 - low

Channel No. Data to make Data to make


ALE low & OE high ALE high & OE high

CH0 10 18
CH1 11 19
CH2 12 1A
CH3 13 1B
CH4 14 1C
CH5 15 1D
CH6 16 1E
CH7 17 1F

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 85

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 86

DIGITAL-TO-ANALOG CONVERTER

Ex.No.12c

AIM:
To write an ALP for digital-to analog converter to generate different types of waveforms at DAC
output

APPARATUS REQUIRED:

1. Microcontroller kit
2. Power supply
3. AC interface board

PROBLEM STATEMENT

The program starts from 4100H location. The input is given in the memory locations 4100H and 4108H.
The output is sent to the output ports. The waveforms are measured at the output port using CRO.

THEORY
Since DAC 0800 is an 8-bit DAC and the output voltage variation is between -5v and +5v.The
basic idea behind the generation of waveforms is the continuous generation of analog output of DAC.
With 00H as input to DAC, the analog output is -5V.Similarly with FFH as input, the output is +5V.
ALGORITHM

MEASUREMENT OF ANALOG VOLTAGE


1. Send the digital value of DAC

2. Read the corresponding analog value of its output.

WAVEFORM GENERATION
SQUARE WAVEFORM
1. Send low value(00) to DAC

2. Introduce suitable delay

3. Send high value to DAC

4. Introduce delay

5. Repeat the above procedure

SAW-TOOTH WAVEFORM
1. Load low value(00) to accumulator

2. Send this value to DAC

3. Increment the Accumulator

4. Repeat step 2 and 3 until accumulator value reaches FF

5. Repeat the above procedure from step1

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 87

TRIANGULAR WAVEFORM
1. Load low value(00) to accumulator

2. Send this value to DAC

3. Increment the Accumulator

4. Repeat step 2 and 3 until accumulator value reaches FF, decrement the accumulator and
send this value to DAC
5. Repeat the above procedure from step1

SQUAREWAVE:

ADDRESS LABEL MNEMONICS


HEXCODE
4100 MOV DPTR, #FFC0
4103 START MOV A, #00
4105 MOVX @DPTR,A
4106 LCALL DELAY
4109 MOVA,#FF
410B MOV X @DPTR,A
410C LCALL DELAY
410F LJMP START
4112 DELAY MOV R1,#05
4114 LOOP MOV R2,#FF
4116 LOOP1 DJNZ R2,LOOP1
4118 DNJZ R1,LOOP
411A RET
411B SJMP START

SAW-TOOTH WAVEFORM

ADDRESS LABEL MNEMONICS


HEXCODE
4100 MOV DPTR, #FFC0
4103 MOV A, #00
4105 LOOP MOVX @DPTR,A
4106 INC A
4107 SJMP LOOP

TRIANGULAR WAVEFORM

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 88

ADDRESS LABEL MNEMONICS


HEXCODE
4100 MOV DPTR, #FFC0
4103 START MOV A, #00
4105 LOOP1 MOVX @DPTR,A
4106 INC A
4107 JNZ LOOP1
4109 MOV A,#FF
410B LOOP2 MOVX @DPTR,A
410C DEC A
410D JNZ LOOP2
410F LJMP START

OUTPUT:

RESULT:

VIVA QUESTIONS:

1.Features of 8051microcontroller.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 89

• 8 bit controller operating on bit and byte.


• 256 bytes internal RAM and 4 kb internal RAM
• 64/60 kb external program memory address space
• 64 kb external data memory address space
• 4 numbers of 8 bit parallel ports.

2. State the functions of RS1 and RS0 bit in the flag register
It is used to select the register banks
RS1 RS0 Bank selection
0 0 00 H – 07 H BANK 0
0 1 08 H - 0F H BANK 1
1 0 10 H – 17 H BANK 2
1 1 18 H – 1F H BANK 3

3. Difference between RR A and RRC A instructions in 8051


RR A --Rotate accumulator right
The 8 bits in the accumulator are rotated 1 bit to the right.bit 0 is rotated in to the bit 7 position. No flags
are affected.

RRC A-- Rotate accumulator right through carry flag


The 8 bits in the accumulator and the carry flag together rotated 1 bit to the right.bit 0 is moves in to the
bit carry flag; the original value of the flag moves in to the bit 7 position. No flags are affected.

5. Show the format of PSW register of 8051


B7 B6 B5 B4 B3 B2 B1 B0
CY AC F0 RS1 RS0 OF – P

6. What are the functions of DPTR register?


• The data pointers consist of a high byte (DPH) and a low byte (DPL).
• It functions is to hold a 16 byte address.
• It serves as a base register in indirect jumps, lookup table instructions and
external data transfer.

7. List the interrupt structures of 8051.


• Priority level structure.
• External interrupts.
• Single step operation.

8. List the instruction sets of 8051.


• Data transfer
• Arithmetic
• Logical
• Branching
• Boolean

9. List the addressing modes supported by 8051.


• Register addressing
• Direct byte addressing
• Register indirect
• Immediate
• Register specific
• Index

10. What are the operating modes of the timer of 8051?


• The operating modes of the timer are mode 0, mode1, mode2, mode3.
• In mode 0, timer will function as 13 bit timer, in mode1 will function as
CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 90

16 bit timer, in mode2, function as 8 bit with auto reload feature.

11. List the interrupts of 8051 microcontroller.


It has
• External interrupt -0
• Timer-0 interrupt
• External interrupt-1
• Timer-1 interrupt
• Serial port interrupts.

12. What are the dedicated address pointers in 8051?


• Program counter
• Data pointer.
• The PC is used as address pointer for program and DPTR is used as
address pointer for data.

13. What are the register banks in 8051?


• The reg banks are internal RAM locations of 8051 which can be used as general purpose reg or scratch
pad reg.
• The first 32 bytes of internal RAM of 8051 and organise as 4 reg banks with each bank consisting 8
locations.
• At any one time the processor can work with only one reg bank depending on the value of bits RS0 and
RS1.

14. How stack is implemented in 8051.


• The 8051 LIFO .Stack can reside anywhere in the internal RAM
• it has 8 bit stack pointer to indicate the top if stack. This can be accessed by
PUSH and POP instructions.
• During PUSH the SP is incremented by 1 and during POP the SP is
decremented by 1.

15. Explain the interrupts of 8051 microcontroller.


The interrupts are:
Vector address
 A External interrupt 0 : IE0 : 0003H
 A Timer interrupt 0 : TF0 : 000BH
 A External interrupt 1 : IE1 : 0013H
 A Timer Interrupt 1 : TF1 : 001BH
 A Serial Interrupt
Receive interrupt : RI : 0023H
Transmit interrupt: TI : 0023H

16. Define stack.


Stack is a sequence of RAM memory locations defined by the Programmer.

17. What is program counter? How it will be useful in program execution?


The program counter keeps track of program execution. To execute a program the
starting address of the program is loaded in program counter. The PC sends out an
address to fetch a byte of instruction from memory and increments its content
automatically.

18.. Explain DJNZ instructions of intel 8051 microcontroller?


a) DJNZ Rn, rel
Decrement the content of the register Rn and jump if not zero.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 91

b) DJNZ direct , rel


Decrement the content of direct 8-bit address and jump if not zero.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 92

Ex.No.13 MINI PROJECT

FINGERPRINT BASED SECURITY SYSTEM

ABSTRACT:
Personal Safes are revolutionary locking storage cases that open with just the touch of your finger. These
products are designed as secure storage for medications; jewelry, weapons, documents, and other
valuable or potentially harmful items. These utilize fingerprint recognition technology to allow access to
only those whose fingerprints you choose. It contains all the necessary electronics to allow you to store,
delete, and verify fingerprints with just the touch of a button. Stored fingerprints are retained even in the
event of complete power failure or battery drain. These eliminates the need for keeping track of keys or
remembering a combination password, or PIN. It can only be opened when an authorized user is present,
since there are no keys or combinations to be copied or stolen, or locks that can be picked. In this project
the fingerprint module from Miaxis Biometrics is used. It can store up to 750 finger prints on its own
memory. It can be controlled through its serial port. The microcontroller AT89S52 interacts with the
module. You can add a fingerprint, Delete a fingerprint and identify the fingerprint. To add a fingerprint,
just show the finger on the module and press the ADD key. Now the microcontroller will send the ADD
command to the module and the module will add it into the memory. To identify the finger, press the
Identify button and if the finger matches then the Relay is complemented. Also the fingerprint ID is
displayed over the LCD display.

SYSTEM REQUIREMENTS:

 Microcontroller AT89S52
 Transistors
 Resistors
 LCD
 Buzzer

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 93

CIRCUIT DIAGRAM:

SOURCE CODE:

RB0 EQU 00H ; Select Register Bank 0


RB1 EQU 08H ; Select Register Bank 1 ...poke to PSW to use
RB2 EQU 10H ; Select Register Bank 1 ...poke to PSW to use
******************************************************************************
PORT DECLERATION
*******************************************************************************
//// ***LCD CONTROL***////
LCD_RS EQU P0.0 ; LCD REGISTER SELECT LINE
LCD_E EQU P0.1 ; LCD ENABLE LINE
LCD_DB4 EQU P0.2 ; PORT 1 IS USED FOR DATA
LCD_DB5 EQU P0.3 ; USED FOR DATA
LCD_DB6 EQU P0.4 ; FOR DATA
LCD_DB7 EQU P0.5 ; FOR DATA

SEARCH EQU P1.0


ADDS EQU P1.1
DELETE EQU P1.2

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 94

LOAD EQU P0.7


ALARM EQU P0.6

***CURSOR CONTROL INSTRUCTIONS***

OFFCUR EQU 0CH


BLINKCUR EQU 0DH

; ***DISPLAY CONTROL INSTRUCTIONS***

CLRDSP EQU 01H


ONDSP EQU 0CH

; ***SYSTEM INSTRUCTIONS***

CONFIG EQU 28H ; 4-BIT DATA,2 LINES,5X7 MATRIX LCD


ENTRYMODE EQU 6 ; INCREMENT CURSOR DON'T SHIFT DISPLAY

DSEG ; this is internal data memory


ORG 20H ; Bit addressable memory
FLAGS1: DS 1
RECEIVED BIT FLAGS1.0

COUNTER: DS 1
BYTE: DS 10
TEMP: DS 1
TEMPS: DS 1
USER_COUNT: DS 1
ERROR_COUNT: DS 1
;*****************************************************************************
*******************************************************************************
CSEG ; Code begins here

; ---------==========----------==========---------=========---------
; Main routine. Program execution starts here.
; ---------==========----------==========---------=========---------
ORG 00H ; Reset
AJMP MAIN
ORG 23H
JMP SERIAL
; ---------==========----------==========---------=========---------
MAIN:
MOV PSW,#RB0 ; Select register bank 0
MOV SP,#60h
MOV A,PCON
SETB ACC.7
MOV PCON,A
MOV TMOD,#20H
MOV TH1,#0FFH
MOV SCON,#50H
SETB ES
SETB EA
SETB TR1

SETB ADDS
SETB SEARCH
CLR LOAD
CLR ALARM
MOV ERROR_COUNT,#00H

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 95

;CHECK TO INITIALIZE THE USER COUNT IN FLASH MEMORY


CLR RECEIVED
MOV DPTR, #READ_FLASH
CALL SEND_SERIAL
CALL DELAY
MOV A, BYTE+4
CJNE A, #0FFH, NOT_INT
MOV DPTR, #STORE_FLASH
CALL SEND_SERIAL
NOT_INT:

CALL RESETLCD4
TOPS: CALL DISPLAY

TOP:
JNB ADDS,ADD_USERS
JNB SEARCH,SEARCH_USERS
JNB DELETE,DELETE_USER
AJMP TOP

SEARCH_USERS:
AJMP SEARCH_USER
ADD_USERS:
AJMP ADD_USER

DELETE_USER:
JNB DELETE,$
CALL DISPLAY_DEL
CLR RECEIVED
MOV DPTR,#SEARCH_USER_DATA
CALL SEND_SERIAL
CALL DELAYS
MOV A, BYTE+4
CJNE A, #39H, NOT_MATCHS
CALL FIN_MATCHED
MOV TEMP, BYTE+6
CALL DELAYS
CALL DELAYS
MOV DPTR, #DEL_USER_DATA
MOV TEMPS, #00H
CALL SEND_SERIAL
MOV SBUF, TEMP
CALL TRANSDELAY
MOV A, TEMPS
ADD A, TEMP
MOV SBUF, A
CALL TRANSDELAY
CALL DELAYS
MOV A, BYTE+4
CJNE A, #31H, NOT_MATCHES
CALL FIN_DELETED
CALL DELAYS
CALL DELAYS
AJMP TOPS
NOT_MATCHES:
CALL NOT_DELETED
CALL DELAYS
CALL DELAYS
AJMP TOPS
NOT_MATCHS:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 96

CALL NOT_MATCHED
CALL DELAYS
CALL DELAYS
AJMP TOPS
ADD_USER:
CALL DISPLAY1
CALL DELAYS
JNB ADDS,$
CLR RECEIVED
MOV DPTR,#SEARCH_USER_DATA
CALL SEND_SERIAL
CALL DELAYS
MOV A,BYTE+4
CJNE A,#39H,NOT_MATCHSS
CALL ALREADY_EXIT
CALL DELAYS
CALL DELAYS
AJMP TOPS
NOT_MATCHSS:
CLR RECEIVED
MOV DPTR,#READ_FLASH ;LOAD USER COUNT FROM
FLASH MEMORY
CALL SEND_SERIAL
CALL DELAY
MOV A, BYTE+4
MOV USER_COUNT,A
CJNE A,#16,USER_NOT_FULL
CALL USER_FULL_DISPLAY
CALL DELAYS
CALL DELAYS
AJMP TOPS

USER_NOT_FULL:
CLR RECEIVED
MOV DPTR,#ADD_USER_DATA
MOV TEMPS, #00H
CALL SEND_SERIAL
MOV SBUF, USER_COUNT
CALL TRANSDELAY
MOV A, TEMPS
ADD A, USER_COUNT
MOV SBUF,A
CALL TRANSDELAY
NEXT:
CALL DELAYS
CALL DELAYS
JNB RECEIVED,$
MOV A,BYTE+4
CJNE A,#31H,NOT_SAVED
CALL DISPLAY_SUCESS
CALL DELAYS
CALL DELAYS
CLR RECEIVED
MOV DPTR,#STORE_FLASH
MOV TEMPS,#00H
CALL SEND_SERIAL
INC USER_COUNT
MOV SBUF, USER_COUNT
CALL TRANSDELAY
MOV A, TEMPS
ADD A, USER_COUNT

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 97

MOV SBUF,A
CALL TRANSDELAY
CLR RECEIVED
AJMP TOPS
NOT_SAVED:
CALL DISPLAY_NOTSUCESS
CALL DELAYS
CALL DELAYS
CLR RECEIVED
AJMP TOPS

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SEND_SERIAL:
CLR A
MOVC A,@A+DPTR
CJNE A,#0FFH,SEND_D
RET
SEND_D:
MOV SBUF,A
ADD A, TEMPS
MOV TEMPS,A
CALL TRANSDELAY
INC DPTR
AJMP SEND_SERIAL
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SEARCH_USER:
JNB SEARCH,$
CALL DISPLAY2

CLR RECEIVED
MOV DPTR,#SEARCH_USER_DATA
CALL SEND_SERIAL
CALL DELAYS

MOV A, BYTE+4
CJNE A,#39H,NOT_MATCH
CPL LOAD
CLR ALARM
MOV ERROR_COUNT,#00H
CALL MATCHED
MOV TEMP, BYTE+6
CALL SPLITDISP
CALL DELAYS
CALL DELAYS
AJMP TOPS
NOT_MATCH:
INC ERROR_COUNT
MOV A,ERROR_COUNT
CJNE A,#04H,ALARM_ON
SETB ALARM
ALARM_ON:
CALL NOT_MATCHED
CALL DELAYS
CALL DELAYS
AJMP TOPS
SPLITDISP:
MOV A,TEMP

mov b,#10 ; Divide By 10


div ab ; Do Divide

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 98

swap a ; Move Result To High Of A


orl a,b ; OR In Remainder

MOV TEMP, A
ANL A, #0F0H
SWAP A
ADD A, #30H
MOV R4,A
CALL WRLCDDATA
CALL MDELAY
MOV A, TEMP
ANL A, #0FH
ADD A, #30H
MOV R4, A
CALL WRLCDDATA
CALL MDELAY
MOV R4, #' '
CALL WRLCDDATA
CALL MDELAY
RET

;---------==========----------==========---------=========---------
ADD_USER_DATA:
DB 4DH, 58H, 10H, 03H, 40H, 00H, 0FFH
DB 4DH, 58H, 10H, 03H, 40H, 00H, 01H, 0F9H, 0FFH
;ADDRESS--------------------------^
SEARCH_USER_DATA:
DB 04DH, 58H, 10H, 05H, 44H, 00H, 00H, 00H, 0FEH, 0FCH, 0FFH

STORE_FLASH:
DB 4DH, 58H, 10H, 05H, 64H, 00H, 00H, 01H, 0FFH
DB 4DH, 58H, 10H, 05H, 64H, 00H, 00H, 01H, 00H, 1FH, 0FFH

READ_FLASH:
DB 4DH, 58H, 10H, 04H, 62H, 00H, 00H, 01H, 1CH, 0FFH
;ADDRESS--------------------------^
;COUNT---------------------------------^

DEL_USER_DATA:
DB 4DH, 58H, 10H, 03H, 42H, 00H, 0FFH
;---------==========----------==========---------=========---------
SERIAL:
PUSH PSW ; save current register set
MOV PSW,#RB1
PUSH ACC
JB TI,TRANSD
MOV A,SBUF
CJNE A,#4DH,DOWN2
MOV COUNTER,#01H
JMP DDWN
TRANSD: AJMP TRANS
DOWN2:
MOV R1,COUNTER
CJNE R1,#01H,YH1
MOV BYTE,A
JMP DOWN1
YH1: CJNE R1,#02H,YH2
MOV BYTE+1,A
JMP DOWN1
YH2: CJNE R1,#03H,YH3

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 99

MOV BYTE+2,A
MOV TEMP,A
JMP DOWN1
YH3: CJNE R1,#04H,YH4
MOV BYTE+3,A
DEC TEMP
MOV A,TEMP
CJNE A,#00H,DOWN1
SETB RECEIVED
JMP DOWN1
YH4: CJNE R1,#05H,YH5
MOV BYTE+4,A
DEC TEMP
MOV A,TEMP
CJNE A,#00H,DOWN1
SETB RECEIVED
JMP DOWN1
YH5: CJNE R1,#06H,YH6
MOV BYTE+5,A
DEC TEMP
MOV A,TEMP
CJNE A,#00H,DOWN1
SETB RECEIVED
JMP DOWN1
YH6: CJNE R1,#07H,YH7
MOV BYTE+6,A
DEC TEMP
MOV A,TEMP
CJNE A,#00H,DOWN1
SETB RECEIVED
JMP DOWN1
YH7: CJNE R1,#08H,DOWN1
MOV BYTE+7,A
DEC TEMP
MOV A,TEMP
CJNE A,#00H,DOWN1
SETB RECEIVED
JMP DOWN1
DOWN1: INC COUNTER
DDWN: CLR RI
POP ACC
POP PSW
RETI

TRANS: CLR TI
POP ACC
POP PSW
RETI
;**********************************************************
;**********************************************************
TRANSDELAY:
MOV R7,#5FH
DJNZ R7,$
RET
;**************************************************************************
;##########################################################
; DISPLAY ROUTINES
;##########################################################
DISPLAY:
MOV DPTR,#MSAG1
CALL LCD_MSG

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 100

RET
MSAG1:
DB 1H,80H,'Fingerprint Based',0C0H,'Security System',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISPLAY1:
MOV DPTR,#MSAG2
CALL LCD_MSG
RET

MSAG2:
DB 1H,83H,'Show your',0C0H,'Finger to ADD..',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISPLAY2:
MOV DPTR,#MSAG3
CALL LCD_MSG
RET
MSAG3:
DB 1H,83H,'Show your',0C3H,'Finger....',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USER_FULL_DISPLAY:
MOV DPTR,#MSAG4
CALL LCD_MSG
RET
MSAG4:
DB 1H,83H,'User memory',0C3H,'## FULL ##',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISPLAY_SUCESS:
MOV DPTR,#MSAG5
CALL LCD_MSG
RET
MSAG5:
DB 1H,83H,'User Added',0C3H,'Sucessfully',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISPLAY_NOTSUCESS:
MOV DPTR,#MSAG6
CALL LCD_MSG
RET
MSAG6:
DB 1H,83H,'User Added',0C2H,'## Failed ##',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MATCHED:
MOV DPTR,#MSAG7
CALL LCD_MSG
RET
MSAG7:
DB 1H,83H,'Fingerprint',0C1H,'Matched ID:',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOT_MATCHED:
MOV DPTR,#MSAG8
CALL LCD_MSG
RET
MSAG8:
DB 1H,83H,'Fingerprint',0C2H,'NOT Matched',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISPLAY_DEL:
MOV DPTR,#MSAG9
CALL LCD_MSG
RET
MSAG9:
DB 1H,83H,'Show your',0C0H,'Finger to DELETE',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 101

FIN_MATCHED:
MOV DPTR,#MSAG10
CALL LCD_MSG
RET
MSAG10:
DB 1H,83H,'Fingerprint',0C4H,'Matched',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FIN_DELETED:
MOV DPTR,#MSAG11
CALL LCD_MSG
RET
MSAG11:
DB 1H,83H,'Fingerprint',0C1H,'## Deleted ##',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOT_DELETED:
MOV DPTR,#MSAG12
CALL LCD_MSG
RET
MSAG12:
DB 1H,83H,'Fingerprint',0C2H,'NOT Deleted',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALREADY_EXIT:
MOV DPTR,#MSAG13
CALL LCD_MSG
RET
MSAG13:
DB 1H,83H,'Fingerprint',0C1H,'Already Exits',00H
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DELAY:
MOV R1,#0FFH
RE1: MOV R2,#0FFH
RE: NOP
DJNZ R2,RE
DJNZ R1,RE1
RET
;**********************************************************
DELAYS: ;One second delay routine
MOV R0,#05H
RS3: MOV R1,#0FFH
RA1: MOV R2,#0FFH
RS2: NOP
DJNZ R2,RS2
DJNZ R1,RA1
DJNZ R0,RS3
RET
;**********************************************************
DELAYSS: ;One second delay routine
MOV R0,#03H
RE3: MOV R1,#0FFH
RZ1: MOV R2,#0FFH
RE2: NOP
DJNZ R2,RE2
DJNZ R1,RZ1
DJNZ R0,RE3
RET
;**********************************************************
; INITIALIZE THE LCD 4-BIT MODE
;**********************************************************
INITLCD4:
CLR LCD_RS ; LCD REGISTER SELECT LINE

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 102

CLR LCD_E ; ENABLE LINE


MOV R4, #CONFIG; FUNCTION SET - DATA BITS,
; LINES, FONTS
CALL WRLCDCOM4
MOV R4, #ONDSP ; DISPLAY ON
CALL WRLCDCOM4
MOV R4, #ENTRYMODE ; SET ENTRY MODE
CALL WRLCDCOM4 ; INCREMENT CURSOR RIGHT, NO SHIFT
MOV R4, #CLRDSP; CLEAR DISPLAY, HOME CURSOR
CALL WRLCDCOM4
RET
; **********************************************************
; SOFTWARE VERSION OF THE POWER ON RESET
; **********************************************************
RESETLCD4:
CLR LCD_RS ; LCD REGISTER SELECT LINE
CLR LCD_E ; ENABLE LINE
CLR LCD_DB7 ; SET BIT PATTERN FOR...
CLR LCD_DB6 ; ... POWER-ON-RESET
SETB LCD_DB5
SETB LCD_DB4
SETB LCD_E ; START ENABLE PULSE
CLR LCD_E ; END ENABLE PULSE
MOV A, #4 ; DELAY 4 MILLISECONDS
CALL MDELAY
SETB LCD_E ; START ENABLE PULSE
CLR LCD_E ; END ENABLE PULSE
MOV A, #1 ; DELAY 1 MILLISECOND
CALL MDELAY
SETB LCD_E ; START ENABLE PULSE
CLR LCD_E ; END ENABLE PULSE
MOV A, #1 ; DELAY 1 MILLISECOND
CALL MDELAY
CLR LCD_DB4 ; SPECIFY 4-BIT OPERATION
SETB LCD_E ; START ENABLE PULSE
CLR LCD_E ; END ENABLE PULSE
MOV A, #1 ; DELAY 1 MILLISECOND
CALL MDELAY
MOV R4, #CONFIG; FUNCTION SET
CALL WRLCDCOM4
MOV R4, #08H ; DISPLAY OFF
CALL WRLCDCOM4
MOV R4, #1 ; CLEAR DISPLAY, HOME CURSOR
CALL WRLCDCOM4
MOV R4,#ENTRYMODE ; SET ENTRY MODE
ACALL WRLCDCOM4
JMP INITLCD4

; **********************************************************
; SUB RECEIVES A COMMAND WORD TO THE LCD
; COMMAND MUST BE PLACED IN R4 BY CALLING PROGRAM
; **********************************************************
WRLCDCOM4:
CLR LCD_E
CLR LCD_RS ; SELECT READ COMMAND
PUSH ACC ; SAVE ACCUMULATOR
MOV A, R4 ; PUT DATA BYTE IN ACC
MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS
MOV LCD_DB4, C ; ONE BIT AT A TIME USING...
MOV C, ACC.5 ; BIT MOVE OPERATOINS
MOV LCD_DB5, C

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 103

MOV C, ACC.6
MOV LCD_DB6, C
MOV C, ACC.7
MOV LCD_DB7, C
SETB LCD_E ; PULSE THE ENABLE LINE
CLR LCD_E
MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE
MOV LCD_DB4, C
MOV C, ACC.1
MOV LCD_DB5, C
MOV C, ACC.2
MOV LCD_DB6, C
MOV C, ACC.3
MOV LCD_DB7, C
CLR LCD_E
SETB LCD_E ; PULSE THE ENABLE LINE
CLR LCD_E
CALL MADELAY
POP ACC
RET
; **********************************************************
; SUB TO RECEIVE A DATA WORD TO THE LCD
; DATA MUST BE PLACED IN R4 BY CALLING PROGRAM
; **********************************************************
WRLCDDATA:
CLR LCD_E
SETB LCD_RS ; SELECT READ DATA
PUSH ACC ; SAVE ACCUMULATOR
MOV A, R4 ; PUT DATA BYTE IN ACC
MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS
MOV LCD_DB4, C ; ONE BIT AT A TIME USING...
MOV C, ACC.5 ; BIT MOVE OPERATOINS
MOV LCD_DB5, C
MOV C, ACC.6
MOV LCD_DB6, C
MOV C, ACC.7
MOV LCD_DB7, C
SETB LCD_E ; PULSE THE ENABLE LINE
CLR LCD_E
MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE
MOV LCD_DB4, C
MOV C, ACC.1
MOV LCD_DB5, C
MOV C, ACC.2
MOV LCD_DB6, C
MOV C, ACC.3
MOV LCD_DB7, C
CLR LCD_E
SETB LCD_E ; PULSE THE ENABLE LINE
CLR LCD_E
NOP
NOP
POP ACC
RET

; **********************************************************
; SUB TAKES THE STRING IMMEDIATELY FOLLOWING THE CALL AND
; DISPLAYS ON THE LCD. STRING MUST BE TERMINATED WITH A
; NULL (0).
; **********************************************************
LCD_MSG:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 104

CLR A ; Clear Index


MOVC A,@A+DPTR ; Get byte pointed by Dptr
INC DPTR ; Point to the next byte
JZ LCD_Msg9 ; Return if found the zero (end of stringz)
CJNE A,#01H,Lcd_Msg1 ; Check if is a Clear Command
MOV R4,A
CALL WRLCDCOM4 ;If yes, RECEIVE it as command to LCD
JMP LCD_MSG ;Go get next byte from stringz

Lcd_Msg1: CJNE A,#0FFH,FLL ;Check for displaying full character


MOV R4,A
CALL WRLCDDATA
JMP LCD_MSG
FLL: CJNE A,#080h,$+3 ; Data or Address? If => 80h then is address.
JC Lcd_Msg_Data ; Carry will be set if A < 80h (Data)
MOV R4,A
CALL WRLCDCOM4 ; Carry not set if A=>80, it is address
JMP Lcd_Msg ; Go get next byte from stringz

Lcd_Msg_Data: ;
MOV R4,A
CALL WRLCDDATA ; It was data, RECEIVE it to Lcd
JMP Lcd_Msg ; Go get next byte from stringz
Lcd_Msg9:

RET ; Return to Caller

; **********************************************************
; 1 MILLISECOND DELAY ROUTINE
; **********************************************************

MDELAY:
PUSH ACC
MOV A,#0A6H
MD_OLP:
INC A
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
JNZ MD_OLP
NOP
POP ACC
RET
MADELAY:
PUSH ACC
MOV A,#036H
MAD_OLP:
INC A
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 105

JNZ MAD_OLP
NOP
POP ACC
RET

END

CONCLUSION:

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 106

VIVA QUESTIONS:

1. What is Microprocessor ?
It is a program controlled semiconductor device (IC}, which fetches,
decode and executes instructions.
2. What are the basic units of a microprocessor ?
The basic units or blocks of a microprocessor are ALU, an array of
registers and control unit.
3.what is Software and Hardware?
The Software is a set of instructions or commands needed for
performing a specific task by a programmable device or a computing
machine.
The Hardware refers to the components or devices used to form
computing machine in which the software can be run and tested.
Without software the Hardware is an idle machine.
4.What is assembly language?
The language in which the mnemonics (short -hand form of
instructions) are used to write a program is called assembly language.
The manufacturers of microprocessor give the mnemonics.
5. What are machine language and assembly language programs?
The software developed using 1's and 0's are called machine language,
programs. The software developed using mnemonics are called
assembly language programs.
6.Give the power supply and frequency of the microprocessoe?
The power supply of 8085 is +5V and clock frequency in 3MHz.
7. 8085 is a 8-bit microprocesspr

8.List the allowed register pairs of 8085.


• B-C register pair
• D-E register pair
• H-L register pair

9. List few applications of microprocessor-based system.


It is used:
i. For measurements, display and control of current, voltage,
temperature, pressure, etc.
ii.For traffic control and industrial tool control.
iii .For speed control of machines.

10. How many operations are there in the instruction set of 8085
microprocessor?
There are 74 operations in the 8085 microprocessor.
11. What are the functions of an accumulator?
The accumulator is the register associated with the ALU operations and
CS 2259 MICROPROCESSORS LAB (CSE)
P a g e | 107

sometimes I/O operations. It is an integral part of ALU. It holds one of data to be


processed by ALU. It also temporarily stores the result of the operation performed
by the ALU.

12. List the 16 – bit registers of 8085 microprocessor.


Stack pointer (SP) and Program counter (PC).

13.What are the various flags used in 8085?

Sign flag, Zero flag, Auxillary flag, Parity flag, Carry flag.

14.What is Stack Pointer?

Stack pointer is a special purpose 16-bit register in the Microprocessor, which holds the address of the
top of the stack.

15.What is Program counter?

Program counter holds the address of either the first byte of the next instruction to be fetched for
execution or the address of the next byte of a multi byte instruction, which has not been completely
fetched. In both the cases it gets incremented automatically one by one as the instruction bytes get
fetched. Also Program register keeps the address of the next instruction.

1.What is an Opcode?
The part of the instruction that specifies the operation to be performed is called the operation
code or opcode.
2.What is an Operand?
The data on which the operation is to be performed is called as an Operand.
3.List out the five categories of the 8085 instructions. Give examples of the
instructions for each group.
• Data transfer group – MOV, MVI, LXI.
• Arithmetic group – ADD, SUB, INR.
• Logical group –ANA, XRA, CMP.
• Branch group – JMP, JNZ, CALL.
• Stack I/O and Machine control group – PUSH, POP, IN, HLT.
4.Name 5 different addressing modes?
Immediate, Direct, Register, Register indirect, Implied addressing modes

5.What happens when HLT instruction is executed in processor?


The Micro Processor enters into Halt-State and the buses are tri-stated.

6.What is the use of JMP instruction?


A JMP instruction permanently changes the program counter.

7.Difference between ADD and DAD?


ADD - Add the contents of register to the contents of the accumulator.
DAD - The instruction DAD is an exception; it adds 16-bit data directly in register pairs.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 108

8.Subtraction concept:
Any 8-bit number, or the contents of a register, or the contents of a memory location can be
subtracted from the contents of the accumulator and the results stored in the accumulator. The
subtraction is performed in 2's compliment, and the results if negative, are expressed in 2's complement.
No two other registers can be subtracted directly.

9.What is the use of SBB?


SBB Subtract from Accumulator Using Borrow (Carry) Flag

10.Explain the instructions used in this exercise:


XCHG Exchange H & L with D & E
LDA Load Accumulator Directly from Memory
STA Store Accumulator Directly in Memory
LHLD Load H & L Registers Directly from Memory
SHLD Store H & L Registers Directly in Memory

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 109

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 110

1.What are the 4 segment registers in 8086?


There are 4 segment registers present in 8086. They are
1. Code Segment (CS ) register
2. Data Segment (DS ) register
3. Stack Segment (SS ) register
4. Extra Segment (ES ) register

2,Discuss the function of instruction queue in 8086?


In 8086, a 6-byte instruction queue is presented at the Bus Interface Unit
(BIU). It is used to prefetch and store at the maximum of 6 bytes of instruction
code from the memory. Due to this, overlapping instruction fetch with instruction
execution increases the processing speed.

3. What is the maximum memory size that can be addressed by 8086?


In 8086, an memory location is addressed by 20 bit address and the address
bus is 20 bit address and the address bus is 20 bits. So it can address up to one mega
byte (2^20) of memory space.

4.What are the different flag available in status register of 8086?


There are 6 one bit flags are present. They are,
AF - Auxiliary Carry Flag
CF - Carry Flag
OF - Overflow Flag
SF - Sign Flag
PF - Parity Flag
ZF - Zero Flag

5. List the various addressing modes present in 8086?


There are 12 addressing modes present in 8086. They are,
(a) Register and immediate addressing modes
Register addressing modes
Immediate addressing mode
(b) Memory addressing modes.
Direct addressing modes
Register indirect addressing modes
Based addressing modes
Indexed addressing modes
Based Indexed addressing modes
String addressing modes
(c) I/O addressing modes
Direct addressing mode
Indirect addressing mode
(d) Relative addressing mode
(e) Implied addressing mode

6. How single stepping can be done in 8086?


By setting the Trace Flag (TF) the 8086 goes to single-step mode. In this mode, after
the execution of each instruction s 8086 generates an internal interrupt and by writing
some interrupt service routine we can display the content of desired registers and
memory locations. So it is useful for debugging the program.

CS 2259 MICROPROCESSORS LAB (CSE)


P a g e | 111

7.What is the clock frequency of 8086?


8086 8086-2 8086-4
Internal clock Frequency 5 MHz 8MHz 4MHz
External Clock Frequency 15MHZ 24MHZ 12MHZ

8.What are the two modes of operations present in 8086?


i. Minimum mode (or) Uniprocessor system
ii. Maximum mode (or) Multiprocessor system

1.

CS 2259 MICROPROCESSORS LAB (CSE)

You might also like