Fork me on GitHub

Project Notes

#532 PIC16F84A Blinky

A quick test of programming a PIC16F84A on a breadboard and 3rd party dev board with MPLabX (assembler)

Build

Here’s a quick demo..

clip

Notes

I’m planning to play around a bit more with low-end (8 bit) PICs. To start I’d like to get my toolchain setup and testing. So for this project I’m programming a PIC16F84A-04 with a simple assembler “LED blinky” routine in order to test my setup and the following tools:

  • MPLABX v5.30 running on MacOSX
    • mplab_ide - the main IDE
    • mplab_ipe - the stand-alone programmer
    • mpasm 5.86
  • PICKit 3 (clone)
  • PIC16F84A-04 on a breadboard
  • PIC16F84A-04 on a 3rd party development/programming board

PIC16F84A Specs

The microchip site has plenty of info and datasheets for the processor. The core specs:

  • 1024 words flash memory
  • 68 bytes SRAM
  • 64 bytes EEPROM
  • 13 I/O ports
  • 1 8-bit timer/counter
  • voltage range: 2.0-5.5
  • up to 4 MHz oscillator (PIC16F84A-04 variant) or 20 MHz (PIC16F84A-20 variant)

PIC16F84A_pinout

Programmer

I got my PICKit 3 in a programmer / minimum system board bundle from a seller on aliexress. Only 5 of the pins are relevant for programming the PIC16F84A:

PIC16F84A Pin Programmer Pin Function Description
MCLR (4) VPP (1) VTEST MODE Program Mode Select
VDD (14) VDD (2) VDD Power Supply
VSS (5) GND (3) VSS Ground
RB7 (13) PGD (4) DATA Data Input/Output
RB6 (12) PGC (5) CLOCK Clock Input

Notes:

  • MCLR is the Master Clear (Reset) input/programming voltage input. This pin is an active low RESET to the device
  • In the PIC16F8X, the programming high voltage is internally generated. To activate the Programming mode, high voltage needs to be applied to MCLR input. Since the MCLR is used for a level source, this means that MCLR does not draw any significant current.

Compileing the Project with the the MPLABX IDE

The PIC16F84ABlinky.X project is a simple single-file program in assembelr that blinks an LED on pin RA3 (2) at about 4Hz. The code was compiled with the MPLABX IDE and device programmed with a PICKit 3.

Project settings selected as follows:

  • Family: Mid-Range 8-bit MCUs (PIC10/12/16/MCP)
  • Device: PIC16F84A
  • Compiler: mpasm 5.86

The configuration bits are set:

  • _FOSC_HS HS oscillator selected (I’m going to use a 4MHz crystal)
  • _WDTE_OFF watchdog timer disabled
  • _PWRTE_OFF power-up timer disabled
  • _CP_OFF code protection disabled

Using the MPLAB Integrated Programming Environment

The MPLAB Integrated Programming Environment (mplab_ipe) is a standalone tool that can be used to erase, program or verify a chip.

Once the code was compiled, I tested erasing and programming. All good:

ipe_erase_and_program

Using the IPE to configure powering the device, I ran into what is apparently a common problem with the PICKit 3 clones - it complained when I selected 5V (hence 4.75V being selected in this example). Strangely, I didn’t have this problem when using the PICKit 3 from MPLABX IDE.

ipe_set_power

Construction

This is a minimal circuit - the application is basically a single LED on RA3. More interesting details in the schematic are the in-circuit programming connections.

Diodes D1 and D2 prevent interference between programming power (VPP) and the pull-up to VDD required to enable the chip for normal operation. Note:

  • the PIC ICSP Guide does not include D2, but I found that without it I could not get the PIC to run with the programmer connected. This may be due to a difference between the clone PICKit 3 I have and the real thing.

Breadboard

Schematic

Running on a breadboard:

Build

Scope trace of the generated LED control signal - bang on 4 Hz:

scope_ra3

Using the Dev Board

After successfully programming on a breadboard, I tried the dev board that I received with the PICKit 3. It turns out to be marginally more convenient, mainly because:

  • the zif socket reduces the chance of damaging the PIC
  • it has a pull-up resistor, and an LED with current-limiting resistor that can be used if needed

However, two limitations:

  • because it is designed to generically handle any PIC up to 40 pin DIP package, it needs the correct connects to be wired up with jumpers
  • it doesn’t include diodes for diode-steering the VPP and VDD-pullup MCLR connections. I added these in the zif socket and wired up accordingly.

devboard_build

devboard_ext_power

Bad Chips!

The first PIC16F84A chips I tried to program came from an aliexpress supplier and were clearly salvaged parts. The programmer was unable to identify them or perform any programming actions.

Connecting to MPLAB PICkit 3...

Currently loaded firmware on PICkit 3
Firmware Suite Version.....01.56.02
Firmware type..............Midrange
Programmer to target power is enabled - VDD = 4.750000 volts.
Target Device ID (0x3fe0) is an Invalid Device ID. Please check your connections to the Target Device.

If I still tried to proceed with programming it would fail:

Programming...

The following memory area(s) will be programmed:
program memory: start address = 0x0, end address = 0x21
configuration memory
program memory
Address: 1 Expected Value: 3400 Received Value: 800
Failed to program device

I put this down to faulty chips. When I switch to some PIC16F84A chips from a reputable source element14.

Credits and References

About LEAP#532 PICLED

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader