Atmega128 and a 7 segment display

In this example we will show you how to connect a 7 segment display to our Atmega128. You can think of a 7 segment display as 7 individual LEDs in a configuration like the picture below.

Image 1 shows the layout and image 2 shows how the segments are arranged

7 seg Blank

So by lighting certain segments you can display numbers, so for example to display the number 1 you would light segments B and C. Here are more examples

7 segment

In this example we connect a HDSP-C3Y3 common anode display to our ATmega16, you can see the connections in the schematic below. We basically connect up segment A to PD0, segment B to PD1 and so on.

Schematic

atmega128 and 7 segment

Code

The code was written in mikroC pro for AVR

 

[c]

int main(void)
{
    DDRD = 0xFF;    // Configure port D as output
    while(1)
    {
        
    PORTD = 0xC0;        // Display Number 0
    delay_ms(1000);        // Wait for 1s
    PORTD = 0xF9;        // Display Number 1
    delay_ms(1000);        // Wait for 1s
    PORTD = 0xA4;        // Display Number 2
    delay_ms(1000);        // Wait for 1s
    PORTD = 0xB0;        // Display Number 3
    delay_ms(1000);        // Wait for 1s
    PORTD = 0x99;        // Display Letter 4
    delay_ms(1000);        // Wait for 1s
    PORTD = 0x92;        // Display Letter 5
    delay_ms(1000);        // Wait for 1s
    PORTD = 0x82;        // Display Letter 6
    delay_ms(1000);        // Wait for 1s
    PORTD = 0xF8;        // Display Letter 7
    delay_ms(1000);        // Wait for 1s
        PORTD = 0x80;        // Display Letter 8
    delay_ms(1000);        // Wait for 1s
    PORTD = 0x90;        // Display Letter 9
    delay_ms(1000);        // Wait for 1s
    }
}

[/c]

 

Links

 

wholesale 50pcs/lot 1bit Common Cathode/Common Anode Digital Tube 0.56″ 0.56in Red LED Digit 7 Segment

20 PCS LD-3161BG 1 Digit 0.36″ GREEN 7 SEGMENT LED DISPLAY COMMON ANODE

Related posts

ATmega128 and MAX7219 8 x 8 matrix

Atmega16 and MAX7219 seven segment display

Attiny2313 PWM flashing LED example