7 Seg Display Interfacing with AVR

Embedded Systems With AVR Tutorial Series

Time to Control 7Segments using AVR

 

Contributed By:- Mitanshu Kumar

BEST_AVR_COACHING_IN_BHOPAL.jpg

-------------------------------------------------------

Seven Segment Display

Seven Segment Display is a combination of 7 rectangular LEDs (hence its name) arranged in such a germane way to display all the numeric digits and as well as few Alphabets that is a best alternative to the more complex dot matrix displays.

 

Each of the seven LEDs is called segment because when illuminated, the segment forms part of a numerical digit (both Decimal and Hex) to be displayed.  There is also an additional 8th LED (called Decimal Point or DP) available to display some decimal values if needed.

 

 BEST_AVR_TRAINING_IN_BHOPAL_1.jpg                                                                    BEST_AVR_TRAINING_IN_BHOPAL2.png

  Fig. Seven-Segment Display

 

The nomenclature of the pins of 7 segment LEDs are shown in figure.

The one side of all the individual LEDs (Anode side or Cathode side, depends on which type of 7 segment display it is.) are connected together to common (COM) pin.

 

  • COM= GND = 0V = logic’0’ (For 7 Segment Common Cathode type)
  • COM= Vcc = 5V = logic’1’   (For 7 Segment Common Anode type)

 

The displays common pin is generally used to identify which type of 7-segment display it is. As each LED has two connecting pins, one called the ‘Anode’ and the other called the ‘Cathode’, there are therefore two types of LED 7-segment display called: Common Cathode (CC) and Common Anode (CA).

 

Common Cathode configuration:

In Common Cathode configuration, all the cathodes of the 7-segments connected together to Ground/LOW or ‘logic 0’ and anodes of individual segments are given HIGH (logic ‘1’) to illuminate or LOW (logic ‘0’) to turn it off as per requirement.

Common Anode configuration:

Similarly, In Common Anode configuration, , all the anodes of the 7-segments connected together to HIGH(5V) or ‘logic 1’ and cathodes of individual segments are given LOW (logic ‘0’) to illuminate or HIGH (logic ‘!’) to turn it off as per requirement.

 

Seven-segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.

We can display numeric digits from 0 to 9 and Alphabets (A, b, C, d, E, F, H, I and U only).

 

Hexadecimal encodings for displaying the digits 0 to F

Digit

Display

Hex Value

DP

g

f

e

d

c

b

a

0

0

0×3F

0

0

1

1

1

1

1

1

1

1

0×06

0

0

0

0

0

1

1

0

2

2

0×5B

0

1

0

1

1

0

1

1

3

3

0×4F

0

1

0

0

1

1

1

1

4

4

0×66

0

1

1

0

0

1

1

0

0

5

0×6D

0

1

1

0

1

1

0

1

6

6

0×7D

0

1

1

1

1

1

0

1

7

7

0×07

0

0

0

0

0

1

1

1

8

8

0×7F

0

1

1

1

1

1

1

1

9

9

0×6F

0

1

1

0

1

1

1

1

A

A

0×77

0

1

1

1

0

1

1

1

b

b

0×7C

0

0

0

1

1

1

1

1

C

C

0×39

0

1

0

0

1

1

1

0

d

d

0×5E

0

0

1

1

1

1

0

1

E

E

0×79

0

1

0

0

1

1

1

1

F

F

0×71

0

1

0

0

0

1

1

1

 

FEW EXAMPLES :-

Things required:

Name

Proteus code

ATmega16 microcontroller

Atmega16

LEDs

Led active

7 segment Display

7 seg cc

wires

-

 

 

Task1

Write a programme to display numeric digits from 0 to 9 in increasing order and vice versa in 7-segment LED display.

 

#define F_CPU 1000000UL

#include

#include

 

void main()

{

DDRD=0XFF;

char mynum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};       

//Defining ARRAY values

int i=0,j=0;

while(1)

{

for(i=0;i<10;i++)    //To run a function for 9 times in increasing value.

       {

              PORTD= mynum[i];

//taking values from ARRAY function to illuminate PortD's LED.      

              _delay_ms(500);//delay

       }

              PORTD= 0x00;

              _delay_ms(500);

//turning off PORTD to make a visual gap between execution of 0 to 9 and 9 to 0.

      

for(j=9;j>=0;j--)   

       {

              PORTD= mynum[j];

              _delay_ms(500);

}

              PORTD= 0x00;

              _delay_ms(500);

       }     

}

 

 

Task2

Write a programme to display numeric digits from 00 to 99 in increasing order and vice versa in 7-segment LED display.

#define F_CPU 1000000UL

#include

#include

 

void main()

{

DDRD=DDRC=0XFF;

char mynum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

int i,j=0;

while(1)

{

for(i=0;i<10;i++)

       {

              PORTC= mynum[i];

       for(j=0;j<10;j++)

       {

              PORTD= mynum[j];

              _delay_ms(300);

       }

       }

       PORTD=PORTC=0x00;

       _delay_ms(300);

                    

       for(i=9;i>=0;i--)

       {

              PORTC= mynum[i];

       for(j=9;j>=0;j--)

       {

              PORTD= mynum[j];

              _delay_ms(300);

       }

       }

       PORTD=PORTC=0x00;

       _delay_ms(300);

       }

       }

 

 

NOTE:-

If we want to change any PIN’s value of any PORT without disturbing other PIN’s values, then using this we can easily do that;

  • PORTX|=  (1<<PXn);
  • PORTX&= ~(1<<PXn);

 

CLICK HERE TO VIEW / DOWNLOAD AVR TRAINING SYLLABUS

 

CLICK HERE TO REGISTER NOW FOR AVR TRAINING..

 

Top