We can provide Delay in 8051 micro-controller by using "MOV" instructions and by using timer. Here we describe the procedure for Delay using "MOV" instruction.
Every instruction takes it's own time (in terms of Machine Cycles) to execute. We can write instruction in such a manner that time required to execute those instructions is nearly equal to the required Delay time. General steps for writing Delay Subroutine is given as follows:
This piece of subroutine will provide delay in seconds. Amount of Delay which will be provided by this code depends on the content of R3, R2, R1. Again, the values to be filled into R3, R2, R1 Depends on the required Delay.
(Note: We will use more registers if required. If after calculation some Registers value is 0, then we will not use corresponding line in the code.)
Following videos further describe the procedure for calculating delay subroutine in more detail.