Discussion in "Software" started by    vijay    Jan 5, 2012.
Thu Jan 05 2012, 01:26 pm
#1
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;


}


Thu Jan 05 2012, 03:06 pm
#2
@ 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

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

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am