LAB: GPIO Digital InOut 7-segment

Date: 2023-09-22

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(main*.c, ecRCC.h, ecGPIO.h etc...).

    • Only the source files. Do not submit project files

Requirement

Hardware

  • MCU

    • NUCLEO-F411RE

  • Actuator/Sensor/Others:

    • 7-segment display(5101ASR)

    • Array resistor (330 ohm)

    • decoder chip(74LS47)

    • breadboard

Software

  • Keil uVision, CMSIS, EC_HAL library

Exercise

Fill in the table

Problem 1: Connecting 7-Segment Display

Procedure

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

The popular BCD 7-segment decoder chips are 74LS47 and CD4511.

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

Do not use the 7-segmment decoder

Connect the common anode 7-segment with the given array resistors.

Apply VCC and GND to the 7-segment display.

Apply 'H' to any 7-segment pin 'a'~'g' and observe if that LED is turned on or off

  • example: Set 'H' on PA5 of MCU and connect to 'a' of the 7-segment.

Connection Diagram

Circuit diagram

You need to include the circuit diagram

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 2: Display 0~9 with button press

Procedure

  1. Create a new project under the directory \repos\EC\LAB\LAB_GPIO_7segment

  • The project name is “LAB_GPIO_7segment”.

  • Create a new source file named as “LAB_GPIO_7segment.c”

  • Refer to the sample code

You MUST write your name on the source file inside the comment section.

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

  • ecGPIO.h, ecGPIO.c

  • ecRCC.h, ecRCC.c

  1. Declare and Define the following functions in your library

    ecGPIO.h

void sevensegment_init(void); 
void sevensegment_decoder(uint8_t  num);
  1. First, check if every number, 0 to 9, can be displayed properly

  2. Then, create a code to display the number from 0 to 9 with each button press. After the number '9', it should start from '0' again.

Configuration

Fill in the table

Code

Sample Code.

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

#define LED_PIN 	5
#define BUTTON_PIN 13

void setup(void);
	
int main(void) { 
	// Initialiization --------------------------------------------------------
	setup();
	unsigned int cnt = 0;
	
	// Inifinite Loop ----------------------------------------------------------
	while(1){
		sevensegment_decode(cnt % 10);
		if(GPIO_read(GPIOC, BUTTON_PIN) == 0) cnt++; 
		if (cnt > 9) cnt = 0;
		for(int i = 0; i < 500000;i++){}
	}
}


// Initialiization 
void setup(void)
{
	RCC_HSI_init();	
	GPIO_init(GPIOC, BUTTON_PIN, INPUT);  // calls RCC_GPIOC_enable()
	sevensegment_init();
}

Your code goes here: ADD Code LINK such as github

Explain your source code with necessary comments.

// YOUR MAIN CODE ONLY
// YOUR CODE

Results

Experiment images and results

Show experiment images /results

Add demo video link

Problem 3: Using both 7-Segment Decoder and 7-segment display

Procedure

Now, use the decoder chip (74LS47). Connect it to the bread board.

Then, you need only 4 Digital out pins of MCU to display from 0 to 9.

Connection Diagram

Circuit diagram

You need to include the circuit diagram

  1. Work on the same project and code.

  • i.e. : project “LAB_GPIO_7segment”. and source file named as “LAB_GPIO_7segment.c”

void sevensegment_display_init(void); 
void sevensegment_display(uint8_t  num);
  1. First, check if every number, 0 to 9, can be displayed properly

  2. Then, create a code to display the number from 0 to 9 with each button press. After the number '9', it should start from '0' again.

Configuration

Reference

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

Troubleshooting

(Option) You can write Troubleshooting section

Last updated