Top Banner
Page | 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)
148
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mp Lab Manual Student

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)

Page 2: Mp Lab Manual Student

P a g e | 2

PROGRAM:ADDRESS LABEL MNEMONICS HEX CODE

4100 MV1 C,00

4102 LDA 5500

4105MOV B,A

4106LDA 5501

4109ADD B

410AJNC L1

410DINR C

410EL1 STA 5502

4111MOV A,C

4112STA 5503

4115HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 3: Mp Lab Manual Student

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)

Page 4: Mp Lab Manual Student

P a g e | 4

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE

4100 MV1 C,00

4102 LDA 5500

4105MOV B,A

4106LDA 5501

4109SUB B

410AJNC L1

410DINR C

410EL1 STA 5502

4111MOV A,C

4112STA 5503

4115HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 5: Mp Lab Manual Student

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)

Page 6: Mp Lab Manual Student

P a g e | 6

ADDRESS LABEL MNEMONICS HEX CODE4100 MVI C,00

4102LHLD 5500

4105XCHG

4106LHLD 5502

4109DAD D

410AJNC L1

410DINR C

410E L1SHLD 5504

4111MOV A,C

4112STA 5506

4115HLT

INPUT & OUTPUT:

RESULT:

SUBTRACTION OF 16-BIT NUMBERS.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 7: Mp Lab Manual Student

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)

Page 8: Mp Lab Manual Student

P a g e | 8

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE4100 MVI C,00

4102LHLD 5500

4105XCHG

4106LHLD 5502

4109MOV A,L

410ASUB E

410BMOV L,A

410CMOV A,H

410DSBB D

410EMOV H,A

410FJNC L1

4112INR C

4113 L1SHLD 5504

4116MOV A ,C

4117STA 5506

411AHLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 9: Mp Lab Manual Student

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)

Page 10: Mp Lab Manual Student

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)

Page 11: Mp Lab Manual Student

P a g e | 11

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE4100 MV1 D,00

4102LDA 5500

4105MOV B,A

4106LDA 5501

4109MOV C,A

410AXRA A

410B L2ADD B

410CJNC L1

410FINR D

4110 L1DCR C

4111JNZ L2

4114STA 5502

4117MOV A,D

4118STA 5503

411BHLT

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 12: Mp Lab Manual Student

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)

Page 13: Mp Lab Manual Student

P a g e | 13

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE4100 MV1 D,00

4102LDA 5500

4105MOV B,A

4106LDA 5501

4109 L1SUB B

410AINR D

410B L2JNC L1

410EADD B

410FDCR D

4110STA 5502

4113MOV A,D

4114STA 5503

4117HLT

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 14: Mp Lab Manual Student

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)

Page 15: Mp Lab Manual Student

P a g e | 15

PROGRAM

OUTPUT:

CS 2259 MICROPROCESSORS LAB (CSE)

ADDRESS LABEL MNEMONICS HEX CODE4100 LHLD 5500

4103XCHG

4104LHLD 5502

4107SPHL

4108LXI B,0000

410BLXI H,0000

410E L2DAD SP

410FJNC L1

4112INX B

4113 L1DCX D

4114MOV A,E

4115ORA D

4116JNZ L2

4119SHLD 5504

411CMOV H,B

411DMOV L,C

411ESHLD 5506

4121HLT

Page 16: Mp Lab Manual Student

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)

Page 17: Mp Lab Manual Student

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)

Page 18: Mp Lab Manual Student

P a g e | 18

PROGRAMADDRESS LABEL MNEMONICS HEX CODE

4100 LHLD 5500

4103XCHG

4104LHLD 5502

4107LXI B,0000

410A L2MOV A,L

410BSUB E

410CMOV L,A

410DMOV A.H

410ESBB D

410FMOV H,A

4110JC L1

4113INX B

4114JMP L2

4117 L1MOV A,L

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

4125HLT

CS 2259 MICROPROCESSORS LAB (CSE)

Page 19: Mp Lab Manual Student

P a g e | 19

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 20: Mp Lab Manual Student

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)

Page 21: Mp Lab Manual Student

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)

Page 22: Mp Lab Manual Student

P a g e | 22

PROGRAM(Smallest):

ADDRESS LABEL MNEMONICS HEX CODE4100 LDA 5500

4103MOV B,A

4104 LXI H,5501

4107DCR B

4108MOV C,M

4109 L1INX H

410AMOV A,M

410BCMP C

410CJZ L2

410FJNC L2

4112MOV C,A

4113 L2DCR B

4114JNZ L1

4117MOV A,C

4118STA 6000

411BHLT

CS 2259 MICROPROCESSORS LAB (CSE)

Page 23: Mp Lab Manual Student

P a g e | 23

PROGRAM(LARGEST):

ADDRESS LABEL MNEMONICS HEX CODE4100 LDA 5500

4103MOV B,A

4104LXI H,5501

4107DCR B

4108MOV C,M

4109 L1INX H

410AMOV A,M

410BCMP C

410CJZ L2

410FJC L2

4112MOV C,A

4113 L2DCR B

4114JNZ L1

4117MOV A,C

4118STA 6000

411BHLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 24: Mp Lab Manual Student

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)

Page 25: Mp Lab Manual Student

P a g e | 25

PROGRAM(ASCENDING):

ADDRESS LABEL MNEMONICS HEX CODE4100 LX1 H,5200

4103MOV B,M

4104 L4MOV D,M

4105INX H

4106 L1MOV A,M

4107 L2DCR D

4108JZ L3

410BINX H

410CCMP M

410DJC L1

4110MOV E,M

4111MOV M,A

4112DCX H

4113MOV M,E

4114INX H

4115JMP L2

4118 L3LXI H,5200

411BDCR B

411CJNZ L4

411FHLT

CS 2259 MICROPROCESSORS LAB (CSE)

Page 26: Mp Lab Manual Student

P a g e | 26

PROGRAM (DESCENDING):

ADDRESS LABEL MNEMONICS HEX CODE4100 LX1 H,5200

4103MOV B,M

4104 L4MOV D,M

4105INX H

4106 L1MOV A,M

4107 L2DCR D

4108JZ L3

410BINX H

410CCMP M

410DJNC L1

4110MOV E,M

4111MOV M,A

4112DCX H

4113MOV M,E

4114INX H

4115JMP L2

4118 L3LXI H,5200

411BDCR B

411CJNZ L4

411FHLT

CS 2259 MICROPROCESSORS LAB (CSE)

Page 27: Mp Lab Manual Student

P a g e | 27

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 28: Mp Lab Manual Student

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)

Page 29: Mp Lab Manual Student

P a g e | 29

CODE CONVERSION –DECIMAL TO HEXEx.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

8000 LXI H,8100Initialize HL reg. to8100H

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 Accumulator800B CMP M Compare M & A

800C JNZ LOOPIf acc and given number are not equal, then go to LOOP

800F MOV A,B Transfer B reg to acc.

8010 STA 8101Store the result in a memory location.

8013 HLT Stop the program

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 30: Mp Lab Manual Student

P a g e | 30

CODE CONVERSION –HEXADECIMAL TO DECIMALEx.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 COMMENTS8000 LXI H,8100 Initialize HL reg. to8100H8003 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 Accumulator800D JNC NEXT If there is no carry go to NEXT.8010 INR C Increment c register.8011 NEXT MOV D,A Transfer A to D8012 MOV A,B Transfer B to A8013 CMP M Compare M & A8014 MOV A,D Transfer D to A8015 JNZ LOOP If acc and given number are not

equal, then go to LOOP8018 STA 8101 Store the result in a memory location. 801B MOV A,C Transfer C to A801C STA 8102 Store the carry in another memory

location.801F HLT Stop the program

CS 2259 MICROPROCESSORS LAB (CSE)

Page 31: Mp Lab Manual Student

P a g e | 31

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 32: Mp Lab Manual Student

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-register2. 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 CODE8000 LDA 4500 3A,00,458003 MOV B,A 478004 ANI 0FH E6,0F8006 CALL SUB CD,1A,428009 STA 4502 32,02,45800C MOV A,B 78800D ANI F0H E6,F0800F RRC 0F8010 RRC 0F8011 RRC 0F8012 RRC 0F8013 CALL SUB CD,1A,428016 STA 4503 32,03,458019 HLT 76

SUBROUTINE SUB:ADDRESS LABEL MNEMONICS HEX CODE

801A CPI 0AH FE ,0A801C JC L1 DA,21,42801F ADI 07H C6,078021 L1 ADI 30H C6,308023 RET C9

CS 2259 MICROPROCESSORS LAB (CSE)

Page 33: Mp Lab Manual Student

P a g e | 33

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 34: Mp Lab Manual Student

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 register6. Store it in memory

PROGRAM:

ADDRESS LABEL MNEMONICS HEX CODE8000 LDA 4500 3A,00,458003 SUI 30 D6,308005 CPI 0A FE,0A8007 JC L1 DA,21,428010 SUI 07 D6,07800A L1 STA 4501 32,01,45800D HLT 76

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 35: Mp Lab Manual Student

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 CALLinstruction leaves information on the stack so that the original program executionsequence 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 movedout at one end is put back in at the other end. The shift instruction loses the datathat 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 locationspecified by the 16-bit address. STA copies the data byte from the accumulator inthe memory location specified by 16-bit address. DAA changes the contents ofthe 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)

Page 36: Mp Lab Manual Student

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 COMMENT8100 MVI C, 00 Clear C reg.8102 LXI H, 4500 Initialize HL reg. to45008105 LOOP2 LXI D, 4600 Load DE register pair 8108 CALL MUL Call subroutine MUL810B MOV B,A Move A to B reg.810C INX H Increment HL register pair .810D INX D Increment DE register pair810E INX D Increment DE register pair810F CALL MUL Call subroutine MUL8112 ADD B Add [B] with [A]8113 CALL STORE Call subroutine STORE8116 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 pair811D INX D Increment DE register pair811E INX D Increment DE register pair811F CALL MUL Call subroutine MUL8122 ADD B Add A with B 8123 CALL STORE Call subroutine MUL8126 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 loop1812C INX H Increment HL register Pair.812D JMP LOOP2 Jump to LOOP2.8130 LOOP1 HLT Stop the program.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 37: Mp Lab Manual Student

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

Page 38: Mp Lab Manual Student

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 RETThe 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 PairAn '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)

Page 39: Mp Lab Manual Student

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)

Page 40: Mp Lab Manual Student

P a g e | 40

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

Page 41: Mp Lab Manual Student

P a g e | 41

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 42: Mp Lab Manual Student

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)

Page 43: Mp Lab Manual Student

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)

Page 44: Mp Lab Manual Student

P a g e | 44

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 45: Mp Lab Manual Student

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

Page 46: Mp Lab Manual Student

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)

Page 47: Mp Lab Manual Student

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.

COPYING A STRING

CS 2259 MICROPROCESSORS LAB (CSE)

Page 48: Mp Lab Manual Student

P a g e | 48

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

Page 49: Mp Lab Manual Student

P a g e | 49

FIND AND REPLACE A CHARACTER IN THE STRINGPROGRAM 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)

Page 50: Mp Lab Manual Student

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)

Page 51: Mp Lab Manual Student

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 ENDSCODE SEGMENTSTART: 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 ENDSEND START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 52: Mp Lab Manual Student

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)

Page 53: Mp Lab Manual Student

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)

Page 54: Mp Lab Manual Student

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)

Page 55: Mp Lab Manual Student

P a g e | 55

MODE 0PROGRAM 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, PORTA(100)

Set DX reg with port A address

IN AL,DX Get the contents of port A in AL

MOV DX, PORTB(102)

Set DX reg with port A address

OUT DX,AL Send the contents of port B to port address

HLT Stop

MODE 1PROGRAM 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 2PROGRAM 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

JZ L1 Check whether it is enabled

CS 2259 MICROPROCESSORS LAB (CSE)

Page 56: Mp Lab Manual Student

P a g e | 56

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)

Page 57: Mp Lab Manual Student

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, whileIn BSR mode only port C (PC0-PC7) can be used to set or reset its individualport bits. Under the IO mode of operation, further there are three modes of operation of 8255, So as to support different types of applications, viz. mode 0, mode 1 and mode 2.Mode 0 - Basic I/O modeMode 1 - Strobed I/O modeMode 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 arepossible.

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 andoutputs both are latched.3. Out of 8-bit port C, PC0-PC2 is used to generate control signals for port B andPC3=PC5 are used to generate control signals for port A. The lines PC6, PC7 maybe used as independent data lines.

4. What are the signals used in input control signal & output control signal?Input control signalSTB (Strobe input)IBF (Input buffer full)INTR(Interrupt request)Output control signalOBF (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 handshakesignals for the 8-bit data transfer on port A.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 58: Mp Lab Manual Student

P a g e | 58

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)

Page 59: Mp Lab Manual Student

P a g e | 59

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 entryKKK- Key Board Mode 000-2Key lockout.

2.Clear Display: Control word-DC H

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

11 A0-3; B0-3 =FF

3. Write Display: Control word-90H

1 0 0 1 0 0 0 0 1 0 0

AI A A A A

CS 2259 MICROPROCESSORS LAB (CSE)

1-Enables Clear display0-Contents of RAM will be displayed

1-FIFO Status is cleared

1-Clear all bits (Combined effect of CD)

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.

Page 60: Mp Lab Manual Student

P a g e | 60

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 C81204 FF 1C 29 FF

RESULT:

MEMORY LOCATION

7-SEGMENT LED FORMAT HEX DATAd c b a dp e g f

1200H1201H1202H1203H1204H1205H1206H1207H

CS 2259 MICROPROCESSORS LAB (CSE)

Page 61: Mp Lab Manual Student

P a g e | 61

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 62: Mp Lab Manual Student

P a g e | 62

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 modeIn the left entry mode, the data is entered from the left side of the displayunit..2. Right Entry ModeIn the right entry mode, the first entry to be displayed is entered on therightmost display.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 63: Mp Lab Manual Student

P a g e | 63

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 Comments4100 START: MVI A, 30 Channel 0 in mode 04102 OUT CE Send Mode Control word4104 MVI A, 05 LSB of count4106 OUT C8 Write count to register4108 MVI A, 00 MSB of count410A OUT C8 Write count to register410C 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)

Page 64: Mp Lab Manual Student

P a g e | 64

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 Comments4100 START: MVI A, 32 Channel 0 in mode 14102 OUT CE Send Mode Control word4104 MVI A, 05 LSB of count4106 OUT C8 Write count to register4108 MVI A, 00 MSB of count410A OUT C8 Write count to register410C OUT D0 Trigger Gate04100 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

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)

Address Opcodes Label Mnemonic Comments4100 3E 74 START: MVI A, 74 Channel 1 in mode 24102 D3 CE OUT CE Send Mode Control word4104 3E 0A MVI A, 0A LSB of count4106 D3 CA OUT CA Write count to register4108 3E 00 MVI A, 00 MSB of count410A D3 CA OUT CA Write count to register410C 76 HLT

Page 65: Mp Lab Manual Student

P a g e | 65

Example:

We utilize Mode 0 to generate a square wave of frequency 150 KHz at channel 0.Address Opcodes Label Mnemonic Operands Comments4100 3E 36 START: MVI A, 36 Channel 0 in mode 34102 D3 CE OUT CE Send Mode Control word4104 3E 0A MVI A, 0A LSB of count4106 D3 C8 OUT C8 Write count to register4108 3E 00 MVI A, 00 MSB of count410A D3 C8 OUT C8 Write count to register410C 76 HLTSet 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 Comments4100 START: MVI A, 36 Channel 0 in mode 04102 OUT CE Send Mode Control word4104 MVI A, 0A LSB of count4106 OUT C8 Write count to register4108 MVI A, 00 MSB of count410A OUT C8 Write count to register410C MVI A, B8 Channel 2 in Mode 4410E OUT CE Send Mode control Word4110 MVI A, 98 LSB of Count4112 OUT CC Write Count to register4114 MVI A, 3A MSB of Count4116 OUT CC Write Count to register4118 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)

Page 66: Mp Lab Manual Student

P a g e | 66

OUTPUT:

RESULT:

VIVA QUESTIONS:

CS 2259 MICROPROCESSORS LAB (CSE)

Address Label Mnemonic Operands Comments4100 START: MVI A, 1A Channel 0 in mode 54102 OUT CE Send Mode Control word4104 MVI A, 05 LSB of count4106 OUT C8 Write count to register4108 MVI A, 00 MSB of count410A OUT D0 Trigger Gate 0410C HLT

Page 67: Mp Lab Manual Student

P a g e | 67

1.What are the modes of operations used in 8253?Each of the three counters of 8253 can be operated in one of the followingsix 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 registerThe control word register accepts data from the data buffer and initializesthe 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 readits 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 theaccumulator.The OUT instruction is used to move data from the accumulator to an I/Oport.The IN & OUT instructions are used only on microprocessor, which use aseparate 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)

Page 68: Mp Lab Manual Student

P a g e | 68

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)

Page 69: Mp Lab Manual Student

P a g e | 69

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)

Page 70: Mp Lab Manual Student

P a g e | 70

PROGRAM (Transmitter):

ADDRESS LABEL MNEMONICS HEX CODE4100 LXI H,4500

4103MVI A,36

4105OUT 0B

4107MVI A,40

4109OUT 08

410BMVI A,01

410DOUT 08

410F L2MVI C,05

4111 L1IN 05

4113ANI 04

4115JZ L1

4118MOV A,M

4119OUT 04

411BINX H

411CCPI 3F

411EJNZ L2

4121DCR C

4122JNZ L1

4125RST 1

CS 2259 MICROPROCESSORS LAB (CSE)

Page 71: Mp Lab Manual Student

P a g e | 71

PROGRAM (Receiver):

ADDRESS LABEL MNEMONICS HEX CODE4100 LXI H,4500

4103MVI A,36

4105OUT 0B

4107MVI A,40

4109OUT 08

410BMVI A,01

410DOUT 08

410F L2MVI C,05

4111 L1IN 05

4113ANI 02

4115JZ L1

4118IN 04

411AMOV M,A

411BINX H

411CCPI 3F

411EJNZ L2

4121DCR C

4122JNZ L1

4125RST 1

CS 2259 MICROPROCESSORS LAB (CSE)

Page 72: Mp Lab Manual Student

P a g e | 72

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 73: Mp Lab Manual Student

P a g e | 73

VIVA QUESTIONS:1.What is an USART?USART stands for universal synchronous/Asynchronous Receiver/Transmitter. It is a programmable communication interface that can communicate byusing 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 theprocessor 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 thecommunication between the modem and the USART.

4.Format for Character Framing:Character framing

5. Explain receiver and transmitterReceiver

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)

Page 74: Mp Lab Manual Student

P a g e | 74

8051 PROGRAMS

8 BIT ADDITION/SUBTRACTIONEx.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)

Page 75: Mp Lab Manual Student

P a g e | 75

8 Bit Subtraction (Immediate Addressing)

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

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

Page 76: Mp Lab Manual Student

P a g e | 76

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)

Page 77: Mp Lab Manual Student

P a g e | 77

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

410ESTOP

SJMP STOP

8 Bit DivisionADDRESS 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

410DSTOP

SJMP STOP

CS 2259 MICROPROCESSORS LAB (CSE)

Page 78: Mp Lab Manual Student

P a g e | 78

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 79: Mp Lab Manual Student

P a g e | 79

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)

Page 80: Mp Lab Manual Student

P a g e | 80

PROGRAM :

ADDRESS LABEL OPCODE OPERAND

ORG

4100 START: MOV

4103 MOV

4105 LOOP: MOVX

4106 PUSH4108 PUSH

410A MOV

410D MOVX

410E MOV4110 DELAY: MOV4112 DELAY1: DJNZ

4114 DJNZ

4116 POP4118 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)

Page 81: Mp Lab Manual Student

P a g e | 81

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)

Page 82: Mp Lab Manual Student

P a g e | 82

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)

Page 83: Mp Lab Manual Student

P a g e | 83

PROGRAM

ADDRESS LABEL MNEMONICSHEXCODE

4100 MOV DPTR, #add14103 MOV A, #data14105 MOVX @DPTR,A4106 MOV A,#data24108 MOVX @DPTR,A4109 MOV DPTR,#add2410C MOV A,#data3410E MOVX @DPTR,A410F MOV A,#data44111 MOVX @DPTR,A4112 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)

Page 84: Mp Lab Manual Student

P a g e | 84

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 85: Mp Lab Manual Student

P a g e | 85

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 kit2. Power supply3. 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.

THEORYSince 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 VOLTAGE1. Send the digital value of DAC

2. Read the corresponding analog value of its output.

WAVEFORM GENERATIONSQUARE WAVEFORM1. 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 WAVEFORM1. 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)

Page 86: Mp Lab Manual Student

P a g e | 86

TRIANGULAR WAVEFORM1. 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 MNEMONICSHEXCODE

4100 MOV DPTR, #FFC04103 START MOV A, #004105 MOVX @DPTR,A4106 LCALL DELAY4109 MOVA,#FF410B MOV X @DPTR,A410C LCALL DELAY410F LJMP START4112 DELAY MOV R1,#054114 LOOP MOV R2,#FF4116 LOOP1 DJNZ R2,LOOP14118 DNJZ R1,LOOP411A RET411B SJMP START

SAW-TOOTH WAVEFORM

ADDRESS LABEL MNEMONICSHEXCODE

4100 MOV DPTR, #FFC04103 MOV A, #004105 LOOP MOVX @DPTR,A4106 INC A4107 SJMP LOOP

TRIANGULAR WAVEFORM

CS 2259 MICROPROCESSORS LAB (CSE)

Page 87: Mp Lab Manual Student

P a g e | 87

ADDRESS LABEL MNEMONICSHEXCODE

4100 MOV DPTR, #FFC04103 START MOV A, #004105 LOOP1 MOVX @DPTR,A4106 INC A4107 JNZ LOOP14109 MOV A,#FF410B LOOP2 MOVX @DPTR,A410C DEC A410D JNZ LOOP2410F LJMP START

OUTPUT:

RESULT:

VIVA QUESTIONS:

1.Features of 8051microcontroller.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 88: Mp Lab Manual Student

P a g e | 88

• 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 registerIt is used to select the register banksRS1 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 8051RR 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 flagThe 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 8051B7 B6 B5 B4 B3 B2 B1 B0CY 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 andexternal 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)

Page 89: Mp Lab Manual Student

P a g e | 89

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 asaddress 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 byPUSH and POP instructions.• During PUSH the SP is incremented by 1 and during POP the SP isdecremented 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 : 0023HTransmit 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 thestarting address of the program is loaded in program counter. The PC sends out anaddress to fetch a byte of instruction from memory and increments its contentautomatically.

18.. Explain DJNZ instructions of intel 8051 microcontroller?a) DJNZ Rn, relDecrement the content of the register Rn and jump if not zero.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 90: Mp Lab Manual Student

P a g e | 90

b) DJNZ direct , relDecrement the content of direct 8-bit address and jump if not zero.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 91: Mp Lab Manual Student

P a g e | 91

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)

Page 92: Mp Lab Manual Student

P a g e | 92

CIRCUIT DIAGRAM:

SOURCE CODE:

RB0 EQU 00H ; Select Register Bank 0RB1 EQU 08H ; Select Register Bank 1 ...poke to PSW to useRB2 EQU 10H ; Select Register Bank 1 ...poke to PSW to use******************************************************************************

PORT DECLERATION*******************************************************************************//// ***LCD CONTROL***////LCD_RS EQU P0.0 ; LCD REGISTER SELECT LINELCD_E EQU P0.1 ; LCD ENABLE LINELCD_DB4 EQU P0.2 ; PORT 1 IS USED FOR DATALCD_DB5 EQU P0.3 ; USED FOR DATALCD_DB6 EQU P0.4 ; FOR DATALCD_DB7 EQU P0.5 ; FOR DATA

SEARCH EQU P1.0ADDS EQU P1.1DELETE EQU P1.2

CS 2259 MICROPROCESSORS LAB (CSE)

Page 93: Mp Lab Manual Student

P a g e | 93

LOAD EQU P0.7ALARM EQU P0.6

***CURSOR CONTROL INSTRUCTIONS***

OFFCUR EQU 0CHBLINKCUR EQU 0DH

; ***DISPLAY CONTROL INSTRUCTIONS***

CLRDSP EQU 01HONDSP EQU 0CH

; ***SYSTEM INSTRUCTIONS***

CONFIG EQU 28H ; 4-BIT DATA,2 LINES,5X7 MATRIX LCDENTRYMODE EQU 6 ; INCREMENT CURSOR DON'T SHIFT DISPLAY

DSEG ; this is internal data memoryORG 20H ; Bit addressable memoryFLAGS1: DS 1RECEIVED BIT FLAGS1.0

COUNTER: DS 1BYTE: DS 10TEMP: DS 1TEMPS:DS 1USER_COUNT: DS 1ERROR_COUNT: DS 1;************************************************************************************************************************************************************CSEG ; Code begins here ; ---------==========----------==========---------=========---------; Main routine. Program execution starts here.; ---------==========----------==========---------=========---------

ORG 00H ; ResetAJMP MAIN

ORG 23HJMP SERIAL

; ---------==========----------==========---------=========---------MAIN: MOV PSW,#RB0 ; Select register bank 0

MOV SP,#60hMOV A,PCONSETB ACC.7MOV PCON,AMOV TMOD,#20HMOV TH1,#0FFHMOV SCON,#50HSETB ESSETB EASETB TR1

SETB ADDSSETB SEARCHCLR LOADCLR ALARMMOV ERROR_COUNT,#00H

CS 2259 MICROPROCESSORS LAB (CSE)

Page 94: Mp Lab Manual Student

P a g e | 94

;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_SERIALNOT_INT:

CALL RESETLCD4TOPS: 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_DELCLR RECEIVEDMOV DPTR,#SEARCH_USER_DATA

CALL SEND_SERIALCALL DELAYSMOV A, BYTE+4CJNE A, #39H, NOT_MATCHSCALL FIN_MATCHEDMOV 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 TOPSNOT_MATCHES:

CALL NOT_DELETEDCALL DELAYS

CALL DELAYS AJMP TOPSNOT_MATCHS:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 95: Mp Lab Manual Student

P a g e | 95

CALL NOT_MATCHEDCALL DELAYS

CALL DELAYS AJMP TOPSADD_USER:

CALL DISPLAY1CALL DELAYSJNB ADDS,$CLR RECEIVEDMOV DPTR,#SEARCH_USER_DATA

CALL SEND_SERIALCALL DELAYSMOV A,BYTE+4CJNE A,#39H,NOT_MATCHSSCALL ALREADY_EXITCALL DELAYS

CALL DELAYS AJMP TOPSNOT_MATCHSS:

CLR RECEIVEDMOV 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 TRANSDELAYNEXT: 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_FLASHMOV 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)

Page 96: Mp Lab Manual Student

P a g e | 96

MOV SBUF,A CALL TRANSDELAY CLR RECEIVED AJMP TOPSNOT_SAVED:

CALL DISPLAY_NOTSUCESS CALL DELAYS CALL DELAYS CLR RECEIVED AJMP TOPS

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$SEND_SERIAL:

CLR AMOVC A,@A+DPTR CJNE A,#0FFH,SEND_DRET

SEND_D:MOV SBUF,AADD A, TEMPSMOV TEMPS,ACALL TRANSDELAYINC DPTRAJMP SEND_SERIAL

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$SEARCH_USER:

JNB SEARCH,$CALL DISPLAY2

CLR RECEIVEDMOV DPTR,#SEARCH_USER_DATA

CALL SEND_SERIALCALL DELAYS

MOV A, BYTE+4CJNE A,#39H,NOT_MATCHCPL LOADCLR ALARMMOV ERROR_COUNT,#00HCALL MATCHEDMOV TEMP, BYTE+6

CALL SPLITDISP CALL DELAYS CALL DELAYS AJMP TOPSNOT_MATCH:

INC ERROR_COUNTMOV A,ERROR_COUNTCJNE A,#04H,ALARM_ONSETB ALARM

ALARM_ON:CALL NOT_MATCHEDCALL DELAYS

CALL DELAYS AJMP TOPSSPLITDISP:

MOV A,TEMP mov b,#10 ; Divide By 10 div ab ; Do Divide

CS 2259 MICROPROCESSORS LAB (CSE)

Page 97: Mp Lab Manual Student

P a g e | 97

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, 0FFHDB 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 ACCJB TI,TRANSDMOV A,SBUFCJNE A,#4DH,DOWN2 MOV COUNTER,#01H JMP DDWN

TRANSD: AJMP TRANSDOWN2:

MOV R1,COUNTERCJNE R1,#01H,YH1MOV BYTE,AJMP DOWN1

YH1: CJNE R1,#02H,YH2MOV BYTE+1,AJMP DOWN1

YH2: CJNE R1,#03H,YH3

CS 2259 MICROPROCESSORS LAB (CSE)

Page 98: Mp Lab Manual Student

P a g e | 98

MOV BYTE+2,AMOV TEMP,AJMP DOWN1

YH3: CJNE R1,#04H,YH4MOV BYTE+3,ADEC TEMPMOV A,TEMPCJNE A,#00H,DOWN1SETB RECEIVEDJMP DOWN1

YH4: CJNE R1,#05H,YH5MOV BYTE+4,ADEC TEMPMOV A,TEMPCJNE A,#00H,DOWN1SETB RECEIVEDJMP DOWN1

YH5: CJNE R1,#06H,YH6MOV BYTE+5,ADEC TEMPMOV A,TEMPCJNE A,#00H,DOWN1SETB RECEIVEDJMP DOWN1

YH6: CJNE R1,#07H,YH7MOV BYTE+6,ADEC TEMPMOV A,TEMPCJNE A,#00H,DOWN1SETB RECEIVEDJMP DOWN1

YH7: CJNE R1,#08H,DOWN1MOV BYTE+7,ADEC TEMPMOV A,TEMPCJNE A,#00H,DOWN1SETB RECEIVEDJMP DOWN1

DOWN1: INC COUNTERDDWN: CLR RI

POP ACC POP PSW

RETI

TRANS: CLR TIPOP ACC

POP PSW RETI

;********************************************************** ;********************************************************** TRANSDELAY:

MOV R7,#5FHDJNZ R7,$RET

;************************************************************************** ;##########################################################; DISPLAY ROUTINES;##########################################################DISPLAY:

MOV DPTR,#MSAG1CALL LCD_MSG

CS 2259 MICROPROCESSORS LAB (CSE)

Page 99: Mp Lab Manual Student

P a g e | 99

RETMSAG1:

DB 1H,80H,'Fingerprint Based',0C0H,'Security System',00H;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DISPLAY1:

MOV DPTR,#MSAG2CALL LCD_MSGRET

MSAG2:DB 1H,83H,'Show your',0C0H,'Finger to ADD..',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DISPLAY2:

MOV DPTR,#MSAG3CALL LCD_MSGRET

MSAG3:DB 1H,83H,'Show your',0C3H,'Finger....',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~USER_FULL_DISPLAY:

MOV DPTR,#MSAG4CALL LCD_MSGRET

MSAG4:DB 1H,83H,'User memory',0C3H,'## FULL ##',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DISPLAY_SUCESS:

MOV DPTR,#MSAG5CALL LCD_MSGRET

MSAG5:DB 1H,83H,'User Added',0C3H,'Sucessfully',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DISPLAY_NOTSUCESS:

MOV DPTR,#MSAG6CALL LCD_MSGRET

MSAG6:DB 1H,83H,'User Added',0C2H,'## Failed ##',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MATCHED:

MOV DPTR,#MSAG7CALL LCD_MSGRET

MSAG7:DB 1H,83H,'Fingerprint',0C1H,'Matched ID:',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NOT_MATCHED:

MOV DPTR,#MSAG8CALL LCD_MSGRET

MSAG8:DB 1H,83H,'Fingerprint',0C2H,'NOT Matched',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DISPLAY_DEL:

MOV DPTR,#MSAG9CALL LCD_MSGRET

MSAG9:DB 1H,83H,'Show your',0C0H,'Finger to DELETE',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CS 2259 MICROPROCESSORS LAB (CSE)

Page 100: Mp Lab Manual Student

P a g e | 100

FIN_MATCHED:MOV DPTR,#MSAG10CALL LCD_MSGRET

MSAG10:DB 1H,83H,'Fingerprint',0C4H,'Matched',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~FIN_DELETED:

MOV DPTR,#MSAG11CALL LCD_MSGRET

MSAG11:DB 1H,83H,'Fingerprint',0C1H,'## Deleted ##',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NOT_DELETED:

MOV DPTR,#MSAG12CALL LCD_MSGRET

MSAG12:DB 1H,83H,'Fingerprint',0C2H,'NOT Deleted',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ALREADY_EXIT:

MOV DPTR,#MSAG13CALL LCD_MSGRET

MSAG13:DB 1H,83H,'Fingerprint',0C1H,'Already Exits',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DELAY:

MOV R1,#0FFHRE1: MOV R2,#0FFHRE: NOP

DJNZ R2,REDJNZ R1,RE1RET

;**********************************************************DELAYS: ;One second delay routine MOV R0,#05HRS3: MOV R1,#0FFHRA1: MOV R2,#0FFHRS2: NOP

DJNZ R2,RS2DJNZ R1,RA1 DJNZ R0,RS3

RET;**********************************************************DELAYSS: ;One second delay routine MOV R0,#03HRE3: MOV R1,#0FFHRZ1: MOV R2,#0FFHRE2: NOP

DJNZ R2,RE2DJNZ 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)

Page 101: Mp Lab Manual Student

P a g e | 101

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)

Page 102: Mp Lab Manual Student

P a g e | 102

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)

Page 103: Mp Lab Manual Student

P a g e | 103

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,ACALL 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,ACALL WRLCDDATAJMP 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,ACALL WRLCDCOM4 ; Carry not set if A=>80, it is address JMP Lcd_Msg ; Go get next byte from stringz

Lcd_Msg_Data: ;

MOV R4,ACALL 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,#0A6HMD_OLP: INC A NOP NOP NOP NOP NOP NOP NOP NOP JNZ MD_OLP NOP POP ACC RETMADELAY: PUSH ACC MOV A,#036HMAD_OLP: INC A NOP NOP NOP NOP NOP NOP NOP NOP

CS 2259 MICROPROCESSORS LAB (CSE)

Page 104: Mp Lab Manual Student

P a g e | 104

JNZ MAD_OLP NOP POP ACC RET

END

CONCLUSION:

CS 2259 MICROPROCESSORS LAB (CSE)

Page 105: Mp Lab Manual Student

P a g e | 105

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 ofregisters and control unit.3.what is Software and Hardware?

The Software is a set of instructions or commands needed forperforming a specific task by a programmable device or a computingmachine.The Hardware refers to the components or devices used to formcomputing 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 ofinstructions) 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 calledassembly 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)

Page 106: Mp Lab Manual Student

P a g e | 106

sometimes I/O operations. It is an integral part of ALU. It holds one of data to beprocessed by ALU. It also temporarily stores the result of the operation performedby 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)

Page 107: Mp Lab Manual Student

P a g e | 107

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 & ELDA Load Accumulator Directly from MemorySTA Store Accumulator Directly in MemoryLHLD Load H & L Registers Directly from MemorySHLD Store H & L Registers Directly in Memory

CS 2259 MICROPROCESSORS LAB (CSE)

Page 108: Mp Lab Manual Student

P a g e | 108

CS 2259 MICROPROCESSORS LAB (CSE)

Page 109: Mp Lab Manual Student

P a g e | 109

1.What are the 4 segment registers in 8086?There are 4 segment registers present in 8086. They are1. Code Segment (CS ) register2. Data Segment (DS ) register3. Stack Segment (SS ) register4. 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 instructioncode from the memory. Due to this, overlapping instruction fetch with instructionexecution 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 addressbus is 20 bit address and the address bus is 20 bits. So it can address up to one megabyte (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 FlagCF - Carry FlagOF - Overflow FlagSF - Sign FlagPF - Parity FlagZF - 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 modesRegister addressing modesImmediate addressing mode(b) Memory addressing modes.Direct addressing modesRegister indirect addressing modesBased addressing modesIndexed addressing modesBased Indexed addressing modesString addressing modes(c) I/O addressing modesDirect addressing modeIndirect 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, afterthe execution of each instruction s 8086 generates an internal interrupt and by writingsome interrupt service routine we can display the content of desired registers andmemory locations. So it is useful for debugging the program.

CS 2259 MICROPROCESSORS LAB (CSE)

Page 110: Mp Lab Manual Student

P a g e | 110

7.What is the clock frequency of 8086?8086 8086-2 8086-4Internal clock Frequency 5 MHz 8MHz 4MHzExternal Clock Frequency 15MHZ 24MHZ 12MHZ

8.What are the two modes of operations present in 8086?i. Minimum mode (or) Uniprocessor systemii. Maximum mode (or) Multiprocessor system

1.

CS 2259 MICROPROCESSORS LAB (CSE)