Learn electronics and microcontroller programming without buying a single piece of hardware.
The goal of this repository is to lower the bar of entry for anyone who wants to learn embedded systems and electronics but lacks immediate access to hardware components, programmers, or oscilloscopes.
By utilizing powerful Open Source software—gputils, SDCC, and gpsim—we can simulate circuits, visualize logic with virtual oscilloscopes, and debug code instruction-by-instruction, entirely on a computer.
Dr. Foad S. Farimani MyLibreLab Organization
- X (Twitter): @fsfarimani
- LinkedIn: fsfarimani
This repository primarily focuses on a fully Free and Open Source Software (FOSS) workflow.
Used for writing Assembly language. It provides gpasm (assembler) and gplink (linker).
sudo apt install gputils
Small Device C Compiler. Used for writing C code for 8-bit microcontrollers like the PIC16F84A.
sudo apt install sdcc
A software simulator for Microchip PIC microcontrollers. It simulates the CPU, GPIO pins, and allows attaching virtual components (LEDs, Buttons, Scopes).
sudo apt install gpsim
(Note: Project 007 demonstrates MPLAB XC8, but the core focus of this repo is the FOSS stack above.)
The repository is organized by complexity, starting from basic blinking LEDs to advanced concepts like Watchdog Timers, Sleep Modes, and Embedded Macros.
| Dir | Project Name | MCU | Language | Key Concepts |
|---|---|---|---|---|
000 |
SDCC Blink | 16F84A | C | Setting up SDCC, basic delay loops. |
001 |
ASM Blink | 10F200 | Asm | Baseline architecture, simple bit toggling. |
002 |
Embedded Blink | 10F200 | Asm | Input processing (Buttons), conditional branching. |
003 |
Slow Blink | 10F200 | Asm | Nested loops for long delays, Relocatable mode. |
004 |
SDCC LED | 16F84A | C | Port manipulation in C. |
0041 |
SDCC Scope | 16F84A | C | Using the gpsim Scope to visualize signals. |
005 |
Embedded Macro | 10F200 | Asm | Using macros for cleaner assembly code. |
006 |
Button Input | 10F200 | Asm | Polling inputs and controlling outputs. |
007 |
XC8 LCD | 16F887 | C | Advanced: HD44780 LCD driver, XC8 Compiler workflow. |
008 |
ASM Fade | 10F200 | Asm | Software PWM (Breathing LED), Absolute Mode. |
0081 |
ASM Fade (Rel) | 10F200 | Asm | Same as 008, but using Relocatable Mode (Linker). |
009 |
Knight Rider | 10F200 | Asm | Larson Scanner, The GP2/T0CKI Trap. |
010 |
Embedded Script | 10F200 | Asm | Unit testing: Embedding sim commands inside ASM source. |
011 |
ASM TMR0 | 10F200 | Asm | Hardware Timer, Prescalers, Polling TMR0. |
012 |
ASM WDT | 10F200 | Asm | Watchdog Timer, fail-safe resets, crash simulation. |
013 |
ASM Sleep | 10F200 | Asm | Sleep Mode, Wake-up on Pin Change, Low power. |
Most directories contain a main.asm (or main.c) and a main.stc (simulation startup script).
Used in projects like 001, 008, 009. No linker script required.
# Generate .hex and .cod file
gpasm -g main.asm
# Run Simulation
gpsim -c main.stc
Used in 0081, 010, 011. Allows modular code and embedded simulation scripts.
# Assemble to Object file
gpasm -c -g main.asm
# Link to Hex file
gplink -o main.hex main.o
# Run Simulation
gpsim -c main.stc
Used in 000, 004.
# Compile
sdcc -mpic14 -p16f84a main.c
# Run Simulation
gpsim -c main.stc
Throughout the creation of these examples, several "gotchas" were documented:
- The GP2 Trap (PIC10F200): Pin GP2 defaults to a Timer Input (T0CKI). You cannot use it as a digital output unless you explicitly clear the
T0CSbit in theOPTIONregister (See Project009). - Absolute vs. Relocatable: Absolute mode (
gpasmonly) is easier for tiny projects. Relocatable mode (gpasm -c+gplink) is required for complex features like.directembedded simulation commands (See Project008vs0081). - Simulation Grounding: In
gpsim, you cannot attach a switch directly to "VSS". You must use apulldownmodule to simulate a ground connection (See Project012). - 12-bit Core Limitations: The PIC10F200 lacks instructions like
ADDLW,SUBLW, andRETURNfound in larger PICs. You must useADDWF,SUBWF, andRETLW(See Project011).
This repository is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0).
You are free to:
- Share — copy and redistribute the material in any medium or format.
- Adapt — remix, transform, and build upon the material.
Under the following terms:
- Attribution — You must give appropriate credit to Dr. Foad S. Farimani and MyLibreLab.
- NonCommercial — You may not use the material for commercial purposes.
- ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.