__delay_ms() problem

Thread Starter

msr

Joined Jul 8, 2008
64
Hello,

Im using a PIC16887 (Pickit2 debug express board) with HITECH PICC Compiler (lite mode) and Im trying to use __delay_ms(unsigned float) function.

Im just trying a "blink led" test, and I want it ON for 1sec and OFF for another second. However, when using 1000 as argument, I get this error:
HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1
Copyright (C) 1984-2009 HI-TECH SOFTWARE
(1273) Omniscient Code Generation not available in Lite mode (warning)
Warning [1355] C:\Users\mribeiro\Documents\PIC_Projects\TESTING_C\test.c; 30. inline delay argument too large
Error [800] C:\Users\mribeiro\AppData\Local\Temp\s520.; 116. undefined symbol "?__delay"
Error [800] C:\Users\mribeiro\AppData\Local\Temp\s520.; 124. undefined symbol "__delay"
I also tried 250 in the argument but it fails. It seems the maximum value I can use is 197. With that value it succeeds and with 198 it fails. Weird?

Any suggestions?

Thanks!
 

retched

Joined Dec 5, 2009
5,208
Im not exactly sure, and it sounds odd, but If it was an 8bit number I would expect it to go to 255.

Post the code.
 

Thread Starter

msr

Joined Jul 8, 2008
64
Ok, here's the code I have:

Rich (BB code):
#include <htc.h>    

#define _XTAL_FREQ 4000000
 
__CONFIG(INTCLK & WDTDIS & PWRTDIS & MCLRDIS & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS);
__CONFIG(BORV40);



void setup(void){

    // everything is OUTPUT
    TRISA = 0x00;
    TRISB = 0x00;
    TRISC = 0x00;
    TRISD = 0x00; // LEDs are connected to these pins
    TRISE = 0x00;
}



int main(void){

    setup();

    while(1){

      PORTD = 0x01;
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);

      PORTD = 0x00;
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);
      __delay_ms(100);

    }

}
This WORKS. It fails on compiling when I use delays of 198 or greater. Until 197 it works.



Edit: I didn't include "delay.h". When I try to do that I get: "can't open include file "delay.h": No such file or directory". Where is that include file? However the function signature Im using isn't equals to that one on edaboard's thread. Its __delay_ms() instead of DelayMs(). I suppose DelayMs() was a function of a previous version of PICC Compiler, maybe.
 
Last edited:

sceadwian

Joined Jun 1, 2009
499
It's obviously a math problem with the compile specific routine and the ASM code it invokes. Call a 100ms delay 10 times... Don't be daft.
You may be trying to include a file from the wrong diretory path, find out where it is and include THAT subdirectory.
 

Macabra

Joined May 31, 2008
49
Sounds to me like you need to find where this delay.h header file is in your project and add it to your project folder that you are currently saving your workplace. Also, don't forget to actually include it in your project from your workplace (ie where you include other header files..)
 

AlexR

Joined Jan 16, 2008
732
The fact that it compiles and works with short delays indicates that there is nothing wrong with paths, declarations or headers file locations.

The problem appears to be with the internal workings of the compiler.

I struck the same sort of problem with HiTechC some time ago. Even though the _delay() function is supposed to accept a long int (32 bits) it kept throwing up an error with values well short of 16 bits (it was a long time ago so I don't remember the exact details). At the time I thought it might be a limitation of the unpaid-for version but there was no way I was going to spend good money to find out.
 

coldpenguin

Joined Apr 18, 2010
165
I had a similar issue when I was trying to use that 'function'

I decided in the end that the __delay_ms 'function' must really just be a macro which called __delay_us() in a loop, which the compiler was trying to optimise to be an inline, making the number too large. I found that changing the Crystal frequency defined would change the value at which things fail, and turning off all optimisations stopped there being a problem.
However, what is the point in having optimisations turned off. All-in-all, not impressed with the Hitech compiler, due to the number of problems that I am having.
 

AlexR

Joined Jan 16, 2008
732
Both the _delay_ms() and _delay_us() are macros that use the crystal frequency setting (whatever the command may be) to translate the delay time into machine cycles and then pass that value to the __delay() function that does the actual work.

In the end I ditched HiTechC and bought a non-commercial licence for SourceBoostC which I am very happy with.
 

coldpenguin

Joined Apr 18, 2010
165
I have a recent install of mplab 8.50, and that is still version 9.70 of Hitech C

Maybe it is a development only version, given the comment that you have linked to (as in it doesn't load old workspaces, bad move)
 

coldpenguin

Joined Apr 18, 2010
165
Ah,
looks like this 'fixed' version is only available to those who wish to pay for a license and register the product.
Given the number of bugs I am having with the compiler, I am not going to pay them for a license I think.

Sorry, but our records don't show that you have a registered copy of the HI-TECH C PRO for the PIC10/12/16 MCU Family - Single-User License.If you have purchased a licence for one or more of our products, you may not have registered it - please register it now.
If you need to purchase a licence for this product, you can do so from our ordering page, or email our sales department <sales@htsoft.com>
 

Thread Starter

msr

Joined Jul 8, 2008
64
Really strange HITECH doesn't offer 9.71 version on their website...
But it works! With the that version "__delays()" are correctly working!

Thank you very much t06afre!
 

t06afre

Joined May 11, 2009
5,934
Really strange HITECH doesn't offer 9.71 version on their website...
But it works! With the that version "__delays()" are correctly working!

Thank you very much t06afre!
It was on the web site but was pulled back due to bugs I guess. If you get strange problems. Try to switch from PRO mode to Lite mode. I had a problem that the optimizer took to much of code away. The optimizer ignored setting ANSEL(H) to zero:mad::confused:. Big problems as I could not read some single BITs in port A. In PRO mode I had to use #asm, #endasm to force setting of bits in the ANSEL registers. Htsoft say the bugfixed version will be (re)released soon
 
Top