When repairing older electronic boards or modifying legacy microchip projects, you will often find that old source code fails to compile on newer toolchains. This guide explains how to fix code incompatibilities caused by HI-TECH C Compiler Version 9+ (PICC Lite) macro updates and shows how to convert a legacy blinking LED program to compile successfully on version 9+.
🛠️ The Core Issue: Syntax Incompatibilities
In newer versions of HI-TECH C (v9.x and up), the compiler transitioned to stricter, standardized naming conventions for configuration bits (__CONFIG) and Special Function Registers (SFRs).
If you try to compile old repair code and get Undefined symbol or Compilation error flags, you need to update the legacy macro tokens to the new standardized format using the translation tables below.
🔹 PIC12F675 Configuration Mapping
| Before Change (v8 and below) | After Change (Version 9+) |
|---|---|
MCLRDIS | MCLRE_OFF |
PWRTEN | PWRTE_ON |
WDTDIS | WDTE_OFF |
INTIO | FOSC_INTRCIO |
OPTION | OPTION_REG |
GODONE | GO_DONE |
🔹 PIC16F84A Configuration Mapping
| Before Change (v8 and below) | After Change (Version 9+) |
|---|---|
UNPROTECT | CP_OFF |
PWRTEN | PWRTE_ON |
WDTDIS | WDTE_OFF |
HS | FOSC_HS |
OPTION | OPTION_REG |
🔹 PIC16F887 Configuration Mapping
| Before Change (v8 and below) | After Change (Version 9+) |
|---|---|
LVPDIS | LVP_OFF |
IESODIS | IESO_OFF |
BORDIS | BOREN_OFF |
MCLRDIS | MCLRE_OFF |
PWRTEN` | PWRTE_ON |
WDTDIS | WDTE_OFF |
INTIO | FOSC_INTRC_NOCLKOUT |
OPTION | OPTION_REG |
💾 Section 1: Legacy Code (HI-TECH C v8 & Below)
Targeting a PIC12F675 at 4MHz using manual delay routines:
// ====================================================================
// Filename: led_onoff.c
// Created on: 2008.9.28 by mit.ueno
// Version: 1.0 (Legacy)
// Compiler: PICC Lite (v8 and below)
// Target MCU: PIC12F675
// Clock: 4MHz (INTIO)
// Overview: Make the GP4 and GP5 LEDs blink at 0.5-second intervals.
// ====================================================================
#include "pic.h"
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS);
static void pic_init();
static void Delay_ms(unsigned char ms);
static void Delay_1ms();
main() {
pic_init(); // Initialize the PIC
while(1) {
GPIO5 = 1;
GPIO4 = 0;
Delay_ms(250);
Delay_ms(250);
GPIO5 = 0;
GPIO4 = 1;
Delay_ms(250);
Delay_ms(250);
}
}
static void pic_init() {
GPIO = 0;
CMCON = 0x07; // Comparator not used
ANSEL = 0x00; // Analog features not used
TRISIO = 0x0F; // GP4 and GP5 configured as Outputs (0), others as Inputs (1)
}
// 1ms x ms Wait Routine
static void Delay_ms(unsigned char ms) {
unsigned char c;
for (c=ms ; c>0 ; c--) {
Delay_1ms();
}
}
// 1ms manual weight routine
static void Delay_1ms() {
unsigned int cnt;
unsigned int i;
cnt = 76;
for (i=0 ; i
🔄 Section 2: Migrated Code (HI-TECH C v9+)
Here is the exact same program logic updated to compile perfectly on the newer v9+ environment. It utilizes the new standard header maps, modern macro tokens, and the compiler's native, precise hardware delay loops.
// ====================================================================
// Filename: led_onoff_v9.c
// Migrated for: HI-TECH C Version 9+ (PICC Lite)
// Target MCU: PIC12F675
// Clock: 4MHz Internal
// Overview: Migrated version alternating GP4 and GP5 at 0.5s intervals.
// ====================================================================
#include // Use the updated header format for v9+
// Define crystal frequency so the native compiler delays work properly
#define _XTAL_FREQ 4000000
// Updated v9 Configuration Bits syntax mapping
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF);
// Modern compilers expect explicit void returns for main
void main(void) {
// PIC Initialization directly inline
GPIO = 0;
CMCON = 0x07; // Comparator not used
ANSEL = 0x00; // Analog features not used
TRISIO = 0x0F; // GP4 and GP5 configured as Outputs (0)
while(1) {
GPIO5 = 1;
GPIO4 = 0;
__delay_ms(500); // Replaced legacy loop with built-in, precise macro
GPIO5 = 0;
GPIO4 = 1;
__delay_ms(500); // Replaced legacy loop with built-in, precise macro
}
}
💡 Summary of Changes:
Header Map: Changed#include "pic.h"to#include.Configuration Registers: Updated tokens to v9 formats.Timing Loops: Replaced custom delays with built-in__delay_ms().