SEVEN SEGMENT DISPLAY COUNTER USING PIC16F877A MICROCONTROLLER




SEVEN SEGMENT DISPLAY COUNTER USING PIC MICROCONTROLLER,In this tutorial, you will learn what is seven segment display? What are applications of seven segment display?  How to interface a 7-segment display with PIC microcontroller PIC16F877A. We have used two 7-segment displays in this project to display a 0-99 counter. Let’s move forward by defining seven segment display. Code for this project is written using Mikro C for pic.




What is seven Segment Display?

Seven segment display is regarded as the most basic and simplest electronics display device. Simplest, because its working is easy to understand and its interface with the controller is quite straight-forward. Seven segments, as the name suggests, consist of seven LEDs organized in a specific pattern. Each LED is known as a segment and it is assigned a name from ‘a’ to ‘g’. Another additional 8th LED named as ‘dp’ is also present sometimes in a 7-segment display which is used to illuminate a dot or a decimal point.

A common pin is also associated with the 7-segment, which is used to identify the type of 7-segment display; whether it is common anode or common cathode. In common anode display, the positive pins of all the LEDs are tied together to form the common pin which needs to be provided a ‘HIGH’ signal. In common cathode display, all the cathode connections of the LEDs are tied together which forms the common pin that needs to be grounded.

SEVEN SEGMENT DISPLAY COUNTER USING PIC MICROCONTROLLER

SEVEN SEGMENT DISPLAY COUNTER USING PIC MICROCONTROLLER




CIRCUIT DIAGRAM FOR 7-SEGMENT DISPLAY INTERFACING WITH PIC 16F877A :

Seven segment display interfacing with pic16f877Aa microcontroller

Seven segment display interfacing with pic16f877Aa microcontroller

To display a counter of 0-99, two 7-segments are interfaced with PIC16F877A in this project, one for tens and the other for ones. The seven pins of each segment are connected to the seven pins of PORTB and PORTC, starting from LSB, via a resistor of 560R. Each pin represents an alphabet which switches the corresponding LED bar on and off with respect to the code. As per the connections shown in the circuit diagram, alphabet ‘a’ of the tens segment is connected to RC0 pin of the MCU, ‘b’ is connected to RC1 pin and so on. Same pattern is followed for the ones segment connected to PORTB. We have chosen both 7-segments with a common anode display. As such, the common pin of both 7-segments are connected to Vcc.

C-CODE FOR TWO 7-SEGMENT COUNTER INTERFACED WITH PIC16F877A :

Write the following code in the Code Editor Window of mikroC Compiler:

  1. /* 7 Segment display counter 0-99 interfacing with PIC1F877A*/
  2. void delay();
  3. void main()
  4. {
  5. unsigned char i,j,ar[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
  6. TRISB=TRISC=0x00;
  7. do
  8. {
  9. for(i=0;i<10;i++)
  10. {
  11. PORTC=ar[i]; // for tens
  12. for(j=0;j<10;j++)
  13. {
  14. PORTB=ar[j];    // for ones
  15. delay();
  16. }
  17. }
  18. }
  19. while (1);
  20. }
  21. void delay() //delay routine
  22. {
  23. unsigned char i,j;
  24. for(i=0;i<255;i++)
  25. for(j=0;j<50;j++);
  26. }

A delay function has been declared at the beginning of the code which is used to slow done the abrupt changes in the counter of ones segment, which is then effective for tens segment as well. Apart from char ‘i’ and ‘j’, an array ‘ar’ has also been declared. The values defined within the brackets corresponds to digits from 0 to 9. But these are not the hex values of the actual digits 0-9. These are the values that needs to be generated on the port pins for the corresponding digit to appear on the 7-segment. For example, to display ‘5’ on the 7-segment, the LEDs that should be illuminated are ‘a’, ‘c’, ‘d’, ‘f’ and ‘g’. So, the port pins should give the output 0b10010010 to the 7-segment, which is equivalent in hex to 0x92.

The inner ‘for’ loop displays the ones counter and the outer ‘for’ loop is for the tens counter. The program is executed infinite times until aborted.

APPLICATION

Seven segment displays are vastly used in our daily life equipment, be it the digital clocks at our homes or the electronic meters at our work stations. It can be used as a countdown or a timer when playing games or in competitions etc. The basic calculators also uses a 7-segment display.To download code and circuit diagram of seven segment display interfacing check following link.

Seven segment display



18 Comments

  1. mark francis July 14, 2015
    • BILAL Malik July 14, 2015
  2. mark francis July 14, 2015
    • BILAL Malik July 14, 2015
  3. mark francis July 14, 2015
    • BILAL Malik July 15, 2015
  4. MOHAMMED ISAH N. July 16, 2015
  5. zeka January 2, 2016
  6. Amen Degago April 6, 2016
  7. M Abdullah Khalid July 20, 2016
    • M Abdullah Khalid July 20, 2016
  8. Adrian DS August 2, 2016
  9. Ebeso-Tech September 19, 2016
    • BILAL Malik September 19, 2016
  10. aliu December 20, 2016
  11. Jamiu March 12, 2017
  12. Jhamiu March 12, 2017
  13. waris kn June 21, 2017

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,376 other subscribers