IMG_4

There are 2 types of  seven segment displays – CC (Common Cathode) & CA (Common Anode).In this post we shall see how to interface CA display with PIC 16F877A.

   The display , as the name indicates , is made up of seven segments of LED.Each one of the seven LEDs in the display is given a positional segment with one of its connection pins being brought out of the  plastic package. These  LED pins are labeled from “ a “ to “ g“ representing each individual LED. The other LED pins are connected together and wired to form a common pin.

In case of CA display +5v is tied to Common pin.

The  common pin is generally used to identify which type of 7-segment display it is. As each LED has two connecting pins, one called the “Anode” and the other called the “Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode (CC) and Common Anode(CA).

Common anode displays are more popular as many logic circuits can sink more current than they can source.

    

Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased. For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Then the various digits from 0 through 9 can be displayed using a 7-segment display as shown.

For a Common Anode Display , the COMMON pin should be connected to HIGH & the corresponding DIGIT segments should be made LOW.Each LED segment can tolerate up to only 1.5v DC .

As the HIGH level from PIC is around 5V , a current limiting resistor of 470 ohms must be used at the common pin.

For e.g., to display digit 1 , the segments b & c should be made LOW while the COM pin is made HIGH.

To display digit 2 , the segments a,b,d,e & g are made LOW while making the COM pin HIGH.

Then for a 7-segment display, we can produce a truth table giving the individual segments that need to be illuminated in order to produce the required decimal digit from 0 through 9 as shown below.

7seg_1

CONNECTIONS :  All segment pins are Enabled by LOW (0)

RD2  –>  DIGIT 1  Common Anode pin made HIGH to display a Digit.

RB7—>  D0               RB0 –> D7    

RB3 –> D4                RB6 –> D1 

RB2 –> D5                RB5 –> D2

RB1 –> D6               RB4 –> D3

 

The Demo board I’m using has 4 PNP Transistors which is connected to Digit1,Digit2,Digit3 & Digit4.When a LOW is applied to Base of transistor,it conducts and apply HIGH to the Common pin of Display.

seg1

 

Open a New project in MPLABX & follow the initial STEPS as described in previous post.

The code to drive a single Display is given below.CONFIG statements to be replaced by the code generated for configuration bits as described in earlier post.

——————————————————————

#define _XTAL_FREQ 16000000
#include <xc.h>

// CONFIG statements here….

unsigned char hexValue[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};
int i=0;

int main()
{
TRISB=0x00;  // Port B pins all OUTPUTs
TRISD2=0; // RD2 as OUTPUT
RD2=1;    // Disable display 1

while(1)
  {
    RD2=0;   // Enable Display 1
    for( i=0; i<10; i++)
    {
        PORTB= hexValue[i];
        __delay_ms(1000);
    }
  }
}

———————————————————————–

PNP transistors are used to drive the Enable common pin of CA displays. A LOW at the base of transistor will make it conduct & provide HIGH at the common Anode pin of Display.

According to the data pin (D0 to D7) levels , digits 0 to 9 are displayed. A LOW at data pin will make the segment GLOW & a HIGH will make it OFF.

7seg

The HEX values for the Digit to be displayed are achieved as shown in the Table above.These values are stored in an Array variable unsigned char hexValue , which is declared to store 10 values.

Port B is defined as Output by TRISB = 0x00;

Port pin D2 is declared as Output , which is used to enable the common pin of display.

Initially RD2 = 1 which makes the PNP transistor OFF & the display is disabled.

Under While loop , the  RD2 is made 0 to enable the Display & the HEX value data is loaded one by one at an interval of 1 sec.

You get display running from 0 to 9 at 1 sec interval repeatedly.