Skip to content

About

PIC18F8722 multi-level parking lot controller with Python/Pygame serial simulator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🅿️ Multi-Level Parking Lot Controller

A real-time embedded parking lot management system built on the PIC18F8722 microcontroller, communicating with a Python/Pygame visual simulator over serial (USART).

The firmware manages a 4-level, 40-space parking garage with subscription support, FIFO queuing, automatic fee calculation, and a multiplexed 7-segment display — all driven by timer and peripheral interrupts.

Python Simulator MCU License


Features

Feature Description
4-Level Parking Levels A–D, 10 spots each (40 total)
Serial Protocol Custom $..# message framing at 115200 baud
FIFO Queue Up to 16 cars wait when the lot is full
Subscriptions Reserve a specific spot for 50 TL; park/exit free
Fee Calculation 1 TL per 250 ms of occupancy, minimum 1 TL
7-Segment Display Shows total revenue or per-level empty spaces
ADC Level Selector Potentiometer selects which level to display
Button Toggle RB4 button toggles display between revenue and spaces
Visual Simulator Pygame-based simulator with real-time parking visualization

Architecture

┌──────────────────────┐          USART (115200, 8N1)          ┌──────────────────────┐
│   PIC18F8722 MCU     │◄────────────────────────────────────►│  Python Simulator    │
│                      │                                       │  (Pygame GUI)        │
│  Timer0 → 100ms TX   │    Commands: $GO#  $PRKXXX#           │                      │
│  Timer2 → 7-seg mux  │              $EXTXXX#  $SUBXXXYZZ#    │  Park / Exit / Sub   │
│  ADC    → level sel   │              $END#                    │  buttons + events    │
│  PORTB  → mode toggle │                                       │                      │
│                      │    Responses: $EMPCC#  $SPCXXXYZZ#    │  Visual parking lot  │
│  Parking logic       │               $FEEXXXMMM#             │  + statistics        │
│  Queue management    │               $RESXXXMM#              │                      │
└──────────────────────┘                                       └──────────────────────┘

Serial Protocol

All messages are framed with $ (start) and # (end). Integers are sent as ASCII strings.

Commands (Simulator → MCU)

Command Format Description
Start $GO# Begin simulation
End $END# Stop simulation after 60s
Park $PRKXXX# Car XXX requests parking
Exit $EXTXXX# Car XXX leaves the lot
Subscribe $SUBXXXYZZ# Car XXX reserves level Y, spot ZZ

Responses (MCU → Simulator, every 100 ms)

Response Format Description
Empty Space $EMPCC# CC = total available spaces
Parking Space $SPCXXXYZZ# Car XXX parked at level Y, spot ZZ
Parking Fee $FEEXXXMMM# Car XXX charged MMM TL
Reserved $RESXXXMM# Subscription result: MM = 50 (success) or 00 (fail)

Hardware Setup

Pin Mapping

Function Port/Pin Direction Notes
USART TX RC6 Output Serial transmit
USART RX RC7 Input Serial receive
7-Seg Segments PORTJ[0:6] Output Segment a–g patterns
7-Seg Digit Enable PORTH[0:3] Output Active digit select (D0–D3)
Potentiometer (ADC) PORTH4 (AN12) Input Level selector (0–1023 → A/B/C/D)
Mode Toggle Button RB4 Input Interrupt-on-change, internal pull-up

ADC Level Mapping

ADC Range Level
0–255 A
256–511 B
512–767 C
768–1023 D

Software Design

Interrupt-Driven Architecture

The main loop only updates the 7-segment display content. All real work happens in the high-priority ISR:

  • USART RX — buffers bytes between $ and #, then parses the complete command
  • Timer0 (100 ms) — dequeues and transmits one message; triggers ADC every 500 ms
  • Timer2 (~5 ms) — multiplexes the 4-digit 7-segment display
  • ADC complete — maps potentiometer reading to a parking level
  • PORTB change — detects RB4 falling edge to toggle display mode

Fee Calculation

fee = floor(parking_duration_ms / 250) + 1
  • Subscribed cars are exempt (fee = 0 TL)
  • Subscription costs 50 TL (or 0 TL if the spot is unavailable)

Building & Running

Firmware (PIC18F8722)

  1. Open parking-lot-simulator in MPLAB X IDE
  2. Ensure the XC8 compiler is installed and selected
  3. Build the project (target: PIC18F8722 @ 40 MHz)
  4. Program the microcontroller via a PICkit programmer

Simulator (Python)

pip install pygame pyserial
python simulator.py
  1. Connect the PIC board via USB-to-serial adapter
  2. Update SERIAL_PORT in the script if needed (default: /dev/ttyUSB0)
  3. Press S to send the $GO# command and start the simulation

Project Structure

├── main.c                  # PIC18F8722 firmware (parking logic, ISRs, display)
├── pragmas.h               # Microcontroller configuration bits
├── simulator.py            # Python/Pygame visual simulator
├── Makefile                # MPLAB X generated build system
├── nbproject/              # MPLAB X project configuration
├── .gitignore
├── LICENSE
└── README.md

License

This project is licensed under the MIT License.

About

PIC18F8722 multi-level parking lot controller with Python/Pygame serial simulator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages