Monday, July 17, 2017

Blinking an LED with a simple PIC microcontroller

There are many different PIC microcontrollers. Some of them are powerful enough to be used with an arduino-like framework (pinguino) and others are much more constrained. For the former, I suggest using this PIC18F2553 I/SO evaluation board. For the latter, I suggest using a PIC12F675 I/P (or a reference kit). Despite being small and cheap, the PIC12F675 can be powerful enough for many simple applications. Let's take a look at its specs:
  • 10-bit A/D converter (4 channels)
  • 6 GPIO pins
  • Timers
  • Analog comparator
  • Memory (ROM: 1K words, RAM: 64B, EEPROM: 128B)
To compile code for the PIC12F675 you need to install the MPLAB-X IDE and the free edition of the MPLAB XC8 (PIC12F675 is an 8-bit microcontroller) compiler.


Then, prepare a circuit like the one in the picture on a breadboard. The PIC12F675 contains an internal oscillator so you don't need to supply one. Here we are just connecting the GP2 pin to an LED with a resistor. Additionally, we connect VPP to VDD through a 10kohm resistor and VDD to VSS (ground) with a 0.1uF for programming the chip with Pickit3.


Build the example source code provided by Paolo Rognoni with the MPLAB-X IDE. Connect the board to a 5V power supply and program it with a Pickit3.

Important: if you just bought the Pickit3 and get a "Connection failed" error and a RED status LED, the firmware in your Pickit3 may need an update. In that case, download the Pickit3 programmer application (I had to use v3.10) and open it with the Pickit3 unplugged. Plug it in and click Tools > Check communication. Hopefully it will be connected. Next, click on Tools > Download Pickit operating system, and choose 'hex' to write onto pickit3. Then, click on Tools > Revert to MPLAB Mode and exit the application (if it says no permissions for writing, change the folder permissions to writable). Finally, start MPLAB IPE program (already installed with MPLAB X), click "Connect" and it will update the firmware for you.

No comments: