#532 PIC16F84A Blinky
A quick test of programming a PIC16F84A on a breadboard and 3rd party dev board with MPLabX (assembler)
Here’s a quick demo..
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
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)
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|
- 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_HSHS oscillator selected (I’m going to use a 4MHz crystal)
_WDTE_OFFwatchdog timer disabled
_PWRTE_OFFpower-up timer disabled
_CP_OFFcode 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:
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.
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.
Running on a breadboard:
Scope trace of the generated LED control signal - bang on 4 Hz:
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.
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.