CHEAPIC This tutorial attempts to explain how to get started programming PIC microcontrollers in the cheapest possible way. To do this you will need the following: 1) IBM compatable PC. An old 286 or 486 machine will do fine if it has a COM port. I assume you will be using DOS. 2) A text editor. I use SLED, (Sam's little editor), written in the '80's by Sam Willmont. Only 17K in size, it is free. get it at: ftp://ftp.funet.fi/pub/msdos/Simtel/editor download the file sled11.zip ,(31K) 3) An assembler. MPASM from Microchip is free. If you stick to just the basics, it is pretty easy to use. get it at: http://www.microchip.com/10/Tools/Picmicro/code/MPASM/asm2300/index.htm Once you unzip the file, throw away all files except mpasm.exe and p16f84.inc. The manual can be found at: http://www.microchip.com/10/Tools/PICmicro/code/MPASM/33014g/index.htm But it is in computerese. Probably best to wait until you really need it. 4) A programmer. The one I will talk about appears at: http://websites.ntl.com/~matthew.rowe/micros/prog.htm for other info from Matthew Rowe leave out the prog.htm, (keep the /) I have pictures and construction notes for this programmer in the file com84bd.zip Another simple serial programmer I have built and works is at: http://www.jdm.homepage.dk/newpic.htm click on 'Ultra Lowcost for PIC16C84 Only' Both programmers get their power from the COM port. Software I use with these programmers is called PIX. It can be found at: http://home5.swipnet.se/~w-53783 download the latest version pix113b.zip 5) A PIC. The PIC16F84 as an obvious choice. Other OTP, (One Time Programable), PICs require more expensive programmers, UV erasers etc. The data sheet for the 'F84' can be found at: http://www.microchip.com/10/Lit/PICmicro/16F8X/index.htm click on 30430c.pdf This is quite technical and better left as a reference also. One of the cheapest sources for the PIC16F84, (4mHz), and also the 78L05 used in the programmer is: http://www.phanderson.com/ordering.html 6) Various small parts. Watch crystal, capacitors, LEDs, batteries etc. I choose to run the PIC off three AA batteries. This frees you from the A.C. line, but means you have to watch current consumption. I have pictures and description of the demo board for these programs in the file called cheapbd.zip 7) Directions. That is what this tutorial is all about. Hopefully it will save you the cost of a $30-$40 book. Many short programs will be presented. You can assemble, run and then modify these to teach yourself PIC programming. Text Editor: You will be amazed at the capability of this little editor. It will hold may separate text files at once with the capability to cut and paste between them. Take some time to play with the editor and become familiar with its use. Especially note operations using the keys F3, F4, F7, F8, alt-x, alt-c and alt-y. Assembler: You use the editor to write a program of instructions which you feed to the assembler, (MPASM). Instructions occur one to a line and are made of short abbreviations that indicate what the instruction does. One of these is NOP which stands for "no operation". To check out MPASM, try to assemble just one line with the instruction nop, ( capitals or lower case, doesn't matter). Create this one line file in the text editor. Name this file 'nop.asm'. You can run MPASM from the editor by using alt-y. When you type 'mpasm nop' you will probably get 2 errors. A further explaination of errors is found in the error file 'nop.err'. Hit the spacebar until you return to the program you were editing, ( nop.asm ), and load nop.err using F3. One of the errors complains of no end statement, the other says you haven't identified the PIC you are using. Hit F8 to return to nop.asm and add lines to make it read: list p=16F84 nop end Save the file, (F4), and re-assemble, (alt-y, mpasm nop). This time you will probably get no errors but 3 warnings. Warnings can be ignored if you know what they mean and can ignore the consequences. Errors always have to be fixed. Using F3 you can load the new 'nop.err' file, (the old one is also still there). The warnings state that each of the three lines started in column one. Column one is reserved for 'labels' which identify the location in the program of the next instruction. Since we don't really need any labels, put a space or three at the beginning of each of the lines and re-compile. This time you should get no errors or warnings. If you use alt-y and type 'dir nop.*' you will see there are 5 files with names beginning with 'nop'. If you load the latest 'nop.err' you will find it blank, (get rid of the other 2 with F7). Some of the other files are quite interesting. The file 'nop.lst' contains much useful information. Load it using F3 and look it over. You will find the program lines we just entered with a line number, in decimal, under 'LINE'. For one line you will also find two 4 digit hexidecimal numbers. These are the actual numbers and locations they will be entered in the PIC's program memory. Each program memory location is 14 bits in size so it takes 4 hex digits to specify what goes in there, (under OBJECT CODE). There are 1024 program memory locations so it also takes 4 hex digits to specify the location, (under 'LOC'). You will also find the number of program memory words used, (1), and the number left, (1023). Programmer: You follow this same process: edit source - assemble - check and correct errors in the source - re-assemble, until you get no errors on assembly. When you finally get no errors you 'burn' the '.HEX' file, 'nop.hex' into a PIC with the programmer. You then take the PIC, place it in an actual circuit and start it up. It may not do what you want, or nothing at all. You then try to guess what is wrong, go back to the original source and do it all over again. Fun huh? The programs: In the zip file with this text you should also find: ( bincnt.asm ) - Count in binary on 4 LEDs - registers; ports, the W register and TMR0 - use of T0IF in delays ( swcnt.asm ) - Count switch closures, display on LEDs - subroutines - debouncing switches - defining registers - instruction execution time ( eggtimer.asm ) - Countdown timer, minutes and 10's sec on LEDs - interrupt routines - saving without changing STATUS - addition and subtraction ( morsenbr.asm ) - Send numbers 0-9 out on piezo speaker - using tables ( xtal0.txt ) - discussion of using watch crystal and TMR0 with 16F84 I'm not finished. I need your input. send comments, questions etc to: ockers@anl.gov