Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

delay function working using for loop

Status
Not open for further replies.

internetuser2k13

Member level 3
Member level 3
Joined
Aug 10, 2013
Messages
56
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
pakistan
Visit site
Activity points
408
hello,
i want to know the basic understanding of delay function, how its working.


Code:
void delay_sec(unsigned char seconds)    // This function provides delay in terms of seconds
{
    unsigned char i,j;

    for(i=0;i<seconds;i++)
        for(j=0;j<100;j++)
            __delay_ms(10);
}
 

Code:
__delay_ms(10);
delays fot 10mSeconds (1/100 of a second)

Code:
for(j=0;j<100;j++)
            __delay_ms(10);
delays fot 1 second , i.e. loops 100 times each delay 10mSec

Code:
 for(i=0;i<seconds;i++)
        for(j=0;j<100;j++)
            __delay_ms(10);
delays for a specified number of seconds

this type of delay means you cannot do anything else in the main control loop (interrupts can do other things but may upset the delay timing)

in practice one would probably use a timing loop driven by interrupts which allowed other things to happen
 

Hello internetuser2k13,

1.
Code:
        for(j=0;j<100;j++)
            __delay_ms(10);

Assuming that __delay_ms(10) functions generates the delay of 10ms.

total_delay_1 = 10ms x 100 = 1000 ms = 1sec

2.
Code:
     for(i=0;i<seconds;i++)
        for(j=0;j<100;j++)
            __delay_ms(10);

total_delay = 1 sec x seconds(variable)

3. It will generate the delay of approx. total_delay. Again for the accurate delay measurement we need to calculate the delay for the for loop and the variable declarations.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top