Pic micro(tm) & Linux

In finnish


The meaning of this document is to describe how efficient it is to use PICmicro (TM) products in Linux.

To start, we need following equipment:



In Win9* envinroment we usually use IDE-tools, such as Microchip MBLab. Soon we can use similar tools in Linux. Take a look to gnupic effort. In this document we start by using texteditor, assembly and programmer-software. In my opinion this isn't much harder than use of MBLab. Only thing which is missing is debugging / simulation.

First choise for texteditor is cooledit. With that you can easily do script that compiles assembly, erases PIC and burns .hex file to chip with just one click (or button press). Also there is support for C/C++/HTML/PERL /JAVA ... languages ! I have made Cooledit to understand PIC-assembly, so it can "highlight" different parts of our asm-files in different colors. You can view it from here... This is made with pic.syntax file.

Much can be done with Emacs, in fact I use it many more times than cooledit. There is strong support for external commands, so it can also compile & burn PICs with just one key-combination.

And of course there is tools like vi and pico. Just any editor is sufficient to write it. Choose our own and learn to use it. ;)

Drawing tools

When you actually make your own experiments you can come across making your own PCBs. Good tool for pcb making is pcb ;) ! With it, you can do most of hobby-pcb's. (Some say that it can do most of commercial pcb's too...) Here is one screenshot of PCB in my desktop. In left there is two pinout-windows (showing PIC 16C84 & D-9 pinouts) and in right there is actual PCB-layout editor. And in one window there is library where you can pick components, such as PICs ... BTW, Window-manager in picture is Enlightenment, much more graphical & flexible than default, the KDE... More sophisticated tool is Eagle. It's free version is enought for me, and I think that it's enough for many others too ;) It has nice GUI and lots of features such as autorouting from schematic... General drawing tools are xfig or xpaint, which can be (hopefully) found from your distribution media.

PIC-spesific software:

Of course we need also PIC-spesific tools. I have used "picprog" and "pp" to burn .hex-files to PIC, and "picasm" to compile them.


In our work envinroment we have two choises:

1. GUI

In my linux version (SOT), the default GUI is KDE. You can view my old KDE-desktop... Nowdays I have found that Enlightenment is much more powerful desktop to work with. Here is a picture of it. With GUI, eg. X11, you can have many virtual desktops. So in one desktop there can be Netscape to read documentation, and in another desktop there might be minicom reading serial data from PIC. And of course there is lot of room for editing .asm listing in Emacs. You can even put your minicom-listing directly to your desktop, so you can always look what serial data is coming from PIC. Here is an example of such arrangment. (It's full dump of 1280x768, so it's quite large, 240k ...)

2. Console based work

Another opportunity is to do everything just in console. We can then use even old 386SX box for our experiments ! Our version of M$ "edit" is "pico". It is quite simple to use. Just press Ctrl and some letter. (Different choises are listed in bottom of screen.)

The "thing" about console is virtual-consols. For example, in one console we can edit asm-source, while another is grabbing data from our pic. And so on... And this works in our 386 box ;)

To use virtual consols, just press Alt+function key. For example, first console is Alt+F1, second is Alt+F2 and so on... Alt+F7 is by default our "first" X-windows (GUI) session.

Compiling tools

It's common that Linux programs are distributed as c/c++ source code. Therefore we must "compile" those source-files to working program. There is almost always some sort of "README" - file, where in-detail instructions are found. Below we compile picasm and pp programs.


Packet name in "linuxpp.zip".

Step by step:

pp settings

You can put settings to 'mypp.sh' -file. It's ordinary text-file, so you can edit it with normal text-editor ;)

My machine uses following setup:

export PPSETUP=3
export PPDELAY=1
export PPLPT=0
/home/henkka/bin/pp $*

And with this setup, pp prints out followin text:

Hardware setup: 7407/PNP using LPT1 at 0378 (delay = 1)
So I use 7407 chip-based prommer. You can try different options with "PPSETUP"-parameter. If you are interested what programmer i use, you can also download drawings if you wish. I guess they are the same prommer what i'm using. I'm not so sure because i bought (uh, shame on me...) my prommer from nearby store...


Distribution packet is "picasm106.tar.gz".

Step by step:


I used picprog-program earlier with my former machine. I can't, however, use it with my new machine anymore, dunno why... So I changed to paraller-prommer, and it worked for me good enough...
In general, compiling should be nearly same as with above programs. And remember to read 'README' files ;)

Compiling PIC-assembly

Notice that asm-listings for Win*-envinroment don't directly compile with picasm. You need to edit some variables to match syntax used in picasm.

At left is Win9x instruction and in right is picasm instruction.

Mbasm instruction

picasm instruction

LIST p=16c84 device pic16f84
__CONFIG 11h CONFIG  CP=off,WDT=off,PWRT=on,OSC=xt
#include <c:\mplab\p16c84.inc> INCLUDE "pic16c84.h"
" " (so MOVLW "#") ' ' (so MOVLW '#')
.120 120

You can use sed, awk or similar to find and replace those instructions.

Sample assemmbly listing

Sample program, which flashes led connected to RA0:

; first.asm
; flashes LED connected to RA0

device  pic16f84

; configuration
config  CP=off,WDT=on,PWRT=on,OSC=xt


porta   equ     0x05
ncount  equ     0x0d
mcount  equ     0x0e
f       equ     1 

;startpoint in memory
        org     0x000

;program start
start   movlw   0x00
        tris    porta
        clrf    porta

;loop start
go      bsf     porta,0
        call    delay
        call    delay
        call    delay
        bcf     porta,0
        call    delay
        goto    go
;loop end

;delay loop
delay   movlw   0xff
        movwf   mcount
loadn   movlw   0xff
        movwf   ncount
repeat  decfsz  ncount,f
        goto    repeat
        decfsz  mcount,f
        goto    loadn
You can write that with any text-editor, pico is just fine. After writing, you compile it with

'picasm first.asm'

After that you should have 'first.hex' file in you directory. And it should look like this:


So here we have assebly compiled to "PIC-language" ;)

And command to burn it to PIC:

'mypp -e! first.hex'

assuming that 'mypp.sh' is in your PATH-variable. (If it's not, you can copy it to 'bin'-directory in your home-dir.

In that command '-e' erases PIC's data-space, and '!' tells that no comfirmation is wanted from user. Here is my prommer... It is connected to first paraller port, so device is /dev/lp0.

Compiling C programs for PIC

Here's a short description how I managed to compile C-programs made for PIC. I got c2c & gpasm working with a sequence like this: That should be it. Here's ex.asm and ex.hex for your reference. If you want, you can also take C-compiling instructions in separate page for maybe clearer reading.

Finally, questions etc.

If and when you have question, I recommend following:
  1. Take a look at gnupic.
  2. Have a look at gpsim simulator, it may help
  3. find net for it (www.hut.fi/~then)
  4. browse newsgroups (www.dejanews.com)
  5. read good book about it (www.sq-1.com)
  6. and of course you can contact author

From link page you can find some PIC-related homepages, software etc.

And for reference:
Pic'n Technicues book source.
Pic'n Up the Space book source.
Serial Pic'n book source.

Those are from www.sq-1.com

You may also want to view my another documents. They describe how i measure temperature from sauna, how it's possible to put temperature to gkrellm-panel at desktop and another stuff i have found interesting enought to make www-pages from them.

I would like to have comments about this page.

29.10.2003 added sudo recommendation to pp's instructions
20.3.2002  updated link to Jaakko Hyvätti's programmer
28.11.2000 added link Jaakko Hyvätti's serial programmer
29.9.2000  added instructions to compile c2c programs
2.8.2000   added link to my wife's page
22.3.2000  added link to gpsim simulator
12.2.2000  added link to prommer-pcb. Took away that counter.
18.9.1999  added link to eagle pcb-software.
18.9.1999  added "links" page because of many queries about authors homepages.
25.7.1999  added link to gnupic-page.
25.7.1999  changed layout a lot & added emacs / enlightenment links.
18.7.1999  added links to source code from books.
25.6.1999  cooledit-patch file added. Link to linux-page was added. Guestbook was added.
23.6.1999  pcb-link was added
4.6.1999   cooledit-link was added
23.5.1999  document was created
(c) Henry Palonen, 1999-2003
h yty dot net

[Skip Prev] [ Prev] [ Next] [ Skip Next]
Random] [ Next 5] [ List Sites] [ Join Ring]