Learning to Program the PIC Microcontroller

I’ve been using Arduino for a while now (2 years on and off) and they are great development boards that are easy to learn. The only problem is that it gets expensive to include full boards in each project so I’ve been looking at cheaper alternatives.

I recently learned about the Microchip PIC range of micro-controllers from a friend at my local makerspace. These chips are easy to use on their own with practically no external components so are much easier to set up in a custom circuit compared to the ATMEGA328P (the micro-controller used in the Arduino Uno). The chips have their own internal oscillator so an external crystal isn’t needed for low-frequency projects.

An external programmer is required to upload code onto the chip so I bought a PICkit 3 for just under $50 (this a low cost alternative to the $200 ICD3). Here’s a photo of my first circuit using a PIC. I’m using the PIC12F683 which is a mid-range 8 pin PIC costing less than $2. The only external components I needed were a voltage regulator to provide a stable 5V and 0.1uF capacitor between the power rails.

pic12f683_breadboard

After installing the MPLAB X IDE and the XC8 compiler (both free), I was able to upload the following code to blink an LED connected to GPIO5 (pin 2). I’ve also made this code available on github (https://github.com/andygrove/blink_led_pic12f683).

This is a small first step in my PIC adventure but I don’t think I’ve ever been so excited about seeing an LED blink. If I can blink an LED I can do anything! Being able to do this for a total cost of around $2 is an order of magnitude cheaper than using an Arduino so this is really going to open up more possibilities for me with this hobby.

I should point out that the learning curve of PIC is a bit steeper than that of the Arduino because the PIC just doesn’t have the rich ecosystem of books, blogs, and tutorials that the Arduino has. Also, the source code is lower level and changes depending on which PIC chip you are using. I wouldn’t recommend PIC for everyone.

However, if you don’t mind reading data sheets and you are comfortable with low level C / Assembler coding and dealing with bit-level logic then these are great micro-controllers to use. I actually like the fact that I’m dealing directly with the hardware rather than going through the abstraction layer provided by the Arduino/Wiring libraries. It is going to result in more efficient code for sure and I will learn much more this way.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

2 thoughts on “Learning to Program the PIC Microcontroller

  1. Sasha Bilton

    Is it mostly that things like the Atmel Tiny needs the crystal that you’re not looking at them? I ask because I’ve been doing some stuff that needs to be very small and obviously PIC chips meet that.

    Reply
  2. andygrove Post author

    Hi Sasha,

    Congratulations on being the first person ever to comment on my blog :-)

    The main reason for using PIC is that I heard a lot of good things from people who use them professionally and chose them over Atmel. They are very resilient and require few external components and that makes life easier for me for sure. One of the big features of PIC though is that you can actually debug them from the IDE since the chips have debugging circuitry built in (although for some of the chips you need to buy an additional header … I’m still learning about this). You can literally step through code live in the IDE and look at the memory registers in the PIC etc, which you can’t do with the Atmel chips without buying expensive tools as far as I know.

    I’m sure I could use either PIC or Atmel though as they are very similar. In fact I just found this video comparing them which is quite hilarious to watch but does cover some good points around 10 minutes in:

    Cheers,

    Andy.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *