0% found this document useful (0 votes)
3 views8 pages

Exp No 3 - 4

The document outlines three experiments involving assembly language programming with the 8051 microcontroller: finding the largest element in an array, interfacing a traffic light controller, and controlling a stepper motor. Each experiment includes the aim, required apparatus, algorithm, program code, and results. The programs were successfully executed, demonstrating the functionality of the 8051 microcontroller in various applications.

Uploaded by

pippaemma22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Exp No 3 - 4

The document outlines three experiments involving assembly language programming with the 8051 microcontroller: finding the largest element in an array, interfacing a traffic light controller, and controlling a stepper motor. Each experiment includes the aim, required apparatus, algorithm, program code, and results. The programs were successfully executed, demonstrating the functionality of the 8051 microcontroller in various applications.

Uploaded by

pippaemma22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

EXP NO: 3

LARGEST ELEMENTS IN AN ARRAY USING 8051


DATE

AIM:
​ Write an assembly language program to find the biggest number in an array of 8-bit unsigned
numbers of predetermined length.

APPARATUS REQUIRED:
8051 microcontroller kit
Key Board
Power Card

ALGORITHM:
1.​ Initialize pointer and counter.
2.​ Load internal memory location 40H as zero.
3.​ Move the first element of an array to R5 Register.
4.​ Compare the data stored in memory location 40H is equal to or less than the value of first
element of an array.
5.​ If it is lesser, then move the data of first element to 40H memory location ELSE increment
pointer and decrement counter.
6.​ Check the counter. If counter is not equal to zero, repeat from the 2nd step else move the R5
Register to 40H memory location.
7.​ Stop the program.

PROGRAM:

Memory
Label Object code Mnemonics Comments
Location
4100 START 90 42 00 MOV DPTR,#4200
4103 75 40 00 MOV 40,#00
4106 7D 0A MOV R5,#0A
4108 L2 E0 MOVX A,@DPTR
4109 B5 40 08 CJNE A,40,4114
410C L3 A3 INC DPTR
410D DD F9 DJNZ R5,4108
410F E5 40 MOV A,40
4111 F0 MOVX @DPTR,A
4112 HLT 80 FE SJMP 4112
4114 L1 40 F6 JC 410C
4116 F5 40 MOV 40,A
4118 80 F2 SJMP 410C

PROCEDURE:
1.​ Enter the opcodes starting from 4100.
2.​ Key in the Data at 4200.
3.​ Execute the program and verify for result at 420A.
4.​ Change the array length and data and repeat.

DISCUSSION:
​ In the above program, the internal memory location 40H is initialized to zero for the first
comparison. This is because the numbers are unsigned and hence after the first comparison, the first
number will come to internal memory location. This number is then used for further comparison. A
new algorithm of doing the same program can also be thought of the algorithm must be changed if the
numbers are signed.

INPUT:
ML INPUT
4200 05
4201 67
4202 76
4203 89
4204 98
4205 49
4206 45
4207 9F
4208 57
4209 7A
OUTPUT:
ML OUTPUT
420A 9A

RESULT:
​ Thus the assembly language program was written to find the largest element in an array
and executed using 8051 Microcontroller.
EXP NO: 4
INTERFACING TRAFFIC LIGHT CONTROLLER
DATE

AIM :
To write a AL Program to interface Traffic Light with 8051.

APPARATUS REQUIRED:
​ 8051 Microcontroller Kit,
Traffic Light Controller Kit,
Bus Interface

ALGORITHM:​ ​ ​ ​ ​ ​

 Initialize accumulator and external memory setup.

 Load pattern counter = 4.

 Save addresses of LOOK and LOOK1 tables.

 Repeat for 4 cycles:​


a. Read 3 bytes from LOOK table.​
b. Output them sequentially to external ports (FF0C, FF0D, FF0E).​
c. Delay (DELAY subroutine).​
d. Read 3 bytes from LOOK1 table.​
e. Output them sequentially to external ports.​
f. Delay (DELAY1 subroutine).​
g. Decrement counter.

 Stop execution after 4 cycles.

PROGRAM:

Memory LABLE OPCODE MNEMONIC COMMENT


Location
4100 START: 74 80 MOV A,#80
4102 90 FF 0F MOV DPTR,#0FF0F
4105 F0 MOVX @DPTR,A
4106 7C 04 MOV R4,#04
4108 90 41 9B MOV DPTR,#419B
410B AA 83 MOV R2,DPH
410D AB 82 MOV R3,DPL
410F 90 41 8F MOV DPTR,#418F
4112 A8 83 MOV R0,DPH
4114 A9 82 MOV R1,DPL
4116 GO: E0 MOVX A,@DPTR
4117 A8 83 MOV R0,DPH
4119 A9 82 MOV R1,DPL
411B 90 FF 0C MOV DPTR,#FF0C
411E F0 MOCX @DPTR,A
411F 09 INC R1
4120 88 83 MOV DPH,R0
4122 89 82 MOV DPL,R1
4124 E0 MOVX A,@DPTR
4125 A8 83 MOV R0,DPH
4127 A9 82 MOV R1,DPL
4129 90 FF 0D MOV DPTR,#FF0D
412C F0 MOVX @DPTR,A
412D 09 INC R1
412E 88 83 MOV DPH,R0
4130 89 82 MOV DPL,R1
4132 E0 MOVX A,@DPTR
4133 A8 83 MOV R0,DPH
4135 A9 82 MOV R1,DPL
4137 90 FF 0E MOV DPTR,#FF0E
413A F0 MOVX @DPTR,A
413B 09 INC R1
413C 12 41 75 LCALL 4175
413F 8A 83 MOV DPH,R2
4141 LOOP1: 8B 82 MOV DPL,R3
4143 E0 MOVX A,@DPTR
4144 AA 83 MOV R2,DPH
4146 AB 82 MOV R3,DPL
4148 90 FF 0C MOV DPTR,#FF0C
414B F0 MOVX @DPTR,A
414C 0B INC R3
414D 8A 83 MOV DPH,R2
414F 8B 82 MOV DPL,R3
4151 E0 MOVX A,@DPTR
4152 AA 83 MOV R2,DPH
4154 AB 82 MOV R3,DPL
4156 90 FF 0D MOV DPTR,#FF0D
4159 F0 MOVX @DPTR,A
415A 0B INC R3
415B 8A 83 MOV DPH,R2
415D 8B 82 MOV DPL,R3
415F E0 MOVX A,@DPTR
4160 AA 83 MOV R2,DPH
4162 AB 82 MOV R3,DPL
4164 90 FF 0E MOV DPTR,#FF0E
4167 F0 MOVX @DPTR,A
4168 0B INC R3
4169 12 41 82 LCALL 4182
416C 88 83 MOV DPH,R0
416E 89 8A MOV DPL,R1
4170 DC A4 DJNZ R4, G0(41 )
4172 12 41 06 LCALL 4106

4175 DELAY: 7D 12 MOV R5,#12


4177 DLY1: 7E FF MOV R6,#0FF
4179 DLY2: 7F FF MOV R7,#0FF
417B DLY3: DF FF DJNZ R7,417B
417D DE FA DJNZ R6,4179
417F DD F6 DJNZ R5,4177
4181 22 RET

4182 DELAY1: 7D 12 MOV R5,#12


4184 DLY_1: 7E FF MOV R6,#0FF
4186 DLY_2: 7F FF MOV R7,#0FF
4188 DLY_3: DF FF DJNZ R7,4188
418A DE FA DJNZ R6,4186
418C DD F6 DJNZ R5,4184
418E 22 RET

418F LOOK: 44 27 12 DB 44H, 27H, 12H


4192 92 2B 10 DB 92H, 2BH, 10H
4195 84 9D 10 DB 84H, 9DH, 10H
4198 84 2E 48 DB 84H, 2EH, 48H
419B LOOK1: 48 27 12 DB 48H, 27H, 12H
419E 92 4B 10 DB 92H, 4BH, 10H
41A1 84 9D 20 DB 84H, 9DH, 20H
41A4 04 2E 49 DB 04H, 2EH, 49H

RESULT:
Thus, the program for interfacing traffic light controller with 8051were executed successfully
and output is verified.

EXP NO: 5
INTERFACING STEPPER MOTOR CONTROLLERS
DATE

AIM:
To run stepper motor in both forward and reverse directions with delay
ALGORITHM:

1.​ Start program.


2.​ Load DPTR with the address of TABLE (4500H).
3.​ Load R0 = 4 (number of steps).
4.​ Repeat until R0 = 0:​
a. Fetch a data byte from TABLE into accumulator.​
b. Save DPTR.​
c. Send the byte to external port FFC0H.​
d. Call DELAY.​
e. Send the same byte to external port FFC8H.​
f. Call DELAY.​
g. Restore DPTR.​
h. Increment DPTR (next table element).​
i. Decrement R0. If not zero, repeat.
5.​ After 4 steps, restart from beginning (continuous rotation).
6.​ Delay subroutine generates required delay for motor speed control.

PROGRAM:

ADDRESS OPCODES LABEL MNEMONICS COMMENTS


4100 90 45 00 START: MOV DPTR, #4500
4103 78 04 MOV R0, #04H
4105 E0 J1: MOVX A, @DPTR
4106 FC MOV R4,A
4107 C0 83 PUSH DPH
4109 C0 82 PUSH DPL
410B 90 FF C0 MOV DPTR,# FFC0
410E F0 MOVX @DPTR,A
410F 12 41 23 LCALL 4123
4112 90 FF C8 MOV DPTR,#FFC8
4115 EC MOV A,R4
4116 F0 MOVX @DPTR,A
4117 12 41 23 LCALL 4123
411A D0 82 POP DPL
411C D0 83 POP DPH
411E A3 INC DPTR
411F D8 E4 DJNZ R0,4105
4121 80 DD SJMP 4100
DELAY:
4123 7A 04 MOV R2, #04H
4125 79 0F MOV R1, #0FH
4127 7B 7F DLY1: MOV R3, #7FH CHANGE THE
MOTOR SPEED
4129 DB FE DLY: DJNZ R3, 4129
412B D9 FA DJNZ R1, 4127
412D DA F6 DJNZ R2, 4125
412F 22 RET
FORWARD REVERS
E
4500 TABLE: DB 09 DB 0A
4501 DB 05 DB 06
4502 DB 06 DB 05
4503 DB 0A DB 09
RESULT :
The stepper motor was interfaced in various modes with 8051.

You might also like