Interfacing 7 segment display with pic16f877 microcontroller

This post will describe that how easily we can do Interfacing 7 segment display with pic16f877 microcontroller. 7 segment displayInterfacing 7 segment display with pic16f877 microcontroller is a basically array of 7 leds with some proper arrangement. From this fig it can be seen that 7 leds arranged with an array starting from a, b, c, d, e, f, g, and h. So from every LED we get one pin and another Pin for providing active high voltage to every pin. Now whatever LEDs we have to glow we have to send active low on corresponding LED pin.

7 segment connection

Now let take an example to clear all, suppose we have to display 5 at 7segment display then what should be our bit pattern? For display5 we have to glow a, f, g, c and d LEDs and off rest. As I discuss earlier, whatever LEDs we have to glow we have to send active low on corresponding LED pin because all others pin of LED got active high signal. So in our case we have to send bit pattern like

Interfacing 7 segment display with pic16f877 microcontroller

Project description:

Now in my project to make you easily understandable the process, Interfacing 7 segment display with pic16f877 microcontroller, I made a counter which will count 0-5 and repeat. For that I used port B of microcontroller pic16f877 as an out port send different bit pattern for different digit to display at 7 segment display. So to display 0-5 we have to create exact bit pattern for every digit which are given bellow .

For 0 = 01000000.
For 1 = 01111001.
For 2 = 00100100.
For 3 = 00110000.
For 4 = 00011001.
For 5 = 00010010.


Here I give you the Proteus simulation circuit and see how I connect the 7 segment display pin with port B of microcontroller pic16f877.

Interfacing 7 segment display with pic16f877 microcontroller

In bellow you will find complete embedded C code on PIC Micro C Pro. From this code you will understand how i send particular bit pattern for individual digit.

Embedded C Code
// Name : Interfacing 7 segment Display with PIC Microcontroller
// Author : Subham Dutta
// Date : 21-06-14
// Website : www.nbcafe.in
void main() {
int kp=0,i;
trisb=0;
while(1){
for (i=0;i<=5;i++)
{if (i==0)
{
kp= 0b01000000;
}
if (i==1)
{
kp= 0b01111001;
}
if (i==2)
{
kp= 0b00100100;
}
if (i==3)
{
kp= 0b00110000;
}
if (i==4)
{
kp= 0b00011001;
}
if (i==5)
{
kp= 0b00010010;
}portb=kp;
delay_ms(200);
kp++;
}
kp=0;
}
}