Summary of PIC16F84A LED blinking code + Proteus simulation
This article provides C code (MPLAB with HI-TECH C) to blink an LED using a PIC16F84A. It explains the minimum circuit: PIC16F84A with up to 20MHz crystal (example uses 20MHz), MCLR pulled high, and an LED on RA0. The code includes htc.h, sets configuration bits, defines LED as RA0 and _XTAL_FREQ as 20MHz, configures RA0 as output, initializes it low, then toggles it in a loop with delays to blink the LED every half second. Download and simulation links are provided.
Parts used in the LED blink with PIC16F84A:
- PIC16F84A microcontroller
- 20MHz crystal (any 0 to 20MHz can be used)
- Capacitors for crystal (as required for oscillator)
- Pull-up resistor for MCLR (to keep MCLR high)
- LED
- Current-limiting resistor for LED
- Power supply (VDD and VSS connections for PIC)
- Optional programming/debugging connector
This post provides the code to make an LED blink using PIC16F84A microcontroller. This code is written in C language using MPLAB with HI-TECH C compiler. This code is intended to be the first step in learning how to use PIC16F84A microcontroller in your projects. You can download this code from the ‘Downloads’ section at the bottom of this page.Following figure shows the minimum circuit required to make an LED blink with PIC16F84A.

microcontrollers, then you have to include “htc.h” file in the code. After including “htc.h” file, configuration bits are being set in the code shown above. To understand the details of how these configuration bits are being programmed, you can read this post.After the configuration bits, LED pin is being defined as the RA0 pin. You can replace RA0 with any other pin name if you want (e-g RB0 etc). After LED pin definition, CPU frequency is being defined.

For more detail: PIC16F84A LED blinking code + Proteus simulation
- What crystal frequency can I use with PIC16F84A?
You can use any crystal from 0 to 20MHz; the example uses 20MHz. - Which pin is used to blink the LED in the example?
The LED is connected to RA0 in the example code. - Do I need to pull MCLR high?
Yes, MCLR is pulled high to keep PIC16F84A out of reset. - What header file must be included for HI-TECH C?
Include htc.h in the code when using HI-TECH C compiler. - How is the LED pin configured as output?
RA0 is set as output using TRISA0 = 0; - How is the CPU frequency specified for delay functions?
Define the _XTAL_FREQ macro (set to 20MHz in the example) to use __delay_us() and __delay_ms(). - How often does the LED toggle in the example?
The LED is toggled every half second in the while loop. - Can I use a different pin instead of RA0?
Yes, you can replace RA0 with any other pin name such as RB0.