Experiment - 4: Delay Generation and Use of Keil Debugger
Experiment - 4: Delay Generation and Use of Keil Debugger
Experiment - 4: Delay Generation and Use of Keil Debugger
OBJECTIVES:
To understand the use of branch instructions available in 8051 assembly language.
To be able to generate a given amount of delay using nested loops such that error is
minimum in the delay
EQUIPMENT/TOOLS:
KeilμVision.3IDE
BACKGROUND:
Every microprocessor needs a clock to execute the program. CPU executing an
instruction takes a certain number of clock cycles. These are referred to as machine cycles.
The length of machine cycle depends on the frequency of the crystal oscillator connected to
8051. In original 8051, one machine cycle lasts 12 oscillator periods. We may use DJNZ
instructions to make nested loops to generate desired amount of delay. Each DJNZ takes 2
machine cycles.
Oscillator frequency=f os
Amount of delay required=t 0
f os × t 0
No .of machine cycles required ¿ generate ¿ delay =
12
f os ×t 0
No .of DJNZs required ¿ generate ¿ delay=
12 ×2
Following examples demonstrate how to compute the execution time in of a program:
Lab Manual of Microprocessor Interfacing & Programming
1. Crystal frequency: The duration of the machine cycle is a function of this crystal
frequency.
2. 8051 design: The original machine cycle duration was set at 12 clocks. Advances in
both IC technology and CPU design in recent years have made
We can use debugger of our IDE to find the time taken by the processor to execute a
program. Following figure demonstrates
Page | 2
Lab Manual of Microprocessor Interfacing & Programming
EXERCISES:
2. Eight LEDs are required to glow according to the patterns mentioned in the table below.
There are two groups of patterns. Each group consists of two patterns. You are required to
design and implement an algorithm that switch between the two patterns every 2 seconds.
Moreover, groups are switched every 8 seconds.
Note: The red color of LED represents HIGH logic and green color represents LOW logic.
Group#
1
Group#
2
Page | 3