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.
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.
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.
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: 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.