BurningSmell.org logo
RSS Links Projects Misc News

Programming the PIC16f628a

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:

Many of these examples are still easily applicable to the 'standard' PIC®, the PIC16F84.

My workstation is as follows:

Header Files

Example Source

Compiling and Linking Instructions

To turn a .c file into a .asm file:

sdcc -S -V -mpic14 -p16f628a -D__16f628a \
	-DCONFIG_WORD=_INTOSC_OSC_NOCLKOUT\\\&_WDT_OFF\\\&_LVP_OFF\\\&_DATA_CP_OFF\\\&_PWRTE_ON \
	file.c

To turn a .asm file into a .o file:

gpasm -c file.asm

To link multiple .o files into one .hex file:

gplink -m -s /usr/share/gputils/lkr/16f628a.lkr \
	-o output.hex /usr/share/sdcc/lib/pic/pic16f628a.lib \
	/usr/share/sdcc/lib/pic/libsdcc.lib	\
	file1.o file2.o file3.o

Other Notes

Comments
Author Message
zolli.italia on 2010-08-27 22:26:02 good examples, i have used sdcc (pic16f628a) for first time... ciao!
Ramesh on 2010-08-24 06:49:17 Dai
Tyler Montbriand on 2010-07-24 11:26:41 A few comments seem to be from the future. Server clock fixed.
Tyler Montbriand on 2010-07-24 11:17:12 'static void main' fixed. Thank you, maxpage.
Tyler Montbriand on 2010-07-24 11:16:07 Typo in linking dir fixed. Thanks, maxpage.
Tyler Montbriand on 2010-07-24 11:15:09 This is not a 'help' board. pic16f628.h should come with SDCC.
Tyler Montbriand on 2010-07-24 11:14:15 Added 0020-keyhost.c. Fixed a bug in tsmdelay.h.
Bipin on 2010-07-08 12:33:10 From where can I get pic16f628a.h file?
fabio.italia on 2010-06-24 08:24:02 very good site and all open source. thank's a lot
maxpage on 2010-03-21 09:36:18 Important: the last snapshoot version of sdcc doesn't allow to declare "static main()". You should use simply "main()"!
maxpage on 2010-03-21 09:33:36 Yoo've made mistake in gplink execution (instead of .../gputils/lrk/.../ it has to be .../gputils/lkr/.../)
Jonas on 2010-03-16 07:50:38 Exactly what I was looking for. Many thanks!
Chris on 2010-03-09 22:19:04 Super useful page - many thanks.
tzicatl on 2010-01-24 20:46:19 Great!! Thanks for sharing!!! Very useful!
Tyler Montbriand on 2009-11-25 11:25:39 Uploaded 0019-watch.c
Tyler Montbriand on 2009-11-14 20:55:47 Uploaded 0017-wdt.c, 0018-bootmode.c, tsmserial.h
Tyler Montbriand on 2009-11-13 14:55:23 Uploaded 0016-ps2mouse.c
Tyler Montbriand on 2009-11-11 15:57:17 Uploaded 0015-delay.c.
Tyler Montbriand on 2009-11-09 02:23:52 Uploaded 0014-ascii.c, 0014-ascii.hex, and tsmee.h. It's a PS/2 to RS232 converter.
Tyler Montbriand on 2009-11-09 02:23:03 Good idea, nt_4, I'll note that in the file.
nt_4 on 2009-10-31 22:02:00 Don't forget disable hardware flow control in terminal when playing with 0005-uart_tr.c %)
James Waples on 2009-10-06 03:30:22 Thanks very much for the SDCC code - it works for me now too :D
aleale99 on 2009-09-14 11:29:57 Fantastico: very usefull THANKS
Tyler Montbriand on 2009-04-18 13:11:17 Added a new example, PS/2 keyboard interfacing
Tyler Montbriand on 2009-04-18 12:24:58 Useless comments deleted. If I had more examples they'd be here, stop asking.
jim on 2008-03-30 16:48:29 Useful info, thanks!
Tyler Montbriand on 2008-03-01 11:01:36 For some versions of SDCC, change 'static void main' to 'void main'.
Tyler Montbriand on 2008-03-01 11:00:50 Added compiling and linking instructions.
Tyler Montbriand on 2007-07-13 09:22:02 Documentation improved in 0004-uart_tx.c and 0005-uart_tr.c
Tyler Montbriand on 2007-07-09 19:52:37 0009-eeprom.c updated similarly.
Tyler Montbriand on 2007-07-09 19:45:49 0004-uart_tx.c updated to support modern versions of SDCC.
Tyler Montbriand on 2007-02-08 19:53:45 0011-ustepper.c added.
Tyler Montbriand on 2006-12-31 00:30:04 0010-eeprom_rd.c added.
Tyler Montbriand on 2006-12-30 22:29:45 0009-eeprom.c added.
Tyler Montbriand on 2006-12-30 20:14:38 0008-vref.c added. Also tweaked many other examples to disable their comparators.
Tyler Montbriand on 2006-12-29 14:40:06 0007-interrupt.c added. Documentation tweaked on 0002 and 0006.
Tyler Montbriand on 2006-12-29 12:51:30 0006-interrupt.c modified again, fixing the backwards comment on PORTB pullups
Tyler Montbriand on 2006-12-29 11:30:49 0006-interrupt.c modified today, paring away many pointless statements
Tyler Montbriand on 2006-12-28 13:28:20 The comments page is now OPEN.
[Use Any Browser]
Contact
Linux User #348010