LAB: GPIO Digital InOut 7-segment(eval board)

LAB: GPIO Digital InOut 7-segment

Date: 2025-09-02

Author/Partner:

Github: repository link

Demo Video: Youtube link

PDF version:

Introduction

In this lab, you are required to create a simple program to control a 7-segment display to show a decimal number (0~9) that increases by pressing a push-button.

You must submit

  • LAB Report (*.pdf)

  • Zip source files(lab***.c, ecRCC2.h, ecGPIO2.h etc...).

    • Only the source files. Do not submit project files

Requirement

Hardware

  • MCU

    • NUCLEO-F411RE

  • Actuator/Sensor/Others:

    • eval board

Software

  • Keil uVision, CMSIS, EC_HAL library

Exercise

Fill in the table

Port/Pin

Description

Register setting

Port B Pin 5

Clear Pin5 mode

GPIOB->MODER &=~(3<<(5*2))

Port B Pin 5

Set Pin5 mode = Output

GPIOB->MODER |=____________

Port B Pin 6

Clear Pin6 mode

GPIOB->MODER &=~___________

Port B Pin 6

Set Pin6 mode = Output

GPIOB->MODER |=____________

Port B Pin Y

Clear PinY mode

GPIOB->MODER &=~___________

Port B Pin Y

Set PinY mode = Output

GPIOB->MODER |=____________

Port B Pin 5~9

Clear Pin5~9 mode

GPIOB->MODER &=~___________

Set Pin5~9 mode = Output

GPIOB->MODER |=____________

Port X Pin Y

Clear Pin Y mode

GPIOX->MODER &=~___________

Set Pin Y mode = Output

GPIOX->MODER |=____________

Port B Pin5

Set Pin5 otype=push-pull

GPIOB->OTYPER =____________

Port B PinY

Set PinY otype=push-pull

GPIOB-> OTYPER =____________

Port B Pin5

Set Pin5 ospeed=Fast

GPIOB->OSPEEDR =____________

Port B PinY

Set PinY ospeed=Fast

GPIOB-> OSPEEDR =____________

Port B Pin 5

Set Pin5 PUPD=no pullup/down

GPIOB->OTYPER =____________

Port B Pin Y

Set PinY PUPD=no pullup/down

GPIOB-> OTYPER =____________


Problem 0: Check FND 7-Segment Display

Procedure

Review 7-segment Decoder and Display from Digital Logic lecture.

1. FND-7-segment display connection

First, connect the eval board with the stm32

Check that all LEDs of 7-segment work properly

  • Give 'H' signal to each 7-segment pin of 'a'~'g' . Observe if that LED is turned ON or OFF

  • Check another 7-segment display same

  • Example: Connect VCC to all 'a'~'g' pins

Connection Diagram

Circuit diagram

You need to include the circuit diagram in the report

image

Discussion

  1. Draw the truth table for the BCD 7-segment decoder with the 4-bit input.

Answer discussion questions

** YOUR Truth-table  goes here**
  1. What are the common cathode and common anode of 7-segment display?

Answer discussion questions

  1. Does the LED of a 7-segment display (common anode) pin turn ON when 'HIGH' is given to the LED pin from the MCU?

Answer discussion questions


Problem 1: Program FND-7-segment decoder

Instead of using the decoder chip, we are going to make the 7-segment decoder with the MCU programming.

Do not use the 7-segment decoder for this problem

Procedure

  1. Use the same project and source file.

  2. Include your updated library in \repos\EC\include\ to your project.

  • ecGPIO2.h, ecGPIO2.c

  • ecRCC2.h, ecRCC2.c

  1. Declare and Define the following functions in your library

void Seven_Seg_FND_init(void); 
void Seven_Seg_FND_display(uint8_t num, uint8_t LED);
  • num: 0 to 9999 only (unsigned)

  1. Configure and connect the MCU to the circuit

  2. First, check that every number, 0 to 9, can be displayed properly

  3. Then, create a code that increases the displayed number from 0 to 30 with each button press.

    • After the number '30', it should start from '0' again.

Configuration

Configure the MCU

Digital In for Button (B1)
Digital Out for 7-Segment

Digital In

Digital Out

PA4

PB7,PB6,PB5,PB4,PB3,PB2,PB1,PB0 ('a'~'h', respectively) PC3,PC4,PA11,PA10 ('LED1'~'LED4', respectively)

PULL-UP

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

Code

Sample Code.

#include "stm32f4xx.h"
#include "ecGPIO2.h"
#include "ecRCC2.h"

#define LED_PIN PA_5
#define BUTTON_PIN PC_13

void setup(void);
	
int main(void) { 
	// Initialiization --------------------------------------------------------
	setup();
	unsigned int cnt = 0;
	
	// Inifinite Loop ----------------------------------------------------------
	while(1){
		Seven_Seg_FND_display(cnt % 10, 1);
		// add code
	}
}


// Initialiization 
void setup(void)
{
	RCC_HSI_init();	
	GPIO_init(BUTTON_PIN, INPUT);  // calls RCC_GPIOC_enable()
	Seven_Seg_FND_init();  // declare a,b,c,d,e,f,g,h / LED1,LED2,LED3,LED4
}

Your code goes here: ADD Code LINK such as github

Explain your source code with necessary comments.

// YOUR MAIN CODE ONLY
// YOUR CODE

Your code goes here: ADD Code LINK such as github

Explain your source code with the necessary comments.

// YOUR MAIN CODE ONLY
// YOUR CODE

Connection Diagram

Circuit diagram

You need to include the circuit diagram

image

Results

Experiment images and results

Show experiment images /results

Add demo video link

Discussion

Analyze the result and explain any other necessary discussion.


Reference

Complete list of all references used (github, blog, paper, etc)


Troubleshooting

(Option) You can write Troubleshooting section

Last updated

Was this helpful?