Page 1 of 1

XC-8 Problen?

PostPosted: Fri Aug 01, 2014 4:16 am
by SLTom992
One of the groups said that there was a ltobcd routine. The answer was very complete and I tried it and couldn't get it to work. So I tried to post on the MC board and it of course was screwing up as it is more than half the time.


Code: Select all

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

extern void ltoBCD( long Value, char *pBCD); // returns a 5byte array

int Display_Convert(long input_data) {

    char *char_ptr = &Display_Buff;

    ltobcd(input_data, char_ptr);
}


When I compile I get the error: "Converter.c:21: warning: (361) function declared implicit int"

I take this to mean that it cannot find the function. Any ideas?

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 4:50 am
by ric
It would be better to post the whole file, or at least point out which line here is line number 361 in your source.

Just adding:
extern void ltoBCD( long Value, char *pBCD); // returns a 5byte array
isn't going to help unless that function is provided by the compiler. In that case you should be including the relevant header file, not declaring it yourself.

The basic fault in the code you posted is you have capitalised "BCD" in the prototype, but not the function call.

There is no occurrence of the string "ltoBCD" in the XC8 header files anyway (even ignoring capitalisation), so that function is NOT provided with the compiler.

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 4:59 am
by ric
Update. I found a post on the mchip forum.
http://www.microchip.com/forums/m161682.aspx
It appears that is an internal function inside stdlib supplied with the C18 compiler.
That is why people would have declared the prototype themselves, as there was no public prototype for it in stdlib.h

The assembler source for it is in: C:\MCC18\src\traditional\stdclib\itoa.asm

So, plainly it is not available in XC8. I think it would be easier just to write your own in C.

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 5:35 am
by ric
SLTom992 wrote:One of the groups said that there was a ltobcd routine. ...

It would have been very helpful to have posted a link to where you saw this discussion.

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 6:23 am
by Ian.M
Undocumented library functions from 2006: http://www.microchip.com/forums/m161682.aspx
They may not even be in recent C18 versions!

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 2:01 pm
by SLTom992
I have tried both both capitalized and both lower case so it appears that it ltoBCD isn't available.

And I haven't been able to get it to give me ltoa either.

Code: Select all
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

// from stdlib.h "extern char *   ltoa(long val, char * buf);"

char Display_Buff[13];

int Display_Convert(long input_data) {

    char *char_ptr = &Display_Buff;

    ltoa(input_data, char_ptr);
}



In the stdlib.h here is the lines:

#ifdef __18CXX
extern char * ltoa(long val, char * buf);
extern char * ultoa(unsigned long val, char * buf);
#else
extern char * ltoa(char * buf, long val, int base);
extern char * ultoa(char * buf, unsigned long val, int base);
#endif

Since this is a PIC18 I would assume that it would use the first definition but it appears to wants the second.
So if that's so how is "base" defined?

The error messages are:

Converter.c:17: warning: (357) illegal conversion of integer to pointer
Converter.c:17: warning: (358) illegal conversion of pointer to integer
Converter.c:17: error: (187) too few function arguments

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 5:35 pm
by SLTom992
OK. I would have expected that since you set the system up for PIC18's the it would be defined but it isn't. So I rearranged the itoa to match the second function layout and used "10" as the base and it appears to compile and give me the correct numbers though I'll have to look closer into it to tell if you have to use "16" to tell the function that the long is not BCD encoded.

When I look in the ltoa description in the Libraries section of the XC-8 manual it doesn't give that description.

Re: XC-8 Problen?

PostPosted: Fri Aug 01, 2014 6:56 pm
by jtemples
__18CXX means C18, not PIC18.