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

20 thoughts on “SEVEN SEGMENT DISPLAY COUNTER USING PIC16F877A MICROCONTROLLER”

  1. SALLAM, PLS I NEED YOUR HELP I AM A COMPUTER SCIENCE STUDENT AND NEED ELECTRICAL PROJECT RELATED TO COMPUTER, OR ANY ELECTRICAL BASE PROJECT THAT AS TO DO WITH PROGRAMMING( PLS WITH THE COMPLETE CODE) THANKS

  2. Sir thanks for the great project sir actually i want to show this temperature result also on 16*2 display on the same time. Sir as you see that the port d is not used in this schematic diagram so please tell ,me how can i show the same temperature on both display and 7 segment on the same time.

  3. Hello billal..how does the delay function works in for loop..how yo get the vale 255 and 50 in the for loop for delay…

  4. hi bilal, i need to design a counter from 1-30 using two seven segment display using push button.i’m using PIC16F877A with Hi-Tech Compiler

Leave a Comment

shares