Delay function for NXP89v51RD2

Status
Not open for further replies.

Sudhp

Member level 4
Joined
Oct 11, 2013
Messages
69
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
India
Activity points
528
I m using NXP89v51RD2 micro......
the oscillator frequency is 11.0593 MHz...
I want to make a delay function as user want to set it....such like for 3 sec,4 sec,8 sec etc....
can anybody help me and provide me codes for this in c language.......
and logic too..
 

Use Compiler and check how much time is needed to make a delay of 1 us then using time taken for one nop make the delay function for 1 us then use this function to get the desired delays.


STEP 1. FOR CRYSTAL FREQUENCY = 11.0592MHz

STEP 2. ONE MACHINE CYCLE FREQUENCY = CRYSTAL FREQUENCY/12 = 11.0592/12 = 921.6ms

STEP 3. ONE MACHINE CYCLE TIME PERIOD = 1/FREQUENCY = 1/921.6ms = 1.085us

1.085 us is the time for one nop.
 
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
code for delay
Code:
void delay(unsigned int val)
{
unsigned int n,m;
	for(n=0;n<val;n++)
		for(m=0;m<=120;m++);
}

pass value in function
1000 = 1 sec.
 
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
thanks embpic .....
but u please tell me what is the role of 120 in this programming and why we taking value 120 only......
 

Actually this is c programme so from this code assembly code get genrate and in for loop that that much instructions get executed.
 
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
thank for reply jayanth..
I m using keil uvision 3 as a compiler....
how can I check time needed to make delay of 1 us....
and than how I make nop function by using this.......
As I have very few knowledge about these things so it 's my request please explain it in simple way.....
 

code for delay
Code:
void delay(unsigned int val)
{
unsigned int n,m;
	for(n=0;n<val;n++)
		for(m=0;m<=120;m++);
}

pass value in function
1000 = 1 sec.

My programming......
void delay(unsigned int time)
{
int a,b;
time=(time*1000*60); //as required delay in min
for(a=0;a<time;a++)
for(b=0;b<120;b++);
}

But I found almost same delay(about 1 min) for any value of time such like time=1,2,3....etc
why is this happening?
 

Delay of 1 minute?????
If ur controller is free to do this one task only then it's ok but ifvyou have no.of task to do then use interrupt.
 
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
Delay of 1 minute?????
If ur controller is free to do this one task only then it's ok but ifvyou have no.of task to do then use interrupt.

thanks for reply....
I don't know how to use interrupts and programming for this.....
Can u help me by providing codes for this or giving any idea about this.......:--(
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…