delay argument too long : showing error

Thread Starter

ect_09

Joined May 6, 2012
180
Code:
#include<htc.h>

__CONFIG(1, OSCSDIS & HSPLL);
__CONFIG(2, BORDIS & PWRTDIS & WDTDIS);
__CONFIG(3, CCP2RC1);
__CONFIG(4, LVPEN & STVREN);
__CONFIG(5, UNPROTECT);
__CONFIG(6, WRTEN);
__CONFIG(7, TRU);

#define _XTAL_FREQ 4000000

void sevenseg(char ch);

void main()
{
   char ch;
   TRISB=0;
   PORTB=0x00;

  while (1)
  {
     ch = (++ch) % 10;
     sevenseg(ch);
     __delay_ms(1000);
    
    
  }
}

void sevenseg(char ch)
{
  switch(ch)
{
   case 0: PORTB=0x3F; break;
   case 1: PORTB=0x06; break;
   case 2: PORTB=0x5B; break;
   case 3: PORTB=0x4F; break;
   case 4: PORTB=0x66; break;
   case 5: PORTB=0x6D; break;
   case 6: PORTB=0x7D; break;
   case 7: PORTB=0x07; break;
   case 8: PORTB=0x7F; break;
   case 9 : PORTB=0x6F; break;
   default: PORTB=0x3F;
}
}
__delay_ms(1000);
error showing that this delay argument is too long :)
 

ErnieM

Joined Apr 24, 2011
8,377
getting error that delay argument is too large.. :)
If you are getting an error your delay argument is too large then you should suspect the delay argument is too large.

So make it smaller. Try two delays of 500, or 4 delays of 250 (I suspect the latter will work).
 

tshuck

Joined Oct 18, 2012
3,534
i also define _XTAL_FREQ
but also getting error that delay argument is too large.. :)
There is a whole other part to the sentence you are referring to. It is there for a reason.

Let's look at it, from the Hi-Tech manual, __delay_ms() wraps around delay (), which delays for a number of cycles. At 4MHz, one cycle is 1/(4Mhz/4), or, 1us. In order to get to a thousand milliseconds, it must be able to count to one million. 1000000 requires log(1000000)/log (2) = 20 bits. I'd be surprised if it would permit anything over 16 bits, though the manual doesn't say what the magic number is.

User a smaller requested delay as Ernie suggested, loop it as necessary.
 

Thread Starter

ect_09

Joined May 6, 2012
180
If you are getting an error your delay argument is too large then you should suspect the delay argument is too large.

So make it smaller. Try two delays of 500, or 4 delays of 250 (I suspect the latter will work).
i tried this way with 250 250 250 250 but didnt get 1 sec delay
 

adam555

Joined Aug 17, 2013
858
Not all PICs have an internal clock running at 4 MHz as default. Have you tried changing the _XTAL_FREQ to 10 MHz? This could be the default internal frequency.
 

tshuck

Joined Oct 18, 2012
3,534
As Adam intimated, there is no internal oscillator on this chip. What value is your external oscillator? Is it 4 MHz?

I find it troubling that you haven't set the oscillator type in your configuration bits - assuming OSCDIS disables clock switching.

The default is an RC oscillator, is that what you're using?
Screenshot_2014-10-24-07-09-33~2.jpg

You must learn to read the manual...
 
Top