This project implements a configurable Traffic Light Controller using the Silicon Labs C8051F020 microcontroller. Written entirely in Assembly, the system simulates a traffic cycle where the duration of the green light is user-programmable via a 7-segment display interface before the cycle begins.
The system demonstrates proficiency in Low-Level Logic Design, controlling GPIOs for LEDs, multiplexing displays, and managing timing constraints manually without an OS.
- Configurable Timer (HMI): Users can set the "Green Light Duration" (Max Count) using increment/decrement buttons before starting the cycle.
- Dual Operation Modes:
- Configuration Mode: Setup the countdown timer value.
- Run Mode: Executes the traffic logic (Green ON -> Countdown -> Red ON -> Reload).
- Variable Frequency Control: Adjustable counting speed (Frequency) via input switches to simulate different time scales.
- Visual Feedback: * 7-Segment Display: Shows the remaining time for the active signal.
- Status LEDs: Indicators for Red and Green traffic states.
Based on the C8051F020 architecture:
| Component | Port/Pin | Function |
|---|---|---|
| Red LED | P0.5 |
Stop Signal Output |
| Green LED | P0.6 |
Go Signal Output |
| 7-Segment Data | P1, P2 |
Multiplexed Digit Output |
| Control Inputs | P5 |
Start, Increment, Decrement Buttons |
| Freq. Control | P0.2 - P0.4 |
Speed Selection Switches |
The assembly code implements a robust state machine:
- INIT: Initialize Registers, disable Watchdog, and poll for User Input (Set Max Count).
- START: Load user-defined values into RAM (
0x50,0x60) and enter the main loop. - MAIN LOOP: * Drive Green LED.
- Decrement Counter on 7-Segment.
- Check for Zero -> Switch to Red LED -> Reload Counter -> Repeat.
- Clone the repository:
git clone [https://github.com/mariamashraf731/Traffic-light-system-8051.git](https://github.com/mariamashraf731/Traffic-light-system-8051.git)
- Hardware Setup:
- Connect Common Anode 7-Segment displays to Ports P1 & P2.
- Connect LEDs to P0.5 (Red) and P0.6 (Green).
- Connect Push Buttons to Port 5 (with Pull-up configuration).
- Build & Flash:
- Open
src/main.asmin Keil µVision. - Build target and flash to C8051F020.
- Open
For detailed schematics and flowcharts, please refer to the System Design Report.
- Register-Level Programming: Direct manipulation of
WDTCN(Watchdog),XBR2(Crossbar), andOSCICN. - Timing Analysis: creating precise delay loops (
DELAY1) for real-time simulation. - Memory Management: Utilizing internal RAM for preserving state variables during context switching.