0% found this document useful (0 votes)
282 views4 pages

Experiment 2 Programming With Time Delay Using Leds Learning Objectives

This document describes an experiment using an 8051 microcontroller to create time delays with LEDs and handle input/output operations. It includes: 1) A procedure to program a time delay using registers and looping that blinks LEDs. 2) Extensions to the program to add register math and display results. 3) A second program using interrupts from switches as input, rotating the LED display with time delays between reads. 4) Questions about the programs and time delays are included for students to answer.

Uploaded by

Raj Daniel Magno
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)
282 views4 pages

Experiment 2 Programming With Time Delay Using Leds Learning Objectives

This document describes an experiment using an 8051 microcontroller to create time delays with LEDs and handle input/output operations. It includes: 1) A procedure to program a time delay using registers and looping that blinks LEDs. 2) Extensions to the program to add register math and display results. 3) A second program using interrupts from switches as input, rotating the LED display with time delays between reads. 4) Questions about the programs and time delays are included for students to answer.

Uploaded by

Raj Daniel Magno
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/ 4

EXPERIMENT 2

PROGRAMMING WITH TIME DELAY USING LEDS

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

Each instruction in any microprocessor or microcontroller requires time to be executed. The


time needed for execution is called the clock cycle. The duration for the instruction to be
executed can be used to come up with the desired delay. Delays can be derived through a
sequence of instructions. The concept of looping should be applied in the development of a
time delay. Looping makes the program short but it can adjust to the number of cycles needed.
It however, has limitations. Time delays can use the maximum value of hexadecimals which is
FFH. The total number of clock states for the instructions in a delay loop is actually the desired
time delay. Take note that in the computation of time delays, every hexadecimal number should
be converted into decimal.

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

PART I. – TIME DELAY USING LEDS


1. Launch the EdSim51DI simulator.
2. A time delay is used to set the number of times that a part of the program should be
executed. Click New and encode the following instructions at the IDE (integrated
development environment): Note: this is case sensitive.

ORG 0000H;initializing the starting address of the program
MAIN: ;start of the main program
CLR A ;clear the content of register Accumulator
MOV A, #06H ;loading the register Accumulator with 06H
MOV B, #03H ;loading the register B with 03H
AGAIN: DEC A ;subtracting one from the content of the register Accumulator
DJNZ B, AGAIN ;subtracting one from the content of the register B until it become 0,otherwise it will jump to AGAIN
END ;end of the program

The Org 0000H is used to initialize the starting address of the program. For normal operation,
you should start at address 0000H. MAIN is just a name or label given to the program. CLR A

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.

PART II. – I/O PORT INTERFACE WITH TIME DELAY


1. Click new in the EdSim51DI IDE.
2. Encode the following at the starting address 0000H.
ORG 0000H ;initializing the starting address of the program
MAIN: ;start of the main program
CLR A ;clear the content of register Accumulator
GETIN:
CALL DELAY ;call the time delay to wait for switch press
MOV A, P2 ;input using two switches
CPL A ;complement the content of the register Accumulator
JZ GETIN ;jump to GETIN if no switch is pressed

CPL A ;complement the content of the register Accumulator
MOV P1, A ;display content of register Accumulator in LEDs
CALL ROT ;call sub program ROT

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

3. Assemble the program.


4. Press two switches (immediately after running the program).
5. Observe the output. Answer Q1.
6. Pause the program and click RST. Change RL to RR. Run the program again and change
the pressed switch. Observe the output. Answer Q2.
7. To analyze the time delay. Answer Q3 and Q4.

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

You might also like