Embedded Systems Tutorial

AVR Microcontroller

8051 Microcontroller

8085 Microprocessor

8086 Microprocessor

8255 Microprocessor

Embedded Systems Practice

AVR | Seven Segments LCD Display

In this tutorial, we will learn what seven segments are and after that we will create a short program to display numbers in seven segments. By Suryaveer Singh Last updated : May 12, 2023

AVR | Seven Segments LCD Display

Here, I will give you a brief knowledge about seven segments, about what a Seven Segment is and how we will use it to display numbers.

So, a Seven Segment is a display device used to display decimal numerals. It is most commonly used in display clocks, electronic meter etc. It has a total of seven segments which we can use to display Arabic Numerals.

Seven Segments

Image source: 7 Segment Display (Wiki)

Here A, B, C, D, E, F, G, H are the segments that we would use to display a number. Here DP stands for Dot Pin.

The segment which we want to glow is given by input 1.

Seven Segments 1

This was all the little thing that you should know about a 7-segmentNowwe will create a simple program using two seven segments to display numbers till 99.

C Program to Print Numbers on Seven Segments LCD Display


int main(void)
	int i,j;


	return 0;	


  • Here, we have taken two variable i,j which are integers. We have taken it because we have to run the loop for the numbers that will appear on the 7-segment.
  • Here, DDRC=0xFF represent the terminals in which our first 7-segment is connected and DDRD=0xFF represents the terminals in which our second, 7-segment is connected.
  • Inside the char seg[], it shows the hexadecimal codes of all the number from zero to nine (more explained in the table above).
  • Inside the while loop, we have written two for conditions such that when the segment connected to PORTD completes its loop of showing numbers till 9, then the segment connected to PORTC shows 1 for the first loop then 2 for the second loop and so on.
  • Basic C is required here to understand these nested for loop.
  • Both, the variables are used for their respective seven segments.
  • A delay of 400 ms is provided to ensure proper visibility of numbers changing.


Seven Segment Simulation

Simulation Explanation

  • Devices Required:
    • ATmega16
    • One ground Terminal
    • Two 7SEG-COM-CAT-GRN of any colour that you want
  • Connect the devices as shown above.
  • Connect the first 7seg to the PORTC and another 7seg to PORTD as shown.
  • Connect the ground terminal as shown.
  • Double click on the Atmega16 and place the HEX file through the program that you created above.
  • Click on the play button and your simulation will start and both the segments will run like a timer runs.

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.