Kamis, 16 Agustus 2012

In this tutorial we are going to explain how to interface 7 segment display to PIC 16f877a with just two pins !!!!  as shown in the following figure :


As you know that 7 segment requires 7 pins to be connected to PIC and if you use display driver such as 7447 IC it will be reduced to only four pins but if you added a decade counter ( a counter that counts from 0 to 9 ) the number of pins will be reduced to two pins only the connection is shown in the following figure :

 
Now it's very simple assume you want display number 5 on the 7 segment , you only have to send 5 pulses to the counter on the clk pin (in this example we use 7493 decade counter) and the output of the counter will be " 0101 " which is decoded by 7447 IC into it's 7 segment code and displayed it's so simple ...

To send for example 5 pulses to the counter set the pin high >> wait for small time  >> clear the pin >> wait for small time and repeat this sequence for 5 times .
Note : you have to reset the counter after every display so that the counter starts from the beginning and here is a sample of the code to display number 5 :
////////////////////////////////////////////////////////////////
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<5;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
///////////////////////////////////////////////////////////////
note that the delay is very small so that you can't notice the counter counts from 0 to 5 on the 7 segment and only see the digit 5.

Here is the complete function :
void display(char w)
{
if(w==0)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4); // reset timer
}

if(w==1)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);// reset timer
output_high(pin_b0);delay_us(50);output_low(pin_b0);// send digital pulse

}
if(w==2)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<2;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==3)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<3;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==4)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<4;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==5)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<5;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==6)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<6;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==7)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<7;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==8)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<8;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}

if(w==9)
{
output_high(pin_b4);delay_us(50);output_low(pin_b4);
for(i=0;i<9;i++)
{
output_high(pin_b0);delay_us(50);output_low(pin_b0);delay_us(50);
}
}
}

Download the code and simulation HERE
Download this tutorial in PDF HERE

0 komentar:

Posting Komentar