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

Discussion in 'The Projects Forum' started by Jackerq1, Nov 12, 2011.

  1. Jackerq1

    Thread Starter New Member

    Nov 1, 2011
    4
    0
    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
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  3. Jackerq1

    Thread Starter New Member

    Nov 1, 2011
    4
    0
    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();
    }
    }
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    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:

    Code ( (Unknown Language)):
    1. unsigned long int i;
    2. unsigned int sec;
    3. {
    4.    for(sec=0;sec<5;sec++)
    5.    {
    6.       for(i=0;i<30000;i=++)
    7.       {
    8.          NOP();
    9.       }
    10.    }
    11. }
    12.  
     
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
Loading...