I've been suprised by the dearth of examples for programming Microchip PIC® processors in SDCC, given there's been continuous effort in improving it's support since about 2001 or so. As such, I am placing the things I've managed to create or find, here.
Mostly I've been experimenting with the PIC16f628a processor. I like it because it has, among other things:
- An internal oscillator that runs at 4MHz or 48KHz -- no more crystal setting madness, and you still get to slow your programs way down when they get uppity!
- A UART. For real. Set it to 9600 BAUD and talk to your computer or Serial LCD.
- An architecture where every instruction except branches takes one cycle. Given a 4.0000MHz clock, a 'nop' instruction will take 1.0000 microseconds.
- It works reliably with my JDM-style programmer, even under Linux®. The exact programmer I use appears available here, but the JDM is an open design -- buy it or build your own, the PIC doesn't care. :) Of course you'll have a hard time finding all the fiddly zeners and transistors so personally I think you're better off buying the whole programmer -- it's got a nice ZIF socket, and comes with useful Windows softare too. Note you need a real serial port, the crap they put in laptops doesn't get enough voltage and the counterfeits you get in USB don't have the right control pins.
Many of these examples are still easily applicable to the 'standard' PIC®, the PIC16F84.
My workstation is as follows:
- A desktop computer running Gentoo Linux, with SDCC and picprog installed.
- A nice digital logic trainer breadbord that the local university idiotically threw away.
- An old 2-channel 20MHz analog oscilloscope that the local university idiotically threw away.
- A logic probe from the era when Radio Shack sold anything but appliances.
- A 200-watt pre-ATX computer power supply.
- Parallax serial LCD for debugging output.
- PS/2 keyboard with RS232 converter
- Proto-18 board, which includes a built-in MAX232 chip and serial connector for easy connecting to computer
- A much-tabbed and benoted datasheet printout