Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Experiment - 4: Delay Generation and Use of Keil Debugger

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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

Two factors can affect the accuracy of the delay:

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:

1. Write an assembly language program to generate a delay of 5 seconds. Use debugger to


measure actual delay and then compute the percentage error in your program. Now optimize
your program to minimize the error in delay. The percentage error should be less than10−3 .

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

You might also like