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
  • Thanks for the reply.As you may have noticed i am taking my first few baby steps in embedded c.
    Yeah i figured it will be a 16 bit int,so i tried 32767,but it gives the same effect.
    Later i realized that my int wasn't unsigned.Once i changed it,it worked perfectly

    -What's more, you should be careful whether an inner/outer Watchdog is employed.

    I am not familiar with this "inner/outer Watchdog" ,could you please explain it in detail.

    -What's more and more, why you declare i=0 and then initial i=0 again?

    Old c habit of mine lol ,when ever i declare an integer ,i initialize it to 0 to avoid any future logical errors/garbage related to that variable int.

Reply
  • Thanks for the reply.As you may have noticed i am taking my first few baby steps in embedded c.
    Yeah i figured it will be a 16 bit int,so i tried 32767,but it gives the same effect.
    Later i realized that my int wasn't unsigned.Once i changed it,it worked perfectly

    -What's more, you should be careful whether an inner/outer Watchdog is employed.

    I am not familiar with this "inner/outer Watchdog" ,could you please explain it in detail.

    -What's more and more, why you declare i=0 and then initial i=0 again?

    Old c habit of mine lol ,when ever i declare an integer ,i initialize it to 0 to avoid any future logical errors/garbage related to that variable int.

Children