1 / 20

TK2633: MICROPROCESSOR & INTERFACING

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.

shively
Download Presentation

TK2633: MICROPROCESSOR & INTERFACING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TK2633:MICROPROCESSOR & INTERFACING Programming Techniques

  2. 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

  3. Time delay using a single register Dr. Masri Ayob: TK2633 figure 2

  4. 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

  5. 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

  6. 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

  7. Time delay using a single register • Therefore the overall delay including the delay outside the loop is as follows: Dr. Masri Ayob: TK2633

  8. 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

  9. 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

  10. 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

  11. 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

  12. Time delay using a loop within a loop Figure 3 Dr. Masri Ayob: TK2633

  13. 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

  14. Counter design with time delay Figure 4 Dr. Masri Ayob: TK2633

  15. Counter design with time delay Rajah 5 Dr. Masri Ayob: TK2633

  16. 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

  17. 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

  18. Counter design with time delay • Delay calculation (TL delay in the loop) : Dr. Masri Ayob: TK2633

  19. 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

  20. Thank youQ&A Dr. Masri Ayob: TK2633

More Related