Programming a PIC 16F84 with SDCC and GPUTILS
|
|
3rd September 2013
Summary of feedback from PIClist:
- the David Tait parallel port programmer is also supported by PikLab, thanks to Gál Zsolt,
- using very very old PICs is made difficult by development languishing because the supporting hardware is not readily available, an alternative is to upgrade to 12F1840 (8 pin), 16F1825 (14 pin), 16F1847 (18 pin), and 16F1938 (28 pin), thanks to Byron Jeff,
- the Pickit2 does not program the 16F84, thanks to Mr Smiley.
31st August 2013
Making the usual LED blinker on a PIC 16F84 with SDCC, GPUTILS, and a Linux system. As a test of the tool chain.
Ingredients
- a PIC 16F84,
- a parallel port programmer for a PIC microcontroller, using the
David Tait design,
- a computer with a parallel port, hard to find these days,
- Debian GNU/Linux,
- prog84 software,
- SDCC from SVN,
- GPUTILS from GIT,
Recipe
Source Code
- C source code,
#include
#include
static __code uint16_t __at (_CONFIG) configword1 = _CP_OFF & _WDT_OFF & _HS_OSC;
void Intr(void) __interrupt 0
{
T0IF = 0;
}
void wink()
{
uint16_t i;
for (i=0;i<30000;i++) continue;
}
void main()
{
setup();
for (;;) {
loop();
}
}
void setup()
{
TRISB = 0;
}
void loop()
{
PORTB = 0xff;
wink();
PORTB = 0;
wink();
}
- build instructions for use by GNU make,
.c.o:
sdcc --use-non-free -mpic14 -p16f84 -c $<
a.hex: a.o
gplink -r -w -m -o a.hex a.o /usr/local/share/sdcc/lib/pic14/libsdcc.lib /usr/local/share/sdcc/non-free/lib/pic14/pic16f84.lib
clean:
rm a.o a.asm
burn:
(cd prog84-2.3 && ./prog84 -T 1684 -x ~/a.hex)
Learnings
- the programmer just worked,
- the Debian packages of sdcc and gputils were a bit old, so they were built from source, and the checkinstall package was used for creating packages corresponding to the /usr/local install,
- sdcc needed --use-non-free to work, without it one sees "ISO C forbids an empty source file",
- gplink needed -r, without it one sees "error: linker script has no definition that matches the type of section UDL_idata_0",
- gplink needed to be explicitly directed to the sdcc object modules libsdcc.lib and pic16f84.lib,
Opinions
- a handy set of tools, though the code space limitation on the microcontroller will hinder the functionality possible,
- some of the documentation is inadequate,
- the strange licensing of the Microchip header files continues to amuse, perhaps a dual-license would have suited them better.
| quozl@us.netrek.org
| up |