In this article, we explore UART communication with the 74HC595 display to create an efficient 7-segment display system.
Things used in this project
Software apps and online services
1-Â STMicroelectronics STM32CubeMX
2-Â STMicroelectronics STM32CubeIDE
3-Â Proteus 8
Using 74HC595 Shift Registers to Control Multiple 7-Segment Displays
In this article, we delve into the intricacies of using the UART and 74HC595 7-Segment Display to control a 7-segment display. We explore the configuration and integration of the 74HC595 Shift Register within embedded systems, specifically focusing on how to efficiently utilize UART communication to cycle through numbers 0 to 9. This approach not only demonstrates the power and flexibility of the 74HC595 but also showcases how to achieve precise control of multiple 7-segment displays through UART.
 7-Segment Display :
The 7-segment display, a ubiquitous component in electronics, offers a simple yet effective means of visualizing numerical data. Comprising seven segments arranged in a pattern resembling the number “8,” each segment can be independently illuminated to represent numeric digits ranging from 0 to 9.
 Its straightforward design makes it a popular choice for displaying numeric information in various applications, from digital clocks and timers to electronic meters and counters.
Exploring the 74HC595 Shift Register :
Â
The 74HC595 Shift Register serves as a fundamental element in expanding GPIO capabilities for driving multiple 7-segment displays within our project. We offer a comprehensive insight into its operational principles, emphasizing its serial-in, parallel-out architecture. Moreover, we highlight its effectiveness in driving a common anode 7-segment display, showcasing its adaptability and efficiency in our project setup.
To kickstart this project, we’ll begin by configuring the GPIO pins (PA3 to PA7) as output pins. Specifically, we define the following pins: SER (PA3), RCLK (PA4), SRCLK (PA5), OE (PA6), and SRCLR (PA7). These definitions set the groundwork for our interface, allowing the microcontroller to communicate effectively with the 74HC595 Shift Register.
Next, we’ll delve into setting up the interface, focusing on using a counter to cycle through numbers 0 to 9 and display them on the 7-segment display. This approach demonstrates how to efficiently and effectively use the 74HC595 Shift Register in embedded systems.
STM32CubeMX Configuration:
- Open CubeMX & Create New Project Choose The Target MCUÂ STM32F103C6Â & Double-Click Its Name
- In Tab System Core Set High Speed Clock : Crystal/Ceramic Resonator
- Go To The Clock Configuration & Set The System Clock To 72MHz
Configuration for the GPIO Mode:
- Configure The GPIO Pins [PA3..PA7] as Output Pin
- Set User Label : PA3 -> SER && PA4 -> RCLK && PA5 -> SRCLK && PA6 -> OE && PA7 -> SRCLR.
- Generate The Initialization Code & Open The Project In CubeIDE
STM32CubeIDE Configuration:
- Write The Application Layer Code
- main.c
/* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart1; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ uint16_t number[10] = { 0b00000011, 0b10011111, 0b00100101, 0b00001101, 0b10011001, 0b01001001, 0b01000001, 0b00011011, 0b00000001, 0b00001001 }; /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ int cnt=0; uint16_t data = 0; /* USER CODE END 1 */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ static uint8_t cnt = 0; // Counter from 0 to 9 uint8_t data = number[cnt]; // Get the data for the current count HAL_GPIO_WritePin(GPIOA, SRCLR_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(OE_GPIO_Port, OE_Pin, GPIO_PIN_SET); for(int i = 0; i < 8; i++) { if(data & (1 << i)) { HAL_GPIO_WritePin(GPIOA, SER_Pin, GPIO_PIN_SET); // SER_Pin, 1 } else { HAL_GPIO_WritePin(GPIOA, SER_Pin, GPIO_PIN_RESET); // SER_Pin, 0 } HAL_GPIO_WritePin(GPIOA, SRCLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA, SRCLK_Pin, GPIO_PIN_RESET); } HAL_GPIO_WritePin(GPIOA, RCLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA, RCLK_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(OE_GPIO_Port, OE_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, SRCLR_Pin, GPIO_PIN_RESET); cnt = (cnt + 1) % 10; // Increment counter and wrap around to 0 after 9 HAL_Delay(1000); // Delay to make the counter increment every second (adjust as needed) } /* USER CODE END 3 */ }
Proteus Configuration :
- Open Proteus & Create New Project and click next
- Click on Pick Device
- Search for STM32F103C6 & 74HC595 & 7-SEG
- Click on Virtual Instruments Mode then choose
- Click on Terminal Mode then choose (DEFAULT & POWER &GROUND)
- finally make the circuit below and start the simulation