Eet 303 M2
Eet 303 M2
MODULE-2
Syllabus
2.1 8085 PROGRAMMING
In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
• LXI SP, FFFFH
• This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
• The Size of the stack is limited only by the available memory
Microprocessor reads the subroutine address from the next two memory location and stores the
higher order 8bit of the address in the W register and stores the lower order 8bit of the address in
the Z register
– Pushes the current value of Program Counter onto the stack [Return address]
– Loads the program counter with the 16-bit address supplied with the CALL instruction from WZ
register.
➢ Delay routines are subroutines used for maintaining the timings of various operations in
microprocessor.
➢ In control applications, certain equipment needs to be ON/OFF after a specified time delay.
In some applications, a certain operation has to be repeated after a specified time interval.
In such cases, simple time delay routines can be used to maintain the timings of the
operations.
The Delay:
➢ The delay time is given by the total time taken to execute the delay routine.
➢ It can be computed by multiplying the total number of T-states required to execute
subroutine and the time for one T-state of the processor.
➢ The total number of T-states can be computed from the knowledge of T-states required for
each instruction.
➢ The time for one T-state of the processor is given by the inverse of the system clock
frequency of the processor.
For example, if the 8085 microprocessor has system clock frequency = 2.5 MHz
Write a delay routine to produce a time delay of 0.5 mS in 8085 processor-based system whose
clock frequency is 3 MHz.
Solution
The delay required is 0.5 mS, hence an 8-bit register of 8085 can be used to store a Count value
and then decrement to zero. The delay routine is written as a subroutine as shown below.
Delay routine
MVI D, N ; Load the count value, N in D-register.
Loop: DCR D ; Decrement the count.
JNZ Loop ; if count not equal to 0 , go to loop
RET ; Return to main program.
The following table shows the T-state required for execution of the instructions in the subroutine.
T-State required for
Number of times the
Instruction execution of an Total T-States
instruction is executed
instruction
MVI D, N 7 1 7x1=7
7 1 7x1=7
RET 10 1 10 x 1 = 10
14N + 14 = 1500
N = (1500 – 14) / 14 = 106.14210 ≈ 10610 = 6AH
Therefore by replacing the count value, N by 6AH in the above program , a delay of 0.5mSec can
be produced.
Delay Routine Using 16-bit register as counter
Example
Write a delay routine to produce a time delay of 0.5 mS in 8085 processor-based system whose
clock frequency is 3 MHz using 16-bit register as counter.
Solution
Delay routine
LXIB, N ; Load the count value, N in BC pair register.
Loop: DCX B ; Decrement the count.
MOV A,B ; Place contents of B in A
ORA C ; OR B with C to set Zero flag
JNZ Loop ; if result not equal to 0 , go to loop
RET ; Return to main program.
The following table shows the T-state required for execution of the instructions in the subroutine.
T-State required for
Number of times the
Instruction execution of an Total T-States
instruction is executed
instruction
LXI B, N 10 1 10 x 1 = 10
MOV A, B 4 N times 4 x N = 4N
ORA C 4 N times 4 x N = 4N
7 1 7x1=7
RET 10 1 10 x 1 = 10
24N + 17 = 1500
N = (1500 – 17) / 24 = 61.7910 ≈ 6210 = 3EH
Therefore by replacing the count value, N by 3EH in the above program , a delay of 0.5mSec can
be produced.
Write a delay routine to produce a time delay of 1 mS in 8085 processor-based system whose clock
frequency is 3 MHz using nested loop.
Solution
Delay routine
MVI B, P ; Load the count value, P in B-register.
LOOP2: MVI C, Q ; Load the count value, Q in B-register.
LOOP1: DCR C ; Decrement the count P.
JNZ LOOP1 ; if count in C not equal to 0 , go to loop LOOP1
DCR B ; Decrement the count Q.
JNZ LOOP2 ; if count in B not equal to 0 , go to loop LOOP2
RET ; Return to main program.
The following table shows the T-state required for execution of the instructions in the subroutine.
T-State required for Number of times the
Instruction execution of an instruction is Total T-States
instruction executed
MVI B, P 7 1 7x1=7
7 P times 7 x P = 7P
DCR C 4 P times 4 x P = 4P
7 1 7
RET 10 1 10
= 1 / 3x106
= 0.333µS
= 1 mS / 0.333µS
= 3003
= 300310
28Q + 50 = 3003
Therefore by replacing the count value, P by 02H and Q by 69H in the above program , a delay of
1mSec can be produced.