User Tools

Site Tools


microcontroller_basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

microcontroller_basics [2013/08/13 12:13] (current)
Line 1: Line 1:
 +=====  Basic Microcontroller Programming Using PIC  =====
 +
 +{{:​18-pdip-chip.jpg?​200}}
 +
 +Due to popular demand, I'm working on a short, basic class on Assembly-language programming for the PIC microcontroller. ​ It has to be short and basic, because I'm not terribly advanced, but I do know how the little insects work, and I can show you.
 +
 +==== When is it? ====
 +
 +Thursday, May 12th, 7pm to whenever.
 +
 +
 +==== What is the point? ====
 +
 +By taking this class (which will probably be two meetings, around 2 hours each), you will learn the basics of PIC ASM using the [[http://​www.microchip.com/​wwwproducts/​Devices.aspx?​dDocName=en010210|16F628 controller]] from Microchip Technology. This class will be 100% in assembly, so be ready to get cross-eyed.
 +
 +Most of you will find that working in PIC is an easy and quick way to solve a lot of control tasks, but getting started can be really infuriating. It seems like no matter how much reading you do, there is always one more thing that doesn'​t work before you get your first few projects off the ground. ​ I will do my best to help you avoid these problems.
 +
 +If you haven'​t done any assembly programming before, don't worry. ​ The entire PIC language (8-bit version) consists of about 30 commands, and they'​re all pretty easy to grasp. It's more about understanding the idea that the language doesn'​t have a lot of built-in functionality. ​ Even simple tasks can require a bit of problem-solving.
 +
 +Another great thing about the PIC is the pricing. Most chips are about 2 dollars, and you can get a really nice USB programmer for about 40 bucks. ​ Microchip also makes a pretty good IDE with a decent simulator, debugger, and programmer driver which you can download for free. Protip: Microchip will send you up to 3 chips for FREEEEEE every 90 days or so if you sign up for their developer program, also free.
 +
 +
 +==== What you need to bring ====
 +
 +I'll be using my laptop and the projector to get you through the basics. ​ But if you want to stay and play with the boards and write your own code, or if you want to work on the problems as we go through them, you will need the following:
 +
 +1) A computer capable of running a PIC IDE.  I'm using an ancient laptop and MPLab runs just fine for me.
 +
 +2) Some software, available for free
 +
 +For PCs (Wintels, whatever), use [[http://​www.microchip.com/​stellent/​idcplg?​IdcService=SS_GET_PAGE&​nodeId=1406&​dDocName=en019469&​part=SW007002|Microchip MPLab IDE]]
 +
 +There are good tools available for 68K Macs running OS9.  Anything newer than that, and you're looking at command-line utilities. There is always emulation, but I have nothing of value to say about that.  Maybe you can try looking at [[http://​www.paintyourdragon.com/?​p=45|this page]] for help.
 +
 +3) Some Paper and a pencil would be nice.
 +
 +
 +
 +==== Sample Code ====
 +
 +Here is some sample code that you can play with once you have installed MPLab. I wrote it for simplicity and straightforwardness,​ and you shouldn'​t have too much trouble figuring it out, because it's heavily commented. ​ It would be very helpful to download the data sheets for the pic (listed below a bit), and maybe print out pages 4, 7, 17, 18, 20-23, as they will be frequently referenced.
 +
 +[[http://​www.mediafire.com/?​y3uycvdol0rbli5|Pic Class]]: Everything you need for May 12
 +
 +[[http://​sharebee.com/​5a22773d|Basic PIC 01]]: Basic setup and managing output pins. Simple assembly.
 +
 +[[http://​www.mediafire.com/?​etpupagg39lvulk|Basic PIC 02]]: This handles a very basic event loop, and input/​output handling.
 +
 +[[http://​www.mediafire.com/?​v1qpygicwce0tc7|Basic PIC 03]]: More advanced event loop, debouncing, multiple inputs
 +
 +[[http://​www.mediafire.com/?​fuqw41w8cj8kp7w|PIC USART 01]]: Learn how to set up the PIC for Asynchronous Serial I/O
 +
 +Note: I have recently noticed that some of these might have some tiny errors in them.  They'​ll compile and link just fine, and they'​ll work great in simulator, but they need a couple of config bits set.  We'll talk about this in the class.
 +
 +==== Additional Information ====
 +
 +Microchip has LOTS of online data, so feel free to check it out beforehand.
 +
 +[[http://​ww1.microchip.com/​downloads/​en/​DeviceDoc/​31029a.pdf|Language Reference for PIC ASM]]: Yes, only 35 commands in the entire language! ​ It's called [[http://​en.wikipedia.org/​wiki/​Reduced_instruction_set_computing|RISC]] for a reason.
 +
 +[[http://​ww1.microchip.com/​downloads/​en/​DeviceDoc/​40044G.pdf|The datasheet for the 16F628A]]
 +
 +[[http://​ww1.microchip.com/​downloads/​en/​DeviceDoc/​51028f.pdf|Manual for MPLab]]
 +
 +We will have to share programmers. I have donated my old RS-232 Olimex to the lab, and there is also a PICKit2 there, or so I have been told. I also bought a [[http://​www.canakit.com/​usb-pic-programmer.html?​gclid=COqX8oDE36MCFQwTbAodqkK64g|new USB kit]]. I really have had no problems with this kit, and I recommend it.
 +
 +{{:pic programmer.jpg}}
 +
 +
 +==== The Latest: ====
 +
 +The class is happening, finally.
 +
 +
 +==== Dev Board ====
 +
 +**--Dev boards will not be available for the class, but if you are interested, we can have a weekend build. ​ I have parts to make a bunch of them--**
 +
 +Dealing with electronics isn't very interesting if you can't get your hands dirty, so, I spent some time building a basic development board for the class. ​ Sorry, it doesn'​t program the chips, but it does connect the chip with 2 momentary-switch inputs, 6 I/O pins you can do whatever you want with, and 8 LED outputs.
 +
 +Everything together costs about 10 bucks a board. (It turns out that all those dimes add up fast.) If you want to pay me back, that would be pretty cool.  If you can't, that's cool, too. Don't sweat it.
 +
 +The PCB version of the dev board is finished. ​ It looks like this:
 +
 +{{:​pic_dev1.jpg?​400}}
 +
 +As soon as the boards are in, I'll assemble some kits and you can come in and build your dev board. ​ I'll plan a work-day if anyone wants to join in.  It's a very easy solder job.  About 50 thru-hole joints. Shouldn'​t take more than an hour.
 +
 +The eagle files are [[http://​www.mediafire.com/?​c7m597lt4ls4o3r|here]],​ in case you wanted them for something.
  
microcontroller_basics.txt ยท Last modified: 2013/08/13 12:13 (external edit)