Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in /home/monttyle/public_html/pic16f628/phpstyle.php on line 59

Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in /home/monttyle/public_html/pic16f628/phpstyle.php on line 60

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/monttyle/public_html/pic16f628/phpstyle.php on line 62
Programming the PIC16f628a logo
RSS Links Projects 3D 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:

My workstation is as follows:

Header Files

Example Source

Compiling and Linking Instructions

Please note the recent change! If you have sdcc 3.0 or newer, nearly every useful PIC header has been odiously moved into the "non-free" header trees, which are off by default, but fortunately can be included with one commandline option, --use-non-free. Some file locations have changed as well. Note the highlighted changes from /pic/ to /pic14/, etc.

Also note, these paths may be distribution-dependent and subject to change. If you run it and it says it "can't find file", it probably can't find the file and you ought to figure out what the correct paths are to fix it.

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

sdcc -S -V -mpic14 -p16f628a -D__16f628a --use-non-free \

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/non-free/lib/pic14/pic16f628a.lib \
	/usr/share/sdcc/lib/pic14/libsdcc.lib	\
	file1.o file2.o file3.o

To burn a .hex file to your PIC:

picprog --device=pic16f628a --erase --burn \
	--pic-serial-port=/dev/ttyS0 --input-hexfile output.hex

Other Notes

Author Message
Johnd694 on 2016-12-23 11:49:07 Article Source a viral game app is not that much cdefkgfeefea
Johnf841 on 2016-12-23 11:49:05 I'm really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, its rare to see a great blog like this one these days.. dddaddbdggd
lnxslack on 2016-09-17 15:11:44 where i get the header file tsmasm.h
Jorge on 2015-12-22 16:24:15 Thanks, I like what I have found here...useful code.
Tyler Montbriand on 2015-09-10 13:12:46 0034-toestubber.c and tsmbcd6.h added.
admin on 2015-09-07 03:58:10 Wellcome Joypurhat
Jim Daldry on 2014-11-13 18:47:50 I use MPLABX and XC8 to "autogenerate" config #pragmas - quick but dirty
Suwang Jang on 2014-10-26 05:17:34 Thank you for your wonderful works. Your examples are very useful.
Tyler Montbriand on 2014-06-20 13:27:33 0033-hdd.c has been added, a program to run hard drive motors without the hard drive.
Tyler Montbriand on 2014-06-20 11:37:09 0032-ustepper.c hsa been added, an improved version of the stepper tester.
Tyler Montbriand on 2014-06-16 14:20:41 Athena: You may use it for whatever purpose.
ronybc on 2014-03-09 07:13:01 Very good... Thanks a Ton..!
Athena on 2014-01-04 00:42:00 Here is the github page of the project -
Athena on 2014-01-04 00:40:42 May I put the code into an open source project?
WertAsdmon on 2013-10-22 14:32:16 '><h1>Cool thanks!</h1>
LilButcher on 2013-10-22 14:29:31 '><h1Cool thanks!></h1>
Knut on 2013-09-20 02:29:06 in "other notes" there is a filename missing after the first #include.
vomitus_maximum on 2012-10-30 06:23:44 I came here looking for the auto vomit circuit but found the PIC micro controller. A pathetic MCU compared to proper MCU
Dave on 2012-09-24 06:29:08 check your html - your need to use entity refs for less than and greater than
Tyler Montbriand on 2012-07-17 13:46:45 uniqdom: That's because you have to give it that file. Download it from this page.
Diego Herranz on 2011-10-24 06:13:04 Brown-Out Reset happens at 4.0V (typical) when enabled regardless of your VDD. That's why if you use BOR with a lower voltage the pic is held at reset.
uniqdom on 2011-10-15 17:51:49 i'm trying to set a uart in a 16f877a using sdcc but tsmtypes.h file can't be found. I have seen another header called usart.h in some projects. I have that one but it have some syntax errors. maybe you can disclose to me the trick. also want to say thank
qwe on 2011-05-17 04:08:15 1234
Tyler Montbriand on 2011-03-08 19:21:02 0031-eetest.c added to settle the EEPROM argument. It produces ASM that *looks* broken but isn't: The useless extra EEPROM bytes are discarded due to 16-bit alignment issues.
Tyler Montbriand on 2011-03-03 13:50:08 Added 0030-crc.c and tsmcrc16.h, code and macros for calculating CRC16 checksums.
Tyler Montbriand on 2011-02-20 22:02:44 Added 0029-servo7.c, an improved 7-output servo controller
Tyler Montbriand on 2011-01-27 21:51:13 Added 0028-uptime.c, a serial-output interval counter/monitor device.
Tyler Montbriand on 2011-01-27 21:50:27 Personally verified that 0014-ascii.c, which heavily uses EEPROM data, actually talks to keyboards given SDCC 3.0 and the new gplink.
Tyler Montbriand on 2011-01-27 21:43:16 I stand corrected. EEPROM data variables now need __code specifier. Fixed the fix of the fix.
Tyler Montbriand on 2011-01-15 19:18:12 EEPROM data variables now need __data specifier in SDCC 3.x Updated 0014-ascii.c to reflect this!
Tyler Montbriand on 2010-12-22 18:54:42 I have updated every source file to reflect changes in header file locations for sdcc 3.0
hesperaux on 2010-12-10 23:09:08 Thank you for making this site. I'm trying to get into C with my 16F628A right now. I have the same serial LCD from parallax. Hoping to use your example code to get a feel for things.
Tyler Montbriand on 2010-10-09 14:42:54 I'm not hiding PIC18 examples in my sleeve, I post what I have. If/when I start using them I'll post their examples too.
Tyler Montbriand on 2010-10-09 14:41:11 .asm and .inc files sound like they need MPASM, not SDCC.
etnalubma on 2010-10-08 23:17:53 Good stuff, dude. This was very useful. I apreciate it.
saurabh on 2010-09-25 00:30:13 i have .asm and .inc files how can i get a .hex file out of it to program my PIC16F628A..THANKS
zolli.italia on 2010-08-27 22:26:02 good examples, i have used sdcc (pic16f628a) for first time... ciao!
Jagdish on 2010-08-24 22:47:44 Any link/resource how to start using SDCC on windows for PIC18 devices ?
Drogba on 2010-08-24 22:42:30 Firstly thanks. I am looking for SDCC code examples on PIC18F(windows platform). someone pls help as I am having difficulty in running SDCC properly
Ramesh on 2010-08-24 06:49:17 Dai
Tyler Montbriand on 2010-08-15 14:26:46 0027-timer2.c uploaded, a simple example using timer #2
Tyler Montbriand on 2010-08-11 10:14:37 0025-servo7.c fixed. I'd uploaded the wrong file.
Tyler Montbriand on 2010-08-11 10:05:24 Added 0025-servo7.c and 0026-pwm.c, also, tsmdelay.h updated again.
Tyler Montbriand on 2010-08-10 12:26:33 A video of my servo controller in action has been linked.
Tyler Montbriand on 2010-08-09 22:43:12 Added 0023-32khz.c, a hack to get a 32Khz squarewave following the crystal out of a 16f628a.
Tyler Montbriand on 2010-08-09 22:42:33 Added 0022-oscint.c, showing how to have the 32Khz crystal cause interrupts.
Tyler Montbriand on 2010-08-09 21:18:50 Added 0024-servo.c, a single channel serial-controlled servo controller. Also, an update to tsmdelay.h to cache values.
Tyler Montbriand on 2010-08-08 13:51:40 Added 0021-freq.c, a very basic timer1 + crystal example
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]
Linux User #348010