Professional Documents
Culture Documents
Experiment 2 Programming With Time Delay Using Leds Learning Objectives
Experiment 2 Programming With Time Delay Using Leds Learning Objectives
Experiment 2 Programming With Time Delay Using Leds Learning Objectives
Learning Objectives:
1. Apply what they have learned in experiment #1.
2. Understand/use the instruction set of 8051.
3. Use the instruction set in creating a time delay using LEDs.
4. Demonstrate how the I/O interface work through time delay, and
5. Understand the use of flowcharts in programming.
DISCUSSION
The time delay is only a part of a program. It is dependent on the programmer on how time
delays will be used, and be part of or implemented in the codes. The sample time delay given
on the procedure may be used only as a reference; it might not give you the desired output that
you were asked to come up with from the given procedure. Changes should be made to come
up with the wanted output.
PROCEDURE
https://www.edsim51.com/index.html
makes sure that the register accumulator content is 00. MOV A, #06H means to load
hexadecimal value 06 to register accumulator. MOV B, #03H means to load hexadecimal value
03 to register B. AGAIN is just a name/label given to the loop or delay. DEC A, means to
subtract one from the content of register accumulator. DJNZ B, AGAIN means to decrement
or subtract one from the content of register B, and if it is not yet equal to zero, it will jump back
to AGAIN to perform instructions following the label. END means to end the whole program.
For additional information about the instruction set of 8051, refer to this link
http://www.keil.com/support/man/docs/is51/is51_opcodes.htm.
3. To speed up the output. Click Update Frequency (Update Freq.). For this program,
choose 1.
4. To save your program. Click Save.
5. Assemble the program. Click Assm.
6. To observe the output. Click Run.
7. To pause the execution. Click Pause.
8. To stop program execution. Click RST.
9. Click Assm.
10. To execute the program line per line. Click Step.
11. Observe the content of the registers at the left side of the simulator.
12. Click Pause.
13. To encode, edit, and debug the program. Click RST.
14. Change #06 to FFFFH and #03 to FFH.
15. Click Assm. Answer Q1.
16. Save the encoded program. Add the following into the encoded program
a. Use register R0 as a counter and store it with 03H.
b. Add the content of registers A and B.
c. Store the result (sum) in register A.
d. Display the result in port 1 (P1)
e. Answer Q2, Q3, Q4, and Q5.
https://www.edsim51.com/index.html
ROT:
RL A ;rotate left the content of register Accumulator
MOV P1, A ;display the rotated content of register Accumulator in LEDs
CALL ROT ;call ROT to continuously rotate the content of the register Accumulator
;time delay
DELAY:
MOV R0, #0FH ;loading register R0 with 0FH
L1: MOV R1, #01H ;loading register R1 with 01H
L2: MOV R2, #01H ;loading register R2 with 01H
DJNZ R2, $ ;decrement R2 until it become 0, otherwise will remain in this line
DJNZ R1, L2 ;decrement R1 until it become 0, otherwise it will jump to L2
DJNZ R0, L1 ;decrement R0 until it become 0, otherwise it will jump to R1
RET ;return from the sub program DELAY to the MAIN program
END ;end of the program
https://www.edsim51.com/index.html
8. The flowchart below illustrates the normal flow of an input/output operation with
time delay of a microprocessor/microcontroller system. Answer Q5.
https://www.edsim51.com/index.html