HI-TECH C and __delay_ms

Thread Starter

trennonix

Joined Jun 6, 2009
2
Hello,
I'm trynig the __delay_ms() function in hi-tech c lite edition
but i always get a warning about "implicit signed to unsigned conversion"
so the program runs as if the delay function was never written

this is the code:

#include​
<htc.h>

int​
_XTAL_FREQ=4000000;

unsigned​
long time=200;


void​
main​
(​
void)
{
TRISB=0;
while (1){
RB0=1;
__delay_ms(time);
RB0=0;
__delay_ms(time);
}

}


tried to add the numbers directly into the function without declaring a variable, but i still got the same error
tried "(unsigned long)value" same thing :S

Any ideas? thanks a lot

btw i'm using the latest compiler (downloaded 3 days ago) for 10\12\16 family lite edition
running in Hi-Tide IDE also latest version
 

Mark44

Joined Nov 26, 2007
628
What does the protype for __delay_ms() look like? Presumably it's in the header file htc.h. You're passing an unsigned long in your call to this function, and very likely it is expecting a different type. The exact error would also be helpful.

Here is your code, formatted for better readability:
Rich (BB code):
#include <htc.h>

int _XTAL_FREQ=4000000;

unsigned long time=200;

void main(void)
{
  TRISB=0;
  while (1)
  {
     RB0=1;
     __delay_ms(time);
     RB0=0;
     __delay_ms(time);
  }
 
}
 

juninho

Joined Aug 1, 2009
1
Look at this:

#include <htc.h>

unsigned long _XTAL_FREQ=4000000;

void vdelay_ms(int from);

int time=200;

void main(void)
{
PORTB=0;
TRISB=0;
while (1)
{
RB0=1;
vdelay_ms(time);
RB0=0;
vdelay_ms(time);
}

}


void vdelay_ms(int from)
{
unsigned int countertmp;
countertmp=0;
while (countertmp<from){
__delay_ms(1);
countertmp++;
}
}
 
Top