Good SDCC for PIC tutorial? - Page 1
Forum section: electronics / general

author: rudika
author_rank: Newbie
timestamp: February 12, 2011, 12:52:03 am
content: 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

author: Psi
author_rank: Super Contributor
timestamp: February 12, 2011, 12:59:17 am
content: 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

author: adam1213
author_rank: Regular Contributor
timestamp: February 12, 2011, 07:11:07 am
content: 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.

author: Unknown
author_rank: Unknown
timestamp: February 12, 2011, 05:45:28 pm
content: Quote from: adam1213 on February 12, 2011, 07:11:07 amIsn't that just for PIC32?Quote from: adam1213 on February 12, 2011, 07:11:07 amSdcc 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.

author: oPossum
author_rank: Super Contributor
timestamp: February 12, 2011, 07:46:25 pm
content: Microchip has two GCC C compilers. One is for PIC32 (32 bit) and the other is for PIC24H, PIC24F, dsPIC30 and dsPIC33 (16 bit).

author: rudika
author_rank: Newbie
timestamp: February 13, 2011, 06:45:04 pm
content: 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

author: cyberfish
author_rank: Regular Contributor
timestamp: February 13, 2011, 08:53:41 pm
content: 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).

author: dfnr2
author_rank: Regular Contributor
timestamp: February 17, 2011, 10:12:27 pm
content: Quote from: rudika on February 12, 2011, 12:52:03 amYou 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

author: disasm
author_rank: Newbie
timestamp: February 28, 2011, 05:39:43 pm
content: 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 compilerpk2cmd from microchip to write the hex files to the PICgputils 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=16f690FAMILY=pic14PRJ=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).cwrite:$(PK2) -M -F$(PRJ).hexon:$(PK2) -Toff:$(PK2) -Werase:$(PK2) -Eclean:rm -f *.o *.cod *.hex *.lst *.errAnd 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 functionvoid 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 onPORTC = 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  theleathers dot net.Sam