You are on page 1of 111

P a g e |1

PROGRAMMING WITH 8085 ADDITION OF TWO 8-BIT NUMBERS. Ex. No.1a AIM: To write an Assembly Language Program (ALP) for performing the addition operations of 8-bit numbers with and without carry. APPARATUS REQUIRED: Microprocessor kit, Power supply. PROBLEM STATEMENT: Write an ALP in 8085 P to add two 8-bit binary numbers stored in the memory location 5500H and 5501H and store the result in the memory location 5502H.Also provide an instruction in the above program to consider the carry also and store the carry in the memory location 5503H. ALGORITHM: a) Initialize the MSBs of sum to 0

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

e) Store LSBs of sum in the location 5502H f) Store MSBs of sum in the location 5503H.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |2

PROGRAM: ADDRESS 4100 4102 4105 4106 4109 410A 410D 410E 4111 4112 4115

LABEL

MNEMONICS MV1 C,00 LDA 5500 MOV B,A LDA 5501 ADD B JNC L1 INR C

HEX CODE

L1

STA 5502 MOV A,C STA 5503 HLT

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |3

SUBTRACTION OF TWO 8-BIT NUMBERS. Ex. No.1b AIM: To write an Assembly Language Program (ALP) for performing the subtraction operations of 8bit numbers with and without carry. APPARATUS REQUIRED: Microprocessor kit, Power supply. PROBLEM STATEMENT: Write an ALP in 8085 P to subtract two 8-bit binary numbers stored in the memory location 5500H and 5501H and store the result in the memory location 5502H.Also provide an instruction in the above program to consider the carry also and store the carry in the memory location 5503H. ALGORITHM: a) Initialize the MSBs of difference to 0

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

e) Store LSBs of difference in the location 5502H g) Store MSBs of difference in the location 55003H.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |4

PROGRAM: ADDRESS 4100 4102 4105 4106 4109 410A 410D 410E 4111 4112 4115 L1 LABEL MNEMONICS MV1 C,00 LDA 5500 MOV B,A LDA 5501 SUB B JNC L1 INR C STA 5502 MOV A,C STA 5503 HLT HEX CODE

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |5

ADDITION OF TWO 16-BIT NUMBERS. Ex.No.1c AIM: To write an Assembly Language Program (ALP) for performing the addition operations of 16bit 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. 2. 3. 4. 5. 6. 7.

Clear the contents of B register Load HL pair with the first 16 bit number, Move this number to the DE pair using Exchange instruction Load the HL Pair with second 16 bit number Add the content of DE pair with contents of HL pair and store the result in HL pair If a carry occurs increment the value of B register Store the sum in memory

PROGRAM:
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |6

ADDRESS 4100 4102 4105 4106 4109 410A 410D 410E 4111 4112 4115

LABEL

MNEMONICS MVI C,00 LHLD 5500 XCHG LHLD 5502 DAD D JNC L1 INR C

HEX CODE

L1

SHLD 5504 MOV A,C STA 5506 HLT

INPUT & OUTPUT:

RESULT:

SUBTRACTION OF 16-BIT NUMBERS.


CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |7

Ex.No.1d AIM: To write an Assembly Language Program (ALP) for performing the subtraction operations of 16-bit numbers with and without carry. APPARATUS REQUIRED: Microprocessor kit, Power supply. PROBLEM STATEMENT: Write an ALP in 8085 P to subtract two 16-bit binary numbers stored in the memory location 5500H and 5503H (in the order of lower byte in the first location, higher byte in the second location) and store the result in the memory location 5504H and 5505H.Also provide an instruction in the above program to consider the carry also and store the carry in the memory location 5506H. ALGORITHM:
1. 2. 3. 4. 5. 6. 7. 8. 9.

Initialize the MSBs of difference to 0 Get the first low byte of data-1in the accumulator. Subtract the low byte of data-2 from that of data-1. Store the low byte of the result. Get the high byte of data-1 in the accumulator Subtract the high byte of data-2 and also the carry from the high byte of data-1. Store the high byte of the result. If there is any carry, increment the contents MSBs by 1. Store MSBs of result.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |8

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

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e |9

VIVA QUESTIONS: 1.What is an Opcode? The part of the instruction that specifies the operation to be performed is called the operation code or opcode. 2.What is an Operand? The data on which the operation is to be performed is called as an Operand. 3.List out the five categories of the 8085 instructions. Give examples of the instructions for each group. Data transfer group MOV, MVI, LXI. Arithmetic group ADD, SUB, INR. Logical group ANA, XRA, CMP. Branch group JMP, JNZ, CALL. Stack I/O and Machine control group PUSH, POP, IN, HLT. 4.Name 5 different addressing modes? Immediate, Direct, Register, Register indirect, Implied addressing modes 5.What happens when HLT instruction is executed in processor? The Micro Processor enters into Halt-State and the buses are tri-stated. 6.What is the use of JMP instruction? A JMP instruction permanently changes the program counter. 7.Difference between ADD and DAD? ADD - Add the contents of register to the contents of the accumulator. DAD - The instruction DAD is an exception; it adds 16-bit data directly in register pairs. 8.Subtraction concept: Any 8-bit number, or the contents of a register, or the contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2's compliment, and the results if negative, are expressed in 2's complement. No two other registers can be subtracted directly. 9.What is the use of SBB? SBB---Subtract from Accumulator Using Borrow (Carry) Flag 10.Explain the instructions used in this exercise: XCHG---Exchange H & L with D & E LDA----Load Accumulator Directly from Memory STA----Store Accumulator Directly in Memory LHLD----Load H & L Registers Directly from Memory SHLD------Store H & L Registers Directly in Memory

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 10

MULTIPLICATION OF TWO 8-BIT NUMBERS. Ex.No.2a

AIM: To write an Assembly Language Program (ALP) for performing the multiplication operation of 8-bit numbers. APPARATUS REQUIRED: Microprocessor kit, Power supply. PROBLEM STATEMENT: Write an ALP in 8085 P to multiply two 8-bit binary numbers stored in the registers B and C and store the result in the memory location 5502H. ALGORITHM:
1. 2. 3. 4. 5. 6.

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 11

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

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 12

DIVISION OF TWO 8-BIT NUMBERS. Ex.No.2b

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 13

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

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 14

MULTIPLICATION OF TWO 16-BIT NUMBERS. Ex.No.2c

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

7. If multiplicand is not equal to 0, repeat from step (d) otherwise store the LSBs MSBs of product.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 15

PROGRAM

ADDRESS 4100 4103 4104 4107 4108 410B 410E 410F 4112 4113 4114 4115 4116 4119 411C 411D 411E 4121

LABEL

MNEMONICS LHLD 5500 XCHG LHLD 5502 SPHL LXI B,0000 LXI H,0000

HEX CODE

L2

DAD SP JNC L1 INX B

L1

DCX D MOV A,E ORA D JNZ L2 SHLD 5504 MOV H,B MOV L,C SHLD 5506 HLT

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 16

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 17

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 . 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: Get the lower order byte of the dividend Get the lower order byte of the divisor Initialize the quotient to 0. Dividend = dividend divisor If the divisor is greater, store the quotient. If dividend is greater, quotient = quotient + 1. Repeat from step (d) If there is borrow, add with higher order byte of the divisor. Get the higher order byte of the dividend Get the higher order byte of the divisor. Dividend = dividend divisor If the divisor is greater, store the quotient. If dividend is greater, quotient = quotient + 1. Repeat from step (d)

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 18

PROGRAM ADDRESS 4100 4103 4104 4107 410A 410B 410C 410D 410E 410F 4110 4113 4114 4117 4118 4119 411A 411B 411C 411D 4120 4121 4122 4125

LABEL

MNEMONICS LHLD 5500 XCHG LHLD 5502 LXI B,0000

HEX CODE

L2

MOV A,L SUB E MOV L,A MOV A.H SBB D MOV H,A JC L1 INX B JMP L2

L1

MOV A,L ADD E MOV L,A MOV A,H ADC D MOV H,A SHLD 5506 MOV L,C MOV H,B SHLD 5508 HLT

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 19

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 20

VIVA QUESTIONS: 1. Multiplication is repeated addition & division is repeated subtraction. 2. What is the use of XRA? XRA -- Exclusive Logical OR with Accumulator 3. what is the use DAD? DAD-- Double Register Add; Add Content of Register Pair to H & L Register Pair Used in 16-bit multiplication 4. Compare the instruction DCR B and DCX B DCX B Decrement register pair BC to HL DCR B Decrement register C 5. What is the use of ADC instruction? Add register with carry. Used in case of 16- bit arthimetic operations

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 21

FINDING THE SMALLEST & LARGEST NUMBER IN A GIVEN ARRAY Ex.No.3a AIM: To write an Assembly Language Program (ALP) for finding the smallest & largest number in a given array. APPARATUS REQUIRED: Microprocessor kit, Power supply. ALGORITHM: To Find The Smallest Element In An Array: 1. Place all the elements of an array in the consecutive memory locations. 2. Fetch the first element from the memory location and load it in the accumulator. 3. Initialize a counter (register) with the total number of elements in an array. 4. Decrement the counter by 1. 5. Increment the memory pointer to point to the next element. 6. Compare the accumulator content with the memory content (next element). 7. If the accumulator content is smaller, then move the memory content 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. 2. 3. 4. 5. 6. 7.

(largest

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

accumulator. Else continue.


8. 9. 10.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 22

PROGRAM(Smallest): ADDRESS 4100 4103 4104 4107 4108 4109 410A 410B 410C 410F 4112 4113 4114 4117 4118 411B L2 L1 LABEL MNEMONICS LDA 5500 MOV B,A LXI H,5501 DCR B MOV C,M INX H MOV A,M CMP C JZ L2 JNC L2 MOV C,A DCR B JNZ L1 MOV A,C STA 6000 HLT HEX CODE

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 23

PROGRAM(LARGEST): ADDRESS 4100 4103 4104 4107 4108 4109 410A 410B 410C 410F 4112 4113 4114 4117 4118 411B L2 L1 LABEL MNEMONICS LDA 5500 MOV B,A LXI H,5501 DCR B MOV C,M INX H MOV A,M CMP C JZ L2 JC L2 MOV C,A DCR B JNZ L1 MOV A,C STA 6000 HLT HEX CODE

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 24

SORTING n NUMBERS Ex. No.3b

AIM: To write an Assembly Language Program (ALP) to sort a given array in ascending and descending order. APPARATUS REQUIRED: Microprocessor kit, Power supply. PROBLEM STATEMENT: An array of length n is given from the location starting from 5200.Sort it into ascending order and descending order and store the result starting from 5200H. ALGORITHM: i) Sorting in ascending order: Load the array count in two registers C1 & C2. Get the first 2 numbers. Compare the numbers and exchange if they are in ascending order. Decrement C2. Decrement C1 and repeat the process until C1 is zero.

1. 2. 3. 4. 5.

ii) Sorting in descending order: Load the array count in two registers C1 & C2. Get the first 2 numbers. Compare the numbers and exchange if they are in descending order. Decrement C2. Get the third number from the array and repeat the process. Decrement C1 and repeat the process until C1 is zero.

1. 2. 3. 4. 5. 6.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 25

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 26

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 27

INPUT & OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 28

VIVA QUESTIONS: 1. What is the use of Label? A label is any sequence of alphabetic or numeric characters starting with an alphabetic. A label is permitted on any line except a line where the opcode is IF, ELSE, or ENDIF. The label is assigned the value of the assembly program counter before any of the rest of the line is processed except when the opcode is EQU, ORG, PAGE, or SET. 2. What is the use of CMP? CMP is a compare instruction. Used to compare register with that of the accumulator 3. Difference between LXI and LDA? The data transfer instructions move data between registers or between memory and registers. LDA Load Accumulator Directly from Memory. An X in the name of a data transfer instruction implies that it deals with a register pair 16bits;LXI 4. What are the different JUMP instructions? JNZ Addr Conditional Jump (Not Zero Flag) JMP Addr Jump to Direct Address JZ Addr Conditional Jump (Zero Flag) JNC Addr Conditional Jump (Not Carry Flag) JC Addr Conditional Jump (Carry Flag) JPO Addr Conditional Jump (Parity Odd, Not Parity Flag) PCHL Jump Indirect HL

JPE Addr Conditional Jump (Parity Even, Parity Flag) JP Addr Conditional Jump (Positive, Not Sign Flag) JM Addr Conditional Jump (Minus, Sign Flag)

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 29

CODE CONVERSION DECIMAL TO HEX Ex.No.4a AIM: To convert a given decimal number to hexadecimal. APPARATUS REQUIRED: 8085 microprocessor kit. Power supply. ALGORITHM: 1. 2. 3. 4. 5. 6. Initialize the memory location to the data pointer. Increment B register. Increment accumulator by 1 and adjust it to decimal every time. Compare the given decimal number with accumulator value. When both matches, the equivalent hexadecimal value is in B register. Store the resultant in memory location.

PROGRAM:
ADDRESS LABEL OPCODE OPERAND COMMENTS

8000 8003 8005 8007 8008 800A 800B 800C 800F 8010 8013 OUTPUT:

LXI MVI MVI INR ADI DAA CMP JNZ MOV STA HLT

H,8100 A,00 B,00 B 01 M LOOP A,B 8101

LOOP

Initialize HL reg. to 8100H Initialize A register. Initialize B register.. Increment B reg. Increment A reg Decimal Adjust Accumulator Compare M & A If acc and given number are not equal, then go to LOOP Transfer B reg to acc. Store the result in a memory location. Stop the program

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 30

CODE CONVERSION HEXADECIMAL TO DECIMAL Ex.No.4b AIM: To convert a given hexadecimal number to decimal. APPARATUS REQUIRED: 8085 microprocessor kit. Power supply. ALGORITHM: 1. 2. 3. 4. 5. 6. Initialize the memory location to the data pointer. Increment B register. Increment accumulator by 1 and adjust it to decimal every time. Compare the given hexadecimal number with B register value. When both match, the equivalent decimal value is in A register. Store the resultant in memory location.

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

LOOP

NEXT

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 31

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 32

CODE CONVERSION HEXADECIMAL TO ASCII Ex.No.4c AIM: To convert a given hexadecimal number to ASCII.. APPARATUS REQUIRED: 8085 microprocessor kit. Power supply. ALGORITHM: 1. Load the data in A-register and then to B-register 2. Mask the upper nibble of the hexadecimal number in A register. 3. Call subroutine to get ASCII of lower nibble. 4. Store it in memory. 5. Move B to A and mask the lower nibble. 6. Rotate the value 7. Call subroutine to get ASCII of upper nibble. 8. Store it in memory PROGRAM: ADDRESS 8000 8003 8004 8006 8009 800C 800D 800F 8010 8011 8012 8013 8016 8019 LABEL MNEMONICS LDA 4500 MOV B,A ANI 0FH CALL SUB STA 4502 MOV A,B ANI F0H RRC RRC RRC RRC CALL SUB STA 4503 HLT MNEMONICS CPI 0AH JC L1 ADI 07H ADI 30H RET HEX CODE 3A,00,45 47 E6,0F CD,1A,42 32,02,45 78 E6,F0 0F 0F 0F 0F CD,1A,42 32,03,45 76 HEX CODE FE ,0A DA,21,42 C6,07 C6,30 C9

SUBROUTINE SUB: ADDRESS LABEL 801A 801C 801F 8021 L1 8023

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 33

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 34

CODE CONVERSION ASCII TO HEXADECIMAL Ex.No.4d AIM: To convert a given ASCII to hexadecimal number.. APPARATUS REQUIRED: 8085 microprocessor kit. Power supply. ALGORITHM: 1. Load the data in A-register. 2. Subtract 30H from A register. 3. Compare the content of A register with 0AH. 4. If A<0A H, jump to step 6. Else proceed to next step. 5. Subtract 07H from A register 6. Store it in memory PROGRAM: ADDRESS 8000 8003 8005 8007 8010 800A 800D OUTPUT: LABEL MNEMONICS LDA 4500 SUI 30 CPI 0A JC L1 SUI 07 STA 4501 HLT HEX CODE 3A,00,45 D6,30 FE,0A DA,21,42 D6,07 32,01,45 76

L1

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 35

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 36

2 X 2 MATRIX MULTIPLICATION Ex.No.5 AIM: To perform the 2 x 2 matrix multiplication. APPARATUS REQUIRED: 8085 microprocessor kit. Power supply. ALGORITHM: 1. Load the 2 input matrices in the separate address and initialize the HL and the DE register pair with the starting address respectively. 2. Call a subroutine for performing the multiplication of one element of a matrix with the other element of the other matrix. 3. Call a subroutine to store the resultant values in a separate matrix. PROGRAM: ADDRESS 8100 8102 8105 8108 810B 810C 810D 810E 810F 8112 8113 8116 8117 8118 811B 811C 811D 811E 811F 8122 8123 8126 8127 8129 812C 812D 8130 LABEL LOOP2 OPCODE MVI LXI LXI CALL MOV INX INX INX CALL ADD CALL DCX DCX CALL MOV INX INX INX CALL ADD CALL MOV CPI JZ INX JMP HLT O C, 00 H, 4500 D, 4600 MUL B,A H D D MUL B STORE H D MUL B,A H D D MUL B STORE A,C 04 LOOP1 H LOOP2 COMMENT Clear C reg. Initialize HL reg. to4500 Load DE register pair Call subroutine MUL Move A to B reg. Increment HL register pair . Increment DE register pair Increment DE register pair Call subroutine MUL Add [B] with [A] Call subroutine STORE Decrement HL register pair Decrement DE register pair Call subroutine MUL Transfer A reg content to B reg. Increment HL register pair Increment DE register pair Increment DE register pair Call subroutine MUL Add A with B Call subroutine MUL Transfer C register cont to Acc. Compare with 04 to check whether all elements are multiplied. If completed, go to loop1 Increment HL register Pair. Jump to LOOP2. Stop the program.
CS 2259 MICROPROCESSORS LAB (CSE)

LOOP1

P a g e | 37

8131 8132 8133 8134 8135 8138 8139 813A 813D 813F 8141 8142 8144 8145 8146 OUTPUT

MUL

LDAX MOV MOV DCR JZ ADD DCR JNZ MVI MVI RET MVI STAX INR RET

D D,A H,M H LOOP3 D H LOOP4 H,85 D,86 B,87 B C

LOOP4 LOOP3 STORE

Load acc from the memory location pointed by DE pair. Transfer acc content to D register. Transfer from memory to H register. Decrement H register. If H is zero go to LOOP3. Add Acc with D reg Decrement H register. If H is not zero go to LOOP4. Transfer 85 TO H register. Transfer 86 to D register. Return to main program. Transfer 87 to B register. Load A from memory location pointed by BC pair. Increment C register. Return to main program.

RESULT

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 38

VIVA QUESTIONS:

1. Why CPI used?


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

2. What is a subroutine?
In 8085 microprocessor a subroutine is a separate program written aside from main program ,this program is basically the program which requires to be executed several times in the main program. 3. What is the difference between CALL and RET The microprocessor can call subroutine any time using CALL instruction . After the subroutine is executed the subroutine hands over the program to main program using RET instruction.

4. diference between STAX andLDAX


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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 39

PROGRAMMING WITH 8086 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 registerregister, memory to register, register to memory, register to immediate, and finally memory to immediate. Hence one of the operands is initially moved to AX. Then using the add instruction, 16- bit addition is performed. The next arithmetic primitive is SUB. As discussed in ADD it permits the same modes of addressing. Hence moving the minuend to a register pair is necessary. Then the result is moved to a location in memory.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 40

ADDITION PROGRAM MOV CX, 0000H MOV AX,[1200] MOV BX, [1202] ADD AX,BX JNC L1 INC CX L1 : MOV [1206],CX MOV [1204], AX HLT SUBTRACTION PROGRAM MOV CX, 0000H MOV AX,[1200] MOV BX, [1202] SUB AX,BX JNC L1 INC CX L1 : MOV [1206],CX MOV [1204], AX HLT COMMENTS Initialize counter CX Get the first data in AX reg Get the second data in BX reg Subtract the contents of BX from AX Check for borrow If borrow exists, increment the CX Store the borrow Store the difference Stop the program COMMENTS Initialize counter CX Get the first data in AX reg Get the second data in BX reg Add the contents of both the regs AX & BX Check for carry If carry exists, increment the CX Store the carry Store the sum Stop the program

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 41

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 42

16 BIT MULTIPLICATION/DIVISION Ex.No.6b AIM: To multiply two 16 bit numbers in memory and store the result in memory and to perform division of a 16 bit number by a 16 bit number and to store quotient and remainder in memory. APPARATUS REQUIRED: 8086 Microprocessor kit, Power supply. ALGORITHAM: (i)16 BIT MULTIPLICATION: 1.Start the program. 2.Get the multiplicand and multiplier. 3.Find the product. 4.Store the result. 5.Terminate the program. (ii)16 bit Division: 1.Start the program. 2.Get the Dividend and Devisor. 3.Find the Quotient and Reminder. 4.Store the result. 5.Terminate the program. The 8086 Processor provides both signed and unsigned multiply in their instruction set to overcome the loss of efficiency in performing the repeated addition. The MUL instruction can have both 16 and 8 bit operands and the multiplicand is AX or AL, accordingly the result for a byte multiply is a 16 bit number in AX while that for a word multiply is a 32 bit number, the lower word of which is in AX and the higher word in DX.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 43

MULTIPLICATION PROGRAM MOV AX,[1200] MOV BX, [1202] MUL BX MOV [1206],AX MOV AX,DX MOV [1208],AX HLT DIVISION PROGRAM MOV AX,[1200] MOV DX, [1202] MOV BX, [1204] DIV BX MOV [1206],AX MOV AX,DX MOV [1208],AX HLT COMMENTS Get the first data Get the second data Divide the dividend by divisor Store the lower order product Copy the higher order product to AX Store the higher order product Stop the program Get the first data COMMENTS Get the first data Get the second data Multiply both Store the lower order product Copy the higher order product to AX Store the higher order product Stop the program

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 44

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 45

VIVA QUESTIONS:

1.8086 Registers: AX (= AH + AL) BX (= BH + BL) CX (= CH + CL) DX (= DH + DL) SI (source index) DI (destination index) SP (stack pointer) BP (base pointer) 2. Explain the process control instructions STC It sets the carry flag & does not affect any other flag CLC it resets the carry flag to zero &does not affect any other flag CMC It complements the carry flag & does not affect any other flag STD It sets the direction flag to 1 so that SI and/or DI can be decremented automatically after execution of string instruction & does not affect other flags CLD It resets the direction flag to 0 so that SI and/or DI can be incremented automatically after execution of string instruction & does not affect other flags STI Sets the interrupt flag to 1. Enables INTR of 8086. CLI Resets the interrupt flagto0. 8086 will not respond to INTR. 3. Explain REPEAT-UNTIL statements REPEAT-UNTIL statements allow executing a series of instructions repeatedly until some condition occurs. The REPEAT defines the start of the loop & UNTIL the end of the loop. UNTIL has a condition when the condition is true the loop is terminated 4. What are the different forms of multiplication?
There are two forms of the multiply instruction: an unsigned multiplication (mul) and a signed multiplication (imul). Unlike addition and subtraction, you need separate instructions for these two operations. The multiply instructions take the following forms: Unsigned Multiplication: mul mul Signed (Integer) Multiplication: imul imul imul imul imul imul imul reg mem reg, reg, reg, reg, reg, reg mem

reg, immediate mem, immediate immediate reg mem

(2) (2) (2) (3) (3)

AAM Instruction - ASCII adjust after Multiplication

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 46

5.What are the different forms of Division?


The 80x86 divide instructions perform a 64/32 division (80386 and later only), a 32/16 division or a 16/8 division. These instructions take the form: div div idiv idiv aad reg mem reg mem For unsigned division For signed division ASCII adjust for division

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 47

STRING MANIPULATION
Ex.No.7

AIM: To write 8086 program 5A) To copy a string of data words from one location to the other. 5B) To search a word from a string. 5C) To find and replace a word from a string. APPARATUS REQUIRED: 8086 Microprocessor kit, power supply. ALGORITHM: 5A)Copying a String 1.Initialise DS, S1, DS, ES. 2.Move the length of the strin in CX register. 3.Move the byte from DS to ES till CX =0. 5B)Search 1.Initialise ES and DI. 2. Move the no. Of characters in the string to CX. 3. Move the byte to be searched to AL. 4. Store the ASCII code of character in BL. 5. Scan for the byte in ES. If the byte is not found ZF 1 and repeat scanning. 6. If the byte is found ZF=1,display 01 in destination address. Otherwise, display 00 in destination address. 5C) Find & Replace 1.Initialise ES and DI. 2. Move the no. Of characters in the string to CX. 3. Move the byte to be searched to AL. 4. Store the ASCII code of character in BL. 5. Scan for the byte in ES. If the byte is not found ZF 1 and repeat scanning. 6. If the byte is found ZF=1, move the content of BC register ES, D1.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 48

COPYING A STRING PROGRAM MOV SI,1200H MOV DI,1300H MOV CX,0006H CLD REP MOVSB HLT

COMMENTS Initialize destination address Initialize starting address Initialize array size Clear direction flag Copy the contents of source into destination until count reaches zero Stop

SEARCHING FOR A CHARACTER IN THE STRING PROGRAM MOV DI,1300H MOV SI, 1400H MOV CX, 0006H CLD MOV AL, 08H REPNE SCASB DEC DI MOV BL,[DI] MOV [SI],BL HLT

COMMENTS

Initialize destination address Initialize starting address Initialize array size Clear direction flag Store the string to be searched Scan until the string is found Decrement the destination address Store the contents into BL reg Store content of BL in source address Stop

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 49

FIND AND REPLACE A CHARACTER IN THE STRING PROGRAM COMMENTS MOV DI,1300H MOV SI,1400H MOV CX, 0006H CLD MOV AL, 08H MOV BH,30H REPNE SCASB DEC DI MOV BL,[DI] MOV [SI],BL MOV [DI],BH HLT Initialize destination address Initialize starting address Initialize array size Clear direction flag Store the string to be searched Store the string to be replaced Scan until the string is found Decrement the destination address Store the contents into BL reg Store content of BL in source address Replace the string Stop

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 50

BIOS/DOS CALLS DISPLAY


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

1. Initialize the data segment and the message to be displayed.


2. Set function value for display. 3. Point to the message and run the interrupt to display the message in the CRT. PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT MSG DB 0DH, 0AH, GOOD MORNING , ODH, OAH, $ DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AH, 09H MOV DX, OFFSET MSG INT 21H MOV AH, 4CH INT 21H CODE ENDS END START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 51

BIOS/DOS CALLS FILE MANIPULATION


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

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 52

BIOS/DOS CALLS DISK INFORMATION


Ex.No.8c

AIM: To display the disk information. ALGORITHM: 1. Initialize the data segment and the message to be displayed. 2. Set function value for disk information. 3. Point to the message and run the interrupt to display the message in the CRT. PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT MSG DB 0DH, 0AH, GOOD MORNING , ODH, OAH, $ DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AH, 36H MOV DX, OFFSET MSG INT 21H MOV AH, 4CH INT 21H CODE ENDS END START

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 53

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 54

I/O MODES: Control Word:

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 55

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

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

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

COMMENTS Initialize DX reg with port address for control word

P a g e | 56

JZ L1 MOV DX, PORTA IN AL,DX MOV DX,PORTB OUT DX,AL HLT

Check whether it is enabled Set DX reg with port A address Get the contents of port A in AL Set DX reg with port B address Send the contents of AL to port B address Stop

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 57

VIVA QUESTIONS:

1. What are the basic modes of operation of 8255? There are two basic modes of operation of 8255, viz. 1. I/O mode. 3. BSR mode. In I/O mode, the 8255 ports work as programmable I/O ports, while In BSR mode only port C (PC0-PC7) can be used to set or reset its individual port bits. Under the IO mode of operation, further there are three modes of operation of 8 255, So as to support different types of applications, viz. mode 0, mode 1 and mode 2. Mode 0 - Basic I/O mode Mode 1 - Strobed I/O mode Mode 2 - Strobed bi-directional I/O 2. Write the features of mode 0 in 8255? 1. Two 8-bit ports (port A and port B) and two 4-bit ports (port C upper and lower) are available. The two 4-bit ports can be combined used as a third 8-bit port. 2. Any port can be used as an input or output port. 3.Output ports are latched. Input ports are not latched. 4. A maximum of four ports are available so that overall 16 I/O configurations are possible. 3. What are the features used mode 1 in 8255? Two groups group A and group B are available for strobed data transfer. 1. Each group contains one 8-bit data I/O port and one 4-bit control/data port. 2. The 8-bit data port can be either used as input or output port. The inputs and outputs both are latched. 3. Out of 8-bit port C, PC0-PC2 is used to generate control signals for port B and PC3=PC5 are used to generate control signals for port A. The lines PC6, PC7 may be used as independent data lines. 4. What are the signals used in input control signal & output control signal? Input control signal STB (Strobe input) IBF (Input buffer full) INTR(Interrupt request) Output control signal OBF (Output buffer full) ACK (Acknowledge input) INTR(Interrupt request) 5. What are the features used mode 2 in 8255? The single 8-bit port in-group A is available. 1. The 8-bit port is bi-directional and additionally a 5-bit control port is available. 2. Three I/O lines are available at port C, viz PC2-PC0. 3. Inputs and outputs are both latched. 4. The 5-bit control port C (PC3=PC7) is used for generating/accepting handshake signals for the 8-bit data transfer on port A.
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 58

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 59

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 60

1. Display Mode Setup: Control word-10 H 0 0 DD 00- 8Bit character display left entry 01- 16Bit character display left entry 10- 8Bit character display right entry 11- 16Bit character display right entry KKK- Key Board Mode 000-2Key lockout. 2.Clear Display: Control word-DC H 1 1 1 1 0 0 1 CD 1 CD 1 CD 0 CF 0 CA 0 0 0 0 1 D 0 D 0 K 0 K 0 K

11

A0-3; B0-3 =FF

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

3. Write Display: Control word-90H 1 1 0 0 0 0 1 0 0 0 0

1-Clear all bits (Combined effect of CD)

AI

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 61

PROGRAM TABLE

PROGRAM START : MOV SI,1200H MOV CX,000FH MOV AL,10 OUT C2,AL MOV AL,CC OUT C2,AL MOV AL,90 OUT C2,AL L1 : MOV AL,[SI] OUT C0,AL CALL DELAY INC SI LOOP L1 JMP START DELAY : MOV DX,0A0FFH LOOP1 : DEC DX JNZ LOOP1 RET LOOK-UP TABLE: 120 0 120 4 98 FF 68 1C 7C 29 C8 FF Initialize array Initialize array size

COMMENTS

Store the control word for display mode Send through output port Store the control word to clear display Send through output port Store the control word to write display Send through output port Get the first data Send through output port Give delay Go & get next data Loop until all the datas have been taken Go to starting location Store 16bit count value Decrement count value Loop until count values becomes zero Return to main program

RESULT: MEMORY LOCATION d 1200H 1201H 1202H 1203H 1204H 1205H 1206H 1207H 7-SEGMENT LED FORMAT c b a dp e g HEX DATA f

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 62

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 63

VIVA QUESTIONS:

1. What is the output modes used in 8279? 8279 provides two output modes for selecting the display options. 1.Display Scan In this mode, 8279 provides 8 or 16 character-multiplexed displays those can be organized as dual 4-bit or single 8-bit display units. 2.Display Entry 8279 allows options for data entry on the displays. The display data is entered for display from the right side or from the left side. 2. What are the modes used in keyboard modes? 1. Scanned Keyboard mode with 2 Key Lockout. 2. Scanned Keyboard with N-key Rollover. 3. Scanned Keyboard special Error Mode. 4. Sensor Matrix Mode. 3. What are the modes used in display modes? 1. Left Entry mode In the left entry mode, the data is entered from the left side of the display unit.. 2. Right Entry Mode In the right entry mode, the first entry to be displayed is entered on the rightmost display.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 64

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

Mode 0 Interrupt on terminal count: The output will be initially low after mode set operations. After loading the counter, the output will be remaining low while counting and on terminal count; the output will become high, until reloaded again.Let us set the channel 0 in mode 0. Connect the CLK 0 to the debounce circuit by changing the jumper J3 and then execute the following program. PROGRAM: Address 4100 4102 4104 4106 4108 410A 410C Label START: Operand MVI OUT MVI OUT MVI OUT HLT Operands A, 30 CE A, 05 C8 A, 00 C8 Comments Channel 0 in mode 0 Send Mode Control word LSB of count Write count to register MSB of count Write count to register

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

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 65

Example: The following program initializes channel 0 of 8253 in Mode 1 and also initiates triggering of Gate 0. OUT 0 goes low, as clock pulse after triggering the goes back to high level after 5 clock pulses. Execute the program, give clock pulses through the debounce logic and verify using CRO. Address 4100 4102 4104 4106 4108 410A 410C 4100 Label START: Mnemonic MVI OUT MVI OUT MVI OUT OUT HLT Operands A, 32 CE A, 05 C8 A, 00 C8 D0 Comments Channel 0 in mode 1 Send Mode Control word LSB of count Write count to register MSB of count Write count to register Trigger Gate0

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

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

Address 4100 4102 4104 4106 4108 410A 410C

Opcodes 3E 74 D3 CE 3E 0A D3 CA 3E 00 D3 CA 76

Label START:

Mnemonic MVI A, 74 OUT CE MVI A, 0A OUT CA MVI A, 00 OUT CA HLT

Comments Channel 1 in mode 2 Send Mode Control word LSB of count Write count to register MSB of count Write count to register

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

Mode 3 Square wave generator:


CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 66

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

Example: We utilize Mode 0 to generate a square wave of frequency 150 KHz at channel 0. Address Opcodes Label Mnemonic Operands Comments 4100 3E 36 START: MVI A, 36 Channel 0 in mode 3 4102 D3 CE OUT CE Send Mode Control word 4104 3E 0A MVI A, 0A LSB of count 4106 D3 C8 OUT C8 Write count to register 4108 3E 00 MVI A, 00 MSB of count 410A D3 C8 OUT C8 Write count to register 410C 76 HLT Set the jumper, so that the clock 0 of 8253 is given a square wave of frequency 1.5 MHz. This program divides this PCLK by 10 and thus the output at channel 0 is 150 KHz. Vary the frequency by varying the count. Here the maximum count is FFFF H. So, the square wave will remain high for 7FFF H counts and remain low for 7FFF H counts. Thus with the input clock frequency of 1.5 MHz, which corresponds to a period of 0.067 microseconds, the resulting square wave has an ON time of 0.02184 microseconds and an OFF time of 0.02184 microseconds. To increase the time period of square wave, set the jumpers such that CLK2 of 8253 is connected to OUT 0. Using the above-mentioned program, output a square wave of frequency 150 KHz at channel 0. Now this is the clock to channel 2. Mode 4: Software Triggered Strobe: The output is high after mode is set and also during counting. On terminal count, the output will go low for one clock period and becomes high again. This mode can be used for interrupt generation. The following program initializes channel 2 of 8253 in mode 4. Example: Connect OUT 0 to CLK 2 (jumper J1). Execute the program and observe the output OUT 2. Counter 2 will generate a pulse after 1 second. Address 4100 4102 4104 4106 4108 410A 410C 410E 4110 4112 Label START: Mnemonic MVI OUT MVI OUT MVI OUT MVI OUT MVI OUT Operands A, 36 CE A, 0A C8 A, 00 C8 A, B8 CE A, 98 CC Comments Channel 0 in mode 0 Send Mode Control word LSB of count Write count to register MSB of count Write count to register Channel 2 in Mode 4 Send Mode control Word LSB of Count Write Count to register
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 67

4114 4116 4118

MVI OUT HLT

A, 3A CC

MSB of Count Write Count to register

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. Address 4100 4102 4104 4106 4108 410A 410C Label START: Mnemonic MVI OUT MVI OUT MVI OUT HLT Operands A, 1A CE A, 05 C8 A, 00 D0 Comments Channel 0 in mode 5 Send Mode Control word LSB of count Write count to register MSB of count Trigger Gate 0

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 68

VIVA QUESTIONS:

1.What are the modes of operations used in 8253? Each of the three counters of 8253 can be operated in one of the following six modes of operation. 1. Mode 0 (Interrupt on terminal count) 2. Mode 1 (Programmable monoshot) 3. Mode 2 (Rate generator) 4. Mode 3 (Square wave generator) 5. Mode 4 (Software triggered strobe) 6. Mode 5 (Hardware triggered strobe) 2.. What are the different types of write operations used in 8253? There are two types of write operations in 8253 (1) Writing a control word register (2) Writing a count value into a count register The control word register accepts data from the data buffer and initializes the counters, as required. The control word register contents are used for (a) Initializing the operating modes (mode 0-mode4) (b) Selection of counters (counter 0- counter 2) (c) Choosing binary /BCD counters (d) Loading of the counter registers. The mode control register is a write only register and the CPU cannot read its contents. 3. Explain the purpose of the I/O instructions IN and OUT. The IN instruction is used to move data from an I/O port into the accumulator. The OUT instruction is used to move data from the accumulator to an I/O port. The IN & OUT instructions are used only on microprocessor, which use a separate address space for interfacing.
4.What is meant by interrupt? Interrupt is an ex ternal signal that causes a microprocessor to jump to a specific subroutine.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 69

INTERFACING USART 8251 Ex.No.10b AIM : To study interfacing technique of 8251(USART) with microprocessor 8085 and write an 8085 ALP to transmit and receive data between two serial ports with Rs 232 cable. APPARATUS REQUIRED: 8085 Kit, Rs232 cable ALGORITHM: 1. Initialise 8253 and 8251 to check the transmission and reception of character 2. Initialise 8253 to give output of 150 Khz at channel 0 which give 9600 baud rate of 8251. 3. The command word and mode word is written to the 8251 to set up for subsequent operations 4. The staus word is read from the 8251 on completion of a serial I/O operation, or when the host CPU is checking the status of the device before starting the next I/O operation. THEORY: The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication. As a peripheral device of a microcomputer system, the 8251 receives parallel data from the CPU and transmits serial data after conversion. This device also receives serial data from the outside and transmits parallel data to the CPU after conversion. Control Words There are two types of control word. 1. Mode instruction (setting of function) 2. Command (setting of operation) 1) Mode Instruction Mode instruction is used for setting the function of the 8251. Mode instruction will be in "wait for write" at either internal reset or external reset. That is, the writing of a control word after resetting will be recognized as a "mode instruction." Items set by mode instruction are as follows: Synchronous/asynchronous mode Stop bit length (asynchronous mode) Character length Parity bit Baud rate factor (asynchronous mode) Internal/external synchronization (synchronous mode) Number of synchronous characters (Synchronous mode)
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 70

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

MODE WORD

STATUS WORD

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 71

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 72

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 73

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 74

VIVA QUESTIONS:

1.What is an USART? USART stands for universal synchronous/Asynchronous Receiver/ Transmitter. It is a programmable communication interface that can communicate by using either synchronous or asynchronous serial data. 2.What is the use of 8251 chip? 8251 chip is mainly used as the asynchronous serial interface between the processor and the external equipment. 3. What is the use of modem control unit in 8251? The modem control unit handles the modem handshake signals to coordinate the communication between the modem and the USART. 4.Format for Character Framing: Character framing

5. Explain receiver and transmitter

Receiver The receiver tests the state of the incoming signal on each clock pulse, looking for the beginning of the start bit. If the apparent start bit lasts at least one-half of the bit time, it is valid and signals the start of a new character. If not, the spurious pulse is ignored. After waiting a further bit time, the state of the line is again sampled and the resulting level clocked into a shift register. Transmitter Transmission operation is simpler since it is under the control of the transmitting system. As soon as data is deposited in the shift register after completion of the previous character, the USART hardware generates a start bit, shifts the required number of data bits out to the line, generates and appends the parity bit (if used), and appends the stop bits. Since transmission of a single character may take a long time relative to CPU speeds, the USART will maintain a flag showing busy status so that the host system does not deposit a new character for transmission until the previous one has been completed; this may also be done with an interrupt. Since fullduplex operation requires characters to be sent and received at the same time, practical USARTs use two different shift registers for transmitted characters and received characters.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 75

8051 PROGRAMS 8 BIT ADDITION/SUBTRACTION Ex.No.11a AIM: To write an ALP to perform 8 bit addition/subtraction in 8051. Apparatus required: 8051 microcontroller kit, power supply. ALGORITHM: 8 bit addition: 1. Clear the program status word. 2. Load the first number in the accumulator. 3. Load the second reg. in the register R0. 4. Load the destination address in the DPTR. 5. Add te 2 numbers. 6. Store the sum and carry in the destination address. 7. Terminate the program. 8 bit subtraction: 1. Clear PSW. 2. Select the register by giving proper values. 3. Lolad the accumulator with 1st data & reg with 2nd data. 4. Subtract 2nd data from 1st data. 5. Store the diff and borrow and terminate the program. 8 Bit Addition (Immediate Addressing) ADDRESS LABEL MNEMONIC 4100 4101 4103 4105 4108 4109 L1 CLR MOV ADDC MOV MOVX SJMP

OPERAND C A,# data1 A, # data 2 DPTR, # 4500H @ DPTR, A L1

HEX CODE

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 76

8 Bit Subtraction (Immediate Addressing)

ADDRESS 4100 4101 4103 4105 4108 4109

LABEL

MNEMONIC CLR MOV SUBB MOV MOVX

OPERAND C A, # data1 A, # data2 DPTR, # 4500 @ DPTR, A L1

HEX CODE

L1

SJMP

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 77

MULTIPLICATION/DIVISION OF 8 BIT NUMBERS Ex.No.11b AIM: To write a program for 8 bit multiplication & 8 bit division using 8051 microcontroller. Apparatus required: 8051 microcontroller kit, power supply. ALGORITHM: 8 bit multiplication: 1. Clear PSW. 2. Select register bank by giving proper values. 3. Load accumulator A with any derived 8 bit data. 4. Load registers B with 2nd data. 5. Multiply there 2 nods. 6. Store the result 7. Terminate the program. 8 BIT DIVISION: 1. Clear PSW. 2. Select register bank by giving proper values. 3. Load A with 1st data dividend. 4. Load B wit 8 bit divisor. 5. Divide A/B. 6. Store the quotient & remainder. 7. Terminate the program.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 78

8 Bit Multiplication ADDRESS LABEL 4100 4102 4104 4106 4109 401A 410B 410D 410E 8 Bit Division ADDRESS 4100 4102 4104 4015 4018 4109 410A 410C 410D STOP STOP

OPCODE MOV MOV MUL MOV MOVX INC MOV MOV SJMP

OPERAND A ,#data1 B, #data2 A,B DPTR, # 4500H @ DPTR, A DPTR A,B @ DPTR, A STOP

HEX CODE

LABEL

OPCODE MOV MOV DIV MOV MOVX INC MOV MOV SJMP

OPERAND A, # data1 B, # data2 A,B DPTR, # 4500H @ DPTR, A DPTR A,B @ DPTR, A STOP

HEX CODE

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 79

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 80

STEPPER MOTOR CONTROLLER Ex.No:12a AIM: To write an ALP in 8051 to rotate the motor at different speeds in clockwise and in anticlockwise directions with delay. APPARATUS REQUIRED: 1. 2. 3. Microcontroller kit Power supply Stepper motor interface board 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.

PROBLEM STATEMENT

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 81

PROGRAM : ADDRESS LABEL OPCODE ORG OPERAND

4100

START:

MOV

4103 4105 4106 4108 410A 410D 410E 4110 4112 4114 4116 4118 411A 411B LOOP:

MOV MOVX PUSH PUSH MOV MOVX MOV MOV DJNZ DJNZ POP POP INC DJNZ

DELAY: DELAY1:

411D

SJMP

411F

TABLE:

DB

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 82

SWITCHING SEQUENCE OF STEPPER MOTOR CLOCKWISE DIRECTION Memory Location A1 A2 B1 B2 Hex Code

ANTICLOCKWISE DIRECTION Memory Location A1 A2 B1 B2 Hex Code

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 83

ANALOG-TO- DIGITAL CONVERTER Ex.No.12b

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

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 84

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

HERE

Add1 Add2

address to select the channel, send ALE & OE signals address to send the SOC signal data to select the channel, ALE low & OE high data to select the channel, ALE high & OE high

Data1 Data2 -

Data3 -send SOC high D0 - high Data4 -send SOC low D0 - low Channel No. Data to make ALE low & OE high CH0 CH1 CH2 CH3 CH4 CH5 CH6 CH7 10 11 12 13 14 15 16 17 Data to make ALE high & OE high 18 19 1A 1B 1C 1D 1E 1F

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 85

OUTPUT:

RESULT:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 86

DIGITAL-TO-ANALOG CONVERTER Ex.No.12c AIM: To write an ALP for digital-to analog converter to generate different types of waveforms at DAC output APPARATUS REQUIRED: 1. 2. Microcontroller kit Power supply

3. AC interface board PROBLEM STATEMENT The program starts from 4100H location. The input is given in the memory locations 4100H and 4108H. The output is sent to the output ports. The waveforms are measured at the output port using CRO. THEORY Since DAC 0800 is an 8-bit DAC and the output voltage variation is between -5v and +5v.The basic idea behind the generation of waveforms is the continuous generation of analog output of DAC. With 00H as input to DAC, the analog output is -5V.Similarly with FFH as input, the output is +5V. ALGORITHM MEASUREMENT OF ANALOG VOLTAGE 1. Send the digital value of DAC 2. Read the corresponding analog value of its output. WAVEFORM GENERATION SQUARE WAVEFORM 1. Send low value(00) to DAC 2. Introduce suitable delay 3. Send high value to DAC 4. Introduce delay 5. Repeat the above procedure SAW-TOOTH WAVEFORM 1. Load low value(00) to accumulator 2. Send this value to DAC 3. Increment the Accumulator 4. Repeat step 2 and 3 until accumulator value reaches FF 5. Repeat the above procedure from step1
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 87

TRIANGULAR WAVEFORM 1. Load low value(00) to accumulator 2. Send this value to DAC 3. Increment the Accumulator 4. Repeat step 2 and 3 until accumulator value reaches FF, decrement the accumulator and send this value to DAC 5. Repeat the above procedure from step1 SQUAREWAVE: ADDRESS 4100 4103 4105 4106 4109 410B 410C 410F 4112 4114 4116 4118 411A 411B LABEL START MNEMONICS MOV DPTR, #FFC0 MOV A, #00 MOVX @DPTR,A LCALL DELAY MOVA,#FF MOV X @DPTR,A LCALL DELAY LJMP START MOV R1,#05 MOV R2,#FF DJNZ R2,LOOP1 DNJZ R1,LOOP RET SJMP START HEXCODE

DELAY LOOP LOOP1

SAW-TOOTH WAVEFORM ADDRESS 4100 4103 4105 4106 4107 LABEL MNEMONICS MOV DPTR, #FFC0 MOV A, #00 MOVX @DPTR,A INC A SJMP LOOP HEXCODE

LOOP

TRIANGULAR WAVEFORM
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 88

ADDRESS 4100 4103 4105 4106 4107 4109 410B 410C 410D 410F

LABEL START LOOP1

MNEMONICS MOV DPTR, #FFC0 MOV A, #00 MOVX @DPTR,A INC A JNZ LOOP1 MOV A,#FF MOVX @DPTR,A DEC A JNZ LOOP2 LJMP START

HEXCODE

LOOP2

OUTPUT:

RESULT:

VIVA QUESTIONS:
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 89

1.Features of 8051microcontroller. 8 bit controller operating on bit and byte. 256 bytes internal RAM and 4 kb internal RAM 64/60 kb external program memory address space 64 kb external data memory address space 4 numbers of 8 bit parallel ports. 2. State the functions of RS1 and RS0 bit in the flag register It is used to select the register banks RS1 RS0 Bank selection 0 0 00 H 07 H BANK 0 0 1 08 H - 0F H BANK 1 1 0 10 H 17 H BANK 2 1 1 18 H 1F H BANK 3 3. Difference between RR A and RRC A instructions in 8051 RR A --Rotate accumulator right The 8 bits in the accumulator are rotated 1 bit to the right.bit 0 is rotated in to the bit 7 position. No flags are affected. RRC A-- Rotate accumulator right through carry flag The 8 bits in the accumulator and the carry flag together rotated 1 bit to the right.bit 0 is moves in to the bit carry flag; the original value of the flag moves in to the bit 7 position. No flags are affected. 5. Show the format of PSW register of 8051 B7 B6 B5 B4 B3 B2 B1 B0 CY AC F0 RS1 RS0 OF P 6. What are the functions of DPTR register? The data pointers consist of a high byte (DPH) and a low byte (DPL). It functions is to hold a 16 byte address. It serves as a base register in indirect jumps, lookup table instructions and external data transfer. 7. List the interrupt structures of 8051. Priority level structure. External interrupts. Single step operation. 8. List the instruction sets of 8051. Data transfer Arithmetic Logical Branching Boolean 9. List the addressing modes supported by 8051. Register addressing Direct byte addressing Register indirect Immediate Register specific Index 10. What are the operating modes of the timer of 8051?
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 90

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 16 bit timer, in mode2, function as 8 bit with auto reload feature. 11. List the interrupts of 8051 microcontroller. It has External interrupt -0 Timer-0 interrupt External interrupt-1 Timer-1 interrupt Serial port interrupts. 12. What are the dedicated address pointers in 8051? Program counter Data pointer. The PC is used as address pointer for program and DPTR is used as address pointer for data. 13. What are the register banks in 8051? The reg banks are internal RAM locations of 8051 which can be used as general purpose reg or scratch pad reg. The first 32 bytes of internal RAM of 8051 and organise as 4 reg banks with each bank consisting 8 locations. At any one time the processor can work with only one reg bank depending on the value of bits RS0 and RS1. 14. How stack is implemented in 8051. The 8051 LIFO .Stack can reside anywhere in the internal RAM it has 8 bit stack pointer to indicate the top if stack. This can be accessed by PUSH and POP instructions. During PUSH the SP is incremented by 1 and during POP the SP is decremented by 1. 15. Explain the interrupts of 8051 microcontroller. The interrupts are: Vector address A External interrupt 0 : IE0 : 0003H A Timer interrupt 0 : TF0 : 000BH A External interrupt 1 : IE1 : 0013H A Timer Interrupt 1 : TF1 : 001BH A Serial Interrupt Receive interrupt : RI : 0023H Transmit interrupt: TI : 0023H 16. Define stack. Stack is a sequence of RAM memory locations defined by the Programmer. 17. What is program counter? How it will be useful in program execution? The program counter keeps track of program execution. To execute a program the starting address of the program is loaded in program counter. The PC sends out an address to fetch a byte of instruction from memory and increments its content automatically.

18.. Explain DJNZ instructions of intel 8051 microcontroller?


CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 91

a) DJNZ Rn, rel Decrement the content of the register Rn and jump if not zero. b) DJNZ direct , rel Decrement the content of direct 8-bit address and jump if not zero.

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 92

Ex.No.13

MINI PROJECT FINGERPRINT BASED SECURITY SYSTEM

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

SYSTEM REQUIREMENTS: Microcontroller AT89S52 Transistors Resistors LCD Buzzer

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 93

CIRCUIT DIAGRAM:

SOURCE CODE:

RB0 EQU 00H ; Select Register Bank 0 RB1 EQU 08H ; Select Register Bank 1 ...poke to PSW to use RB2 EQU 10H ; Select Register Bank 1 ...poke to PSW to use ****************************************************************************** PORT DECLERATION ******************************************************************************* //// ***LCD CONTROL***//// LCD_RS EQU P0.0 ; LCD REGISTER SELECT LINE LCD_E EQU P0.1 ; LCD ENABLE LINE LCD_DB4 EQU P0.2 ; PORT 1 IS USED FOR DATA LCD_DB5 EQU P0.3 ; USED FOR DATA LCD_DB6 EQU P0.4 ; FOR DATA LCD_DB7 EQU P0.5 ; FOR DATA SEARCH ADDS EQU EQU P1.0 P1.1
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 94

DELETE LOAD EQU ALARM

EQU P0.7 EQU

P1.2 P0.6

***CURSOR CONTROL INSTRUCTIONS*** OFFCUR EQU 0CH BLINKCUR EQU 0DH ; ***DISPLAY CONTROL INSTRUCTIONS*** CLRDSP EQU 01H ONDSP EQU 0CH ; ***SYSTEM INSTRUCTIONS*** CONFIG EQU 28H ; 4-BIT DATA,2 LINES,5X7 MATRIX LCD ENTRYMODE EQU 6 ; INCREMENT CURSOR DON'T SHIFT DISPLAY DSEG ; this is internal data memory ORG 20H ; Bit addressable memory FLAGS1: DS 1 RECEIVED BIT FLAGS1.0 COUNTER: DS 1 BYTE: DS 10 TEMP: DS 1 TEMPS: DS 1 USER_COUNT: DS 1 ERROR_COUNT: DS 1 ;***************************************************************************** ******************************************************************************* CSEG ; Code begins here ; ---------==========----------==========---------=========--------; Main routine. Program execution starts here. ; ---------==========----------==========---------=========--------ORG 00H ; Reset AJMP MAIN ORG 23H JMP SERIAL ; ---------==========----------==========---------=========--------MAIN: MOV PSW,#RB0 ; Select register bank 0 MOV SP,#60h MOV A,PCON SETB ACC.7 MOV PCON,A MOV TMOD,#20H MOV TH1,#0FFH MOV SCON,#50H SETB ES SETB EA SETB TR1 SETB ADDS SETB SEARCH CLR LOAD
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 95

CLR ALARM MOV ERROR_COUNT,#00H ;CHECK TO INITIALIZE THE USER COUNT IN FLASH MEMORY CLR RECEIVED MOV DPTR, #READ_FLASH CALL SEND_SERIAL CALL DELAY MOV A, BYTE+4 CJNE A, #0FFH, NOT_INT MOV DPTR, #STORE_FLASH CALL SEND_SERIAL NOT_INT: TOPS: TOP: JNB ADDS,ADD_USERS JNB SEARCH,SEARCH_USERS JNB DELETE,DELETE_USER AJMP TOP SEARCH_USERS: AJMP SEARCH_USER ADD_USERS: AJMP ADD_USER DELETE_USER: JNB DELETE,$ CALL DISPLAY_DEL CLR RECEIVED MOV DPTR,#SEARCH_USER_DATA CALL SEND_SERIAL CALL DELAYS MOV A, BYTE+4 CJNE A, #39H, NOT_MATCHS CALL FIN_MATCHED MOV TEMP, BYTE+6 CALL DELAYS CALL DELAYS MOV DPTR, #DEL_USER_DATA MOV TEMPS, #00H CALL SEND_SERIAL MOV SBUF, TEMP CALL TRANSDELAY MOV A, TEMPS ADD A, TEMP MOV SBUF, A CALL TRANSDELAY CALL DELAYS MOV A, BYTE+4 CJNE A, #31H, NOT_MATCHES CALL FIN_DELETED CALL DELAYS CALL DELAYS AJMP TOPS NOT_MATCHES: CALL NOT_DELETED CALL DELAYS CALL DELAYS
CS 2259 MICROPROCESSORS LAB (CSE)

CALL RESETLCD4 CALL DISPLAY

P a g e | 96

AJMP TOPS NOT_MATCHS: CALL NOT_MATCHED CALL DELAYS CALL DELAYS AJMP TOPS ADD_USER: CALL DISPLAY1 CALL DELAYS JNB ADDS,$ CLR RECEIVED MOV DPTR,#SEARCH_USER_DATA CALL SEND_SERIAL CALL DELAYS MOV A,BYTE+4 CJNE A,#39H,NOT_MATCHSS CALL ALREADY_EXIT CALL DELAYS CALL DELAYS AJMP TOPS NOT_MATCHSS: CLR RECEIVED MOV DPTR,#READ_FLASH FLASH MEMORY CALL SEND_SERIAL CALL DELAY MOV A, BYTE+4 MOV USER_COUNT,A CJNE A,#16,USER_NOT_FULL CALL USER_FULL_DISPLAY CALL DELAYS CALL DELAYS AJMP TOPS USER_NOT_FULL: CLR RECEIVED MOV DPTR,#ADD_USER_DATA MOV TEMPS, #00H CALL SEND_SERIAL MOV SBUF, USER_COUNT CALL TRANSDELAY MOV A, TEMPS ADD A, USER_COUNT MOV SBUF,A CALL TRANSDELAY NEXT: CALL DELAYS CALL DELAYS JNB RECEIVED,$ MOV A,BYTE+4 CJNE A,#31H,NOT_SAVED CALL DISPLAY_SUCESS CALL DELAYS CALL DELAYS CLR RECEIVED MOV DPTR,#STORE_FLASH MOV TEMPS,#00H CALL SEND_SERIAL INC USER_COUNT MOV SBUF, USER_COUNT CALL TRANSDELAY
CS 2259 MICROPROCESSORS LAB (CSE)

;LOAD USER COUNT FROM

P a g e | 97

MOV A, TEMPS ADD A, USER_COUNT MOV SBUF,A CALL TRANSDELAY CLR RECEIVED AJMP TOPS NOT_SAVED: CALL DISPLAY_NOTSUCESS CALL DELAYS CALL DELAYS CLR RECEIVED AJMP TOPS ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ SEND_SERIAL: CLR A MOVC A,@A+DPTR CJNE A,#0FFH,SEND_D RET SEND_D: MOV SBUF,A ADD A, TEMPS MOV TEMPS,A CALL TRANSDELAY INC DPTR AJMP SEND_SERIAL ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ SEARCH_USER: JNB SEARCH,$ CALL DISPLAY2 CLR RECEIVED MOV DPTR,#SEARCH_USER_DATA CALL SEND_SERIAL CALL DELAYS MOV A, BYTE+4 CJNE A,#39H,NOT_MATCH CPL LOAD CLR ALARM MOV ERROR_COUNT,#00H CALL MATCHED MOV TEMP, BYTE+6 CALL SPLITDISP CALL DELAYS CALL DELAYS AJMP TOPS NOT_MATCH: INC ERROR_COUNT MOV A,ERROR_COUNT CJNE A,#04H,ALARM_ON SETB ALARM ALARM_ON: CALL NOT_MATCHED CALL DELAYS CALL DELAYS AJMP TOPS SPLITDISP: MOV A,TEMP

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 98

mov b,#10 ; Divide By 10 div ab ; Do Divide swap a ; Move Result To High Of A orl a,b ; OR In Remainder MOV TEMP, A ANL A, #0F0H SWAP A ADD A, #30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV A, TEMP ANL A, #0FH ADD A, #30H MOV R4, A CALL WRLCDDATA CALL MDELAY MOV R4, #' ' CALL WRLCDDATA CALL MDELAY RET ;---------==========----------==========---------=========--------ADD_USER_DATA: DB 4DH, 58H, 10H, 03H, 40H, 00H, 0FFH DB 4DH, 58H, 10H, 03H, 40H, 00H, 01H, 0F9H, 0FFH ;ADDRESS--------------------------^ SEARCH_USER_DATA: DB 04DH, 58H, 10H, 05H, 44H, 00H, 00H, 00H, 0FEH, 0FCH, 0FFH STORE_FLASH: DB 4DH, 58H, 10H, 05H, 64H, 00H, 00H, 01H, 0FFH DB 4DH, 58H, 10H, 05H, 64H, 00H, 00H, 01H, 00H, 1FH, 0FFH READ_FLASH: DB 4DH, 58H, 10H, 04H, 62H, 00H, 00H, 01H, 1CH, 0FFH ;ADDRESS--------------------------^ ;COUNT---------------------------------^ DEL_USER_DATA: DB 4DH, 58H, 10H, 03H, 42H, 00H, 0FFH ;---------==========----------==========---------=========--------SERIAL: PUSH PSW ; save current register set MOV PSW,#RB1 PUSH ACC JB TI,TRANSD MOV A,SBUF CJNE A,#4DH,DOWN2 MOV COUNTER,#01H JMP DDWN TRANSD: AJMP TRANS DOWN2: MOV R1,COUNTER CJNE R1,#01H,YH1 MOV BYTE,A JMP DOWN1 YH1: CJNE R1,#02H,YH2 MOV BYTE+1,A
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 99

YH2:

YH3:

YH4:

YH5:

YH6:

YH7:

DOWN1: DDWN: CLR RI

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

TRANS:

CLR TI POP ACC POP PSW RETI ;********************************************************** ;********************************************************** TRANSDELAY: MOV R7,#5FH DJNZ R7,$ RET ;************************************************************************** ;########################################################## ; DISPLAY ROUTINES ;########################################################## DISPLAY:
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 100

MOV DPTR,#MSAG1 CALL LCD_MSG RET MSAG1: DB 1H,80H,'Fingerprint Based',0C0H,'Security System',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY1: MOV DPTR,#MSAG2 CALL LCD_MSG RET MSAG2: DB 1H,83H,'Show your',0C0H,'Finger to ADD..',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY2: MOV DPTR,#MSAG3 CALL LCD_MSG RET MSAG3: DB 1H,83H,'Show your',0C3H,'Finger....',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USER_FULL_DISPLAY: MOV DPTR,#MSAG4 CALL LCD_MSG RET MSAG4: DB 1H,83H,'User memory',0C3H,'## FULL ##',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY_SUCESS: MOV DPTR,#MSAG5 CALL LCD_MSG RET MSAG5: DB 1H,83H,'User Added',0C3H,'Sucessfully',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY_NOTSUCESS: MOV DPTR,#MSAG6 CALL LCD_MSG RET MSAG6: DB 1H,83H,'User Added',0C2H,'## Failed ##',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MATCHED: MOV DPTR,#MSAG7 CALL LCD_MSG RET MSAG7: DB 1H,83H,'Fingerprint',0C1H,'Matched ID:',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOT_MATCHED: MOV DPTR,#MSAG8 CALL LCD_MSG RET MSAG8: DB 1H,83H,'Fingerprint',0C2H,'NOT Matched',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY_DEL: MOV DPTR,#MSAG9 CALL LCD_MSG RET MSAG9:
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 101

DB 1H,83H,'Show your',0C0H,'Finger to DELETE',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FIN_MATCHED: MOV DPTR,#MSAG10 CALL LCD_MSG RET MSAG10: DB 1H,83H,'Fingerprint',0C4H,'Matched',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FIN_DELETED: MOV DPTR,#MSAG11 CALL LCD_MSG RET MSAG11: DB 1H,83H,'Fingerprint',0C1H,'## Deleted ##',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOT_DELETED: MOV DPTR,#MSAG12 CALL LCD_MSG RET MSAG12: DB 1H,83H,'Fingerprint',0C2H,'NOT Deleted',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ALREADY_EXIT: MOV DPTR,#MSAG13 CALL LCD_MSG RET MSAG13: DB 1H,83H,'Fingerprint',0C1H,'Already Exits',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAY: MOV R1,#0FFH RE1: MOV R2,#0FFH RE: NOP DJNZ R2,RE DJNZ R1,RE1 RET ;********************************************************** DELAYS: ;One second delay routine MOV R0,#05H RS3: MOV R1,#0FFH RA1: MOV R2,#0FFH RS2: NOP DJNZ R2,RS2 DJNZ R1,RA1 DJNZ R0,RS3 RET ;********************************************************** DELAYSS: ;One second delay routine MOV R0,#03H RE3: MOV R1,#0FFH RZ1: MOV R2,#0FFH RE2: NOP DJNZ R2,RE2 DJNZ R1,RZ1 DJNZ R0,RE3 RET ;********************************************************** ; INITIALIZE THE LCD 4-BIT MODE ;**********************************************************
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 102

INITLCD4: CLR CLR MOV

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

LCD_RS ; LCD REGISTER SELECT LINE LCD_E ; ENABLE LINE R4, #CONFIG; FUNCTION SET - DATA BITS, ; LINES, FONTS WRLCDCOM4 R4, #ONDSP ; DISPLAY ON WRLCDCOM4 R4, #ENTRYMODE ; SET ENTRY MODE WRLCDCOM4 ; INCREMENT CURSOR RIGHT, NO SHIFT R4, #CLRDSP; CLEAR DISPLAY, HOME CURSOR WRLCDCOM4

; ********************************************************** ; 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...
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 103

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 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).
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 104

; ********************************************************** LCD_MSG: CLR A ; Clear Index MOVC A,@A+DPTR ; Get byte pointed by Dptr INC DPTR ; Point to the next byte JZ LCD_Msg9 ; Return if found the zero (end of stringz) CJNE A,#01H,Lcd_Msg1 ; Check if is a Clear Command MOV R4,A CALL WRLCDCOM4 ;If yes, RECEIVE it as command to LCD JMP LCD_MSG ;Go get next byte from stringz Lcd_Msg1: CJNE A,#0FFH,FLL MOV R4,A CALL WRLCDDATA JMP LCD_MSG FLL: CJNE A,#080h,$+3 JC Lcd_Msg_Data MOV R4,A CALL WRLCDCOM4 JMP Lcd_Msg Lcd_Msg_Data: ; MOV R4,A CALL WRLCDDATA JMP Lcd_Msg Lcd_Msg9: RET ;Check for displaying full character

; Data or Address? If => 80h then is address. ; Carry will be set if A < 80h (Data) ; Carry not set if A=>80, it is address ; Go get next byte from stringz

; It was data, RECEIVE it to Lcd ; Go get next byte from stringz

; Return to Caller

; ********************************************************** ; 1 MILLISECOND DELAY ROUTINE ; ********************************************************** MDELAY: PUSH ACC MOV A,#0A6H MD_OLP: INC A NOP NOP NOP NOP NOP NOP NOP NOP JNZ MD_OLP NOP POP ACC RET MADELAY: PUSH ACC MOV A,#036H MAD_OLP: INC A NOP NOP NOP NOP NOP NOP
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 105

NOP NOP JNZ NOP POP RET END

MAD_OLP ACC

CONCLUSION:

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 106

VIVA QUESTIONS: 1. What is Microprocessor ? It is a program controlled semiconductor device (IC}, which fetches, decode and executes instructions. 2. What are the basic units of a microprocessor ? The basic units or blocks of a microprocessor are ALU, an array of registers and control unit. 3.what is Software and Hardware? The Software is a set of instructions or commands needed for performing a specific task by a programmable device or a computing machine. The Hardware refers to the components or devices used to form computing machine in which the software can be run and tested. Without software the Hardware is an idle machine. 4.What is assembly language? The language in which the mnemonics (short -hand form of instructions) are used to write a program is called assembly language. The manufacturers of microprocessor give the mnemonics. 5. What are machine language and assembly language programs? The software developed using 1's and 0's are called machine language, programs. The software developed using mnemonics are called assembly language programs. 6.Give the power supply and frequency of the microprocessoe? The power supply of 8085 is +5V and clock frequency in 3MHz. 7. 8085 is a 8-bit microprocesspr 8.List the allowed register pairs of 8085. B-C register pair D-E register pair H-L register pair 9. List few applications of microprocessor-based system. It is used: i. For measurements, display and control of current, voltage, temperature, pressure, etc. ii.For traffic control and industrial tool control. iii .For speed control of machines. 10. How many operations are there in the instruction set of 8085 microprocessor? There are 74 operations in the 8085 microprocessor.
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 107

11. What are the functions of an accumulator? The accumulator is the register associated with the ALU operations and sometimes I/O operations. It is an integral part of ALU. It holds one of data to be processed by ALU. It also temporarily stores the result of the operation performed by the ALU. 12. List the 16 bit registers of 8085 microprocessor. Stack pointer (SP) and Program counter (PC). 13.What are the various flags used in 8085? Sign flag, Zero flag, Auxillary flag, Parity flag, Carry flag. 14.What is Stack Pointer? Stack pointer is a special purpose 16-bit register in the Microprocessor, which holds the address of the top of the stack. 15.What is Program counter? Program counter holds the address of either the first byte of the next instruction to be fetched for execution or the address of the next byte of a multi byte instruction, which has not been completely fetched. In both the cases it gets incremented automatically one by one as the instruction bytes get fetched. Also Program register keeps the address of the next instruction.

1.What is an Opcode? The part of the instruction that specifies the operation to be performed is called the operation code or opcode. 2.What is an Operand? The data on which the operation is to be performed is called as an Operand. 3.List out the five categories of the 8085 instructions. Give examples of the instructions for each group. Data transfer group MOV, MVI, LXI. Arithmetic group ADD, SUB, INR. Logical group ANA, XRA, CMP. Branch group JMP, JNZ, CALL. Stack I/O and Machine control group PUSH, POP, IN, HLT. 4.Name 5 different addressing modes? Immediate, Direct, Register, Register indirect, Implied addressing modes 5.What happens when HLT instruction is executed in processor? The Micro Processor enters into Halt-State and the buses are tri-stated. 6.What is the use of JMP instruction? A JMP instruction permanently changes the program counter. 7.Difference between ADD and DAD? ADD - Add the contents of register to the contents of the accumulator.
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 108

DAD - The instruction DAD is an exception; it adds 16-bit data directly in register pairs. 8.Subtraction concept: Any 8-bit number, or the contents of a register, or the contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2's compliment, and the results if negative, are expressed in 2's complement. No two other registers can be subtracted directly. 9.What is the use of SBB? SBB Subtract from Accumulator Using Borrow (Carry) Flag 10.Explain the instructions used in this exercise: XCHG Exchange H & L with D & E LDA Load Accumulator Directly from Memory STA Store Accumulator Directly in Memory LHLD Load H & L Registers Directly from Memory SHLD Store H & L Registers Directly in Memory

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 109

CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 110

1.What are the 4 segment registers in 8086? There are 4 segment registers present in 8086. They are 1. Code Segment (CS ) register 2. Data Segment (DS ) register 3. Stack Segment (SS ) register 4. Extra Segment (ES ) register 2,Discuss the function of instruction queue in 8086? In 8086, a 6-byte instruction queue is presented at the Bus Interface Unit (BIU). It is used to prefetch and store at the maximum of 6 bytes of instruction code from the memory. Due to this, overlapping instruction fetch with instruction execution increases the processing speed. 3. What is the maximum memory size that can be addressed by 8086? In 8086, an memory location is addressed by 20 bit address and the address bus is 20 bit address and the address bus is 20 bits. So it can address up to one mega byte (2^20) of memory space. 4.What are the different flag available in status register of 8086? There are 6 one bit flags are present. They are, AF - Auxiliary Carry Flag CF - Carry Flag OF - Overflow Flag SF - Sign Flag PF - Parity Flag ZF - Zero Flag 5. List the various addressing modes present in 8086? There are 12 addressing modes present in 8086. They are, (a) Register and immediate addressing modes Register addressing modes Immediate addressing mode (b) Memory addressing modes. Direct addressing modes Register indirect addressing modes Based addressing modes Indexed addressing modes Based Indexed addressing modes String addressing modes (c) I/O addressing modes Direct addressing mode Indirect addressing mode (d) Relative addressing mode (e) Implied addressing mode 6. How single stepping can be done in 8086? By setting the Trace Flag (TF) the 8086 goes to single-step mode. In this mode, after the execution of each instruction s 8086 generates an internal interrupt and by writing some interrupt service routine we can display the content of desired registers and memory locations. So it is useful for debugging the program.
CS 2259 MICROPROCESSORS LAB (CSE)

P a g e | 111

7.What is the clock frequency of 8086? 8086 8086-2 8086-4 Internal clock Frequency 5 MHz 8MHz 4MHz External Clock Frequency 15MHZ 24MHZ 12MHZ 8.What are the two modes of operations present in 8086? i. Minimum mode (or) Uniprocessor system ii. Maximum mode (or) Multiprocessor system 1.

CS 2259 MICROPROCESSORS LAB (CSE)