Skip to content

Latest commit

 

History

History

README.md

🔬 Microprocessors & Microcontrollers — Lab 2

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

📌 Overview

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.

Tech Stack

  • MCU: STM32F103C6 (ARM Cortex-M3)
  • IDE: STM32CubeIDE (HAL Library)
  • Simulation: Proteus 8
  • Language: C
  • Key Peripheral: TIM2, TIM3 (Timer Interrupts)

📂 Repository Structure

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 Breakdown

Part 1 — Timer Interrupts & 7-Segment Multiplexing

# 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

Part 2 — Digital Clock

# 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

Part 3 — LED Matrix

# 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

⚙️ How to Run

Proteus Simulation (Recommended)

  1. Open the .pdsprj file in Proteus 8+
  2. Double-click the STM32 → load the corresponding .hex file
  3. Click Run to start simulation

Flash to Hardware

  1. Open .c file in STM32CubeIDE
  2. Create a new STM32F103C6 project, configure TIM2/TIM3 interrupts
  3. Replace main.c and build
  4. Flash via ST-Link

📝 Key Implementation Details

Timer Interrupt Architecture

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)

Software Timer Pattern (Exercise 8+)

void setTimer7seg(int duration) { timer7seg = duration; }
void timerRun() {
    if(timer7seg > 0) timer7seg--;
    if(timerClock > 0) timerClock--;
}
// In main loop: poll timer == 0, then act & reset

LED Matrix Font Encoding

Character "A" on 8×8 matrix:
  ··██··    0x18
  ·█··█·    0x24
  █····█    0x42
  ██████    0x7E
  █····█    0x42
  █····█    0x42
  █····█    0x42
  ······    0x00

📄 Report

The full lab report (PDF) with schematics, source code, and explanations is available in the course submission.


📜 License

This project is developed for educational purposes as part of the Microprocessors & Microcontrollers course at HCMUT.