8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage, majoka
Author Post
vijay.parmar1992
Thu Jan 05 2012, 02:56AM

Registered Member #35657
Joined: Fri Sep 23 2011, 11:33AM
Location (Home Town): gujarat
Posts: 111
frnds i type this code for generate 1 second delay but it goes to infinite....why?


#include<reg51.h>
void todelay(void);




void main (void)
// timer for 1 second
{
while(1)

todelay();


}






void todelay()
{
TMOD=0x01;

TL0=0xfc;
TH0=0x4b;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;


}


Back to top
majoka
Thu Jan 05 2012, 04:36AM

Registered Member #22104
Joined: Thu Sep 10 2009, 03:04PM
Location (Home Town): Wah Cantt, Pakistan
Posts: 3900
@ vijay.parmar1992
in while(1) loop u only call the delay function that is why it is seems to infinite
u can also use this delay

CODE:
void delay_ms (unsigned int count)
{
unsigned int i;                          
while(count)
{
i = 115;
while(i>0) i--;
count--;
}
}


delay_ms(1000); means 1 sec delay
Back to top
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

© 2010 Rickey's World
Render time: 0.0568 sec, 0.0054 of that for queries. DB queries: 34. Memory Usage: 2,755kB