PIC16F887 877 programming in C Tutorial 2 S S Display Interfacing


Interfacing Seven Segment (c.c) Display

In this tutorial i will show you how to interface S.S display with PIC16F887/877. For this we required 74hc573 latches, 74hc238 decoder, and 74ls48 bcd2dec converter.

Latches are used to enable/disable the S.S, 74hc234 a 3x8 decoder selects the appropriate latch to be enable/disable. 74ls48 just converts the bcd input to respective decimal output to operate S.S properly. 

Now lets write a small program that display the digital manual input at S.S, enter by the user; by using 8-way dip switch.

Code:   
void main() {

     int x,y,i,j;
     trisc=0;
     portc=0;
     trisd=255;      //all bits for input

 ///////////////// comment 4 pic16f877/////////
     ansel=0;
     anselh=0;
    
     c1on_bit=0;
     c2on_bit=0;
////////////////////////////////////////////

     while(1){
       j=0;
       i=3;
       x=portd;

       while(i>0){
          y=x%10;
          y=y|j;
          delay_ms(100);
          portc=y;
          x=x/10;
          i--;
          j=j+16;

     }

  }
}

Now come towards the code; portc is utilized for o/p, and manual i/p is applied at portd, here. As the ports are 8-bit so, maximum i/p would be 255(0-255); we have to display them on three S.S, for this we have to separate the digits of i/p. Modulus '%'  do this job; let say the i/p is 255, then first we have to display 5 then 5 and then 2; to do this we use x%10. Where x is an integer that has the manual i/p. Where modulus operator returns the remainder of integer division, so after this we have 5 stored in y (as 255%10 = 5, remainder is 5).

After getting the digit, it should be display on 3rd S.S; so to select this latch just or '|' y with proper integer, which in this case is 0 (as my 3rd S.S as attached to 0 o/p of latch, 2nd is to 1st and so on). So, after doing this we have 5 in 8-bit and latch 0 is selected. Now display it by assigning it to port.

To display 2nd digit first reduce the i/p by dividing it with 10; 255/10 gives 25, as we are storing this value in an integer; so x is equal to 25, now. J is incremented by 16 because we have to select the first latch (see the diagram for more detail).



In the same fashion, to display the first digit; select proper latch, divide and take modulus and display it, that is it. Here i is used to run this process for three times (means to display all the i/p digit on three S.S).


Schematic:   
For reset circuitry  please refer to first tutorial.
connection diagram

Comments

Popular posts from this blog

Metal Detector Based on the TDA0161

On line Ladder Program Editing for RSLogix 500

Simple 8 Channel DTMF Link Encoder