Tutorial: 7-Segment Display

Overview

Display decimal number (0~9) on a 7-segment display

  • Inputs: 4-bit numbers (D C B A) // (00001111)

  • Output:

    • 7-segment decoder: 7-bit numbers ( a to g)

    • 7-segment display: decimal number 0~9

Hardware Specification

Hardware

7-segment display (5101ASR)

Detail information about 7 segment display - click here

  • Common anode: (common pin is connected to VCC)

  • Giving ‘LOW’ to the pin -> LED ON

  • Needs a load resistor for each pin

Please check the difference between the common cathode and common anode.

We will use common anode.

BCD 7-segment decoder

Model: 74LS47N (datasheet download)

  • All output pins are active low

Array resistor (B331J)

Circuit Configuration

Connecting with BCD 7-segment decoder

Connecting 7-segment without decoder

Code

Tutorial code : "TU_GPIO_LED_7segment_student.c" here

  • Creating 7-segment decoder (without using decoder chip)

If you want to use 7-segment decoder chip: read about 7-segment and Decoder

#include "stm32f4xx.h"
#include "ecRCC.h"
#include "ecGPIO.h"

void setup(void);
	
int main(void) {	
	// Initialiization --------------------------------------------------------
	setup();
	
	// Inifinite Loop ----------------------------------------------------------
	while(1){
		GPIO_write(GPIOA, 5, LOW);
		GPIO_write(GPIOA, 6, LOW);
		GPIO_write(GPIOA, 7, HIGH);
		GPIO_write(GPIOB, 6, HIGH);
		GPIO_write(GPIOC, 7, HIGH);
		GPIO_write(GPIOA, 9, LOW);
		GPIO_write(GPIOA, 8, LOW);
		GPIO_write(GPIOB, 10, LOW);
	}
}

void setup(void){
	RCC_HSI_init();
	GPIO_init(GPIOA, 5, OUTPUT);
	GPIO_init(GPIOA, 6, OUTPUT);
	GPIO_init(GPIOA, 7, OUTPUT);
	GPIO_init(GPIOB, 6, OUTPUT);
	GPIO_init(GPIOC, 7, OUTPUT);
	GPIO_init(GPIOA, 9, OUTPUT);
	GPIO_init(GPIOA, 8, OUTPUT);
	GPIO_init(GPIOB, 10, OUTPUT);
}

Last updated