Sep 28, 2014 #1 I internetuser2k13 Member level 3 Joined Aug 10, 2013 Messages 56 Helped 0 Reputation 0 Reaction score 0 Trophy points 6 Location pakistan 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); }
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); }
Sep 28, 2014 #2 H horace1 Advanced Member level 5 Joined Nov 18, 2008 Messages 2,118 Helped 596 Reputation 1,188 Reaction score 571 Trophy points 1,393 Location Norwich, UK Activity points 13,063 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
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
Oct 4, 2014 #3 M mdvrajkot Newbie level 6 Joined Jun 13, 2013 Messages 14 Helped 1 Reputation 2 Reaction score 1 Trophy points 1,283 Location India Activity points 1,376 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: Oct 4, 2014
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.