Skip to content

MyLibreLab/PIC10F200-Sim-Examples

Repository files navigation

Virtual Embedded Development: PIC10F200 & Beyond

Learn electronics and microcontroller programming without buying a single piece of hardware.

🎯 Goal

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.

👤 Author

Dr. Foad S. Farimani MyLibreLab Organization


🛠️ The Toolchain (Linux)

This repository primarily focuses on a fully Free and Open Source Software (FOSS) workflow.

1. gputils (The Assembler)

Used for writing Assembly language. It provides gpasm (assembler) and gplink (linker).

sudo apt install gputils

2. sdcc (The C Compiler)

Small Device C Compiler. Used for writing C code for 8-bit microcontrollers like the PIC16F84A.

sudo apt install sdcc

3. gpsim (The Simulator)

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.)


📂 Project Catalog

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.

🚀 How to Run a Project

Most directories contain a main.asm (or main.c) and a main.stc (simulation startup script).

1. Absolute Assembly (Simple)

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

2. Relocatable Assembly (Advanced)

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

3. SDCC (C Language)

Used in 000, 004.

# Compile
sdcc -mpic14 -p16f84a main.c

# Run Simulation
gpsim -c main.stc

💡 Key Lessons Learned

Throughout the creation of these examples, several "gotchas" were documented:

  1. 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 T0CS bit in the OPTION register (See Project 009).
  2. Absolute vs. Relocatable: Absolute mode (gpasm only) is easier for tiny projects. Relocatable mode (gpasm -c + gplink) is required for complex features like .direct embedded simulation commands (See Project 008 vs 0081).
  3. Simulation Grounding: In gpsim, you cannot attach a switch directly to "VSS". You must use a pulldown module to simulate a ground connection (See Project 012).
  4. 12-bit Core Limitations: The PIC10F200 lacks instructions like ADDLW, SUBLW, and RETURN found in larger PICs. You must use ADDWF, SUBWF, and RETLW (See Project 011).

⚖️ License

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published