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.
| 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 |
┌──────────────────────┐ 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# │ │
└──────────────────────┘ └──────────────────────┘
All messages are framed with $ (start) and # (end). Integers are sent as ASCII strings.
| 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 |
| 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) |
| 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 Range | Level |
|---|---|
| 0–255 | A |
| 256–511 | B |
| 512–767 | C |
| 768–1023 | D |
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 = 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)
- Open
parking-lot-simulatorin MPLAB X IDE - Ensure the XC8 compiler is installed and selected
- Build the project (target: PIC18F8722 @ 40 MHz)
- Program the microcontroller via a PICkit programmer
pip install pygame pyserial
python simulator.py- Connect the PIC board via USB-to-serial adapter
- Update
SERIAL_PORTin the script if needed (default:/dev/ttyUSB0) - Press S to send the
$GO#command and start the simulation
├── 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
This project is licensed under the MIT License.