7 Segment Display

Seven Segment display are of two types

  1. Common Cathode
  2. Common Anode

Common Cathode:- In the common cathode type 7 segment displays, the –Ve terminal of all LEDs is connected to the COM pin. A 7 segment can be lightening up when +5v is given to the respective LED segment and ground connected to common.

Common Anode:- In the common cathode type 7 segment the +5v terminal of all the LEDs is commonly connected to the common port of the 7 segment. A seven segment can be lighten up when the COM port is connected to the +5v battery supply and ground is given to respective LED segment.

In this section we only discuss about user-defined function and switch statement.

C functions can be classified into two categories, namely, library functions and user-defined function. In order to make use of a user defined function, we need to establish three elements that are related to functions.

  1. Function definition
  2. Function call
  3. Function declaration

The format is

                        Function declaration
                        int main(void)
                        {
                         function call;
                        return 0;
                           }
                          Function definition

Note that function definition does not terminate with a semicolon.

Function definition (Formation)

function_type function_name(parameter list)
      {
       local variable declarations;
      executable ststement;
      —————————–
       return (Value)
     }

Here function name may be any name you give, data type may be int, or float, or char…etc. and parameter list may be (int m,n,float name,char lift);

Function declaration (Formation)

            function_type function_name(parameter list);

Function call (Formation)

            data_type= function_name(return_data_type);

Switch:-  It is a conditional expression that check the resultant value compare with a set of value and give an appropriate result corresponding to that value.

            Formation

          switch(expression)
                        {
                          case value-1:block 1;
                          break;
                          case value-2:block 2;
                          break;
                          case value-3:block 3;
                         break;
                         —————–
                         default:
                         default –block;
                         break;
                       }
                      statement –x;

Let make our own seven segment display header file with the help of this switch function. Let choose a cathode LED and our user defined function should be an integer argument and integer return function. So that in user-defined function will be

            int seven_segment(int value);                           ——-> Function declaration
            int digit=seven_segment(digit you desire);   ——-> Function Call
            int seven_segment(int value)                           ——-> Function Definition

 

Let separate the total user-defined function to three part. Make two new file and save as in the same folder where the main.c file saved and named it -> segment.c and segment.h. Our main goal is to separate the user-defined function and each part should include

            main.c file                —————–> Function call
            segment.c file          —————–> Function definition
            segment.h file          —————–> Function declaration

Here interesting thing that in segment.c  file we include segment.h file because we store function declaration in segment.h  file.

Now our main.c file is very simple. In this program we display 0-9 in 7 segment and the process repeat.

In AVR IDE platform to integrate all three file we need some change in WinAVR and Microchip Stdio. In WinAVR just change in MFile  ->

One interesting about that in WinAVR the F_CPU=8MHz and Microchip Studio F_CPU=1MHz by default.