Back to posts
4. Create
Create
Create

Microchip XC8 Compiler Installation via Terminal
Aryan Kanojia / March 16, 2025
Installing and Using XC8 Compiler on VS Code or any Terminal for compiling C code without MPLab
Prerequisite: Install Windows Subsystem for Linux (WSL)
If you haven't set up WSL on your system, follow these steps.
1. Install XC8 Compiler
Visit Microchip and download XC8 compiler for Linux.
# Navigate to the directory where the installer is downloaded and move it into your Ubuntu distro's download folder:
wsl
cd Downloads/
# Give execution permission to the installer
chmod +x xc8-v3.00-full-install-linux-x64-installer.run
# Run the installer with sudo
sudo ./xc8-v3.00-full-install-linux-x64-installer.run
2. Add XC8 Compiler to System Path
# Open the shell configuration file (use ~/.zshrc if you use zsh)
nano ~/.bashrc
# Add the following line at the end of the file
export PATH=$PATH:/opt/microchip/xc8/v3.00/bin
# Apply changes
source ~/.bashrc # Or use source ~/.zshrc if using zsh
3. Verify Installation
xc8-cc --version
4. Create input.c
and Makefile
in the same folder
Create input.c
File
#include <pic.h>
void main() {
// your desire code
}
Create Makefile
CC = /opt/microchip/xc8/v3.00/bin/xc8-cc
CHIP = -mcpu=16F84A -traditional
SRC = input.c
HEX = main.hex
WIN_DIR = /mnt/c/Users/aryan/Desktop/HEX-folder
transfer: $(HEX)
rm -f "$(WIN_DIR)/$(HEX)" # Remove existing HEX file if it exists
cp $(HEX) $(WIN_DIR) # Copy HEX file to Windows directory
build: $(HEX)
$(HEX): $(SRC)
$(CC) $(CHIP) $(SRC) -o $(HEX)
clean:
rm -f "$(WIN_DIR)/$(HEX)" # Also Delete the HEX file in your desktop
rm -rf $(HEX) __eeprom.* main.* startup.* *.o *.p1 *.d *.cmf *.elf *.hxl *.sdb *.lst *.rlf *.sym
5. Compile and Clean and transfer
To compile
make
To clean the directory
make clean
6. Transfer HEX File to Windows
make transfer