/*It genarates a approximate delay of 10us for each count,
if 5000 is passed as the argument then it generates a delay of apprx 50ms.*/
void delay_us(unsigned int us_count)
{
while(us_count!=0)
{
us_count--;
}
}
/*It genarates a approximate delay of 1ms for each count,
if 1000 is passed as the argument then it generates delay of apprx 1000ms(1sec)*/
void delay_ms(unsigned int ms_count)
{
while(ms_count!=0)
{
delay_us(112); //delay_us is called to generate 1ms delay
ms_count--;
}
}
/*It genarates a approximate delay of 1sec for each count,
if 10 is passed as the argument then it generates delay of apprx 10sec
note: A max of 255 sec delay can be generated using this function.*/
void delay_sec(unsigned char sec_count)
{
while(sec_count!=0)
{
delay_ms(1000); //delay_ms is called to generate 1sec delay
sec_count--;
}
}
several way to create delay function . but best way is using _nop_() instruction and count cycle using stop watch to get better result .
void DelayMicro (int us)
{
for( ; us > 0 ; us--)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
void DelayMs (int mS)
{
unsigned int a ;
unsigned char b ;
for(a = 0 ; a < mS ; a++)
{
for(b = 0 ; b < 190 ; b++)
{
_nop_();
_nop_();
}
}
}
in my 89c51rd2 and crystal 11.0592 delay for 1 microsecond is below
Code:void DelayMicro (int us) { for( ; us > 0 ; us--) { _nop_(); _nop_(); _nop_(); _nop_(); } }
and 1 mSec
Code:void DelayMs (int mS) { unsigned int a ; unsigned char b ; for(a = 0 ; a < mS ; a++) { for(b = 0 ; b < 190 ; b++) { _nop_(); _nop_(); } } }
several way to create delay function . but best way is using _nop_() instruction and count cycle using stop watch to get better result .
For small delays, such as around few micro seconds, no problem.
However, for somewhat on magnitude of mili seconds and higher, this implementation waste excessive computer processing of the microcontroler.
On that circumstances, is better suitable employ time slot approach, interrupt driven, in order to release overall program processing.
+++
For small delays, such as around few micro seconds, no problem.
However, for somewhat on magnitude of mili seconds and higher, this implementation waste excessive computer processing of the microcontroler.
On that circumstances, is better suitable employ time slot approach, interrupt driven, in order to release overall program processing.
+++
in my 89c51rd2 and crystal 11.0592 delay for 1 microsecond is below
Code:void DelayMicro (int us) { for( ; us > 0 ; us--) { _nop_(); _nop_(); _nop_(); _nop_(); } }
and 1 mSec
Code:void DelayMs (int mS) { unsigned int a ; unsigned char b ; for(a = 0 ; a < mS ; a++) { for(b = 0 ; b < 190 ; b++) { _nop_(); _nop_(); } } }
...I have to keep delay more then an hour also or for few hours...can you help me to get idea to complete this...
I already did that on other core with DS1307 RTC using C language, and it is extremely easy, due this device can be configured to generate a precise 1s at output pin which can be read from microcontroler through I/O interrupt routine.
Check if this helps you: https://www.edaboard.com/threads/225009/#post959855
+++
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?