Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] best compiler for PIC controllers

Status
Not open for further replies.

Ranbeer Singh

Full Member level 5
Joined
Jul 30, 2015
Messages
259
Helped
22
Reputation
44
Reaction score
22
Trophy points
1,298
Location
Faridabad India
Activity points
3,266
Hello,

At this time i am working with C18 compiler for pic18f series controllers. When i wrote some complicated mathematical calculation and/or USART string (string comparison, transmit ROM string, transmit RAM strings) codes it's always fail(Fusss). Code debugging eat time a lot. Many times i found that my codes are ok but why not working?

I want to know a compiler witch know total c library, string, USART and other as well.
 

It is not a compilier issue. It is lack of expirience and bad programming skills. The C code itself more or less will be compilied the same way with any compiliers.
 

I have used C18 Compiler. Zip and post your MPLAB C18 complete project and I will fix it so that everything works fine.
 

I have used C18 Compiler. Zip and post your MPLAB C18 complete project and I will fix it so that everything works fine.

Thank you for your interest.

If you used it for big project, What do you say about C18 that i mentioned in #1?

- - - Updated - - -

Actually i was asking for other best compiler. Microchip form experts says Xc8 compiler.
 

Yes, I have used C18 for big projects (3000 line code). Only problem with C18 is using delays. If you need different delays then you have to manually calculate it and use DelayxTcyZ() functions. XC8 is newer and good. it supports all microchip 8-bit microcontrollers. There is a free version of it. You can try it. You can try it in Pro mode free for 45 days. C18 has reached end of life and so it will not support new devices. Better switch to XC8. I use C18, Hi-Tech C, XC and mikroC PRO Compilers.
 

I have talk to some of persons on it. They also say that it is old, it understand string value in two ways ROM and RAM type.
if i send a string value to usart library fuction for exa.

Code:
char *val = "Hello";
putsUSART("Hello);   //it is ok.
putsUSART(val);   //it's not ok. compiler gives warning and print garbage value

Finally i want to get out of it.

- - - Updated - - -

Better switch to XC8. I use C18, Hi-Tech C, XC and mikroC PRO Compilers.

What will best in given names.
 

First of all, * val should be placed in flash.
Code:
const char *val = "Hello";
And compilier should reserve the memory for it with null-termination. You can take a look in debugger, that null character is following last letter.
Such basics things...

- - - Updated - - -

Yes, I have used C18 for big projects (3000 line code). Only problem with C18 is using delays. If you need different delays then you have to manually calculate it and use DelayxTcyZ() functions. XC8 is newer and good. it supports all microchip 8-bit microcontrollers. There is a free version of it. You can try it. You can try it in Pro mode free for 45 days. C18 has reached end of life and so it will not support new devices. Better switch to XC8. I use C18, Hi-Tech C, XC and mikroC PRO Compilers.
Try MikroE C compilier for PIC. 7 years ago I used it very often. Works well.
 

Your code

Code:
char *val = "Hello";
putsUSART("Hello);   //it is ok.
putsUSART(val);   //it's not ok. compiler gives warning and print garbage value

Have you checked the prototype of putsUSART() ? Maybe it takes array argument.

Try

Code:
char val[] = "Hello";
putsUSART(val);

If you define the string as char array or char* then it will be in RAM and not ROM.


Code:
const rom char msg1[] = "Hello!";
char msg[];

//copy const rom string to ram string
char *CopyConst2Ram(char *dest, const rom char *src) {
    char *d;
    
    d = dest;

    for(;*dest++ = *src++;)asm clrwdt;

    return d;
}

//Usage

CopyConst2Ram(&msg, &msg1);
putsUSART(CopyConst2Ram(&msg, &msg1));

Prototype is like this.

Code:
putsUSART(const char *str)

You can use casting

Code:
char *val = "Hello";
putsUSART((const char*)"Hello!");
 
Last edited:

Come on! Every one knows that PIC doesn't initializy RAM with zeroes. It is always consist of a garbage. So, to make a string null-terminated, null have to be added manually or whole content of RAM have to be erased first.

- - - Updated - - -

Code:
char *val = {'H', 'e', 'l', 'l', 'o', 0 };
putsUSART(val);
This will work for sure.
 

I have done it with make own transmitting function. But it is wasting of time. I am looking Compiler should work as GCC. Only put your any type string ,compiler should manage automatically itself.
 

It depends upon how much C standards the Compiler follows.
 

If we will dig one by one point in whole life, when will write codes.

In an Indian song a lady says to his husband "Whole day/night you will work, when will you love?".
 

Yes. Only in PRO mode you get optimizations. In evaluation try PRO mode for 45 days. In project properties you have to select XC8 Compiler and select optimizations in drop down box and set PRO mode.
 
But optimisations are not always necessary and generally are turned off for debugging purposes.
I've used the free versions of the XC* series of compilers for years and they work well.
Susan
 

But optimisations are not always necessary and generally are turned off for debugging purposes.
I've used the free versions of the XC* series of compilers for years and they work well.
Susan

I searched microchip website inquiry for XC8 compiler. license is so costly only for one year and free version is only for 45 days. But you says you used free version for years. How?
 

Free version doesn't have optimization feature. It has all other functionality of PRO version and it is free for forever.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top