# Delay time coding knowledge~~~~~~~~~~~

#### Jackerq1

Joined Nov 1, 2011
4
Unsigned long int i;
{
For(i=0;i<30000;i=++)
{
NOP();
}
}

Above is the delay time for 1 second .I wan change to 5 second how should i modify the coding .i using software MBLAB and PIC16F628A.thanks

#### hgmjr

Joined Jan 28, 2005
9,029
If 30000 loops equals one second of delay then 30000 times 5 should produce 5 seconds of delay. I suggest you replace 30000 with 150000.

hgmjr

#### Jackerq1

Joined Nov 1, 2011
4
but duno y cannot work then i use this also gt error cna hlp me c wat problem ?
unsigned long int j;
void delay5s()
{
for(j=i;j<5i;j++)
{
NOP();
}
}

#### SgtWookie

Joined Jul 17, 2007
22,210
The maximum you can store in an unsigned long int on your machine is 65535; so you are getting an error when you overflow the variable i.
Use nested loops like this:

Rich (BB code):
unsigned long int i;
unsigned int sec;
{
for(sec=0;sec<5;sec++)
{
for(i=0;i<30000;i=++)
{
NOP();
}
}
}

#### hgmjr

Joined Jan 28, 2005
9,029
I have always considered and this wiki link appears to confirm that an "unsigned long" is 32 bits rather than 16 bits.

I associate 16-bit variables with "word".

hgmjr