In this project, we explore how to use the 74HC595 Shift Register to control a 7-segment display with an STM32 microcontroller. By leveraging the shift register’s serial-in, parallel-out capability, we can expand GPIO control and efficiently drive the display. A counter is implemented to cycle through digits 0–9, demonstrating a practical method of controlling multiple 7-segment displays in embedded systems.
7-Segment Display
The 7-segment display provides a simple way to visualize numeric values. It consists of seven LEDs arranged in the form of the digit “8.” By selectively powering different segments, digits from 0 to 9 can be displayed.
Exploring the 74HC595 Shift Register
The 74HC595 is an 8-bit serial-in, parallel-out shift register with a storage latch. It allows microcontrollers with limited GPIO pins to control multiple outputs efficiently. In this project, it is used to drive a common-anode 7-segment display.
Key control pins include:
- SER (Serial Data)
- SRCLK (Shift Clock)
- RCLK (Latch Clock)
- OE (Output Enable)
- SRCLR (Shift Register Clear)
- MCU Selection: STM32F103C6 (72MHz clock)
- GPIO Configuration:
- PA3 → SER
- PA4 → RCLK
- PA5 → SRCLK
- PA6 → OE
- PA7 → SRCLR
- UART1 Configuration:
- Baud Rate: 115200
- Data: 8 bits, No Parity
- Generate initialization code in STM32CubeIDE.
Key Functions
- Shift Register Control:
- void Write_7Segment(uint8_t digit);
- UART (Optional)
Main Loop Example
for(uint8_t i = 0; i < 10; i++) {
Write_7Segment(i);
printf("Displaying: %d\r\n", i);
HAL_Delay(1000);
}Components:
- STM32F103C6
- 74HC595
- 7-SEG-COM-ANODE
- Virtual Terminal (115200 baud)
Connections:
- Match PA3–PA7 to shift register pins (SER, RCLK, SRCLK, OE, SRCLR)
- Connect 74HC595 outputs to the 7-segment display
- Connect UART TX to Virtual Terminal
- Simulation Steps:
- Load the compiled .hex file into STM32.
- Observe digits 0–9 displayed sequentially.
- Monitor UART messages for debugging.
If you have any questions or suggestions don't hesitate to leave a comment below





Comments