Author Topic: Good SDCC for PIC tutorial?  (Read 19924 times)

0 Members and 1 Guest are viewing this topic.

Offline rudikaTopic starter

  • Newbie
  • Posts: 2
Good SDCC for PIC tutorial?
« on: February 12, 2011, 12:52:03 am »
Hi,

I'm beginner in programing microcontroller. I want to learn programing PIC mirocontroller in C language. I bought Microchip Pickit2 programmer with Low Pin Count Demo Board. I planing to use demo board to learn C language. I try to search tutorials for SDCC but didn't found anything :'(. I'm using Linux operating system and I don't want to use any demo, cracked or restricted in function C compiler.

Rudolf
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10140
  • Country: nz
Re: Good SDCC for PIC tutorial?
« Reply #1 on: February 12, 2011, 12:59:17 am »
This is the first time i've heard the abbreviation SDCC which may explain why you're having problems searching for it.

I'm also not aware of many linux tools for PIC's, most of the time when you hear of people working with micros under linux they are using avrs with avrgcc.

Maybe someone with more PIC experience can help
« Last Edit: February 12, 2011, 01:01:35 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Good SDCC for PIC tutorial?
« Reply #2 on: February 12, 2011, 07:11:07 am »
which pic are you using?

the microchip compiler for some pics is based on a modified version of gcc.

Last time I tried SDCC i found it fairly limited in terms of lack of support for passing structs easily (it is still possible though) and lack of support for function pointers.
 

alm

  • Guest
Re: Good SDCC for PIC tutorial?
« Reply #3 on: February 12, 2011, 05:45:28 pm »
the microchip compiler for some pics is based on a modified version of gcc.
Isn't that just for PIC32?

Last time I tried SDCC i found it fairly limited in terms of lack of support for passing structs easily (it is still possible though) and lack of support for function pointers.
Sdcc definitely seems less mature and supported than avr-gcc. I think there is also a gcc port for msp430, not sure how mature that is. I MPLAB X is available for Linux, but the compilers are probably feature limited after a trial period (no optimizations).

My suggestion for a free, full-featured C compiler would probably to switch MCU vendor, unless there is some other compiler for PIC < 32 I'm not aware of. I know avr-gcc is almost the standard C compiler for AVR, certainly in the hobbyist community, and is well supported by the community. Mspgcc also seems to be fairly popular for MSP430 development. Same with arm-gcc. No idea about other architectures like 8051, STM8 and whatever NEC is pushing.
 

Offline oPossum

  • Super Contributor
  • ***
  • Posts: 1431
  • Country: us
  • Very dangerous - may attack at any time
Re: Good SDCC for PIC tutorial?
« Reply #4 on: February 12, 2011, 07:46:25 pm »
Microchip has two GCC C compilers. One is for PIC32 (32 bit) and the other is for PIC24H, PIC24F, dsPIC30 and dsPIC33 (16 bit).
 

Offline rudikaTopic starter

  • Newbie
  • Posts: 2
Re: Good SDCC for PIC tutorial?
« Reply #5 on: February 13, 2011, 06:45:04 pm »
Hi,

Thanks for the help. I see nobody know any tutorial for SDCC for PIC. I want use Low Pin Count Demo Board. The board came with PIC16F690 microconttroler. I checked before for Microchip GCC compiler but it was not included PIC16F family. Anyway I started slowly to learn C language and SDCC compiler.

Rudolf
 

Offline cyberfish

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
Re: Good SDCC for PIC tutorial?
« Reply #6 on: February 13, 2011, 08:53:41 pm »
We have used SDCC for PIC in a pretty big project, because we also run Linux, and like free stuff.

If you have a choice, though, AVR with avr-gcc is much better.

SDCC doesn't support a lot of things, generates very suboptimal (if not just wrong) code most of the time (we had to write a lot of things in inline assembly), and is very buggy.

One of our group members reported about 12 bugs on SDCC. Some as simple as only the LSB is checked in logical expressions (eg. if (x) { ... } doesn't run if x is 2).

If you are just learning a language, you'll definitely want to use a good compiler, so that you know when your program doesn't work, it's your fault, not the compiler's (that wasn't true on a few occassions for us with SDCC...). With GCC, you can typically assume that.

8051 is in a similar situation. Keil is the "standard" commercial compiler. The only open source compiler is SDCC.

Therefore I also recommend AVR. It's the only 8-bit micro that has a state of art open source compiler (avr-gcc).
 

Offline dfnr2

  • Regular Contributor
  • *
  • Posts: 240
  • Country: us
Re: Good SDCC for PIC tutorial?
« Reply #7 on: February 17, 2011, 10:12:27 pm »
I'm using Linux operating system and I don't want to use any demo, cracked or restricted in function C compiler.

Rudolf

You can probably scratch SDCC off your list, then, as it's PIC support was pretty rudimentary last time I checked, and the output very suspect.  It's strongest for the '51 parts.

For a mid-range or 18-series part (PIC 12/16/18).  I recommend you do check out the LITE version of the Hi-Tech compilers (Now part of Microchip).  Even if you don't have all the optimizations, you do get some of them, and the LITE compilers are otherwise fully functional, and support all the Microchip parts.  Similarly, the Microchip C30 and C24 remove advanced optimizations from the evaluation versions, but the compilation and part support is otherwise unrestricted (and you can compile these from source, with effort, to enable the optimizations.)  I would trust the output from either of these far more than SDCC, and the optimization, though limited, will be better.

For hobby stuff (or development for a low-budget start-up) it's not a big deal if the generated code is a bit bigger and a bit slower; you can always jump to a similar part with more memory.  When you are ready to build your product in sufficiently high volume that a $2 difference in price matters, you can probably afford to buy the optimizing version of the compiler.

Anyway, you can usually find more room and more time by reviewing your algorithms and code design than by better compiler optimization.

Before switching to Hi-Tech, I used the CCS compiler, which is great for hobbyists because it is really easy to use, and provided super-easy setup and interfaces for all the peripherals.  I was able to get up and running quickly even without any prior PIC experience.  However, the opacity of their development process, constant introduction of new bugs, and constant lagging of their Linux version behind the windows version finally convinced me that this was not my best choice for professional development.  Hi-Tech was a night-vs-day improvement from the software maintenence and reliabilty standpoint.


Dave
« Last Edit: February 17, 2011, 10:21:46 pm by dfnr2 »
 

Offline disasm

  • Newbie
  • Posts: 3
Re: Good SDCC for PIC tutorial?
« Reply #8 on: February 28, 2011, 05:39:43 pm »
Funny I just came across your post. I've been toying with this for the last month or so. Here's how I'm working:

sdcc compiler
pk2cmd from microchip to write the hex files to the PIC
gputils for gpasm and gplink (sdcc calls automatically when installed)

Lets start with a Makefile:

# Makefile for PIC microcontrollers using sdcc and pk2cmd

# Specific microcontroller type:
DEVICE=16f690
FAMILY=pic14
PRJ=helloled
# C compiler, assembler, device programmer:
CC=sdcc --use-non-free -m$(FAMILY)
PK2=pk2cmd -Ppic$(DEVICE)

All: $(PRJ).hex

$(PRJ).hex: helloled.c
    $(CC) -p$(DEVICE) $(PRJ).c

write:
    $(PK2) -M -F$(PRJ).hex

on:
    $(PK2) -T

off:
    $(PK2) -W

erase:
    $(PK2) -E

clean:
    rm -f *.o *.cod *.hex *.lst *.err


And a simple program for LPC Demo Board:

#include "pic14/pic16f690.h"
#include "stdio.h"
#pragma preproc_asm-
typedef unsigned int config;
config __at 0x2007 __CONFIG =
 _INTRC_OSC_NOCLKOUT &
 _WDT_OFF &
 _PWRTE_OFF &
 _MCLRE_OFF &
 _CP_OFF &
 _BOR_OFF &
 _IESO_OFF &
 _FCMEN_OFF;

// ------------------------------------------------
// a simple delay function

void delay_ms(long ms)
{
    long i;

    while (ms--)
        for (i=0; i < 330; i++)
            ;
}
void main()
{
    short display;
    TRISC = 0x0;
    display = 0xf; // Turn all 4 lights on
    PORTC = display;
}

Just run make to build the hex and make write to write the hex file to the PIC.

If you want to contact me, send me an e-mail sam [at] theleathers dot net.

Sam
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf