AVR Tutorials
The Best AVR Microcontroller Tutorials on the Web

Interfacing Seven-Segment Display with the AVR Microcontroller

Introduction to the Seven Segment Display


This AVR tutorial will discuss interfacing a Seven Segment Display with the AVR 8-bits microcontrollers . A Seven Segment Display is just seven LEDs arranged and packaged in a configuration shown in Fig 1 and it is therefore recommended to complete the tutorial on Interfacing LEDs with the AVR Microcontrollers before going through this tutorial.


The seven LEDs in the seven segment display are labelled with the letters A, B, C, D, E. F and G as indicated in Fig 2 below. Some seven segment display may include 1 or 2 additional LEDs which are used as decimal point(s).

Seven

Seven Segment Displays are mainly used to display numerical digits. The figure below shows which LEDs to turn ON to display the digits 1, 2, 3, 4, 5 and 6. Other numbers can be displayed by turning ON the appropriate LEDs.

Seven Segment Numbers Display

A Seven Segment Display can also be used to display certain letters of the alphabet. The figure below gives the LEDs to turn ON to display A, F, H, L and P.

Seven Segment Letter Display


Interfacing a Seven Segment Display with a Microcontroller

The figure below shows a Seven Segment Display (LDS-C305RI) connected to an ATMega16 microcontroller. Since the seven segment display consists of LEDs it can be connected directly to the ATMega16 or other AVR microcontrollers as shown in the schematic below and as discussed in the Interfacing LEDs with the AVR Microcontrollers tutorial.

Seven Segment Display ATMega16 Microcntroller Interfacing

Important Note: In order for the circuit to operate as describe the internal oscillator of the microcontroller must be program to run at 4MHz.

The code that follows if downloaded to the microcontroller will display continuously the sequence 1, 2, 3, 4, A, C, E, F. Note that other microcontrollers such as the ATMega8515 can be used to replace the ATMega16 but the connections would have to be adjusted. For connection information for this seven segment display please see the LDS-C305RI DataSheet. The video at the end of this page shows the circuit in operation when the code is downloaded to the ATMega16 microcontroller.

/*
 * numbers_letters.c
 * Written in AVR Studio 5
 * Compiler: AVR GNU C Compiler (GCC)
 *
 * Created: 10/06/2011 05:31:57 PM
 * Author: AVR Tutorials
 * Website: www.AVR-Tutorials.com
 */ 
 
#include <avr/io.h>
 
#define F_CPU	4000000UL
#include <util/delay.h>
 
int main(void)
{
	DDRA = 0xFF;	// Configure port B as output
 
    while(1)
    {
        //TODO:: Please write your application code
 
		PORTA = 0b00110000;		// Display Number 1
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b01011011;		// Display Number 2
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b01001111;		// Display Number 3
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b01100110;		// Display Number 4
		_delay_ms(1000);		// Wait for 1s
 
		PORTA = 0b01110111;		// Display Letter A
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b00111001;		// Display Letter C
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b01111001;		// Display Letter E
		_delay_ms(1000);		// Wait for 1s
		PORTA = 0b01110001;		// Display Letter F
		_delay_ms(1000);		// Wait for 1s
 
    }
 
	return 0;
}



Video of the seven segment display in Operation
Below is a video showing the operation of the seven segment display when the above code is downloaded to the ATMega16 microcontroller in the schematic given above. The following AVR projects also utilizes the seven segment display.

1 - ATMega16 AVR Microcontroller Seven Segment Single Digit Digital Dice
2 - ATMega8515 Microcontroller Seven Segment Double Digit Digital Dice
3 - ATMega16 AVR Microcontroller Seven Segment Digital Clock



AVR Tutorials hopes this AVR project on the ATMega16 Single Digit Digital Dice was benificial to you and looks forward to your continued visits for all your AVR microcontroller projects needs.