Monday, October 5, 2009

Configuring your PC..

Having experimented with different ideas, I arrived at a way of working that is quick and convenient. This page provides a step by step guide to configuring your PC to work with my chosen range of software. Please note - I'm not necessarily saying that this is the best way to do this, but if you're in a hurry to get started, this will ensure your system is the same as mine and all of the following sections will work. Once you've gained confidence and experience, I hope you'll feel free to try different ways of working. If you discover a better way, please let me know...

In short, here's what we need to do:

  1. Check the (modest) system requirements.
  2. Install MPASM, the free assembler from Microchip (a half-meg download)
  3. Install IC-Prog, a free PIC programmer (another half-meg download)
  4. Install ConTEXT, the best ever text editor! (Just over a MB)


1. System requirements:

For PIC programming, I use my workshop PC that has a minimal installation of Windows 98. Because I rely on this machine, I deliberately keep it "lean". Despite being an old OS, it's absolutely fine - in fact, it's one of the quickest, most stable Windows machines I've ever used. Note that it doesn't connect to the Internet, so it doesn't need to run a virus checker or a firewall - this makes a big difference to the performance. It's a 333MHz Celeron with 256MB of RAM, and a fast 30GB hard drive. It reboots in less than a minute, so on the rare occasions that you see a GPF, it's no hardship to restart it. Keeping it free from XP and all the pretty but pointless visual widgets is the key to the performance.

I've run all the applications very successfully on much slower machines (Pentium 1's with much less RAM). The software is not demanding, and the machine spec really affects the way Windows runs more than anything else. You hardly need any disc space either. In general, it seems safest to stick to low-spec machines that run Windows 98 - a good use for old machines that have been obsoleted by Microsoft!

Having said that, all of this should work just fine under XP but I haven't tested it yet! I might expect problems from IC-Prog because of the serial port control. Also, some laptops don't provide the full 12 volts from their serial ports, so this might cause problems. Note that I've had problems getting the ConTEXT function keys to work with NT4, so this is best avoided.

2. Install MPASM:

You need the latest version of MPASM, the Microchip PIC Assembler. This can be found on the Microchip website - just type "MPASM" into the search box on the front page. At the time of writing, it's a 565KB download.

If you like, you can download MPLAB, which is their development environment that includes MPASM. Personally, I don't use MPLAB, but don't let that stop you. Recent versions of MPLAB are really quite good, and it includes a simulator which is occasionally useful. If you're on a dial-up connection, you may not want to do this as it's a 38MB download! (version 6.6)

Installing it is just a case of following the instructions. Decide now which drive and folder you are planning to install it to, as you'll need to know this later. For all sorts of complicated historic reasons (habit!), I installed it on my F: drive, in F:\CAD\PIC\MPLAB (Yes, I did install MPLAB)

The installation will create a program group, and you should have a shortcut to MPASMWIN (there is a DOS version of MPASM). Run this, and check the options:


From memory, you shouldn't need to change too many of these, but make sure the List File box is ticked. The "Default" setting is appropriate for most options, because all of these can be specified in the source code that you'll write later.




3. Install IC-Prog:

Download IC-Prog from http://www.ic-prog.com/ - it's a 550KB download. Decide now which drive and folder you are planning to install it to, as you'll need to know this later. For all sorts of complicated historic reasons (habit!), I installed it on my F: drive, in F:\CAD\PIC\PICProg (You have to create your own folder).

You'll need to configure it to work with your programmer. The screenshot shows the options I set for my JDM programmer, but feel free to experiment. You'll note that I've selected the PIC16F877 - you have to set this before loading the .HEX file, because when you change device, it empties the buffer. If you are running this from ConTEXT (see below), you'll need to run up IC-Prog before and select the processor.


Another option that I changed is to enable Verify during programming, which is in the Options dialogue. Otherwise, it will spend ages programming the device, and won't flag up a problem until it starts to verify. A PIC16F877 has 8KB of programme memory so this takes a while, and is very frustrating!

Before proceeding, you should ensure that you can write a .HEX file to a PIC, and read one back from the PIC. Use the .HEX files discussed previously.

4. Install ConTEXT:

I discovered some years ago that ConTEXT is the best text editor for many applications, particularly PIC programming. I haven't seen a better option yet. We are going to install and configure ConTEXT to behave as our "shell", or environment.

Download the latest version from http://www.context.cx/ - note that this text refers to 0.x versions (0.97.5 at time of writing). For some time now, we've been anticipating the release of Version 1 which promises to be radically different, which I hope is a good thing. Should version 1 be available, the following instructions might not work.

The download is 1.18MB, so fairly dial-up friendly. Installation is a simple case of running the .EXE, and choosing which directory to install to. For all sorts of complicated historic reasons (also habit!), I installed it on my D: drive, in D:\Program Files\WinUtils\ConTEXT

(After installing Windows, I create Program Files on my D: drive and install all applications there, thus keeping the C: drive as clean as possible. This makes reformatting and rebuilding much easier)

Next I place a shortcut to ConTEXT (and IC-Prog) on the quick-launch area of the taskbar. I've never like the Start menu...


Now, the fun begins. First, we need to install the correct Microchip PIC highlighter. My version is here, but feel free to make your own, as mine is a "work in progress". Every few months I discover a new keyword that should be in the list! Alternatively you can download one from the ConTEXT site - I haven't tried this, so I can't comment on it. Either way, copy the appropriate .CHL file to the Highlighters directory within the ConTEXT programme directory and restart ConTEXT.

Please note that the following step might not be necessary with the most recent version of ConTEXT:

Before this will work correctly, we need to tell ConTEXT not use the x86 Assembler with .ASM files. Open a file within ConTEXT - any sort of file, we just need to run ConTEXT with all the menus showing. Then, drop down the Tools menu and go to Set Highlighter. Choose Customize Types... and find x86 Assembler in the list. Click on Edit, and change the asm that appears to something else. I just placed an underscore (_) at the beginning. "OK" that, and you should find it uses the correct custom highlighter for .ASM files.

You might be wondering why I feel that syntax highlighting is so important. Apart from making the source code look nice, it performs an essential role for beginners - there are so many new instructions and keywords to learn that any help you get from the computer has got to be welcome. As you're typing in your source code, seeing that the instruction changes colour and is shown in bold is good positive feedback - you know you've just typed something that the assembler can understand!

Next, make sure you have a .ASM file to play with. It can be anything - we just need to have the file open in the editor, because we're going to customise the function keys. You're about to see why ConTEXT is so good!

Drop down the Options menu and select Environment Options... In the dialogue box, click the Execute Keys tab - you should see a tree in a white box showing "asm" as a branch, with F9 to F12 hanging from it.

F9 - Assemble this program:

First, click on F9, then click the button on the right of the Execute box (). Browse to the folder you installed MPASM in, and select MPASMWIN.EXE - note that if you installed MPLAB, you'll find MPASM in a sub-folder called "MCHIP_Tools" or similar.

This means that if you press F9 while editing a .ASM file, the Microchip Assembler will run. Pretty neat! But, to make this do something useful, we need to configure the remaining options:

As you can see, we are saving the file, and passing on the filename using %p%f - looking now, I'm not sure why I'm not using %n, perhaps it wasn't an option when I first set this up (there have been many versions of ConTEXT released since I first installed it)

F10 - Programme PIC:

Next, click on F10 and browse to the folder that contains ICProg.EXE


You'll note that I've got F12 set up here - this is because I couldn't get IC-Prog to work properly at first, so I set up F10 to run a batch file to run the JDM DOS programmer - which only worked with the PIC16F84. F11 opened the current .ASM file in Notepad, for no particular reason, but I thought it might be a good idea at the time. F12 simply ran IC-Prog, and I opened the .HEX file manually.

But eventually I found that to load a file into IC-Prog from the command line, you must preface the filename with -l. So, to load PREAMP.HEX, you would type icprog -lpreamp.hex at the DOS prompt. Knowing this, we can get ConTEXT to work by typing -l%p%F.hex into the Parameters box - %F means the current file minus the extension - a neat option.

General ConTEXT options:

Have a hunt around the options dialogue - ConTEXT is very configurable. Of course, most options are a matter of personal choice, but I've found the following settings useful:

The print options are equally configurable - you can define some nice headers and footers, and you can choose whether to use syntax highlighting and colours - very useful.


Summary:

So that's all you need - a handful of small applications running on a modest machine. You should have configured ConTEXT so that pressing F9 assembles the program, and F10 programmes the PIC. This makes the programming cycle (explained later) very quick and simple. I find this approach easier than using MPLAB, but feel free to try it both ways. You'll soon find that ConTEXT becomes your text editor of choice - I've already converted everyone at work!

On to the next Post - the PIC architecture...