RAJALAKSHMI ENGINEERING COLLEGE Thandalam, Chennai – 602 105 Dept OF BIO-MEDICAL ENGG.

BM2306-Microprocessor and Microcontroller Lab Lab Manual

BM2306: MICROPROCESSORS & MICROCONTROLLERS LAB MANUAL V SEM BME

BM2306 - Microprocessors And Microcontrollers Lab V Semester BME Syllabus 1. Programming with 8085 – 8-bit/16-bit multiplication/ division using repeated addition/subtraction. 2. Programming with 8085- code conversion, decimal arithmetic, bit manipulations. 3. Programming with 8085 – matrix multiplication, floating point operations. 4. Programming with 8086 – String manipulation, search, find and replace, copy operations, sorting. 5. Using BIOS/DOS calls: keyboard control, display, file manipulation. 6. Using BIOS/DOS calls: Disk operations. 7. Interfacing with 8085/8086 – 8255, 8253. 8. Interfacing with 8085/8086 – 8279, 8251. 9. 8051 Microcontroller based experiments – Simple assembly language programs 10.8051 Microcontroller based experiments – simple control applications.

2

BM2306 Microprocessors and Microcontrollers Lab CYCLE I
8085 Programming Introduction to 8085 8 bit Addition and Subtraction 1. 8 bit Multiplication and Division 2. 16 bit Addition and Subtraction 3. 16 bit Multiplication and Division 4. Largest and Smallest number in an array 5. Sorting in Ascending and Descending Order 6. Code Conversions using 8085
7. BCD Addition and Subtraction

8. Matrix Multiplication BIOS/DOS calls 9. BIOS/DOS calls – Display 10. BIOS/DOS calls – File Manipulation 11. BIOS/DOS calls – Disk information

3

CYCLE II 8086 Programming 1. Stepper motor interface 4 . Interfacing 8279 Keyboard/Display IC with 8085 8. String Manipulation – Find and replace a Word 3. String Manipulation – Copy a string 4. Interfacing 8255 PPI IC with 8085 6. String manipulation – Search a word 2. String Manipulation – Sorting Interfacing 5. Interfacing 8253 Timer IC with 8085 7. Sum of elements in an array 10. Code conversions 11. 16 bit addition 12. 8 bit multiplication 13. Interfacing 8251 Serial communication IC with 8085 8051 Programming 9.

temporary registers. 5 flags and arithmetic and logic circuits. The carry flag also serves as a borrow flag for subtraction. it is a negative number and if it is 0. it is a positive number. requires +5 V power supply and can operate with 3MHz single phase clock. the carry flag is set. • Parity flag After arithmetic – logic operation. If it is 1. the sign flag is set. the auxillary flag is set. If it has odd number of 1’s it is reset. INTRODUCTION TO 8085 INTEL 8085 is one of the most popular 8-bit microprocessor capable of addressing 64 KB of memory and its architecture is simple. This flag is used with signed numbers. ALU (Arithmetic Logic Unit): The 8085A has a simple 8-bit ALU and it works in coordination with the accumulator. They are as follows: • Sign flag After the execution of the arithmetic . The device has 40 pins.logic operation if the bit D7 of the result is 1. ALU has the capability of performing several mathematical and logical operations. • Carry flag If an arithmetic operation results in a carry. if the result has an even number of 1’s the flag is set. This flag is modified by the result in the accumulator as well as in other registers. The result is stored in the accumulator and the flags are set or reset according to the result of the operation.1. • Auxillary carry flag In an arithmetic operation when a carry is generated by digit D3 and passed on to D4. The temporary registers are used to hold the data during an arithmetic and logic operation. 5 . • Zero flag The zero flag is set if the ALU operation results in zero. The flags are affected by the arithmetic and logic operation.

Accumulator Accumulator is an 8-bit register that is part of the ALU. they can be combined as BC. DE and HL to perform 16-bit operation. called the Stack. D. H and L.Timing and control unit This unit synchronizes all the microprocessor operation with a clock and generates the control signals necessary for communication between the microprocessor and peripherals. The decoder decodes the instruction and establishes the sequence of events to follow. 6 . Instruction register and decoder The instruction register and decoder are part of the ALU. Stack pointer It is a 16-bit register which points to the memory location in R/W memory. Register array The 8085 has six general purpose registers to store 8-bit data during program execution. The result of an operation is stored in the accumulator. C. When an instruction is fetched from memory it is loaded in the instruction register. E. These registers are identified as B. Program counter The program counter is a 16-bit register used to point to the memory address of the next instruction to be executed. This register is used to store 8-bit data and to perform arithmetic and logic operation. The control signals RD (read) and WR (write) indicate the availability of data on the data bus.

7 .e. The address bus is unidirectional i. The data ranges from 00 – FF. It is capable of addressing 216 memory locations. the bits flow in one direction from microprocessor to the peripheral devices. Control bus – it consist of various single lines that carry synchronizing signals. They are address bus. • • Data bus – it is a group of 8 lines used for data flow and it is bidirectional.Communication lines 8085 microprocessor performs data transfer operations using three communication lines called buses.. The microprocessor uses such signals for timing purpose. • Address bus – it is a group of 16-bit lines generally identified as A0 – A15. data bus and control bus.

8 BIT DATA ADDITION AIM: To add two 8 bit numbers stored at consecutive memory locations. Initialize memory pointer to data location. Get the second number and add it to the accumulator. ALGORITHM: 1. Get the first number from memory in accumulator. 2. 8 . Store the answer at another memory location. 4. 3.2(A). RESULT: Thus the 8 bit numbers stored at 4500 &4501 are added and the result stored at 4502 & 4503.

FLOW CHART: START [C] 00H [HL] 4500H [A] [M] [HL][HL]+1 [A][A]+[M] NO Is there a Carry ?YES [C][C]+1 [HL][HL]+1 [M] [A] [HL][HL]+1 [M] [C] STOP 9 .

to memory. Increment HL reg. to point next memory Location.PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 OBSERVATION: INPUT 4500 4501 4502 4503 OUTPUT L1 MNEMONICS OPERAND MVI C. Initialize HL reg. to point next memory Location. Increment C reg. Increment HL reg. C 10 . Content. Add first number to acc. A H M. Transfer the result from acc. to point next memory Location. Jump to location if result does not yield carry. 00 LXI MOV INX ADD JNC H. 4500 A. to 4500 Transfer first data to accumulator Increment HL reg. Move carry to memory Stop the program INR INX MOV INX MOV HLT C H M. M H M L1 COMMENT Clear C reg.

is complemented and 01H is added to it (2’s complement). RESULT: Thus the 8 bit numbers stored at 4500 &4501 are subtracted and the result stored at 4502 & 4503. 8 BIT DATA SUBTRACTION AIM: To Subtract two 8 bit numbers stored at consecutive memory locations. A register is cleared and the content of that reg. Get the first number from memory in accumulator. is directly taken as the result. 2.2(B). 11 . ALGORITHM: 1. 3. is incremented in case there is a borrow. Get the second number and subtract from the accumulator. If there is no borrow the content of the acc. If the result yields a borrow. 5. Store the answer at next memory location. the content of the acc. Initialize memory pointer to data location. 4.

FLOW CHART: START [C] 00H [HL] 4500H [A] [M] [HL][HL]+1 [A][A]-[M] Is there a Borrow ? NO YES Complement [A] Add 01H to [A] [C][C]+1 [HL][HL]+1 [M] [A] [HL][HL]+1 [M] [C] STOP 12 .

Subtract first number from acc.PROGRAM: ADDRESS OPCODE LABEL 4100 START 4102 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 OBSERVATION: INPUT 4500 4501 4502 4503 OUTPUT MNEMONICS OPERAND MVI C. A H M. content Add 01H to content of acc. Jump to location if result does not yield borrow. Increment HL reg. Location. to 4500 Transfer first data to accumulator Increment HL reg. Transfer the result from acc. Content. M H M L1 COMMENT Clear C reg. Increment C reg. to point next mem. Complement the Acc. Move carry to mem. 4500 A. Initialize HL reg. Increment HL reg. Stop the program INR CMA ADI L1 INX MOV INX MOV HLT C 01H H M. Location. to point next mem. C 13 . Location. to point next mem. 00 LXI MOV INX SUB JNC H. to memory.

3. ALGORITHM: LOGIC: Multiplication can be done by repeated addition. Move multiplicand to a register. 2. 4. 8 BIT DATA MULTIPLICATION AIM: To multiply two 8 bit numbers stored at consecutive memory locations and store the result in memory. 14 . is stored in a memory location. 6. Clear the accumulator. 1.3(A). 8. Initialize memory pointer to data location. Add multiplicand to accumulator Decrement multiplier Repeat step 5 till multiplier comes to zero. 5. 7. The result. Move the multiplier to another register. which is in the accumulator. RESULT: Thus the 8-bit multiplication was done in 8085µp using repeated addition method.

FLOW CHART: START [HL] ←4500 B ←M [HL] ← [HL]+1 A ← 00 C ← 00 [A] ← [A] +[M] Is there any carry YES C ← C+1 B ← B-1 NO NO IS B=0 YES A 15 .

A [HL][HL]+1 [M] [A] [HL][HL]+1 [M] [C] STOP 16 .

Location. Stop the program NEXT INR DCR JNZ INX MOV INX MOV HLT C B L1 H M. to point next mem. C . to memory. to point next mem. 4500 B. to 4500 Transfer first data to reg. Clear the acc. Jump to NEXT if there is no carry Increment C reg Decrement B reg Jump to L1 if B is not zero. Transfer the result from C reg. Location. Transfer the result from acc. Increment HL reg. Location.PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 OBSERVATION: INPUT 4500 4501 4502 4503 17 OUTPUT L1 MNEMONICS LXI MOV INX MVI MVI ADD JNC OPERAND H. M H A. B Increment HL reg. to memory. to point next mem. 00H M NEXT COMMENT Initialize HL reg. A H M. 00H C. Clear C reg for carry Add multiplicand multiplier times. Increment HL reg.

RESULT: Thus an ALP was written for 8-bit division using repeated subtraction method and executed using 8085µ p kits 18 . Otherwise go to step 2. Count the number of times of subtraction which equals the quotient 4. Stop subtraction when the dividend is less than the divisor . 5. Load Divisor and Dividend 2. 1.The dividend now becomes the remainder. ALGORITHM: LOGIC: Division is done using the method Repeated subtraction. stop the program execution. Subtract divisor from dividend 3. 8 BIT DIVISION AIM: To divide two 8-bit numbers and store the result in memory.3(B).

FLOWCHART: START B ← 00 [HL] ←4500 A ←M [HL] ← [HL]+1 M ← A-M [B] ← [B] +1 IS A<0 YES A ← A+ M NO B ← B-1 [HL][HL]+1 [M] [A] [HL][HL]+1 [M] [B] STOP 19 .

Increment HL reg. Subtract divisor from dividend Increment B reg Jump to LOOP if result does not yield borrow Add divisor to acc. Stop the program ADDRESS 4502 4503 4502 4503 20 . Location. Location. Location. to point next mem.B COMMENTS Clear B reg for quotient Initialize HL reg. to point next mem. to memory. to 4500H Transfer dividend to acc. Transfer the quotient from B reg.PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 OBSERVATION: S. Transfer the remainder from acc.M H M B LOOP M B H M. Increment HL reg.00 H. to point next mem. to memory. Decrement B reg Increment HL reg.4500 A.A H M.NO 1 2 ADDRESS 4500 4501 4500 4501 INPUT DATA OUTPUT DATA LOOP OPCODE LABEL MNEMO NICS MVI LXI MOV INX SUB INR JNC ADD DCR INX MOV INX MOV HLT OPERA ND B.

4(A). 3. 21 . RESULT: Thus an ALP program for 16-bit addition was written and executed in 8085µp using special instructions. Initialize memory pointer to data location. Get the second number in memory and add it to the Register pair. 16 BIT DATA ADDITION AIM: To add two 16-bit numbers stored at consecutive memory locations. 4. Get the first number from memory and store in Register pair. Store the sum & carry in separate memory locations. ALGORITHM: 1. 2.

FLOW CHART: START [L] [H] [DE] [L] [H] [8050 H] [8051 H] [HL] [8052H] [8053H] [A]00H [HL][HL]+[DE] Is there a Carry? NO YES [A][A]+1 [8054][ L] [8055] [H] [8056] [A] STOP 22 .

PROGRAM: ADDRESS OPCODE LABEL 8000 START 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 LOOP MNEMONICS OPERAND LHLD 8050H XCHG LHLD MVI DAD JNC INR SHLD STA HLT COMMENT Load the augend in DE pair through HL pair. 00H D LOOP A 8054H 8056H Load the addend in HL pair. Otherwise increment reg. If there is no carry. go to the instruction labeled LOOP. OBSERVATION: INPUT DATA OUTPUT DATA ADDRESS 8050H 8051H 8052H 8053H ADDRESS 8054H 8055H 8056H 23 . A Store the content of HL Pair in 8054H(LSB of sum) Store the carry in 8056H through Acc. Initialize reg. A for carry Add the contents of HL Pair with that of DE pair. (MSB of sum). Stop the program. 8052H A.

3. 2. Initialize memory pointer to data location. RESULT: Thus an ALP program for subtracting two 16-bit numbers was written and executed. Get the subtrahend from memory and transfer it to register pair. Subtract subtrahend from minuend. 5. 16 BIT DATA SUBTRACTION AIM: To subtract two 16-bit numbers stored at consecutive memory locations. Get the minuend from memory and store it in another register pair. ALGORITHM: 1. 4.4(B). 24 . Store the difference and borrow in different memory locations.

FLOW CHART: START [L] [H] [DE] [L] [H] [8050 H] [8051 H] [HL] [8052H] [8053H] [HL][HL]-[DE] Is there a borrow? NO YES [C][C]+1 [8054][ L] [8055] [H] [8056] [C] STOP 25 .

to the memory location 8506H Stop the program execution. Move the content of Acc. Subtract the content of reg. H D H. go to the instruction labeled NEXT. H to Acc. H Store the content of HL pair in memory location 8504H. Move the content of reg. C Transfer the content of reg. Store the content of acc. Transfer content of acc. C to Acc.PROGRAM: ADDRESS OPCODE LABEL 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A OBSERVATION: ADDRESS 8050H 8051H 8052H 8053H START MNEMO NICS MVI LHLD XCHG LHLD MOV SUB MOV MOV SBB MOV SHLD JNC INR MOV STA HLT OPER COMMENTS AND C. D with that of Acc. 00 Initialize C reg. Subtract content of reg. Pair through HL reg. Increment reg. L to Acc. A 8054H NEXT C A. Pair. L E L. A A. If there is borrow. pair. E from that of acc. to reg. Load the minuend in HL reg. C 8056H NEXT INPUT DATA ADDRESS 8054H 8055H 8056H 26 . L Move the content of reg. to reg. 8050H Load the subtrahend in DE reg. OUTPUT DATA 8052H A.

RESULT: Thus the 16-bit multiplication was done in 8085µp using repeated addition method.5(A). 16 BIT MULTIPLICATION AIM: To multiply two 16 bit numbers and store the result in memory. Store the result in consecutive memory locations. Initialize a register to store partial product. Add multiplicand. multiplier times. 3. ALGORITHM: 1. 4. 2. Get the multiplier and multiplicand. 27 .

FLOWCHART: START L H [8050] [8051] SP HL L H [8052] [8053] DE HL HL0000 BC0000 HLHL+SP NO Is Carry flag set? YES BCBC+1 DEDE+1 NO Is Zero flag set? YES A 28 .

A [8054] [8055] L H [8056] [8057] C B STOP 29 .

C 8056 A.E D LOOP 8054 A. Move the content of reg. B 8057 Add SP with HL pair. B to Acc. in stack pointer through HL reg. B. 0000H Clear HL & DE reg. 0000H SP NEXT B D A. If there is no carry. C to Acc. E to Acc. If there is no zero. Store the content of Acc. pair SPHL LHLD XCHG LXI LXI 8052 Load the second No. pair.ADDRESS OPCODE LABEL MNEM 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A 801B 801C 801D 801E 801F 8020 8021 8022 8023 8024 OBSERVATION: INPUT START OPERAN COMMENTS O D N I C S LHLD 8050 Load the first No. in memory location 8056. pairs. Store the content of Acc. in memory location 8056. OR Acc. in HL reg. H. pair Decrement DE reg. Move the content of reg. go to the instruction labeled NEXT Increment BC reg. pair & Exchange with DE reg. Stop program execution LOOP DAD JNC INX DCX MOV ORA JNZ SHLD MOV STA MOV STA HLT OUTPUT NEXT 30 . go to instruction labeled LOOP Store the content of HL pair in memory locations 8054 & 8055. with D reg. pair. Move the content of reg.

BIT DIVISION AIM: To divide two 16-bit numbers and store the result in memory using 8085 mnemonics. Get the dividend and divisor. RESULT: Thus the 16-bit Division was done in 8085µp using repeated subtraction method. Initialize the register for quotient. 2. Count the number of subtraction which equals the quotient. 5.ADDRESS DATA ADDRESS DATA 8050 8051 8052 8053 8054 8055 8056 8057 5(B). 31 . Repeatedly subtract divisor from dividend till dividend becomes less than divisor. 16. ALGORITHM: 1. Store the result in memory. 3. 4.

AA.Borrow HA BCBC+ 1 Is Carry flag set ? NO YES A 32 .E LA AH AA.FLOWCHART: START L [8051] H [8052] HL DE L [8050] H [8051] BC 0000H A L.H.

A BCBC.1 HLHL+DE L[8054] H[8055] AC [8056] A AB [8057] A STOP 33 .

Subtract reg. in memory 8057. LOOP MOV SUB MOV MOV SBB MOV INX JNC DCX DAD SHLD MOV STA MOV STA HLT A. Subtract reg. Clear BC reg. L E L. Store the content of Acc. Add content of HL and DE reg. in HL reg. pairs. pair. A A. pair 8050 B. pair & Exchange with DE reg. pair. Move the content of Acc to H. B 8057 Move the content of reg. L to Acc. Increment reg. B to Acc. pair. Store the content of Acc. C 8056 A.PROGRAM: ADDRESS OPCODE LABEL 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A 801B 801C 801D 801E 801F 8020 8021 OBSERVATION: INPUT ADDRESS DATA 8050 8051 8052 8053 START MNEM ONICS LHLD XCHG LHLD LXI OPERA ND 8052 COMMENTS Load the first No. C to Acc. Move the content of Acc to L. in stack pointer through HL reg. Decrement BC reg. Stop the program execution. H D H. H Acc. E from that of Acc. Move the content of reg. Store the content of HL pair in 8054 & 8055. Pair BC If there is no carry. D from that of Acc. in memory 8056 Move the content of reg. Move the content of reg. OUTPUT ADDRESS DATA 8054 8055 8056 8057 34 . 0000H Load the second No. A B LOOP B D 8054 A. go to the location labeled LOOP.

2. Increment the memory pointer to point to the next element. 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. Store the result (accumulator content) in the specified memory location. Else continue. RESULT: Thus the largest number in the given array is found out.6(A). Compare the accumulator content with the memory content (next element). 3. 35 . 4. then move the memory content (largest element) to the accumulator. Decrement the counter by 1. 7. Place all the elements of an array in the consecutive memory locations. 5. LARGEST ELEMENT IN AN ARRAY AIM: To find the largest element in an array. 6. Repeat steps 5 to 8 until the counter reaches zero 10. 9. 8. If the accumulator content is smaller. Decrement the counter by 1. ALGORITHM: 1.

FLOW CHART: START [HL]  [8100H] [B]  04H [A]  [HL] [HL  [HL] + 1 NO IS [A] < [HL]? YES [A] [HL] [B]  [B]-1 IS [B] = 0? YES [8105]  [A] STOP NO 36 .

M H M LOOP A. Stop the program LOOP 37 . to point next memory location Compare M & A If A is greater than M then go to loop Transfer data from M to A reg Decrement B reg If B is not Zero go to loop1 Store the result in a memory location. of comparisons(n-1) Transfer first data to acc. Increment HL reg.PROGRAM: ADDRE SS 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 OBSERVATION: INPUT ADDRESS DATA 8100 8101 8102 8103 8104 OUTPUT ADDRESS DATA 8105 OPCO DE LABEL MNEM ONICS LXI MVI LOOP1 MOV INX CMP JNC MOV DCR JNZ STA HLT OPER AND H. to 8100H Initialize B reg with no.M B LOOP1 8105 COMMENTS Initialize HL reg.8100 B.04 A.

then move the memory content (largest element) to the accumulator. Fetch the first element from the memory location and load it in the accumulator. Store the result (accumulator content) in the specified memory location. ALGORITHM: 1. 5. Decrement the counter by 1. 38 . 6. Increment the memory pointer to point to the next element. 9. SMALLEST ELEMENT IN AN ARRAY AIM: To find the smallest element in an array. Else continue. 4. RESULT: Thus the smallest number in the given array is found out. 3. 2. Repeat steps 5 to 8 until the counter reaches zero 10. Initialize a counter (register) with the total number of elements in an array. Compare the accumulator content with the memory content (next element).6(B). If the accumulator content is smaller. Decrement the counter by 1. Place all the elements of an array in the consecutive memory locations. 8. 7.

FLOW CHART: START

[HL]  [8100H] [B]  04H [A]  [HL] [HL  [HL] + 1

YES

IS [A] < [HL]? NO [A] [HL] [B]  [B]-1

IS [B] = 0? YES [8105]  [A] STOP

NO

39

PROGRAM: ADDRE SS 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 OBSERVATION: INPUT ADDRESS DATA 8100 8101 8102 8103 8104 OUTPUT ADDRESS DATA 8105 OPCO DE LABEL MNEM ONICS LXI MVI LOOP1 MOV INX CMP JC MOV DCR JNZ STA HLT OPER AND H,8100 B,04 A,M H M LOOP A,M B LOOP1 8105 COMMENTS Initialize HL reg. to 8100H Initialize B reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg. to point next memory location Compare M & A If A is lesser than M then go to loop Transfer data from M to A reg Decrement B reg If B is not Zero go to loop1 Store the result in a memory location. Stop the program

LOOP

40

7(A).ASCENDING ORDER
AIM: To sort the given number in the ascending order using 8085 microprocessor. ALGORITHM: 1. Get the numbers to be sorted from the memory locations. 2. Compare the first two numbers and if the first number is larger than second then I interchange the number. 3. If the first number is smaller, go to step 4 4. Repeat steps 2 and 3 until the numbers are in required order RESULT: Thus the ascending order program is executed and thus the numbers are arranged in ascending order.

41

1 [HL]  [D] [HL]  [HL] + 1 [C]  [C] – 01 H A 42 .FLOWCHART: START [B]  04H [HL]  [8100H] [C]  04H [A]  [HL] [HL  [HL] + 1 YES IS [A] < [HL]? NO [D] [HL] [HL]  [A] [HL]  [HL] .

A IS [C] = 0? YES [B]  [B]-1 NO IS [B] = 0? YES STOP NO PROGRAM: 43 .

M H M LOOP1 D.D H C LOOP2 B LOOP3 COMMENTS Initialize B reg with number of comparisons (n-1) Initialize HL reg.A H M.04 A.ADDR E SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A OPCO DE LABEL MNEM ONICS MVI OPER AND B. to 8100H Initialize C reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg.M M. to point next memory location Compare M & A If A is less than M then go to loop1 Transfer data from M to D reg Transfer data from acc to M Decrement HL pair Transfer data from D to M Increment HL pair Decrement C reg If C is not zero go to loop2 Decrement B reg If B is not Zero go to loop3 Stop the program LOOP 3 LXI MVI LOOP2 MOV INX CMP JC MOV MOV DCX MOV INX DCR JNZ DCR JNZ HLT LOOP1 OBSERVATION: INPUT MEMORY LOCATION 8100 8101 8102 8103 8104 DATA MEMORY LOCATION 8100 8101 8102 8103 8104 OUTPUT DATA 44 .04 H.8100 C.

DESCENDING ORDER AIM: To sort the given number in the descending order using 8085 microprocessor. If the first number is larger. 3.7(B). Repeat steps 2 and 3 until the numbers are in required order RESULT: Thus the descending order program is executed and thus the numbers are arranged in descending order. 2. Get the numbers to be sorted from the memory locations. 45 . ALGORITHM: 1. go to step 4 4. Compare the first two numbers and if the first number is smaller than second then I interchange the number.

1 [HL]  [D] [HL]  [HL] + 1 [C]  [C] – 01 H A 46 .FLOWCHART: START [B]  04H [HL]  [8100H] [C]  04H [A]  [HL] [HL  [HL] + 1 NO IS [A] < [HL]? YES [D] [HL] [HL]  [A] [HL]  [HL] .

A IS [C] = 0? YES [B]  [B]-1 NO IS [B] = 0? YES STOP NO PROGRAM: 47 .

ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A OPCO DE LABEL MNEM ONICS MVI LXI MVI OPER AND B. of comparisons(n-1) Transfer first data to acc.8100 C. CODE CONVERSION –DECIMAL TO HEX 48 . to 8100H Initialize C reg with no.D H C LOOP2 B LOOP3 COMMENTS Initialize B reg with number of comparisons (n-1) Initialize HL reg.04 H. to point next memory location Compare M & A If A is greater than M then go to loop1 Transfer data from M to D reg Transfer data from acc to M Decrement HL pair Transfer data from D to M Increment HL pair Decrement C reg If C is not zero go to loop2 Decrement B reg If B is not Zero go to loop3 Stop the program LOOP 3 LOOP2 MOV INX CMP JNC MOV MOV DCX MOV INX DCR JNZ DCR JNZ HLT LOOP1 OBSERVATION: INPUT MEMORY LOCATION 8100 8101 8102 8103 8104 DATA MEMORY LOCATION 8100 8101 8102 8103 8104 OUTPUT DATA 8(A).M H M LOOP1 D.A H M.04 A.M M. Increment HL reg.

2. Initialize the memory location to the data pointer. 5. Store the resultant in memory location. 4. Compare the given decimal number with accumulator value. RESULT: Thus an ALP program for conversion of decimal to hexadecimal was written and executed. Increment B register. ALGORITHM: 1. When both matches.AIM: To convert a given decimal number to hexadecimal. 6. 49 . Increment accumulator by 1 and adjust it to decimal every time. 3. the equivalent hexadecimal value is in B register.

FLOWCHART: START HL 4500H A 00 B B 00H B+1 A A +1 Decimal adjust accumulator NO Is A=M? YES A B 8101 A Stop 50 .

Stop the program 51 .8100 A..00 B. Store the result in a memory location. Increment B reg.B 8101 COMMENTS Initialize HL reg.PROGRAM: ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 RESULT: INPUT ADDRESS DATA 8100 OUTPUT ADDRESS DATA 8101 OPCO DE LABEL MNEM ONICS LXI MVI MVI LOOP INR ADI DAA CMP JNZ MOV STA HLT OPER AND H.00 B 01 M LOOP A. then go to LOOP Transfer B reg to acc. Initialize B register. to 8100H Initialize A register. Increment A reg Decimal Adjust Accumulator Compare M & A If acc and given number are not equal.

3. 5.8(B). Increment accumulator by 1 and adjust it to decimal every time. 6. 2. Initialize the memory location to the data pointer. the equivalent decimal value is in A register. CODE CONVERSION –HEXADECIMAL TO DECIMAL AIM: To convert a given hexadecimal number to decimal. RESULT: Thus an ALP program for conversion of hexadecimal to decimal was written and executed. Compare the given hexadecimal number with B register value. When both match. Increment B register. 4. ALGORITHM: 1. 52 . Store the resultant in memory location.

A B. A C YES A Stop 53 . Is A=M? NO 8101 8102 A.FLOWCHART: HL START 8100H A 00 B C B 00H 00H B+1 A A +1 Decimal adjust accumulator Is there carry? C C+1 D A.

C 8102 COMMENTS Initialize HL reg. Initialize B register.B M A.D LOOP 8101 A. Increment B reg. Increment A reg Decimal Adjust Accumulator If there is no carry go to NEXT.00 B 01 NEXT C D. Initialize C register for carry.00 C. Increment c register. then go to LOOP Store the result in a memory location. Transfer A to D Transfer B to A Compare M & A Transfer D to A If acc and given number are not equal.00 B.8100 A.PROGRAM: ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A 801B 801C 801D 801E 801F RESULT: INPUT ADDRESS 8100 DATA OUTPUT ADDRESS 8101 8102 DATA OPCO DE LABEL MNEM ONICS LXI MVI MVI MVI LOOP INR ADI DAA JNC INR MOV MOV CMP MOV JNZ STA MOV STA HLT OPER AND H. Transfer C to A Store the carry in another memory location. Stop the program NEXT 54 .A A. to 8100H Initialize A register.

ALGORITHM: 1. RESULT: Thus the 8 bit BCD numbers stored at 4500 &4501 are added and the result stored at 4502 & 4503. 3. 55 . Initialize memory pointer to data location. Get the first number from memory in accumulator. 5.9(A) BCD ADDITION AIM: To add two 8 bit BCD numbers stored at consecutive memory locations. Get the second number and add it to the accumulator Adjust the accumulator value to the proper BCD value using DAA instruction. 2. Store the answer at another memory location. 4.

FLOW CHART: START [C] 00H [HL] 4500H [A] [M] [HL][HL]+1 [A][A]+[M] Decimal Adjust Accumulator NO YES Is there a Carry ? [C][C]+1 [HL][HL]+1 [M] [A] [HL][HL]+1 [M] [C] STOP 56 .

Add first number to acc. to 4500 Transfer first data to accumulator Increment HL reg. to memory. M H M COMMENT Clear C reg. C 57 . 00 LXI MOV INX ADD DAA JNC L1 H. Content. Increment C reg. Decimal adjust accumulator Jump to location if result does not yield carry. to point next memory Location. Increment HL reg. Transfer the result from acc. Increment HL reg. Initialize HL reg. to point next memory Location. Move carry to memory Stop the program INR INX MOV INX MOV HLT C H M.PROGRAM: ADDRESS OPCODE LABEL 4100 START 4103 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 OBSERVATION: INPUT 4500 4501 4502 4503 OUTPUT L1 MNEMONICS OPERAND MVI C. 4500 A. to point next memory Location. A H M.

Load the minuend and subtrahend in two registers. 3. Store the content of the accumulator (result)and borrow register in the specified memory location RESULT: Thus the 8 bit BCD numbers stored at 4500 &4501 are subtracted and the result stored at 4502 & 4503. If there is a carry ignore it. 4. BCD SUBTRACTION AIM: To Subtract two 8 bit BCD numbers stored at consecutive memory locations. increment the carry register by 1 7. 6. 2. 5. Add the result with the minuend which yields the result. Initialize Borrow register to 0. Take the 100’s complement of the subtrahend. Adjust the accumulator value to the proper BCD value using DAA instruction. 58 . ALGORITHM: 1. If there is no carry.9(B).

FLOW CHART: START [D] 00H HL 4500 B M HL HL+ 1 C M A 99 [A] [A] – [C] [A] [A]+1 [A][A]+[B] DAA Is there a Carry ? YES NO [D][D]+1 [HL][HL]+1 [4502] A [4503] D STOP 59 .

Transfer D register content to memory.PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 OBSERVATION: INPUT 4500 4501 4502 4503 OUTPUT LOOP INR INX MOV INX MOV HLT D H M. M A. to B reg. to 4500 Transfer first data to accumulator Increment HL reg. Move second no. to point next mem. Increment HL register pair Move the Acc.content to the memory location Increment HL reg. 4500 B. Move 99 to the Accumulator Subtract [C] from acc. 00 Clear D reg. D Increment D reg. Stop the program MNEMONICS OPERAND COMMENT MVI D.A H M. 99 C A B LOOP Initialize HL reg. Location. Content. M H C. Increment A register Add [B] with [A] Adjust Accumulator value for Decimal digits Jump on carry to loop 60 . Location. to point next mem. LXI MOV INX MOV MVI SUB INR ADD DAA JC H.

4702 & 4703.10. 3. Call a subroutine for performing the multiplication of one element of a matrix with the other element of the other matrix. 2. ALGORITHM: 1. Call a subroutine to store the resultant values in a separate matrix. Load the 2 input matrices in the separate address and initialize the HL and the DE register pair with the starting address respectively. RESULT: Thus the 2 x 2 matrix multiplication is performed and the result is stored at 4700. 2 X 2 MATRIX MULTIPLICATION AIM: To perform the 2 x 2 matrix multiplication.4701 . 61 .

DE DE+1 Call subroutine MUL A C A A+B Is A=04H ? YES NO Increment HL reg. pair STOP Call subroutine STORE HL HL-1 D DE DE-1. Call subroutine MUL B B A B A A 62 Call subroutine MUL . DE DE+1 Call subroutine MUL DE 8600H Call subroutine MUL A B A A+B Call subroutine STORE HL HL+1 D DE DE+1.FLOW CHART: START C HL 00H 8500H A HL HL+1 D DE DE+1.

1 B 87 [A][[BC]] C C+ 1 Is H=0 ? YES RET NO [D][D]+1 H H.MUL STORE [A] [[DE]] D A H M H H.1 NO Is H=0 ? YES [H]85. [D]86 RET 63 .

Initialize HL reg.A H D D MUL B STORE A. to 4500 Load DE register pair Call subroutine MUL Move A to B reg.C Transfer A reg content to B reg.A H D D MUL B STORE H D MUL COMMENT Clear C reg.PROGRAM: ADDRESS OPCOD LABEL E 8100 8101 8102 8103 8104 8105 LOOP2 8106 8107 8108 8109 810A 810B 810C 810D 810E 810F 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 811A 811B 811C 811D 811E 811F 8120 8121 8122 8123 8124 8125 8126 MOV INX INX INX CALL ADD CALL MOV B. 8600 MUL B. 00 H. 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 content to Acc. Increment HL register pair . 8500 D. 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 64 . MNEM ONICS MVI LXI LXI CALL MOV INX INX INX CALL ADD CALL DCX DCX CALL OPERAN D C.

8127 8128 8129 812A 812B 812C 812D 812E 812F 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 813A 813B 813C 813D 813E 813F 8140 8141 8142 8143 8144 8145 8146 CPI JZ INX JMP LOOP1 MUL HLT LDAX MOV MOV DCR JZ LOOP4 ADD DCR JNZ MVI MVI STORE RET MVI STAX INR RET 04 LOOP1 H LOOP2 Compare with 04 to check whether all elements are multiplied. go to loop1 Increment HL register Pair.M H LOOP3 D H LOOP4 H.87 B C LOOP3 OBSERVATION: 4500 4501 4502 4503 INPUT 4600 4601 4602 4603 OUTPUT 4700 4701 4702 4703 65 .86 B. Transfer from memory to H register. Return to main program. Load A from memory location pointed by BC pair. Transfer acc content to D register. Decrement H register. Increment C register. D D. Transfer 85 TO H register. Return to main program. Transfer 86 to D register. Transfer 87 to B register. If completed. Jump to LOOP2. Load acc from the memory location pointed by DE pair.A H.85 D. If H is not zero go to LOOP4. Stop the program. Add Acc with D reg Decrement H register. If H is zero go to LOOP3.

3. “GOOD MORNING” . OFFSET MSG INT 21H MOV AH.11. Initialize the data segment and the message to be displayed. DATA MOV DS. 4CH INT 21H CODE ENDS END START RESULT: A message is displayed on the CRT screen of a microcomputer using DOS calls 66 . DS: DATA DATA SEGMENT MSG DB 0DH. 09H MOV DX. Set function value for display. 2. “$” DATA ENDS CODE SEGMENT START: MOV AX. AX MOV AH. BIOS/DOS CALLS – DISPLAY AIM: To display a message on the CRT screen of a microcomputer using DOS calls. OAH. PROGRAM: ASSUME CS: CODE. ODH. Point to the message and run the interrupt to display the message in the CRT. 0AH. ALGORITHM: 1.

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

OAH. ODH. 4CH INT 21H CODE ENDS END START RESULT: The disk information is displayed. 36H MOV DX. 0AH. 2. 68 . DS: DATA DATA SEGMENT MSG DB 0DH. DATA MOV DS. Initialize the data segment and the message to be displayed. Set function value for disk information. OFFSET MSG INT 21H MOV AH. Point to the message and run the interrupt to display the message in the CRT. 3. “$” DATA ENDS CODE SEGMENT START: MOV AX. ALGORITHM: 1. BIOS/DOS CALLS – DISK INFORMATION AIM: To display the disk information. “GOOD MORNING” . AX MOV AH.13. PROGRAM: ASSUME CS: CODE.

ALGORITHM: 1. BM2306-Microprocessor and Microcontroller Lab Lab Manual 1. Load the source and destination index register with starting and the ending address respectively. Chennai – 602 105 Dept OF BIO-MEDICAL ENGG. Otherwise. display 01 in destination address. display 00 in destination address. Use the string manipulation instruction SCASW with the prefix REP to search a word from string. 3.8086 STRING MANIPULATION – SEARCH A WORD AIM: To search a word from a string. Clear the direction flag for auto incrementing mode of transfer. 4. If a match is found (z=1). 5. Initialize the counter with the total number of words to be copied. 69 . 2.RAJALAKSHMI ENGINEERING COLLEGE Thandalam. RESULT: A word is searched and the count of number of appearances is displayed.

COUNT MOV AX. AX MOV AX. DEST MOV CX. AX 70 . 01 LOOP MOV [DI]. 19H. OFFSET LIST MOV DI. 02H DEST EQU 3000H COUNT EQU 05H DATA ENDS CODE SEGMENT START: MOV AX. DATA MOV DS. 00 CLD REP SCASW JZ LOOP MOV AX. 15H MOV SI. 15H.PROGRAM: ASSUME CS: CODE. DS: DATA DATA SEGMENT LIST DW 53H.

MOV AH. 02H OUTPUT: 3000 01 71 . 15H. 19H. 4CH INT 21H CODE ENDS END START INPUT: LIST: 53H.

8086 STRING MANIPULATION –FIND AND REPLACE A WORD AIM: To find and replace a word from a string. Clear the direction flag for auto incrementing mode of transfer. 5. Otherwise. 72 . ALGORITHM: 1. RESULT: A word is found and replaced from a string. Use the string manipulation instruction SCASW with the prefix REP to search a word from string. If a match is found (z=1). replace the old word with the current word in destination address. Initialize the counter with the total number of words to be copied.2. Load the source and destination index register with starting and the ending address respectively. 2. stop. 3. 4.

02H REPLACE EQU 30H COUNT EQU 05H DATA ENDS CODE SEGMENT START: MOV AX. LABEL LIST MOV [DI]. REPLACE LOOP CODE ENDS END START INPUT: LIST: 53H. 19H.PROGRAM: ASSUME CS: CODE. 15H. DATA MOV DS. 15H MOV SI. 4CH INT 21H 73 . 15H. 00 CLD REP SCASW JNZ LOOP MOV DI. OFFSET LIST MOV CX. 02H MOV AH. DS: DATA DATA SEGMENT LIST DW 53H. AX MOV AX. COUNT MOV AX. 19H.

Use the string manipulation instruction MOVSW with the prefix REP to copy a string from source to destination. 8. 02H 3. ALGORITHM: 6. 8086 STRING MANIPULATION – COPY A STRING AIM: To copy a string of data words from one location to the other. 9. 7. RESULT: A string of data words is copied from one location to other. 19H. Load the source and destination index register with starting and the ending address respectively.OUTPUT: LIST: 53H. Initialize the counter with the total number of words to be copied. Clear the direction flag for auto incrementing mode of transfer. 74 . 30H.

DS: DATA DATA SEGMENT SOURCE EQU 2000H DEST EQU 3000H COUNT EQU 05H DATA ENDS CODE SEGMENT START: MOV AX. DEST MOV CX. COUNT CLD REP MOVSW MOV AH. DATA MOV DS. 4CH INT 21H CODE ENDS END START INPUT: 2000 2001 48 84 OUTPUT: 3000 3001 48 84 75 . SOURCE MOV DI. AX MOV SI. AX MOV ES.PROGRAM: ASSUME CS: CODE.

2002 2003 2004 67 90 21 3002 3003 3004 67 90 21 76 .

swap the content of accumulator with the content of memory location. o Load the first element in the accumulator o Do the following steps until the counter C reaches 0.4. Initialize two counters DX & CX with the total number of elements in the array. 77 . RESULT: A group of data bytes are arranged in ascending order. Increment the memory pointer to point to the next element. 3. Compare the accumulator content with the next element present in the next memory location. Decrement the counter C by 1. 1. Stop the execution.8086 STRING MANIPULATION – SORTING AIM: To sort a group of data bytes. otherwise. ALGORITHM: • • • Place all the elements of an array named list (in the consecutive memory locations). 2. If the accumulator content is smaller go to next step. Do the following steps until the counter B reaches 0.

PROGRAM: ASSUME CS: CODE. COUNT-1 LOOP2: AGAIN: MOV CX. 25H. DS: DATA DATA SEGMENT LIST DW 53H. AX XCHG [SI]. 4CH INT 21H CODE ENDS END START INPUT: 78 . [SI+2] JC LOOP1 XCHG [SI +2]. DATA MOV DS. OFFSET LIST MOV AX. 19H. DX MOV SI. AX MOV DX. [SI] CMP AX. 02 LOOP AGAIN DEC DX JNZ LOOP2 MOV AH. 02H COUNT EQU 04H DATA ENDS CODE SEGMENT START: MOV AX. AX LOOP1: ADD SI.

19H. 53H 79 .LIST: 53H. 19H. 25H. 02H OUTPUT: LIST: 02H. 25H.

VXT parallel bus 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. DC regulated power supply. APPARATUS REQUIRED: 8085 µp kit. 8255Interface board. In this mode all the ports can be configured either as input or output port.mode1 and BSR mode.4. Let us initialize port A as input port and port B as output port 80 . INTERFACING 8255 WITH 8085 AIM: To interface programmable peripheral interface 8255 with 8085 and study its characteristics in mode0.

B4 Initialize port A as Input port in 4101 mode 1. MODE1 STROBED I/O MODE: In this mode.5 4109 410A SIM 81 .PROGRAM: ADDRESS OPCODES LABEL MNEMONICS OPERAND COMMENTS 4100 START: MVI A.08 Enable RST5. port A and port B are used as data ports and port C is used as control signals for strobed I/O data transfer. Let us initialize port A as input port in mode1 MAIN PROGRAM: ADDRESS OPCODES LABEL MNEMONICS OPERAND COMMENTS 4100 START: MVI A. 4102 OUT C6 Send Mode Control word 4103 4104 IN C0 Read from Port A 4105 4106 OUT C2 Display the data in port B 4107 4108 STA 4200 Store the data read from Port A 4109 in 4200 410A 410B HLT Stop the program. 90 Initialize port A as Input and Port 4101 B as output.09 Set the PC4 bit for INTE A 4105 4106 OUT C6 Display the data in port B 4107 EI 4108 MVI A. 4102 OUT C6 Send Mode Control word 4103 4104 MVI A.

Sub program: ADDRESS OPCODES LABEL MNEMONICS OPERAND COMMENTS 405E JMP 4200 Go to 4200 405F 4060 BSR MODE (Bit Set Reset mode) 82 . ADDRESS OPCODES LABEL MNEMONICS OPERAND COMMENTS 4200 START: IN C0 Read from port A 4201 4202 STA 4500 Store in 4500. 4203 4204 4205 HLT Stop the program.410B ISR (Interrupt Service Routine) EI HLT Stop the program.

PROGRAM: ADDRESS OPCODES LABEL MNEMONICS 4100 START: MVI 4101 4102 OUT 4103 4104 MVI 4105 4106 OUT 4107 OPERAND COMMENTS A. 01 Set PC0 C6 A.07 C6 Send Mode Control word Set PC3 Send Mode Control word 83 . Let us set PC0 and PC3 bits using this mode.Any lines of port c can be set or reset individually without affecting other lines using this mode.

4109 RESULT: HLT Stop the program. APPARATUS REQUIRED: 8085 µp kit. DC regulated power supply.mode1 and BSR mode is studied. until reloaded again. After loading the counter. 05 OUT C8 MVI A. Thus 8255 is interfaced and its characteristics in mode0. CRO. Let us set the channel 0 in mode 0. 30 OUT CE MVI A. INTERFACING 8253 TIMER WITH 8085 Interfacing 8253 Programmable Interval Timer with 8085 µp AIM: To interface 8253 Interface board to 8085 µp and verify the operation of 8253in six different modes. the output will be remaining low while counting and on terminal count. VXT parallel bus. 6. Connect the CLK 0 to the debounce circuit by changing the jumper J3 and then execute the following program. the output will become high. Mode 0 – Interrupt on terminal count: The output will be initially low after mode set operations. Program: Address Opcodes 4100 4102 4104 4106 4108 410A 410C Label Mnemonic Operands START: MVI A. 8253 Interface board. 00 OUT C8 HLT Comments Channel 0 in mode 0 Send Mode Control word LSB of count Write count to register MSB of count Write count to register 84 .

Address Opcodes 4100 4102 4104 4106 4108 410A 410C 4100 Label Mnemonic Operands START: MVI A. Connect the CLK1 to PCLK. 05 OUT C8 MVI A. After giving six clock pulses. 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. 00 OUT C8 OUT D0 HLT 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. hence the output will remain low for the full count. the output goes HIGH. 0A LSB of count 4106 D3 CA OUT CA Write count to register 4108 3E 00 MVI A. The output will go high on the terminal count.It is observed in CRO that the output of Channel 0 is initially LOW. after any rising edge of the gate input. 00 MSB of count 410A D3 CA OUT CA Write count to register 410C 76 HLT In CRO observe simultaneously the input clock to channel 1 and the output at Out1. 74 Channel 1 in mode 2 4102 D3 CE OUT CE Send Mode Control word 4104 3E 0A MVI A. OUT 0 goes low. Example: The following program initializes channel 0 of 8253 in Mode 1 and also initiates triggering of Gate 0. Address Opcodes Label Mnemonic Operands Comments 4100 3E 74 START: MVI A. the output will remain low following the rising edge of the gate input. It is retriggerable. as clock pulse after triggering the goes back to high level after 5 clock pulses. Mode 1 – Programmable ONE-SHOT: After loading the counter. Execute the program. give clock pulses through the debounce logic and verify using CRO. Example: Using Mode 2. The period from one output pulse to the next equals the number of input counts in the count register. 32 OUT CE MVI A. Let us divide the clock present at Channel 1 by 10. Mode 3 Square wave generator: 85 . The output will be low for one period of the input clock.

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

7. the initially HIGH output goes LOW. After giving Six clock pulses. Address Opcodes 4100 4102 4104 4106 4108 410A 410C Label Mnemonic Operands START: MVI A. INTERFACING 8279 WITH 8085 8. The counter is retriggerable. 05 OUT C8 MVI A.410E 4110 4112 4114 4116 4118 OUT MVI OUT MVI OUT HLT CE A. Execute the program. 98 CC A. 1A OUT CE MVI A. Example: The program that follows initializes channel 0 in mode 5 and also triggers Gate 0. you can see using CRO. INTERFACING 8251 WITH 8085 87 . 3A CC Send Mode control Word LSB of Count Write Count to register 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. Connect CLK 0 to debounce circuit. The output ( OUT 0 pin) goes high on the next clock pulse. 00 OUT D0 HLT Comments Channel 0 in mode 5 Send Mode Control word LSB of count Write count to register MSB of count Trigger Gate 0 Result: Thus the 8253 has been interfaced to 8085 µp and six different modes of 8253 have been studied.

SUM OF ELEMENTS IN AN ARRAY AIM: To find the sum of elements in an array.9. 8051 . ALGORITHM: 88 .

continue Decrement the counter and if it reaches 0. Load the total number of elements in a separate register as a counter. 2. 6. The sum of elements in an array is calculated.1. 4. Clear the accumulator. RESULT: Load the array in the consecutive memory location and initialize the memory pointer with the starting address. 5. pointer. Check for carry. PROGRAM: 89 . if exist. otherwise. Load the other register with the value of the memory Add the register with the accumulator. 3. increment the carry register by 1. 7. Otherwise increment the memory pointer by 1 and go to step 4. stop.

#4200 MOVX A. R1 MOVX @DPTR. #00 MOV R1. A MOV B. A HLT: SJMP HLT INPUT 4200 4201 4201 4202 4203 04 05 06 03 02 OUTPUT: 4500 4501 0F 00 90 . A JNC LOOP INC R1 LOOP: INC DPTR DJNZ R0. A INC DPTR MOV A. B INC DPTR LOOP2: CLR C MOVX A. B MOV B. LOOP2 MOV DPTR. @DPTR ADD A. @DPTR MOV R0. #4500 MOV A. B MOVX @DPTR.MOV DPTR.

4. If the number is less than 100 (64H). Store the result and carry in the specified memory location. If the number is less than 10 (0AH). ALGORITHM: 1. go to next step. 3. otherwise. subtract 10 (0AH) repeatedly until the remainder is less than 10 (0AH). RESULT The given hexadecimal number is converted into decimal number. 2. Have the count(100’s value) in separate register which is the carry. Load the number to be converted into the accumulator.8051 .HEXADECIMAL TO DECIMAL CONVERSION AIM: To perform hexadecimal to decimal conversion. Multiply the ten’s value by 10 and add it with the units. The accumulator now has the units. 5. subtract 100 (64H) repeatedly until the remainder is less than 100 (64H). 6.10(A). Have the count(ten’s value) in separate register. 91 . otherwise. go to next step.

#4501 MOVX @DPTR. @DPTR MOV B. A INC DPTR MOV A. B MOV B. #64 DIV A. A MOV A. #4500 MOVX A. B MOV DPTR. #0A DIV A.PROGRAM: MOV DPTR. B INC DPTR MOVX @DPTR. B MOVX @DPTR. A HLT: INPUT 4500 D7 SJMP HLT OUTPUT: 4501 4502 15 02 92 .

Store the result in the specified memory location.DECIMAL TO HEXADECIMAL CONVERSION AIM: To perform decimal to hexadecimal conversion ALGORITHM: Load the number to be converted in the accumulator. A INC DPTR MOVX A. @DPTR ADD A. 4. A HLT: INPUT 4500 23 SJMP HLT OUTPUT 4501 17 1. 3. PROGRAM: MOV DPTR. #0A MUL A. 2.8051 . RESULT: The given decimal number is converted to hexadecimal number. Multiply the higher order digit by 10 and add it with the lower order digit.10(B). @DPTR MOV B. Separate the higher order digit from lower order. B INC DPTR MOVX @DPTR. #4500 MOVX A. 93 . B MOV B.

13. STEPPER MOTOR INTERFACING WITH 8051
AIM: To interface a stepper motor with 8051 microcontroller and operate it. THEORY: A motor in which the rotor is able to assume only discrete stationary angular position is a stepper motor. The rotary motion occurs in a step-wise manner from one equilibrium position to the next. Stepper Motors are used very wisely in position control systems like printers, disk drives, process control machine tools, etc. The basic two-phase stepper motor consists of two pairs of stator poles. Each of the four poles has its own winding. The excitation of any one winding generates a North Pole. A South Pole gets induced at the diametrically opposite side. The rotor magnetic system has two end faces. It is a permanent magnet with one face as South Pole and the other as North Pole. The Stepper Motor windings A1, A2, B1, B2 are cyclically excited with a DC current to run the motor in clockwise direction. By reversing the phase sequence as A1, B2, A2, B1, anticlockwise stepping can be obtained. 2-PHASE SWITCHING SCHEME: In this scheme, any two adjacent stator windings are energized. The switching scheme is shown in the table given below. This scheme produces more torque.
STEP A1 ANTICLOCKWISE A2 B1 B2 DATA STEP A1 CLOCKWISE A2 B1 B2 DATA

1 2 3 4

1 0 0 1

0 1 1 0

0 0 1 1

1 1 0 0

9h 5h 6h Ah

1 2 3 4

1 0 0 1

0 1 1 0

1 1 0 0

0 0 1 1

Ah 6h 5h 9h

ADDRESS DECODING LOGIC: The 74138 chip is used for generating the address decoding logic to generate the device select pulses, CS1 & CS2 for selecting the IC 74175.The 74175 latches the data bus to the stepper motor driving circuitry. Stepper Motor requires logic signals of relatively high power. Therefore, the interface circuitry that generates the driving pulses use silicon darlington pair transistors. The inputs for the interface circuit are TTL pulses generated under software control using

94

the Microcontroller Kit. The TTL levels of pulse sequence from the data bus is translated to high voltage output pulses using a buffer 7407 with open collector.

95

PROGRAM : Address 4100
OPCODES

Label

Comments

START:

ORG MOV

4100h DPTR, #TABLE

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

LOOP:

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

R0, #04 A, @DPTR DPH DPL DPTR, #0FFC0h @DPTR, A R4, #0FFh R5, #0FFh R5, DELAY1 R4, DELAY DPL DPH DPTR R0, LOOP START

DELAY : DELAY 1:

Load the start address of switching scheme data TABLE into Data Pointer (DPTR) Load the count in R0 Load the number in TABLE into A Push DPTR value to Stack Load the Motor port address into DPTR Send the value in A to stepper Motor port address Delay loop to cause a specific amount of time delay before next data item is sent to the Motor POP back DPTR value from Stack Increment DPTR to point to next item in the table Decrement R0, if not zero repeat the loop Short jump to Start of the program to make the motor rotate continuously Values as per twophase switching scheme

411F

TABLE:

DB

09 05 06 0Ah

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. RESULT: 96

97 .Thus a stepper motor was interfaced with 8051 and run in forward and reverse directions at various speeds.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.