210 likes | 227 Views
TK2633: MICROPROCESSOR & INTERFACING. Programming Techniques. DELAY. Procedure to use delay is almost similar to counter. A register is loaded with a number; depending on the delay required; the register is subtracted until zero is achieved by putting the conditional jump instruction.
E N D
TK2633:MICROPROCESSOR & INTERFACING Programming Techniques
DELAY • Procedure to use delay is almost similar to counter. • A register is loaded with a number; depending on the delay required; the register is subtracted until zero is achieved by putting the conditional jump instruction. Dr. Masri Ayob: TK2633
Time delay using a single register Dr. Masri Ayob: TK2633 figure 2
Time delay using a single register • From the example, noticed that the MVI instruction uses 7 Time states for it to execute. • Suppose the 8085 µp has a clock frequency of 2MHz, the MVI instruction will execute within 3.5µs. • Below is the example to calculate the time of execution. Dr. Masri Ayob: TK2633
Where • TL = Time delay in the loop. • T = time states of the system (1/f) • N10 = decimal number Time delay using a single register • If the clock frequency given is 1MHz, then the MVI instruction will take 7µs to execute. • To calculate the time delay in a loop, the total T-states and total instructions must be predetermined. • In figure 2, register C is loaded with FFH (25510). • DCR and JNZ in the loop use 14 T-states. And the loop will repeat 255 times until C gets zero. • Then the delay calculation is determined as follows: Dr. Masri Ayob: TK2633
Time delay using a single register • Most of the time, the delay calculation is almost accurate, however to get better accuracy the calculation for JNZ has to be modified. • The T-states for JNZ shows 10/7. It means the 8085 µp requires 10 T-states for JNZ to jump within the loop process, and 7 T-states when JNZ jump out of the loop. • Therefore in the final loop (255th loop) the JNZ instruction uses 7 T-states and the following calculation shows how to modified this accuracy. Dr. Masri Ayob: TK2633
Time delay using a single register • Therefore the overall delay including the delay outside the loop is as follows: Dr. Masri Ayob: TK2633
Time delay using register pair • Longer delay can be achieved by using register pair and 16-bits number. • The 16-bit numbers require DCX instruction to decrement. However the DCX instruction will not affect Z flag. • Therefore special technique has to be added. Below is the example of using BC register pair as delay register. Dr. Masri Ayob: TK2633
Time delay using register pair • In the previous example, the instruction • LXI B, 2384H, causes B=23H and C = 84H. • DCX instruction will decrement the BC by one. • MOV A,C and ORA B, are to determine the content of Z flag. • The OR instruction set the Z register whenever B and C have the same value that is zero. • Therefore this loop will repeat 2384H times. • The total T-states in the loop is 24 (for instructions DCX, MOV, ORA and JNZ). • The conversion of 2384H times equivalent to its decimal: Dr. Masri Ayob: TK2633
Time delay using register pair • Suppose the time interval in the system is 0.5µs, the delay in the loop is: • The same time delay technique can be used to calculate the delay of nested loop delay technique (loop within a loop). Dr. Masri Ayob: TK2633
Time delay using a loop within a loop • A longer time delay can be achieved using two loops; one loop is inside the other loop. • As shown in the instructions below, the C register is used in the inner loop (LOOP1) and the B register is used in the outer loop (LOOP2). • Example: Dr. Masri Ayob: TK2633
Time delay using a loop within a loop Figure 3 Dr. Masri Ayob: TK2633
Time delay using a loop within a loop • Delay in the LOOP1 is equal to the previous example, TL1 = 1783.5µs. • The second loop, LOOP2 is generated 56 times equivalent to 38H in B register. • Delay calculation for LOOP2 is as follows: Dr. Masri Ayob: TK2633
Counter design with time delay Figure 4 Dr. Masri Ayob: TK2633
Counter design with time delay Rajah 5 Dr. Masri Ayob: TK2633
Counter design with time delay • Example : • Write a programme to count number from FFH to 00H in a system with time interval of 0.5 µs. • Use C register as delay register with the delay of 1ms for every count. • Display the count at the output port. • Analysis: • The hexadecimal counter is loaded in a register and decremented until zero is reached. • After reaches zero the counter will start again at FFH. • To get 1ms delay, one value will be loaded into register C, and the delay calculation is as shown in previous example. Dr. Masri Ayob: TK2633
Counter design with time delay MVI B, 00H NEXT DCR B MVI C, COUNT DELAY DCR C JNZ DELAY MOV A, B OUT PORT JMP NEXT Dr. Masri Ayob: TK2633
Counter design with time delay • Delay calculation (TL delay in the loop) : Dr. Masri Ayob: TK2633
Exercise • Write a program to turn a light ON and OFF every 2 seconds. Use data bit D7 (at OUTPORT) to operate the light. Logic ‘0’ will ON the light, whilst logic ‘1’ OFF the light. The clock frequency of the MPU is 2 MHz. Dr. Masri Ayob: TK2633
Thank youQ&A Dr. Masri Ayob: TK2633