This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

delay value problem

Hello everyone,
I am not able to figure out the maximum delay value i can give.If i give to high the simulator stops at that function,please suggst me the maximum delay i can give.
Here's the code:

//square wave generator
#include <reg52.h>

#define on 1;
#define off 0;

void delay(void);

sbit switchpin = P1^0;
sbit sqgen = P2^1;

void main(void)
{
        P2 = off;
        while(1)
        {
                if(switchpin == 1)
                {
                        sqgen = on;
                        delay();
                        sqgen = ~sqgen;
                }
                else
                        sqgen = off;
        }
}
void delay(void)
{
        int i=0;
        for(i=0;i<=29000;i++);
}


The value of 'i' in the delay function is what i am referring to.
Thanks in advance,
Arun

Parents
  • "so i tried 32767,but it gives the same effect."

    But that means you actually tried 32768. Why? Because the loop should repeat as long as i was <= 32767. The only way to get i > 32767 is to get it to reach 32768. Which doesn't exist for a 16-bit 2-complement integer. Always keep track of the end limits. It's too easy to get hurt by off-by-one errors.

Reply
  • "so i tried 32767,but it gives the same effect."

    But that means you actually tried 32768. Why? Because the loop should repeat as long as i was <= 32767. The only way to get i > 32767 is to get it to reach 32768. Which doesn't exist for a 16-bit 2-complement integer. Always keep track of the end limits. It's too easy to get hurt by off-by-one errors.

Children
No data