HI-TECH C and __delay_ms

Discussion in 'Programmer's Corner' started by trennonix, Jun 12, 2009.

  1. trennonix

    Thread Starter New Member

    Jun 6, 2009
    2
    0
    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
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    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:
    Code ( (Unknown Language)):
    1.  
    2. #include <htc.h>
    3.  
    4. int _XTAL_FREQ=4000000;
    5.  
    6. unsigned long time=200;
    7.  
    8. void main(void)
    9. {
    10.   TRISB=0;
    11.   while (1)
    12.   {
    13.      RB0=1;
    14.      __delay_ms(time);
    15.      RB0=0;
    16.      __delay_ms(time);
    17.   }
    18.  
    19. }
    20.  
     
  3. juninho

    New Member

    Aug 1, 2009
    1
    0
    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++;
    }
    }
     
Loading...