Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

7 - Segment Display with PIC microcontroller

7 - Segment Display with PIC microcontroller





Fig: Seven segment display

In this tutorial i will discuss how to interface a seven segment display with PIC Microcontroller. You can also check out my previous post on Interfacing PIC Microcontroller with Relay.

A 7 Segment LED Display is a electronic device that contains an array of 8 individual LEDs. Each of the 8 segments that make up the display can be either be on the ON state or the OFF state. Depending on which LEDs are lit determines the character which is displayed on the LED. The LED can be made to show  numerical digits from 0-9 and some characters. The versatility of a 7 segment display lies in the fact that it can be a numerical value indicator. LED displays are used in all types of products, including alarm clocks, scoreboards, and all other signs showing character outputs.

Types of 7 - Segment Displays:

Based on wiring and connection, there are two types of 7 - Segment display which are:

  • Common - Cathode Display
  • Common - Anode  Display
LEDs have two terminals one is referred to as the Anode and the other is the Cathode. The Anode is the terminal that is usually connected to the positive voltage terminal  while the Cathode is connected to the negative terminal of the supply. When the Cathodes of the array of eight (8) LEDs are connected together, such is referred to as a Common -Cathode Display but when the Anode terminals are all connected together we have the Common Anode Display.

Fig a: Common - Cathode Display



Fig b: Common - Anode Display



In this tutorial we will be discussing the Common Cathode Display.
The Image below shows a look - up table for our segment display to guide us in writing our code. Every hex value represents a pattern for every digit. Every LED segment is represented with an alphabet from a to g and so if we want to display the number "7" we will turn ON segments a, b, and c by sending a 1 to these segments i.e. for "x g f e d c b a" we have " x 0 0 0 0 1 1 1" respectively  which is equivalent to 0x07 in hexadecimal and must reflect in our code  ( "x" is the eight unused bit ) . A binary to  hexadecimal calculator will help here .The image below gives a better description.



Our Aim in this project is to display 0 to 9 on the segment display over and over again with a second delay.



CODE:

/*
    Name:     7 - Segment display with PIC MCU
    Author   : Daniel Oluwole
                       (C) 2020 Danitronics
                       danieloluwole51@gmail.com, danieloluwole51@yahoo.com
    Mobile:    +234 8188508765.
 
    Notes    :   Our aim is to display numbers 0 -9 on a 7 - segment display
  
*/

 //DECLARE VARIABLES AND ARRAYS
     unsigned char segment[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
     unsigned char i;
      
void main()
 {
         TRISD = 0;// Set PORTD as Output


       while(1)
       {
            for(i = 0; i< 10; i++)
              {
                  PORTD = segment[i];     // go through array
                  delay_ms(1000);        // 1 sec delay
             }
       }
}

Next Post

Post a Comment

0 Comments

Ad Code

Responsive Advertisement