Added following to wiki page needed for SDCC 3.0.0; header moved for licensing reason.
Tim S.
PIC Normal Compiler search directory for SDCC 3.0 and later of "C:\Program Files\SDCC\non-free\include"
Edit: I can not yet get SDCC 3.0.0 to link. I am not likely to have time to work on this till Final Week is over.
I am looking at http://sourceforge.net/apps/trac/sdcc/wiki/SDCC_tutorial for more info.
I added this to the simpleio.c file and it linked; I have no time to find the hardware to see if it created good code or not.
// Define Port A
__sfr __at (0xF92) TRISA;
__sfr __at (0xF80) PORTA;
volatile __PORTAbits_t __at (0xf80) PORTAbits;
// Define Port B
__sfr __at (0xF93) TRISB;
__sfr __at (0xF81) PORTB;
volatile __PORTBbits_t __at (0xf81) PORTBbits;
It seems there is something wrong with the current CB revision (as well as previous ones) or my understanding of how to configure CB for SDCC. I just compiled from SVN 7075.
I get this error:
sdcc -mpic16 -p18f2321 -I/usr/share/sdcc/non-free/include/pic16 -I/usr/share/sdcc/include/pic16 -I/home/andrew/projects/programming/Incubator/ -c Incubator.c -o obj/Release/Incubator.rel
INFO: changing configuration word at 0x300006 from 0xfb to 0xbb due to pic16devices.txt
sdcc -L/usr/share/sdcc/lib/pic16 -L/usr/share/sdcc/non-free/lib/pic16 -o bin/Release/Incubator -mpic16 -p18f2321 obj/Release/Incubator.rel
at 1: warning 119: don't know what to do with file 'obj/Release/Incubator.rel'. file extension unsupported
SDCC : pic16/pic14 3.0.0 #6037 (Nov 7 2010) (Linux)
When I remove '-c' and '-o' from the first command, and add the '-L' paths and run the command in a terminal, I get the properly linked hex file and no errors. e.g.: sdcc -mpic16 -p18f2321 -I/usr/share/sdcc/non-free/include/pic16 -I/usr/share/sdcc/include/pic16 -I/home/andrew/projects/programming/Incubator/ -L/usr/share/sdcc/non-free/lib/pic16/ -L/usr/share/sdcc/lib/pic16/ Incubator.c
The problem (I think) is that CB is trying to split compiling and linking into separate steps, while the sdcc can handle all of that at once. I suspect that previous versions of SDCC would link the second command's *.rel files, but version 3.0.0 won't. Anyway, I'm not quite sure how to fix the settings, but at least this might help someone else who is having this problem.
I used a modification of the code on the wiki, as shown below. Pushbutton on RA4, LED on RB1, holding down PB turns on LED, releasing turns it off.
#include <pic18f2321.h>
__code char __at __CONFIG1H conf2 = _OSC_INTIO2_1H; // Internal Oscillator
__code char __at __CONFIG2H conf4 = _WDT_OFF_2H; // Disable WDT
__code char __at __CONFIG3H conf6 = _MCLRE_OFF_3H;
__code char __at __CONFIG4L conf7 = _LVP_OFF_4L; // Disable LVP
void main(){
// Initializing ports
PORTA = 0;
PORTB = 0;
// Set RA4 as input and RB3-RB0 as output
TRISA |= 0x10;
TRISB &= 0xF0;
// Set value 0x0A to PORTB
PORTB = 0x0A;
// While button is pressed, turn on RB1
while(1) {
if(PORTAbits.RA4 != 0){PORTBbits.RB1 = 1;}
else PORTBbits.RB1 = 0;
}
}