Skip to content

imoroc/ARM7-PIC-Ring-Expansion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARM7-PIC-Ring-Expansion

C ASM Proteus LPC2103 PIC10F200

ABOUT THIS PROJECT: Implementation of a remote I/O expansion system using a Master-Slave architecture over a ring network topology (Poor Man's Token Ring). The LPC2103 ARM7 master discovers, configures, and controls multiple PIC10F200 slave modules through a custom serial protocol, with real-time feedback on a 2×16 LCD display.

All firmware runs bare-metal with no RTOS. The PIC slaves implement full-duplex serial communication entirely in software (bit-banging) due to the absence of a hardware UART on the PIC10F200.

Proteus Simulation Schematic

Architecture & Key Features

  • Master-Slave Ring Topology: The LPC2103 drives a daisy-chained ring of PIC10F200 modules via UART1 at 38400 bps. Each slave decrements the address field and forwards the frame to the next node.
  • Dynamic Node Discovery: On startup, the master sends a Ping frame (value 127) and counts the returning decremented value to automatically detect how many slaves are in the ring — no hardcoded device count.
  • Custom Binary Protocol: 2-byte frames (1 address byte + 1 command byte) with MSB used as frame-type discriminator (0 = address, 1 = command/data).
  • 6-Command Instruction Set: SET_DIR, PIN_OUT, PIN_SET, PIN_CLR, GET_DIR, GET_PIN for full bidirectional control of each slave's GPIO.
  • Software UART on PIC10F200 (Bit-Banging): Since the PIC10F200 has no hardware UART, the slave firmware implements both TX (GP2) and RX (GP3) in assembly, including start bit detection, center-sampling, and baud-rate generation via calibrated delay loops.
  • LCD User Interface: 2×16 HD44780 display (8-bit mode) shows the currently selected slave, pin, direction, and voltage level. Four physical buttons allow navigating and toggling the state of any pin in the ring.

Project Structure

HEMP-Remote-IO-Expansion
 ┣ 📂 assets/
 ┃ ┗ 🖼️ Project.png           ← Proteus schematic screenshot
 ┣ 📂 docs/
 ┃ ┗ 📜 technical_report.pdf  ← Full technical report
 ┣ 📂 simulation/
 ┃ ┣ 📜 Project.pdsprj        ← Proteus 8 project file
 ┣ 📂 src/
 ┃ ┣ 📂 master/               ← LPC2103 firmware (C)
 ┃ ┃ ┣ 📜 main.c
 ┃ ┃ ┣ 📜 Makefile
 ┃ ┃ ┣ 📜 clock.h
 ┃ ┃ ┣ 📜 lpc21xx.h
 ┃ ┃ ┣ 📜 minilib.h
 ┃ ┃ ┣ 📜 crt.S
 ┃ ┃ ┣ 📜 linker_flash.ld
 ┃ ┃ ┗ 📜 linker_ram.ld
 ┃ ┗ 📂 slave/                ← PIC10F200 firmware (PIC Assembly)
 ┃   ┗ 📜 slave.asm
 ┗ 📜 README.md

Communication Protocol

The protocol uses 2-byte frames. The MSB distinguishes frame types:

Byte MSB Remaining bits Description
Address 0 [6:0] Target address 0 = process this frame; N = decrement and forward
Command 1 [6:4] CMD · [1:0] Params Marked as command/data by the leading 1

Supported commands:

CMD Name Params Description
000 SET_DIR P1, P0 Set pin direction (1=Input, 0=Output)
001 PIN_OUT P1, P0 Write logic level (1=High, 0=Low)
010 PIN_SET P1, P0 Force pins HIGH (mask)
011 PIN_CLR P1, P0 Force pins LOW (mask)
100 GET_DIR Query pin direction (slave responds)
101 GET_PIN Read current pin state (slave responds)
11x NOP/PING Used for node discovery

Node discovery algorithm: The master sends address 127. Each slave decrements it by 1 and forwards it. When the frame completes the ring, total_slaves = 127 - returned_value.


Getting Started

Prerequisites

To build and simulate this project you need:

  • GCC ARM cross-compiler (arm-none-eabi-gcc) for the LPC2103 firmware
  • MPASM or GPASM to reassemble the PIC slave firmware (optional — f200.hex is prebuilt)
  • Proteus 8 for simulation

1. Clone the Repository

git clone https://github.com/imoroc/HEMP-Remote-IO-Expansion.git
cd HEMP-Remote-IO-Expansion

2. Build the Master Firmware (LPC2103)

Compile the C firmware using the provided Makefile:

cd src/master
make

This produces code.bin and code.elf in the same directory. The Proteus project is configured to load code.elf from this path.

3. (Optional) Reassemble the Slave Firmware (PIC10F200)

A prebuilt simulation/f200.hex is already included and ready to use. If you modify src/slave/slave.asm, reassemble it with:

# Using GPASM (Linux/macOS)
gpasm -p p10f200 src/slave/slave.asm -o simulation/f200.hex

# Using MPASM (Windows, included with MPLAB)
mpasmwin /p10F200 src\slave\slave.asm

4. Run the Simulation in Proteus 8

  1. Open simulation/Proyecto.pdsprj in Proteus 8.
  2. Verify the LPC2103 component points to src/master/code.elf (right-click the chip → Edit Properties → Program File).
  3. Verify each PIC10F200 component points to simulation/f200.hex.
  4. Press Play (▶) to start the simulation.

The debug terminal (UART0) will print discovery and status logs:

--- INITIATING MASTER SYSTEM ---
Modules found: 2
[LOG] Expander 0, Pin 0 | Direction: INPUT | Level: HIGH

Button Controls (Simulation)

Button Pin Action
BTN1 P0.21 Cycle to the next slave module
BTN2 P0.22 Toggle between Pin 0 and Pin 1
BTN3 P0.23 Toggle pin direction (Input ↔ Output)
BTN4 P0.24 Toggle pin voltage level (High ↔ Low)

Buttons use active-low logic (pulled up, pressed = 0V).


👨‍💻 Author

Iván Moro Cienfuegos

About

Remote I/O expansion system over a ring network using LPC2103 (ARM7) as master and PIC10F200 slaves. Custom binary protocol, dynamic node discovery, and bit-banging UART in PIC assembly. Simulated in Proteus 8.

Topics

Resources

License

Stars

Watchers

Forks

Contributors