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

7-segment circuit
image
image

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)

array resistor

Circuit Configuration

Connecting with BCD 7-segment decoder

image
image

Connecting 7-segment without decoder

image
circuit on breadbord

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 "ecRCC2.h"
#include "ecGPIO2.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);
}

7-Segment Display (eval board)

Overview

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

  • Inputs: display number, choosing 7-segment // ex) 9, 3 -> choosing 7-segment 3, display 9

  • Outputs:

    • 7-segment display: decimal number 0~9

    • Using 7-segment: The selected one of the four 7-segments

    • If you want to display different numbers on the four 7-segments, you need to use a very short delay to display the numbers

Hardware Specification

  • 7-Segment Display (JKIT - Nucleo 64): link

7-Segment Display (JKIT - Nucleo 64)

  • Connect directly to the STM board

  • Giving 'High' to the pin -> LED on

Digital Out for 7-Segment(number)
Digital Out for 7-Segment(LED)

Digital Out

Digital Out

PB_7, PB_6, PB_5, PB_4, PB_3, PB_2, PB_1, PB_0

PC_3, PC_4, PA_11, PA_10

Push-Pull, No Pull-up-Pull-down, Medium Speed

Push-Pull, No Pull-up-Pull-down, Medium Speed

Code

Tutorial code:

#include "../../include/ecGPIO2.h"
#include "../../include/ecSysTick2.h"
#include "stm32f4xx.h"
#include "../../include/ecRCC2.h"
#include "../../include/ecEXTI2.h"


void setup(void);
void Seven_Seg_FND_init(void);
void Seven_Seg_FND_display(uint8_t num, uint8_t LED);

int main(void) {
	setup();

	while (1) {
		for(int i = 0; i < 100000;i++){}  //delay_time(100);
		Seven_Seg_FND_display(5, 0);
		for(int i = 0; i < 100000;i++){}  //delay_time(100);
		Seven_Seg_FND_display(6, 1);
		for(int i = 0; i < 100000;i++){}  //delay_time(100);
		Seven_Seg_FND_display(8, 2);
		for(int i = 0; i < 100000;i++){}  //delay_time(100);
		Seven_Seg_FND_display(9, 3);

	}
}

void Seven_Seg_FND_init(void){
	
	//pinname array
	char PinName[12]={PB_7, PB_6, PB_5, PB_4, PB_3, PB_2, PB_1, PB_0, PC_3, PC_4, PA_11, PA_10};
	
    //fill output setting
	
}

void Seven_Seg_FND_display(uint8_t num, uint8_t LED) {

}

// Initialiization
void setup(void) {
	RCC_PLL_init();
	SysTick_init(1000);

	// initialize the pushbutton pin as an input:
	Seven_Seg_FND_init();
}

Last updated

Was this helpful?