LINUX/EDA/PIC

From E&E Students
Jump to: navigation, search

Easy Linux PIC'n

Introduction

This article explains the details of programming your favourite PIC under Linux in the E&E Labs. Wether it be for Ontwerp or your Skripsie, the stability and performance of Linux makes this an attractive alternative to doing it in Windows98. All testing was performed using the MPLAB ICD Module and a PIC16F877A in the 4th floor E&E Lab. I assume the reader is familiar with basic Linux usage (file system navigation, command excecution, etc). For those of you in the dark read this short Linux Primer

Setting up the Hardware

In the 4th floor lab the benches at the front are already configured for use - look for the little black boxes next to the PCs. The set up involves a RS-232 cable from the serial port of the computer to the MPLAB ICD Module inside the black box and a RJ-11 terminated cable to connect to your Project. Consult the Microchip In-Circuit Serial Programming Guide for details on the ICSP programming interface for the PIC, or ask your favourite lecturer ;-)
So in a nutshell you plug the RJ-11 cable into the socket on your project and make sure your project has power. Simple!

Setting up the Software

Below I will outline the steps needed to compile your C-code into Intel Hex format and upload the Hex file to your PIC.

Wine

Wine Is Not an Emulator, which makes it perfect for running any windows program under Linux. Luckily for us, Wine is already installed in the 4th floor lab.

CCSC

This section explains compiling your C-code source file under Linux. If you're writing code for the PIC in assembler, you shouldn't be here! We use the same compiler thats on the Windows partition (CCSC) except we are now launching it through Wine. Grab a copy of CCSC here and unpack it with the command

tar jxvf picc.tar.bz2 

If you look inside the picc folder you will see a file called Ccsc.exe - this is our compiler. From the command line excecute

wine Ccsc.exe

Don't WorryTM about the messages it spits out - Wine gets confused sometimes. You'll see a new window pop up prompting you for a filename, just as if you had ran the file under Windows! Neat... Anyway because CCSC doesn't provide us with a file browser interface, we need to send it the source code filename via the command line. To aid in this we'll make use of some basic aliases, explained in the next section.

ICD

ICD is the software that performs the task of transferring HEX data between your PC and your PIC. A copy is available here. Unpack it using the command

tar jxvf icds.tar.bz2

Inside the icds folder there is a file named Icd.exe - this is the programming software. Just as above, excecute it from the command line with

wine Icd.exe

Once again, Don't WorryTM about all the End-of-the-World messages it spits out. Wait a while and ICD will open up - at this stage you will recieve some errors if your hardware setup is incorrect. Use the ICD software exactly as if you were in Windows!

Setting up the aliases

To make life easier we'll set up two aliases. One for ccsc and one for icd. Open up your ~/.bashrc with your favourite editor and add the following two lines in the alias section

alias ccsc='/usr/bin/wine /home/students/YOURUSERNAMEHERE/picc/Ccsc.exe'
alias icd='/usr/bin/wine /home/students/YOURUSERNAMEHERE/icds/Icd.exe'

Exit your editor, type

source ~/.bashrc 

and you're sorted. Now you go to your work directory containing all your C-code source files and type

ccsc myPicProgram.c 

followed by

icd

And thats a wrap...

Other Resources

Instead of using wine, native Linux compilers such as GPUtils and programmers like ICDProg are available although I haven't been able to get icdprog to work correctly... feel free to add to this article if you get them working.