XC-8 Problen?

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

XC-8 Problen?

Postby SLTom992 » Fri Aug 01, 2014 4:16 am

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?
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC-8 Problen?

Postby ric » Fri Aug 01, 2014 4:50 am

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: XC-8 Problen?

Postby ric » Fri Aug 01, 2014 4:59 am

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: XC-8 Problen?

Postby ric » Fri Aug 01, 2014 5:35 am

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: XC-8 Problen?

Postby Ian.M » Fri Aug 01, 2014 6:23 am

Undocumented library functions from 2006: http://www.microchip.com/forums/m161682.aspx
They may not even be in recent C18 versions!
Ian.M
Verified identity
 
Posts: 95
Joined: Wed May 28, 2014 12:47 am
PIC experience: Professional 1+ years with MCHP products

Re: XC-8 Problen?

Postby SLTom992 » Fri Aug 01, 2014 2:01 pm

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
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC-8 Problen?

Postby SLTom992 » Fri Aug 01, 2014 5:35 pm

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.
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC-8 Problen?

Postby jtemples » Fri Aug 01, 2014 6:56 pm

__18CXX means C18, not PIC18.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 11 guests

cron