PICProgramming

ShscWiki :: LogIn :: PageIndex :: RecentChanges
This page was never completed. I apologize for that. If anyone wants to take over let me know. I just don't have the time anymore.

As you can see I am still assembling this guide. If you just can't take it and you would like some personal help with your project please feel free to email me nimming@gmail.com. -Noxious

 Table of content 

PIC Microcontrollers

"A single-chip microcomputer with on-board program ROM and I/O that can be programmed for various control functions." - http://www.icinsights.com/links/glossary.html

PIC microcontrollers come in a huge variety from a couple of I/O pins to upwards of 40 I/O pins with several banks of RAM. PIC microcontrollers are a version of RISC microcontrollers, (reduced instruction set computer).

Getting Started

Acquiring the necassary equipment to develop PIC microcontrollers does not have to be expensive. And after the initial hardware investment individual chips are quite inexpensive, most PIC chips run under $10.

Hardware

There are essentially only three pieces of hardware that you will need in order to start burning your microcontrollers. You will need a computer, preferably a PC running some flavor of windows or DOS. There is an ASM compiler for linux, http://www.gnupic.org/ it is still in development and has an active mailing list. For this guide I will be using a Windows IDE.  The second device you will need is a Programmer. There are many options when it comes to programmers, including many build your own options.

Chip Programmer

Microchip


PICSTART
This is the programmer that I use. It will program DIP packaged chips upto 40pins, wich is more than enough for most tasks. It works directly with the MPLAB IDE, wich is nice but not neccassary.

Other Microchip Programmers
I haven't used any of the other programmers. However, they do sell a cheap ICP programmer that could possibly be the best solution. ICP, or in circuit programming is a very easy way to build projects, it allows for the programming of a chip through a simple hardware interface. I won't go into the technicalities of it, but you can read more about it on the Microchip website. The upshot is that you can prototype your project and then program the chip without removing it from the circuit. This has obvious benifits, like not bending pins on your only chip.

Other

I have also used the EPIC programmer from Micro Engineering labs, http://www.melabs.com/products/epic.htm It will work fine for most standard DIP chips. You can also get an adapter for other packages. It even has a header for ICP (In Circuit Programming). It has a standalone program that allows you to burn .hex files to your chip.

Software


Microchip

http://www.microchip.com offers a free full IDE including MPASM, a Macro assembler. This is the software that I recommend for development of your projects. The manufacturer provides it so it is more likely to have a high degree of compatibility, a huge repository of information about it is available, and it is free. To get this IDE you will need to browse to their development section from the homepage provided.
http://www.melabs.com/ offers an IDE that is designed to work with their PICBasic and PICbasicPro languages. The CodeDesigner Lite is free but PICBASIC is to limited for something you pay money for. PICBasicPro does have extended features but you pay double the price.

Other

There are other language compilers available, including several C compilers available directly from Microchip. I have no personal experience with these, and I would only recommend them if you plan to do some larger firmware development on some of the higher end chips.

Assembly Language


Getting Started


MPASM
MPASM is the core tools needed to translate the assembly source code into machine code usable by the PIC microcontroller. The MPASM includes a MACRO interpreter as well as a linker.

Your First Programs


Blinky, Inky, Pinky and Clyde


Blinky, turn on the lights!
list p=16f676 #include "p16f676.inc" cblock 0x20 usec msec count endc org 0x0000 bcf STATUS, RP0 clrf PORTC movlw 0x07 movwf CMCON bsf STATUS, RP0 movlw 0x01 movwf ANSEL movlw 0xff movwf TRISA movlw 0x00 movwf TRISC bcf STATUS, RP0 BSF STATUS, RP0 ; Select Bank1 CLRF ADCON1 ; Configure A/D inputs BCF PIE1, ADIE ; Disable A/D interrupts BCF STATUS, RP0 ; Select Bank0 MOVLW b'01000001' ; RC Clock, A/D is on, Channel 0 is selected MOVWF ADCON0 ; BCF PIR1, ADIF ; Clear A/D interrupt flag bit BCF INTCON, PEIE ; Disable peripheral interrupts BCF INTCON, GIE ; Disable all interrupts ; ; Ensure that the required sampling time for the selected input ; channel has elapsed. Then the conversion may be started. ; main call read_analog RRF count RRF count movfw count movwf PORTC ;call delay goto main read_analog bsf ADCON0, GO wait_analog btfsc ADCON0, GO goto wait_analog movfw ADRESH movwf count return delay movlw 0xff movwf msec msec_delay movlw 0xff movwf usec decfsz msec goto usec_delay return usec_delay decfsz usec goto $-1 goto msec_delay end

This article is ©2008 by the respective authors. Reproduction is prohibited without express permission from all contributors.