2356
2356
8-bit Microprocessor 1. Simple arithmetic operations: Multi precision addition / subtraction / multiplication / division. 2. Programming with control instructions: Increment / Decrement, Ascending / Descending order, Maximum / Minimum of numbers,Rotate instructions Hex / ASCII / BCD code conversions. 3. A/D Interfacing. 4. D/A Interfacing. 5. Traffic light controller interfacing 6. Steeper Motor Interfacing 7. Simple experiments using 8251, 8279, 8254. 16-bit Microprocessor 8. Simple arithmetic operations: Multi Precision addition / substraction/multiplication / division. 8-bit Microcontroller 9. Demonstration of basic instructions with 8051 Micro controller execution, including: a. Conditional jumps, looping b. Calling subroutines. c. Stack parameter testing 10. Interfacing Keyboard and Display 11. Stepper motor Interfacing\ a. D/A Interfacing b. Traffic light controller Interfacing c. 8051 based Serial Port Communication.
I (a). ADDITION OF TWO 8-BIT NUMBERS AIM: To perform 8-bit addition operation with carry using 8085 and to store the result in memory. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Start the program. 2. Load the first data in the accumulator. 3. Move the content of A to B register. 4. Load the second data in the accumulator. 5. Initialize the carry with zero. 6. Add the content of B register to the accumulator. 7. If the carry is 0 then store the result in address which is specified. 8. If the carry is 1 then increment the C register and store the result. 9. Stop the program.
ADD DATA
NO INCREMENT CARRY
STOP
www.Vidyarthiplus.com
OBSERVATION:
RESULT: Thus the addition of two 8-bit numbers performed using 8085 Microprocessor and the output was stored in memory.
www.Vidyarthiplus,com
Page 4
www.Vidyarthiplus.com
I (a). ADDITION OF TWO 8-BIT NUMBERS PROGRAM: ADDRESS LABEL MNEMONICS HEX CODE COMMENTS
www.Vidyarthiplus,com
Page 5
www.Vidyarthiplus.com
9100 9103 9104 9107 9108 910A 910D 910E 9111 9112 9115 LDA 9200 MOV B,A LDA 9201 ADD B MVI C,00 INC 910E INR C STA 9600 MOV A,C STA 9601 RST 1 3A,00,92 Load the data in the accumulator 47 Move the content of A register to B
3A,01,92 Load the second value in accumulator 80 0E,00 02,0E,91 0C 32,00,96 79 32,00,96 CF Add the content of B to A Initialize C register with 00 Jump on No carry to the specified address Increment the C register Store the result in specified address Move the content of C to accumulator Store the carry in specified address Terminate the process
www.Vidyarthiplus,com
Page 6
www.Vidyarthiplus.com
I (b). SUBTRACTION OF TWO 8-BIT NUMBERS AIM: To perform 8-bit subraction operation with carry using 8085 and to store the result in memory. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Start the program. 2. Load the first data in the accumulator. 3. Move the content of A to B register. 4. Load the second data in the accumulator. 5. Subtract the content of B register from the accumulator. 6. If the borrow is 0 then go to step 7. 7. Store the result. 8. Stop the program.
www.Vidyarthiplus,com
Page 7
www.Vidyarthiplus.com
FLOW CHART:
START
ADD DATA
IF BORROW =0
NO
INCREMENT BORROW
STOP
www.Vidyarthiplus,com
Page 8
www.Vidyarthiplus.com
OBSERVATION:
RESULT: Thus the subtraction of two 8-bit numbers performed using 8085 Microprocessor and the output was stored in memory.
www.Vidyarthiplus,com
Page 9
www.Vidyarthiplus.com
HEX CODE
COMMENTS
www.Vidyarthiplus,com
Page 10
www.Vidyarthiplus.com
9100 9103 9104 9107 9108 910A 910D 910E 9111 9112 9115 LSB LDA 9200 MOV B,A LDA 9201 SUB B MVI C,00 JNC 910E INR C STA 9300 MOV A,C STA 9301 RST 1 3A,00,92 Load the data in the accumulator 47 Move the content of A register to B
3A,01,92 Load the second value in accumulator 90 0E,00 02,0E,91 0C 32,00,93 79 32,00,93 CF Subtract the data Move borrow as 00 Jump on No borrow to the specified address Increment the C register Store the result in specified address Move the content of C to accumulator Store the carry in specified address Terminate the process
www.Vidyarthiplus,com
Page 11
www.Vidyarthiplus.com
To perform the 8-bit multiplication operation by using 8085 microprocessor. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Start the program. 2. Get the multiplier and multiplicand. 3. Initialize the carry register 4. Initialize count register with multiplier 5. Clear accumulator. 6. Add accumulator with multiplicand 7. If carry occurs increment the carry register. 8. Decrement the count register. 9. If zero go to step 1. 10. Else go to step 6. 11. Sore accumulator. 12. Store carry register. 13: Stop the program.
www.Vidyarthiplus,com
Page 12
www.Vidyarthiplus.com
FLOW CHART:
START
IF CARRY=0
DECREMENT COUNT
YES
www.Vidyarthiplus,com
Page 13
www.Vidyarthiplus.com
STOP
I (c). MULTIPLICATION OF TWO 8-BIT NUMBERS PROGRAM: ADDRESS LABEL MNEMONICS HEX CODE COMMENTS
www.Vidyarthiplus,com
Page 14
www.Vidyarthiplus.com
9100 9103 9104 9107 9108 910A 910B 910C 910F 9110 9111 9114 9117 9118 911B LDA 9200 MOV D,A LDA 9201 MOV B,A DCR D MVI C,00 ADD B JNC 9110 INR C DCR D JNZ 910B STA 9600 MOV A,C STA 9601 RST 1 3A,00,92 57 3A,01,92 47 15 0E,00 80 D2,10,91 0C 15 C2,0B,91 Jump on no zero 32,00,96 79 32,01,96 CF Store the result in specified address Move the content of C to accumulator Store the carry in specified address Terminate the process Clear the accumulator Add register D to A Jump on no carry Load the data in the accumulator Move the content of A register to D Load the second value in accumulator Move the content of A register to B
www.Vidyarthiplus,com
Page 15
www.Vidyarthiplus.com
OBSERVATION:
RESULT: Thus the multiplication of two 8-bit numbers performed using 8085 Microprocessor and the output was stored in memory
www.Vidyarthiplus,com
Page 16
www.Vidyarthiplus.com
I(d). DIVISION OF 8-BIT NUMBERS AIM: To perform the 8-bit division operation by using 8085 microprocessor. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Start the program. 2. Get the divisor and dividend. 3. Initialize count register with divisor 4. Clear accumulator. 5. Move the dividend into accumulator 6. Subtract divisor from accumulator. 7. Increment the count register. 8. Compare accumulator with divisor. 9. If division is less go to step 5 else to next step. 10. Stop the program.
www.Vidyarthiplus,com
Page 17
www.Vidyarthiplus.com
IF NO ZERO
STORE THE A
www.Vidyarthiplus,com
MOVE C TO A
Page 18
www.Vidyarthiplus.com
STORE A
Address
Label
Mnemonics
Hex Code
Comments
www.Vidyarthiplus,com
Page 19
www.Vidyarthiplus.com
9100 9103 9104 9107 9109 910A 910B 910C 910F 9112 9113 9116 LDA 9200 MOV D,A LDA 9201 MVI C,00 SUB D INR C CMP D JNC 9109 STA 9600 MOV A,C STA 9601 RST 1 3A,00,92 57 3A,01,92 0E,00 92 0C BA D2,09,91 32,00,96 79 32,01,96 CF Load the dividend in the accumulator Move the content of A register to D Load the second value in accumulator Get the divisor Subtract D from A Increment C Compare C and D Jump on no zero Store the result in specified address Move the content of C to accumulator Store the carry in specified address Terminate the process
www.Vidyarthiplus,com
Page 20
www.Vidyarthiplus.com
OBSERVATION:
RESULT: Thus the division of two 8-bit numbers performed using 8085 Microprocessor and the output was stored in memory.
www.Vidyarthiplus,com
Page 21
www.Vidyarthiplus.com
II. (a). LARGEST ELEMENT IN AN ARRAY AIM: To find the largest element in an array. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Place all the elements of an array in the consecutive memory locations. 2. Fetch the first element from the memory location and load it in the accumulator. 3. Initialize a counter (register) with the total number of elements in an array. 4. Decrement the counter by 1. 5. Increment the memory pointer to point to the next element. 6. Compare the accumulator content with the memory content (next element). 7. If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue. 8. Decrement the counter by 1. 9. Repeat steps 5 to 8 until the counter reaches zero 10. Store the result (accumulator content) in the specified memory location.
www.Vidyarthiplus,com
Page 22
www.Vidyarthiplus.com
[HL]
[8100H]
04H [HL]
[HL] + 1
[A]
[HL]
[B]
[B]-1
www.Vidyarthiplus,com
Page 23
www.Vidyarthiplus.com
STOP
PROGRAM:
ADDRESS
OPCODE
LABEL
MNEM ONICS
COMMENTS
8001
21,00,81
LXI
8004
06,04
MVI
B,04
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 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
8006 8007
7E 23 LOOP1
MOV INX
A,M H
8008 8009
BE D2,0D,80
CMP JNC
M LOOP
7E 05 C2,07,80 LOOP
A,M B LOOP1
www.Vidyarthiplus,com
Page 24
www.Vidyarthiplus.com
8011 32,05,81 STA 8105 Store the result in a memory location. Stop the program
8014
76
HLT
OBSERVATION:
RESULT:
www.Vidyarthiplus,com
Page 25
www.Vidyarthiplus.com
Thus the largest number in the given array is found out.
II. (b) SMALLEST ELEMENT IN AN ARRAY AIM: To find the smallest element in an array. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. Place all the elements of an array in the consecutive memory locations.
www.Vidyarthiplus,com
Page 26
www.Vidyarthiplus.com
2. Fetch the first element from the memory location and load it in the accumulator. 3. Initialize a counter (register) with the total number of elements in an array. 4. Decrement the counter by 1. 5. Increment the memory pointer to point to the next element. 6. Compare the accumulator content with the memory content (next element). 7. If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue. 8. Decrement the counter by 1. 9. Repeat steps 5 to 8 until the counter reaches zero 10. Store the result (accumulator content) in the specified memory location.
[HL]
[8100H]
www.Vidyarthiplus,com
[B]
04H
Page 27
www.Vidyarthiplus.com
[HL]
[HL] + 1
[B]
[B]-1 NO IS
STOP
ADDRE SS
OPCO DE
LABEL
MNEM ONICS
OPER AND
COMMENTS
www.Vidyarthiplus,com
Page 28
www.Vidyarthiplus.com
8001 21,00,81 LXI H,8100 Initialize HL reg. to 8100H 8004 06,04 MVI B,04 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
8006 8007
7E 23 LOOP1
MOV INX
A,M H
8008 8009
CMP JC
M LOOP
8014
76
HLT
www.Vidyarthiplus,com
Page 29
www.Vidyarthiplus.com
OBSERVATION:
RESULT: Thus the smallest number in the given array is found out.
www.Vidyarthiplus,com
Page 30
www.Vidyarthiplus.com
II. (c ). ASCENDING ORDER AIM: To sort the given number in the ascending order using 8085 microprocessor. APPARATUS REQUIRED: 8085-Microprocessor kit -1 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 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.
www.Vidyarthiplus,com
Page 31
www.Vidyarthiplus.com
FLOWCHART: START
[B] [HL]
04H [8100H]
[C] [A]
04H [HL]
[HL
[HL] + 1
[D]
[HL]
[HL]
[A]
www.Vidyarthiplus,com
Page 32
www.Vidyarthiplus.com
[HL] YES [HL] - 1
[HL] [HL]
[D] [HL] + 1 NO
[C]
[C] - 01 H A
www.Vidyarthiplus,com
Page 33
www.Vidyarthiplus.com
PROGRAM: ADD RE SS 8000 06,04 MVI B,04 Initialize B reg with number of comparisons (n-1) Initialize HL reg. to 8100H 8005 0E,04 MVI C,04 Initialize C reg with no. of comparisons(n-1) OPCO DE LABE L MNEM ONICS OPER AND COMMENTS
8002
21,00,81
LOOP 3
LXI
H,8100
www.Vidyarthiplus,com
Page 34
www.Vidyarthiplus.com
8007 8008 7E 23 LOOP2 MOV INX A,M H Transfer first data to acc. Increment HL reg. 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
8009 800A
BE DA,12,80
CMP JC
M LOOP1
800D 800E 800F 8010 8011 8012 8013 8016 8017 801A
MOV MOV DCX MOV INX DCR JNZ DCR JNZ HLT
OBSERVATION:
OUTPUT DATA
www.Vidyarthiplus,com
Page 35
www.Vidyarthiplus.com
8100 8101 8102 8103 8104 8100 8101 8102 8103 8104
RESULT: Thus the ascending order program is executed and thus the numbers are arranged in ascending order.
www.Vidyarthiplus,com
Page 36
www.Vidyarthiplus.com
To sort the given number in the descending 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 smaller than second then interchange the number. 3. If the first number is larger, go to step 4 4. Repeat steps 2 and 3 until the numbers are in required order
www.Vidyarthiplus,com
Page 37
www.Vidyarthiplus.com
FLOWCHART:
START
[B] [HL]
04H [8100H]
[C] [A]
04H [HL]
[HL
[HL] + 1
[D]
[HL]
[HL]
[A]
[HL]
[HL] - 1
[HL] NO [HL]
[D] [HL] + 1
[C]
[C] - 01 H
YES
www.Vidyarthiplus,com
Page 38
www.Vidyarthiplus.com
NO
NO
www.Vidyarthiplus,com
Page 39
www.Vidyarthiplus.com
PROGRAM: ADDRE SS 8000 LABEL MNEM ONICS MVI OPER AND B,04 06,04 Initialize B reg with number of comparisons (n-1) Initialize HL reg. to 8100H 8005 MVI C,04 0E,04 Initialize C 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 greater than M then go to loop1 Transfer data from M to D reg Transfer data from acc to M Decrement HL pair OPCODE COMMENTS
8002
LOOP 3
LXI
H,8100
21
8007 8008
LOOP2
MOV INX
A,M H
7E 23
8009 800A
CMP JNC
M LOOP1
BE D2,12,80
D,M M,A H
56 77 2B
www.Vidyarthiplus,com
Page 40
www.Vidyarthiplus.com
8010 8011 8012 8013 8016 8017 8019 801A HLT 76 Stop the program LOOP1 MOV INX DCR JNZ DCR JNZ M,D H C LOOP2 B LOOP3 72 23 0D C2,07,80 05 C2,02,80 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
OBSERVATION:
INPUT MEMORY LOCATION 8100 8101 8102 8103 8104 DATA MEMORY LOCATION 8100 8101 8102 8103 8104
OUTPUT DATA
RESULT:
www.Vidyarthiplus,com
Page 41
www.Vidyarthiplus.com
Thus the descending order program is executed and thus the numbers are arranged in descending order.
II.(e). CODE CONVERSION -DECIMAL TO HEX AIM: To convert a given decimal number to hexadecimal. APPARATUS REQUIRED: 8085-Microprocessor kit -1 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.
www.Vidyarthiplus,com
Page 42
www.Vidyarthiplus.com
FLOWCHART:
START
HL
4500H
00
00H
www.Vidyarthiplus,com
Page 43
www.Vidyarthiplus.com
B+1
A +1
NO
Is A=M?
YES
8101
Stop
PROGRAM: ADDRE SS 8000 OPCO DE 21 LABEL MNEM ONICS LXI OPER AND H,8100 Initialize HL reg. to COMMENTS
www.Vidyarthiplus,com
Page 44
www.Vidyarthiplus.com
8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 00 81 3E 00 06 00 03 C6 01 27 BE C2 07 80 78 32 01 81 76 HLT Stop the program MOV STA A,B 8101 Transfer B reg to acc. Store the result in a memory location. DAA CMP JNZ M LOOP Decimal Adjust Accumulator Compare M & A If acc and given number are not equal, then go to LOOP LOOP INR ADI B 01 Increment B reg. Increment A reg MVI B,00 Initialize B register.. MVI A,00 Initialize A register. 8100H
OUTPUT:
www.Vidyarthiplus,com
Page 45
www.Vidyarthiplus.com
INPUT ADDRESS 8100 DATA OUTPUT ADDRESS DATA 8101
RESULT: Thus an ALP program for conversion of decimal to hexadecimal was written and executed.
www.Vidyarthiplus,com
Page 46
www.Vidyarthiplus.com
II. (f). CODE CONVERSION -HEXADECIMAL TO DECIMAL AIM: To convert a given hexadecimal number to decimal.
APPARATUS REQUIRED: 8085-Microprocessor kit -1 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.
www.Vidyarthiplus,com
Page 47
www.Vidyarthiplus.com
FLOWCHART:
START
HL A
8100H 00
B C B
Is there carry?
YES
C D
C+1 A, A B,
Is
NO
A=M?
YES
www.Vidyarthiplus,com
Page 48
www.Vidyarthiplus.com
8101 A, A C
Stop
PROGRAM: ADD RE SS 8000 21,00,81 LXI H,8100 Initialize HL reg. to 8100H 8003 8005 8007 8009 800A 800C 800D 8010 8011 8012 8013 8014 8015 3E,00 06,00 0E,00 04 C6,01 27 D2,11,80 0C 57 78 BE 7A C2,09,80 NEXT LOOP MVI MVI MVI INR ADI DAA JNC INR MOV MOV CMP MOV JNZ NEXT C D,A A,B M A,D LOOP A,00 B,00 C,00 B 01 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 OPCO DE LABEL MNEM ONICS OPER AND COMMENTS
www.Vidyarthiplus,com
Page 49
www.Vidyarthiplus.com
8018 32,01,81 STA 8101 Store the result in a memory location. Transfer C to A Store the carry in another memory location. Stop the program
801B 801C
79 32,02,81
MOV STA
A,C 8102
801F
76
HLT
DATA
DATA
RESULT: Thus an ALP program for conversion of hexadecimal to decimal was written and executed.
www.Vidyarthiplus,com
Page 50
www.Vidyarthiplus.com
AIM: To write an assembly language program to convert BCD data to binary and binary to BCD using 8085 Microprocessor kit. APPARATUS REQUIRED: S.No 1 2 3 APPARATUS 8085 Microprocessor Kit Power Supply Opcode Sheet QUANTITY 1 1
www.Vidyarthiplus,com
Page 51
www.Vidyarthiplus.com
ALGORITHM FOR BCD TO BINARY CONVERSION: 1. Get the BCD data in A register and save in E register. 2. Mark the lower units of BCD data in A register. 3. Rotate the upper units to lower units position and save in B register. 4. Clear the accumulator. 5. Move 0AH to C register. 6. Decrement C register. 7. If zf=0, go to the previous step. 8. Add B register to A register. 9. Save the product in B register. 10. Get the BCD data in A register from E register and mark the upper nibble. 11. Add the units in A register with the product in B register. 12. Store the binary value in A register. 13.Stop the program.
www.Vidyarthiplus,com
Page 52
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 53
www.Vidyarthiplus.com
PROGRAM FOR BCD TO BINARY CONVERSION:
MEMORY ADDRESS 4100 4103 4104 4106 4107 4108 410A 410B 410C 410D 410E 410F 4111 4112 4113 4114 4117 4118
LABEL
MNEMONICS
OPCODE
COMMENTS
START
LXI H, 5100H MOV A,M ANI 0F MOV B,A MOV A,M ANI F0 RRC RRC RRC RRC MOV D, A MVI E, 0A XRA A
MULT
www.Vidyarthiplus,com
Page 54
www.Vidyarthiplus.com
411B HLT 76
1. Initialize memory pointer to store BCD numbers. 2. Move data to accumulator. 3. Mark the most significant nibble. 4. Store it in B register. 5. Move the divider to C register. 6. Call division sub routine. 7. Store the result in the memory location mentioned. 8. Move the divider to C register. 9. Store the result. 10. End the program.
ALGORITHM FOR DIVISION SUBROUTINE: 1. Move ff to B register. 2. Count number of 100s, 10s and 1s. 3. Subtract this from the content of C register. 4. If carry=1, then extract the remainder.
www.Vidyarthiplus,com
Page 55
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 56
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 57
www.Vidyarthiplus.com
MEMORY LOCATION 4200 4202 4203 4206 4208 420B 420D 420E 4211 4213 4216 4217 4218 4219 421C
LABEL
MNEMONICS
OPCODE
COMMENTS
START
HUND
TEN
14 C3,11,42 4F
www.Vidyarthiplus,com
Page 58
www.Vidyarthiplus.com
421D 421E MOV A, D RLC 7A 07
MEMORY LOCATION 421F 4220 4221 4222 4223 4226 4227 422A
LABEL
MNEMONICS
OPCODE
COMMENTS
RLC RLC RLC ADD C STA 4301H MOV A, E STA 4302H HLT
07 07 07 81 32,01,43 7B 32 76
www.Vidyarthiplus,com
Page 59
www.Vidyarthiplus.com
www.Vidyart
Page 60
www.Vidyarthiplus.com
MEMORY LOCATION
DATA 1
DATA 2
INPUT OUTPUT
5100H 5101H
MEMORY LOCATION
DATA 1
DATA 2
INPUT
4300H
www.Vidyarthiplus,com
Page 61
www.Vidyarthiplus.com
OUTPUT 4301H 4302H
RESULT: Thus the conversion from BCD to Binary and Binary to BCD were obtained.
ADC INTERFACING AIM: To interface DAC with 8085 and get the digital output. APPARATUS REQUIRED: 8085-Microprocessor kit -1
ALGORITHM: 1. Apply Control word for port A as input, Port B and Port C as Output 2. Out it in control register. 3. Make write pin high. 4. Port C is enabled for output. 5. Conversion is obtained using subroutine.
www.Vidyarthiplus,com
Page 62
www.Vidyarthiplus.com
PROGRAM:
ADDRESS 8500
LABEL
MNEMONICS MVI A, 90 H
OPCOCDE 3E, 90
COMMENTS Control word for A as input, B and C aS Output Out it in control reg
32,F3,40 Make write pin high 3E, FF Port C is enabled for output 32,F2,40
www.Vidyarthiplus,com
Page 63
www.Vidyarthiplus.com
850A 850C 850F 8511 8514 8517 851A 851B 851D 51F 8520 8521 8522 8523 8524 8525 8528 8529 852C MVI A, 00H STA 40F2 MVI A, FFH STA 40F2 CALL 851B LDA 40F0 RST 1 MOV B,OF MVI A,FF NOP NOP NOP NOP NOP DCR A JNZ 851F DCR A JNZ 851D RET 3E, 00 32,F2,40 3E, FF 32,F2,40 CD,86,00 3A,F0,40 CF 06,0F 3E, FF 00 00 00 00 00 3D C2,1F,85 3D C2,1F,85 C9 Return to main program in out Delay routine End of conversion port A as input Break point Delay count Start of conversion
FLOWCHART:
Start Control word for port A as input, Port B and Port C as Output
www.Vidyarthiplus,co
Page 64
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 65
www.Vidyarthiplus.com
www.Vidyarthiplus.com
RESULT: Thus the analog to digital conversion is obtained using 8085 microprocessor.
www.Vidyarthiplus,com
Page 67
www.Vidyarthiplus.com
AIM: To interface DAC with 8085 to demonstrate the generation of square, saw tooth and Triangular wave. APPARATUS REQUIRED: 8085Trainer Kit DAC Interface Board THEORY: DAC 0800 is an 8-bit DAC and the output voltage variation is between -5V and 5V.The output voltage varies in steps of 10/256=0.04(appx.).The digital data input and The corresponding output voltages are presented in the Table below. Input Data in HEX 00 01 02 7F FD FE 4.96 Output Voltage 5.00 4.96
www.Vidyarthiplus,com
Page 68
www.Vidyarthiplus.com
FF 5.00
Referring toTable1, with 00 H as input to DAC, the analog output is -5 V.Similarly, With FF H input, the output is +5V.Outputting digital data 00 and FF at regular intervals, to DAC, results in different waveforms namely square, triangular, etc, the port address of DAC is 08H.
ALGORITHM: (a) Square Wave Generation 1. Load the initial value (00) to Accumulator and move it to DAC 2. Call the delay program 3. Load the final value (FF)to accumulator and move it to DAC 4. Call the delay program. 5. Repeat Steps 2 to 5
(b) Saw tooth Wave Generation 1.Load the initial value(00) to Accumulator 2.Move the accumulator content to DAC 3.Increment the accumulator content by 1. 4.Repeat Steps 3 and 4.
(c) Triangular Wave Generation 1. Load the initial value (00) to Accumulator 2. Move the accumulator content to DAC 3. Increment the accumulator content by1. 4. If accumulator content is zero proceed to next step. Else go to step3.
www.Vidyarthiplus,com
Page 69
www.Vidyarthiplus.com
5. Load value (FF) to Accumulator 6. Move the accumulator content to DAC 7. Decrement the accumulator content by1. 8. If accumulator content is zero go to step2. Else go to step7.
ADDRESS
LABEL
MNEMONICS
OPCODE
COMMENTS
www.Vidyarthiplus,com
Page 70
www.Vidyarthiplus.com
8000 8002 8004 8007 8009 800B 800E 8011 8013 8015 8016 8019 DCR B 801A JNZ L1 801D RET 05 C2,11,80 C9 DELAY L1 L2 START MVI A, 00 OUT Port address of DAC CALL DELAY MVI A, FF OUT Port address of DAC CALL DELAY JMP START MVI B, 05 MVI C, FF DCR C JNZ L2 3E,00 D3,01 CD,0E,80 3E,FF D3,02 CD,0E,80 C3,00,80 3E,05 0E,FF 0D C2,13,80 Call the delay program Call the delay program Load the final value (FF)to accumulator and move it to DAC Load the initial value (00) to Accumulator and move it to DAC
www.Vidyarthiplus,com
Page 71
www.Vidyarthiplus.com
(B) Saw tooth Wave Generation ADDRE SS 8020 8022 8023 8025 8026 JNZ L1 8029 802B 802C 802E 802F 8032 L2 MVI L, FF MOV A, L OUT Port address of DAC DCR L JNZ L2 JMP START LABEL START L1 MNEMONICS MVI L, 00 MOV A, L OUT Port address of DAC INR L OPCODE 2E,00 7D D3,01 2C C2,22,80 2E,FF 7D D3,02 2D C2,2B,80 C3,20,80 Move the accumulator content to DAC COMMENTS Load the initial value(00) to Accumulator
www.Vidyarthiplus,com
Page 72
www.Vidyarthiplus.com
LABEL START L1
www.Vidyarthiplus,com
Page 73
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 74
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 75
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 76
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 77
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 78
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 79
www.Vidyarthiplus.com
RESULT: Thus the square, triangular and saw tooth waveform were generated by interfacing DAC with 8085 trainer kit.
www.Vidyarthiplus,com
Page 80
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 81
www.Vidyarthiplus.com
To control traffic light using 8085 microprocessor. APPARATUS REQUIRED: 8085 Microprocessor kit with traffic light interfacing. ALGORITHM: 1. Initialize 8255, port A and port B in output mode 2. Send data on PA to glow R1 and R2. 3. Send data on PB to glow G3 and G4. 4. Load multiplier count (40) for delay. 5. Call delay subroutine. 6. Send data on PA to glow Y1 and Y2. 7. Send data on PB to glow Y3 and Y4. 8. Load multiplier count (10) for delay. 9. Call delay subroutine. 10. Send data on PA to glow G1 and G2. 11. Send data on PB to glow R3 and R4. 12. Load multiplier count (40) for delay. 13. Call delay subroutine. 14. Send data on PA to glow Y1 and Y2. 15. Send data on PA to glow Y3 and Y4. 16. Load multiplier count (10) for delay. 17. Call delay subroutine
www.Vidyarthiplus,com
Page 82
www.Vidyarthiplus.com
FLOWCHART: Start
Send data on PA to glow R1 and R2. Send data on PB to glow G3 and G4.
Send data on PA to glow Y1 and Y2. Send data on PB to glow Y3 and Y4.
Send data on PA to glow G1 and G2. Send data on PB to glow R3 and R4. Call delay subroutine
Send data on PA to glow Y1 and Y2. Send data on PA to glow Y3 and Y4. Call delay subroutine
End
www.Vidyarthiplus,com
Page 83
www.Vidyarthiplus.com
PROGRAM: Source program: ADDRESS LABEL 8000 8002 8004 8006 8008 800A 800C 800E 8011 8013 8015 8017 8019 801C 801E 8020 8022 8024 START MNEMONICS MVI A, 80 H OUT 83H(CR) MVI A,09H OUT 80H(PA) MVI A,24H OUT 81H(PB) MVI C,28H CALL DELAY MVI A, 12H OUT (81H) PA OUT (81H) PB MVI C,OAH CALL DELAY MVI A,24H OUT (80H) PA MVI A, 09H OUT (81H) PB MVI C,28H OPCODE 3E,80 D3,83 3E,09 D3,80 3E,24 D3,81 0E,28 CD,40,80 3E,12 D3,81 D3,81 0E,0A CD,40,80 3E,24 D3,80 3E,09 D3,81 0E,28 Send data on PB to glow R3 and R4 Load multiplier count (40) for Send data on PA to glow G1 and G2 Send data on PA to glow Y1 and Y2 Send data on PB to glow Y3 and Y4 Load multiplier count (10) for delay Call delay subroutine Send data on PB to glow G3 and G4 Load multiplier count (40) for delay Call delay subroutine Send data on PA to glow R1 and R2 COMMENTS Initialize 8255, port A and port B in output mode
www.Vidyarthiplus,com
Page 84
www.Vidyarthiplus.com
8026 8029 802B 802D 802F 803B 803F CALL DELAY MVI A, 12H OUT PA OUT PB MVI C,OAH CALL DELAY JMP START CD,40,80 3E,12 D3,80 D3,81 0E,0A CD,40,80 C3,04,80 Send data on PA to glow Y1 and Y2 Send data on PA to glow Y3 and Y4 Load multiplier count (10) for delay Call delay subroutine delay Call delay subroutine
Delay subroutine:
MNEMONICS LXI D,COUNT DCX D MOV A,D ORA E JNZ BACK DCR C JNZ DELAY RET
COMMENTS Load the count to give 0.5 sec delay Decrement counter
Check whether count is 0 If not zero, repeat Check if multiplier zero, otherwise repeat
www.Vidyarthiplus,com
Page 85
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 86
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 87
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 88
www.Vidyarthiplus.com
VI. STEPPER MOTOR CONTROL AIM: To write a program to rotate stepper motor in clockwise direction to 90 degree. APPARATUS REQUIRED: (i) 8085 Microprocessor kit (ii) Stepper motor interfacing (iii) Power supply. ALGORITHM: 1. Move the data 60 to accumulator. 2. Move data count 90 degree to E register. 3. Send the accumulator to the input. 4. Wait for some delay. 5. Decrement the count. 6. Stop execution.
www.Vidyarthiplus,com
Page 89
www.Vidyarthiplus.com
PROGRAM:
ADDRESS 8020 8022 8024 8026 8029 802A 802B 802E 8030 8032 8034 8035 8038 8039 803C
LABEL
MNEMONICS MVIA, 66 MVIE,50 OUT CO CALL DELAY RLC D CR E JNZ 8024 HLT
COMMENTS Move initial data to accumulator Move number count Set it port 1 Wait for delay Repeat left to accumulator` Repeat count to 0 Repeat until zero Stop execution Move other count Decrement inner count Decrement B register Repeat until 0
DELAY
MVI C, 03 MVI B,FF DCR B JNZ 8034 DCR C JNZ 8032 RET
www.Vidyarthiplus,com
Page 90
www.Vidyarthiplus.com
STEPPER MOTOR:
www.Vidyarthiplus,com
Page 91
www.Vidyarthiplus.com
Initialize ports
www.Vidyarthiplus,com
Is count =0?
Page 92
www.Vidyarthiplus.com
NO YES
RESULT: Thus the program to rotate stepper motor in clockwise direction of 90 degree.
www.Vidyarthiplus,com
Page 93
www.Vidyarthiplus.com
VII (a). USART ( 8251) AIM: To write ALP to interface the universal synchronous asynchronous receiver and transmitter using 8085 microprocessor. APPARATUS REQUIRED: (i) 8085 microprocessor (ii) Power supply (iii) 8251 interfacing card
www.Vidyarthiplus,com
Page 94
www.Vidyarthiplus.com
ALGORITHM: 1. Initialize the serial port controller. 2. Get data from serial port 3. Transmit the byte serial port 4. Receive the byte from serial port.
www.Vidyarthiplus,com
Page 95
www.Vidyarthiplus.com
Initialize 8251
Read status
Is transmitter ready?
NO
Decrement counter
Is counter=0? NO
End YES
www.Vidyarthiplus,com
Page 96
www.Vidyarthiplus.com
RECEIVER 8251 Start
Initialize 8251
Read status
NO
Is receiver ready?
Decrement counter
NO
Is counter=0?
www.Vidyarthiplus,com
End
Page 97
www.Vidyarthiplus.com
YES
www.Vidyarthiplus,com
Page 98
www.Vidyarthiplus.com
www.Vidyarthiplus.com
PROGRAM: Look back test of 8251: ADDRESS 8000 8003 8005 8007 800A 800C 800D 8010 8013 8014 8017 8018 801A 801C 801D 8020 LABEL MNEMONICS CALL 8331 IN 01 ANI, 07H JZ INZ 00 MOV B,A CALL 8350 CALL 8346 CHP B JNZ PUSH PSW MVI A, 90 H OUT 01 POP PSW CALL 835C JHP OPCOCDE CD,31,83 DB,01 E6,07 CA, COMMENTS
www.Vidyarthiplus,com
Page 100
www.Vidyarthiplus.com
Initialize serial port controller: ADDRESS 8331 8333 8335 8337 8339 833B 833D 833E 8341 8343 8345 Retrieve a byte from serial byte 8346 8348 834A 834D 834F Transmit a byte to serial port 8350 8351 8353 PUSH PSW IN 41 ANI 01 F5 DB 41 E6,01 LABEL MNEMONICS MVI A, 00H OUT 41 OUT 41 OUT 41 MVI A, 40H OUT 41 MVI A, 4FH OUT 41 MVI A, 31H OUT 41 RET OPCOCDE 3E,00 D3,41 D3,41 D3,41 3E,40 D3,41 3E,4F D3,41 3E,31 D3,41 C9 COMMENTS Move immediate data to Acc. Display Display Display Move immediate data to Acc. Display Move immediate data to Acc. Display Move immediate data to Acc. Display Return
IN 41 ANI 02 JZ IN 40 RET
DB 41 E6,02 CA
DB,40 return C9
www.Vidyarthiplus,com
Page 101
www.Vidyarthiplus.com
8355 8358 8359 835B JZ POP PSW OUT 40 RET CA F1 D3,40 C9
RESULT: Thus the transmission and reception byte is achieved serially by interfacing 8085 with USART.
www.Vidyarthiplus,com
Page 102
www.Vidyarthiplus.com
VII (b) INTERFACING 8085 WITH 8279 AIM: To write the program to show the LED segment in 8279 by interfacing 8085 with 8279.
(iii) Keyboard (iv) 8279 interfacing card. ALGORITHM: 1. Start the program. 2. Get the Hex code at the memory location 809, 800B,8011,8015 3. State results interfacing card 0123. 4. Stop the execution
www.Vidyarthiplus,com
Page 103
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 104
www.Vidyarthiplus.com
8000 8002 8004 8006 8008 800A 800C 800E 8010 8012 8014 8016 8018 801B DELAY MVIA, 00 OUT C2 MVIA, 90 OUT C2 MVIA, 3F OUT C0 MVIA, 06 OUT C0 MVIA, 5B OUT C0 MVIA, 4F OUT C0 JMP 8018 HLT 3E,00 D3,C2 3E,90 D3,C2 3E,3F D3,C0 3E,06 D3,C0 3E,5B D3,C0 3E,4F D3,C0 C3,18,80 76 Initialize accumulator output from accumulator move immediate data to accumulator output data from accumulator move immediate data to accumulator output data from accumulator move immediate data to accumulator output data from accumulator move immediate data to accumulator output data from accumulator move immediate data to accumulator output data from accumulator Jump to specify address End of program
www.Vidyarthiplus,com
Page 105
www.Vidyarthiplus.com
FLOWCHART:
Start
NO
Is count =0?
yes Start
www.Vidyarthiplus,com
Page 106
www.Vidyarthiplus.com
www.Vidyarthiplus.com
RESULT: Thus the LED segment display in 8279 by interfacing with 8085 was performed and verified.
www.Vidyarthiplus,com
Page 108
www.Vidyarthiplus.com
AIM: To write a program for interfacing the 8253 with 8085 microprocessor.
APPARATUS REQUIRED: (i) 8085 microprocessor (ii) Power supply (iii) 8254 interfacing card ALGORITHM: 1. Move the content of word to Accumulator. 2. Move data to accumulator. 3. Move maximum content in acc to display in it output. 4. Move maximum count in operation 5. Stop execution.
www.Vidyarthiplus,com
Page 109
www.Vidyarthiplus.com
FLOW CHART:
End
www.Vidyarthiplus,com
Page 110
www.Vidyarthiplus.com
PROGRAM: ADDRESS 8000 8002 8004 8006 8008 800A 800C LABEL MNEMONICS MVI A, 30 H OUT 43 MVI A, FFH OUT 40 MVI A, FFH OUT 40 HLT OPCOCDE 3E, 30 D3,43 3E,FF D3,40 3E,FF D3,40 76 COMMENTS Move immediate data to Acc. Send the data from acc to port Move immediate data to Acc. Send the data from acc to port Move immediate data to Acc. Send the data from acc to port End the program
www.Vidyarthiplus,com
Page 111
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 112
www.Vidyarthiplus.com
www.Vidyarthiplus.com
RESULT:
Thus the program for interfacing 8354 with 8085 microprocessor was performed.
www.Vidyarthiplus,com
Page 114
www.Vidyarthiplus.com
VIII (a)16 BIT DATA ADDITION AIM: To add two 16-bit numbers stored at consecutive memory locations. APPARATUS REQUIRED: 8085-Microprocessor kit -1 ALGORITHM: 1. 2. 3. 4. Initialize memory pointer to data location. Get the first number from memory and store in Register pair. Get the second number in memory and add it to the Register pair. Store the sum & carry in separate memory locations.
www.Vidyarthiplus,com
Page 115
www.Vidyarthiplus.com
FLOW CHART:
[HL]
[HL]+[DE]
Is there a Carry?
YES
NO
[A]
[A]+1
[8054]
[ L]
[8055]
[H]
[8056]
[A]
STOP
www.Vidyarthiplus,com
Page 116
www.Vidyarthiplus.com
PROGRAM: ADDRESS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 OPCODE 2A 50 80 EB 2A 52 80 3E 00 19 DAD D Add the contents of HL Pair with that of DE pair. 800A 800B 800C 800D D2 0E 80 1C INR A Otherwise increment reg. A Store the content of HL Pair in 8054H(LSB of sum) JNC LOOP If there is no carry, go to the instruction labeled LOOP. MVI A, 00H Initialize reg. A for carry XCHG LHLD 8052H Load the addend in HL pair. LABEL START MNEMONICS LHLD OPERAND 8050H COMMENT Load the augend in DE pair through HL pair.
22 54 80 32 56
LOOP
SHLD
8054H
STA
8056H
www.Vidyarthiplus,com
Page 117
www.Vidyarthiplus.com
8013 8014 80 76 HLT (MSB of sum). Stop the program.
OBSERVATION:
INPUT ADDRESS 8050H 8051H 8052H 8053H DATA ADDRESS 8054H 8055H 8056H
OUTPUT DATA
RESULT: Thus an ALP program for 16-bit addition was written and executed in 8085 p using special instructions.
www.Vidyarthiplus,com
Page 118
www.Vidyarthiplus.com
VIII.(b). 16 BIT DATA SUBTRACTION AIM: To subtract two 16-bit numbers stored at consecutive memory locations. APPARATUS REQUIRED: 8085-Microprocessor kit -1
ALGORITHM: 1. 2. 3. 4. 5. Initialize memory pointer to data location. Get the subtrahend from memory and transfer it to register pair. Get the minuend from memory and store it in another register pair. Subtract subtrahend from minuend. Store the difference and borrow in different memory locations.
www.Vidyarthiplus,com
Page 119
www.Vidyarthiplus.com
FLOW CHART:
START
[L] [H]
[8050 H] [8051 H]
[DE]
[HL]
[L] [H]
[8052H] [8053H]
[HL]
[HL]-[DE]
www.Vidyarthiplus,com
Page 120
www.Vidyarthiplus.com
Is there a borrow?
YES
[C]
[C]+1
NO
[8054]
[ L]
[8055]
[H]
[8056]
[C]
STOP
PROGRAM: ADDRESS OPCODE LABEL MNEMO NICS 8000 8002 8005 8006 0E,00 2A,50,80 EB 2A,52,80 START MVI LHLD XCHG LHLD 8052H Load the minuend in HL reg. Pair. Move the content of reg. L to Acc. OPER AND C, 00 8050H Initialize C reg. Load the subtrahend in DE reg. Pair through HL reg. pair. COMMENTS
8009
7D
MOV
A, L
www.Vidyarthiplus,com
Page 121
www.Vidyarthiplus.com
800A 93 SUB E Subtract the content of reg. E from that of acc. Move the content of Acc. to reg. L Move the content of reg. H to Acc. Subtract content of reg. D with that of Acc. Transfer content of acc. to reg. H Store the content of HL pair in memory location 8504H. If there is borrow, go to the instruction labeled NEXT. Increment reg. C Transfer the content of reg. C to Acc. Store the content of acc. to the memory location 8506H Stop the program execution.
800B
6F
MOV
L, A
800C
7C
MOV
A, H
800D
9A
SBB
800E
67
MOV
H, A
800F
22,54,80
SHLD
8054H
8012
D2,16,80
JNC
NEXT
8015 8016
0C 79 NEXT
INR MOV
C A, C
8017
32,56,80
STA
8056H
801A
76
HLT
www.Vidyarthiplus,com
Page 122
www.Vidyarthiplus.com
ADDRESS 8050H 8051H 8052H 8053H RESULT: Thus an ALP program for subtracting two 16-bit numbers was written and executed. DATA ADDRESS 8054H 8055H 8056H DATA
www.Vidyarthiplus,com
Page 123
www.Vidyarthiplus.com
To multiply two 16 bit numbers and store the result in memory. APPARATUS REQUIRED: 8085-Microprocessor kit -1
ALGORITHM: 1. 2. 3. 4. Get the multiplier and multiplicand. Initialize a register to store partial product. Add multiplicand, multiplier times. Store the result in consecutive memory locations.
www.Vidyarthiplus,com
Page 124
www.Vidyarthiplus.com
FLOWCHART: START L H SP [8050] [8051] HL
L H DE
[8052] [8053] HL
HL BC HL
NO
DE
DE+1
NO
www.Vidyarthiplus,com
Page 125
www.Vidyarthiplus.com
A
[8054] [8055]
L H
[8056] [8057]
C B
STOP
www.Vidyarthiplus,com
Page 126
www.Vidyarthiplus.com
PROGRAM:
www.Vidyarthiplus,com
Page 127
www.Vidyarthiplus.com
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 8020 8021 8022 8023 8024 OPCODE 2A 50 80 F9 2A 52 80 EB 21 00 00 01 00 00 39 D2 13 80 03 1B 7B B2 C2 0E 80 22 54 80 79 32 56 80 78 32 57 80 76 LABEL START MNEMO NICS LHLD OPERAND 8050 COMMENTS Load the first No. in stack pointer through HL reg. pair
SPHL LHLD
8052
Load the second No. in HL reg. pair & Exchange with DE reg. pair.
XCHG LXI
LXI
B, 0000H
LOOP
DAD JNC
SP NEXT
Add SP with HL pair. If there is no carry, go to the instruction labeled NEXT Increment BC reg. pair Decrement DE reg. pair. Move the content of reg. E to Acc. OR Acc. with D reg. If there is no zero, go to instruction labeled LOOP Store the content of HL pair in memory locations 8054 & 8055. Move the content of reg. C to Acc. Store the content of Acc. in memory location 8056. Move the content of reg. B to Acc. Store the content of Acc. in memory location 8056. Stop program execution
NEXT
B D A,E D LOOP
SHLD
8054
MOV STA
A, C 8056
MOV STA
A, B 8057
HLT
www.Vidyarthiplus,com
Page 128
www.Vidyarthiplus.com
OBSERVATION: INPUT ADDRESS 8050 8051 8052 8053 DATA OUTPUT ADDRESS 8054 8055 8056 8057 DATA
RESULT:
Thus the 16-bit multiplication was done in 8085p using repeated addition method.
www.Vidyarthiplus,com
Page 129
www.Vidyarthiplus.com
To divide two 16-bit numbers and store the result in memory using 8085 mnemonics.
ALGORITHM: 1. 2. 3. 4. 5. Get the dividend and divisor. Initialize the register for quotient. Repeatedly subtract divisor from dividend till dividend becomes less than divisor. Count the number of subtraction which equals the quotient. Store the result in memory.
www.Vidyarthiplus,com
Page 130
www.Vidyarthiplus.com
FLOWCHART:
START
L H HL
[8051] [8052] DE
L H BC
L; A L A
A- E
A A
H A- H- Borrow
BC
BC+ 1
NO
www.Vidyarthiplus,com
Page 131
www.Vidyarthiplus.com
BC HL L H A
[8056]
A B
[8057]
STOP
www.Vidyarthiplus,com
Page 132
www.Vidyarthiplus.com
PROGRAM: ADDRESS OPCODE LABEL MNEM ONICS LHLD XCHG LHLD 8050 Load the second No. in HL reg. pair & Exchange with DE reg. pair. Clear BC reg. pair. Move the content of reg. L to Acc. Subtract reg. E from that of Acc. Move the content of Acc to L. Move the content of reg. H Acc. Subtract reg. D from that of Acc. Move the content of Acc to H. Increment reg. Pair BC If there is no carry, go to the location labeled LOOP. Decrement BC reg. pair. Add content of HL and DE reg. pairs. Store the content of HL pair in 8054 & 8055. Move the content of reg. C to Acc. OPERA ND 8052 Load the first No. in stack pointer through HL reg. pair COMMENTS
2A,52,80 EB 2A,50,80
START
B, 0000H A, L E L, A A, H D H, A B LOOP
0B 19 22,54,80
B D 8054
8019
79
MOV
A, C
www.Vidyarthiplus,com
Page 133
www.Vidyarthiplus.com
801A 801D 801E 8021 32,56,80 78 32,57,80 76 STA MOV STA HLT 8056 A, B 8057 Store the content of Acc. in memory 8056 Move the content of reg. B to Acc. Store the content of Acc. in memory 8057. Stop the program execution.
OBSERVATION: INPUT ADDRESS 8050 8051 8052 8053 DATA OUTPUT ADDRESS 8054 8055 8056 8057 DATA
RESULT: Thus the 16-bit Division was done in 8085p using repeated subtraction method.
www.Vidyarthiplus,com
Page 134
www.Vidyarthiplus.com
www.Vidyarthiplus.com
AIM: To perform addition of two 8-bit numbers using 8051 instruction set. ALGORITHM: 1. Clear C-register for Carry 2. Get the data immediately. 3. Add the two data 4. Store the result in memory pointed by DPTR
www.Vidyarthiplus,com
Page 136
www.Vidyarthiplus.com
PROGRAM: ADDRESS LABEL MNEMONICS ORG 4100 CLR C MOV A,#data1 ADD A,#data2 MOV DPTR,#4500 HERE: MOVX ,@DPTR,A SJMP HERE OPCODE COMMENTS
FLOWCHART:
www.Vidyarthiplus,com
Page 137
www.Vidyarthiplus.com
OBSERVATION:
www.Vidyarthiplus,com
Page 138
www.Vidyarthiplus.com
Input: 66 23
Output:
89(4500)
RESULT: Thus the program to perform addition of two 8-bitnumbers using 8051 instruction set was executed.
www.Vidyarthiplus,com
Page 139
www.Vidyarthiplus.com
AIM: To perform Subtraction of two 8-bit numbers using 8051 instruction set.
ALGORITHM: 1. Clear C-register for Carry 2. Get the data immediately. 3. Subtract the two data 4. Store the result in memory pointed by DPTR
PROGRAM:
ADDRESS LABEL
MNEMONICS ORG 4100 CLR C MOV A, #data1 SUBB A, #data2 MOV DPTR, #4500 MOVX @DPTR, A
OPCODE COMMENTS
HERE
SJMP HERE
www.Vidyarthiplus,com
Page 140
www.Vidyarthiplus.com
FLOWCHART:
www.Vidyarthiplus,com
Page 141
www.Vidyarthiplus.com
OBSERVATION:
Input:
66 23
Output:
43(4500)
RESULT:
Thus the program to perform subtraction of two 8-bit numbers using 8051 instruction Set was executed.
www.Vidyarthiplus,com
Page 142
www.Vidyarthiplus.com
AIM: To perform multiplication of two 8-bit numbers using 8051 instruction set.
ALGORITHM: 1. Get the data in A-reg. 2. Get the value to be multiplied in B-reg. 3. Multiply the two data 4. The higher order of the result is in B-reg. 5. The lower order of the result is in A-reg. 6. Store the results.
PROGRAM:
www.Vidyarthiplus,com
Page 143
www.Vidyarthiplus.com
ADDRESS LABEL MNEMONICS ORG 4100 CLR C MOV A,#data1 MOV B,#data2 MUL AB MOV DPTR,#4500 MOVX @DPTR,A INC DPTR MOV @DPTR,A MOVX A,B HERE SJMP HERE OPCODE COMMENTS
OBSERVATION:
Input:
80 80
Output:
00(4500) 19(4501)
www.Vidyarthiplus,com
Page 144
www.Vidyarthiplus.com
RESULT:
Thus the program to perform multiplication of two 8-bit numbers using 8051 Instruction set was executed.
AIM: To perform division of two 8-bit numbers using 8051 instruction set. ALGORITHM: 1. Get the data in A-reg. 2. Get the value to be divided in B-reg. 3. Divide the two data
www.Vidyarthiplus,com
Page 145
www.Vidyarthiplus.com
4. The quotient is in A-reg. 5. The remainder is in B-reg. 6. Store the results.
PROGRAM: ADDRESS LABEL MNENONICS ORG4100 CLR C MOV A,#data1 MOV B,#data2 DIV AB MOV DPTR,#4500 MOVX @DPTR,A INC DPTR MOV A,B HERE MOV@DPTR,A SJMP HERE OPCODE COMMENTS
OBSERVATION:
Input:
05
www.Vidyarthiplus,com
Page 146
www.Vidyarthiplus.com
03
Output:
01(4500) 02(4501)
RESULT:
Thus the program to perform division of two 8-bit numbers using 8051 Instruction set was executed.
www.Vidyarthiplus,com
Page 147
www.Vidyarthiplus.com
AIM: To write a program for key board/display interfacing with 8051 microcontroller.
ALGORITHM: 1. Initialize P1.0, P1.1, P1.2, P1.3 as inputs i.e. write 1to these pins. 2. Check if all the keys are released by writing 0 to P1.4, P1.7 and check if all return lines are in state,1,. If No then wait. Call debounce. 3. Wait for key closure. Ground all scan lines by writing ,0, and then check if at least one of return li nes shows 0 level. Key pressed? No step 4. Yes step 5. 4. Call debounce. 5. Is key really pressed? (Ground all sacn lines by writing ,0, and then check if at least one of return lines shows 0 lev el) No step 4.Yes step 7. 6. Find key code and display the key pressed on 7 segment display. ( By Grounding one scan line at a time and checking for any line to go to 0 level). 7. Go to step 1.
www.Vidyarthiplus,com
Page 148
www.Vidyarthiplus.com
PROGRAM: ADDRESS LABEL BEG MNEMONICS MOV P1, #0FH MOV DPTR, #4000H AGA MOV A, #P1 ANL A, #0FH CJNE A, #0FH, AGA LCALL DELAY GO MOV A, #P1 ANL A, #0FH CJNE A, #0FH, GO LJMP AGAL LCALL DELAY MOV A, #P1 ANL A, #0FH CJNE A, #0FH, GOL LJMP AGAL GOL MOV R1, #01H MOV R0, #0EFH MOV R3, #04H AGA 3 MOV P1,R0 MOV A,P1 JNB .ACC.0, DISPLAY INC DPTR Initialize counter 1 Store word for column selection Initialize column counter Select only l column Get the status of return lines Check bit 0 and if it is 1 junp to display Is key pressed Call delay routine for key debounce Check for key presssed Check for key released Call delay routine for key debounce OPCO CDE COMMENTS Configure lower 4 lines of port1 as input Initialize dptr with lookup table address
www.Vidyarthiplus,com
Page 149
www.Vidyarthiplus.com
JNB .ACC.1, DISPLAY INC DPTR JNB .ACC.2, DISPLAY INC DPTR Increment lookup-table pointer Check bit 1 and if it is 1 junp to display Increment lookup-table pointer Check bit 2 and if it is 1 junp to display Increment lookup-table pointer
JNB .ACC.3, DISPLAY INC DPTR MOV A,R0 MOV R1,A MOV R0,A DJNZ R3, AGA 3 LJMP BEG END
Check bit 3 and if it is 1 junp to display Increment lookup-table pointer Get the word for column selection Select next column Store 4the word for column selection Check for last column If any key is not pressed scan again
www.Vidyarthiplus,com
Page 150
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 151
www.Vidyarthiplus.com
KEY BOARD/DISPLAY INTERFACING
www.Vidyarthiplus,com
Page 152
www.Vidyarthiplus.com
XI. STEPPER MOTOR INTERFACING WITH 8051 AIM: To interface a stepper motor with 8051 microcontroller and operate it. APPARATUS REQUIRED: 1. 8051-microcontroller kit and Stepper motor 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. ANTICLOCKWISE STEP A1 A2 B1 1 2 3 1 0 0 0 1 1 0 0 1 CLOCKWISE STEP A1 A2 1 2 3 1 0 0 0 1 1
B2 1 1 0
DATA 9h 5h 6h
B1 1 1 0
B2 0 0 1
DATA Ah 6h 5h
www.Vidyarthiplus,com
Page 153
www.Vidyarthiplus.com
4 1 0 1 0 Ah 4 1 0 0 1 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 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.
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 vary direction of rotation. order can
www.Vidyarthiplus,com
Page 154
www.Vidyarthiplus.com
STEPPER MOTOR
www.Vidyarthiplus,com
Page 155
www.Vidyarthiplus.com
FLOWCHART:
Start
Initialize ports
NO
www.Vidyarthiplus,com
Page 156
www.Vidyarthiplus.com
PROGRAM : ADDRE SS MNEMONICS
OPCODES
LABEL
COMMENTS
4100h DPTR, #TABLE 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
MOV MOVX
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
410D
MOVX
@DPTR, A
R4, DELAY DPL DPH DPTR 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 POP back DPTR value from Stack
411B
DJNZ
R0, LOOP
411D
SJMP
START
www.Vidyarthiplus,com
Page 157
www.Vidyarthiplus.com
411F TABLE: DB 09 05 06 0Ah Values as per two-phase switching scheme
RESULT: Thus a stepper motor was interfaced with 8051 and run in forward and reverse directions at various speeds.
www.Vidyarthiplus,com
Page 158
www.Vidyarthiplus.com
XI (A) INTERFACING DAC WITH 8051 AIM: To interface DAC with 8051 parallel port to demonstrate the generation of square, Saw tooth and triangular wave. APPARATUS REQUIRED: 8051Trainer Kit DAC Interface Board THEORY: DAC 0800 is an 8-bit DAC and the output voltage variation is between -5V and 5V.The output voltage varies in steps of 10/256=0.04(appx.).The digital data input and The corresponding output voltages are presented in the Table below
www.Vidyarthiplus,com
Page 159
www.Vidyarthiplus.com
FD FE FF 4.96 5.00
Referring to Table1,with 00 H as input to DAC, the analog output is -5 V. Similarly, With FF H as input, the output is +5V. Outputting digital data 00 and FF at regular intervals, to DAC , results in different waveforms namely square, triangular ,etc,.
ALGORITHM: (a) 1. 2. 3. 4. 5. 6. (b) 1. 2. 3. 4. 5. Square Wave Generation Move the port address of DAC to DPTR Load the initial value(00) to Accumulator and move it to DAC Call the delay program Load the final value(FF) to accumulator and move it to DAC Call the delay program. Repeat Steps 2 to 5 Saw tooth Wave Generation Move the port address of DAC to DPTR Load the initial value (00) to Accumulator Move the accumulator content to DAC Increment the accumulator content by 1. Repeat Steps 3 and 4.
www.Vidyarthiplus,com
Page 160
www.Vidyarthiplus.com
1. 2. 3. 4. 5. 6. 7. 8. 9. Move the port address of DAC to DPTR Load the initial value (00) to Accumulator Move the accumulator content to DAC Increment the accumulator content by 1. If accumulator content is zero proceed to next step. Else go to step3. Load value(FF) to Accumulator Move the accumulator content to DAC Decrement the accumulator content by 1. If accumulator content is zero go to step 2. Else go to step 7.
PROGRAM:
ADDRESS
LABEL
MNEMONICS
OPCODE
COMMENTS
www.Vidyarthiplus,com
Page 161
www.Vidyarthiplus.com
ORG 4100 MOV DPTR,PORTADDRESSOFDAC MOV A,#00 START MOVX @DPTR,A LCALL DELAY MOV A,#FF MOVX @DPTR,A LCALL DELAY LJUMP START DELAY: LOOP: HERE MOV R1,#05 MOV R2,#FF DJNZ R2,HERE DJNZ R1,LOOP RET SJMP START
www.Vidyarthiplus,com
Page 162
www.Vidyarthiplus.com
ADDRESS LABEL MNEMONICS ORG 4100 MOV DPTR, PORT ADDRESS OF DAC MOV A,#00 LOOP MOVX @DPTR ,A INC A SJMP LOOP OPCODE COMMENTS
(c) Triangular Wave Generation ADDRESS LABEL MNEMONICS ORG 4100 MOV DPTR, PORT ADDRESS OF DAC START LOOP1 MOV A,#00 MOVX @DPTR ,A INC A JNZ LOOP1 MOV A,#FF LOOP2: MOVX @DPTR,A DEC A JNZ LOOP2 LJMP START OPCODE COMMENTS
www.Vidyarthiplus,com
Page 163
www.Vidyarthiplus.com
FLOWCHART:
www.Vidyarthiplus,com
Page 164
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 165
www.Vidyarthiplus.com
DAC INTERFACING
www.Vidyarthiplus,com
Page 166
www.Vidyarthiplus.com
RESULT: Thus the square, triangular and saw tooth waveform were generated by interfacing DAC with 8051 trainer kit.
www.Vidyarthiplus,com
Page 167
www.Vidyarthiplus.com
I(B) TRAFFIC LIGHT CONTROL INTERFACING
AIM: To control traffic light using 8051 microcontroller. APPARATUS REQUIRED: 8051 microcontroller kit with traffic light interfacing . ALGORITHM: 1. Initialize R0 to make P1.0 high. 2. Initialize R1 to make P1.1 high. 3. Initialize R2 to make P1.2 high. 4. Make P1.0 high. Wait for 20 seconds 5. Make P1.1 high. Wait for 5 seconds 6. Make P1.2 high. Wait for 20 seconds 7. Make P1.1 high. Wait for 5 seconds. 8. Jump to start.
www.Vidyarthiplus,com
Page 168
www.Vidyarthiplus.com
PROGRAM: ADDRESS LABEL MNEMONICS MOV R0, #01H MOV R1, #02H MOV R2, #04H MOV P1, R0 Wait for 20 seconds LCALL DELAY1 Make P1.1 high MOV P1, R1 Wait for 5 seconds LCALL DELAY2 Make P1.2 high MOV P1, R2 Wait for 20 seconds LCALL DELAY1 Make P1.1 high MOV P1, R1 Wait for 5 seconds. LCALL DELAY2 Jump to start. LJMP START OPCOCDE COMMENTS Initialize R0 to make P1.0 high. Initialize R1 to make P1.1 high. Initialize R2 to make P1.2 high. Make P1.0 high
www.Vidyarthiplus,com
Page 169
www.Vidyarthiplus.com
www.Vidyarthiplus,com
Page 170
www.Vidyarthiplus.com
RESULT: Thus traffic light control using 8051 microcontroller was performed
www.Vidyarthiplus,com
Page 171
www.Vidyarthiplus.com
XI (C) 8051 SERIAL PORT COMMUNICATION AIM: To write assembly language program to receive bytes serially with baud rate 9600, 8-bit data and 1 stop bit. Simultaneously sent received bytes to port2. APPARATUS REQUIRED: (i) 8051 microcontroller (ii) Power supply ALGORITHM: 1. Load the TMOD register with the value 20H to use timer 1 in mode 2 to set the baud rate. 2. Load TH1 to set the desire baud rate for serial data transfer. 3. Load SCON register with the value 50 H to use serial mode 1, where an 8-bit data is framed with start and stop bits. 4. Set TR1 to 1 to start timer 1. 5. Clear the RI with CLR RI instruction. 6. Check the RI flag bit with instruction JNB RI, XXXX to see if an entire character has been received yet. 7. If RI is set, SBUF has the byte. Save this byte. 8. Go to step 5 to receive the next character.
www.Vidyarthiplus,com
Page 172
www.Vidyarthiplus.com
PROGRAM:
ADDRESS
LABEL
MNEMONICS MOV TMOD, #20H MOV TH1, #FDH MOV SCON, #50H SETB TR1
OPCOCDE
COMMENTS Timer 1, mode 2 9600 baud rate 8-bit, 1-stop, REN enabled Start timer 1 Wait for character receive Completely Save the received character Sent character to port 2 Get ready to receive next byte Go to receive next character
HERE
JNB RI, HERE MOV A, SBUF MOV P2, A CLR RI SJMP HERE
www.Vidyarthiplus,com
Page 173
www.Vidyarthiplus.com
XI (C) 8051 SERIAL PORT COMMUNICATION
www.Vidyarthiplus,com
Page 174
www.Vidyarthiplus.com
RESULT: Thus the data was received in port 2 using 8051 serial port communication.
www.Vidyarthiplus,com
Page 175