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(PA_5, LOW);
		GPIO_write(PA_6, LOW);
		GPIO_write(PA_7, HIGH);
		GPIO_write(PB_6, HIGH);
		GPIO_write(PC_7, HIGH);
		GPIO_write(PA_9, LOW);
		GPIO_write(PA_8, LOW);
		GPIO_write(PB_10, LOW);
	}
}

void setup(void){
	RCC_HSI_init();
	GPIO_init(PA_5, OUTPUT);
	GPIO_init(PA_6, OUTPUT);
	GPIO_init(PA_7, OUTPUT);
	GPIO_init(PB_6, OUTPUT);
	GPIO_init(PC_7, OUTPUT);
	GPIO_init(PA_9, OUTPUT);
	GPIO_init(PA_8, OUTPUT);
	GPIO_init(PB_10, OUTPUT);
}

Last updated