STM32F103C6 Timer Interrupts, 7-Segment Multiplexing & LED Matrix
| Student | Dang Thai Khang — 2352464 |
| Course | C03010 — CC02 |
| Institution | Ho Chi Minh University of Technology (HCMUT) |
| Lecturer | Phan Van Sy |
| Semester | 2025 |
This lab builds on Lab 1 by introducing hardware timer interrupts (TIM2/TIM3) to replace blocking HAL_Delay() calls. The exercises progressively cover timer-based LED blinking, multiplexed 7-segment displays, software timers, digital clock implementation, 8×8 LED matrix driving, and a shift animation — all running concurrently via interrupt-driven scheduling.
- MCU: STM32F103C6 (ARM Cortex-M3)
- IDE: STM32CubeIDE (HAL Library)
- Simulation: Proteus 8
- Language: C
- Key Peripheral: TIM2, TIM3 (Timer Interrupts)
VXL_VDK_Lab_2_2352464/
├── EXERCISE_1/ # Timer interrupt + 2-digit 7SEG multiplexing
├── EXERCISE_2/ # 4-digit 7SEG multiplexing + dual LED blink
├── EXERCISE_3/ # Refactored update7SEG() function
├── EXERCISE_4/ # Faster multiplexing (reduced flicker)
├── EXERCISE_5/ # Digital clock (HH:MM) on 4-digit 7SEG
├── EXERCISE_7/ # Clock with button input (hour/minute adjust)
├── EXERCISE_8/ # Software timer abstraction (setTimer/timerRun)
├── EXERCISE_9/ # 8×8 LED matrix static display (character "A")
└── EXERCISE_10/ # Full system: Clock + LED matrix shift animation
Note: Exercise 6 is not included as it was not required in this lab.
Each folder contains:
| File | Description |
|---|---|
*.c |
Main source code (C, HAL library) |
*.hex |
Pre-compiled firmware for Proteus simulation |
*.pdsprj |
Proteus schematic & simulation project |
| # | Exercise | Description | Key Concepts |
|---|---|---|---|
| 1 | Timer + 2-Digit 7SEG | Use TIM2 interrupt (~10ms) to multiplex 2 digits and blink an LED | HAL_TIM_PeriodElapsedCallback, multiplexing |
| 2 | 4-Digit 7SEG | Extend to 4 multiplexed digits + 2 alternating LEDs | Multi-digit scan, led_buffer[] |
| 3 | update7SEG() Refactor |
Extract digit selection into a clean update7SEG(index) function |
Code modularization |
| 4 | Faster Scan Rate | Reduce multiplex interval from 100 to 25 ticks (less flicker) | Timing optimization |
| # | Exercise | Description | Key Concepts |
|---|---|---|---|
| 5 | HH:MM Clock | Display hours and minutes on 4-digit 7SEG, auto-increment | updateClockBuffer(), time tracking |
| 7 | Clock + Buttons | Add button inputs to adjust hours/minutes manually | GPIO input, debouncing |
| 8 | Software Timers | Abstract timing with setTimer() / timerRun() pattern |
Non-blocking timer design |
| # | Exercise | Description | Key Concepts |
|---|---|---|---|
| 9 | Static Matrix Display | Drive 8×8 LED matrix to show character "A" using TIM3 | Column scanning, font bitmap |
| 10 | Full System Integration | Clock (7SEG) + LED matrix with right-shift animation, all concurrent | Dual timers (TIM2+TIM3), animation |
- Open the
.pdsprjfile in Proteus 8+ - Double-click the STM32 → load the corresponding
.hexfile - Click Run to start simulation
- Open
.cfile in STM32CubeIDE - Create a new STM32F103C6 project, configure TIM2/TIM3 interrupts
- Replace
main.cand build - Flash via ST-Link
TIM2 (~10ms period)
├── Multiplex 7-segment digits (round-robin scan)
├── Software timer countdown (timerRun)
└── LED blink counter
TIM3 (~2ms period) [Exercise 9-10 only]
└── Multiplex LED matrix columns (8 columns)
void setTimer7seg(int duration) { timer7seg = duration; }
void timerRun() {
if(timer7seg > 0) timer7seg--;
if(timerClock > 0) timerClock--;
}
// In main loop: poll timer == 0, then act & resetCharacter "A" on 8×8 matrix:
··██·· 0x18
·█··█· 0x24
█····█ 0x42
██████ 0x7E
█····█ 0x42
█····█ 0x42
█····█ 0x42
······ 0x00
The full lab report (PDF) with schematics, source code, and explanations is available in the course submission.
This project is developed for educational purposes as part of the Microprocessors & Microcontrollers course at HCMUT.