Docstoc

PIC 16f877a with 7 segment and keypad.pdf

Document Sample
PIC 16f877a with 7 segment and keypad.pdf Powered By Docstoc
					      PIC 16f877a with Seven-Segment Display and
                                          keypad

 Introduction to seven segments display:

The segments in a 7-segment display are arranged to form a single digit from 0 to F.
We can display a multi-digit number by connecting additional displays. Even though
LCD displays are more comfortable to work with , 7-segment displays are still standard in
the industry. This is due to their temperature robustness and visibility.



Segments are marked with non-capital letters: a, b, c, d, e, f, g and
dp , where dp is the decimal point. The 8 LEDs inside each
display can be arranged with a common cathode or common
anode. With a common cathode display, the common cathode
must be connected to the 0V rail and the LEDs are turned on
with a logic one. Common anode displays must have the
common anode connected to the +5V rail. The segments are
turned on with a logic zero. 7-segment displays come in different
colors, including: red,orange, and green.

 Interfacing :

1- Use a display driver such as the 7447 IC which
convert the BCD number to it's seven segment
code with the PIC (number of pins used is 4 ).

2- Alternatively displays can be driven by a
microcontroller (number of pins used is 7 plus the
decimal point ).

3- Use 7447 with a decade counter (counter
counts from 0 to 9) with the microcontroller (uses
one pin but is not so fast)
 Multiplixing :

if more than one display is required, the method of driving them is called "multiplexing."
The main difference between the two methods is the number of "drive lines." If a single
display is to be driven from a microcontroller, 7 lines will be needed plus one for the
decimal point. For each additional display, only one extra line is needed.

Each display is turned on at a rate above 100 times per second, and it will appear that all
the displays are turned on at the same time. As each display is turned on, the appropriate
information must be delivered to it so that it will give the correct reading. Up to 6
displays can be accessed like this without the brightness of each display being affected.

The following truth table shows the seven segment code for each number from 0 to 9
when we used common anode seven- segment:
 Keypad :

It's an array of switches such as the following figure :




                                                   This is an example of a 3x4 keypad to connect it to
                                                   the microcontroller it needs 12 digital pins !! which
                                                   is a large number .




 Scanning keypad :

To decrease the number of digital pins
required . the keypad is divided into 3
columns and 4 rows only one column is
enabled at a time for example column 1 is
enabled by connecting it to 5v . if button 1is
pressed then A will be high ,if button 4 is
pressed then B will be high and so on then
column 2 is enabled and then column 3 is
enabled and this sequence is repeated very
fast so it appears that it's scanning all the 12
buttons but in fact it scans only four buttons
at a time in this manner we decrease the
number of digital pins to 7.
The next program scans a keypad and the key pressed is dissplayed on the seven segment
display. the microcontroller used is PIC16f877A .

the keypad is connected to PORTC and the 7447 driver is connected to PORTB as shown




#include<16f877a.h>
#fuses xt
#use delay(clock=20000000)

void main()
{
int w=0;
set_tris_b(0x00);
set_tris_c(0x78);
set_tris_d(0x00);
output_high(pin_d0);output_high(pin_d1);

while(1)
{
output_high(pin_c0); output_low(pin_c1); output_low(pin_c2);

if(input(pin_c3))
{
w=3;
while(input(pin_c3));
}
if(input(pin_c4))
{
w=6;
while (input( pin_c4));
}
if(input(pin_c5))
{
w=9;
while(input(pin_c5));
}

If(input(pin_c6))
{
w=0;
while(input(pin_c6));
}

output_low(pin_c0); output_high(pin_c1); output_low(pin_c2);

if(input(pin_c3))
{
w=2;
while(input(pin_c3));
}
if(input(pin_c4))
{
w=5;
while(input(pin_c4 ));
}
If(input(pin_c5))
{
w=8;
while(input(pin_c5));
}

If(input(pin_c6))
{
w=0;
while(input(pin_c6));
}

output_low(pin_c0); output_low(pin_c1); output_high(pin_c2);
if(input(pin_c3))
{
w=1;
while(input(pin_c3));
}
if(input(pin_c4))
{
w=4;
while(input(pin_c4));
}
if(input(pin_c5))
{
w=7;
while(input( pin_c5));
}

If(input(pin_c6))
{
w=0;
while(input(pin_c6));
}

if(w==0)
{
output_low(pin_d0);output_high(pin_d1);
output_b(0);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);
}

if(w==1)
{
output_low(pin_d0);output_high(pin_d1);
output_b(1);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);
}

if(w==2)
{
output_low(pin_d0);output_high(pin_d1);
output_b(2);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);
}
if(w==3)
{
output_low(pin_d0);output_high(pin_d1);
output_b(3);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}

if(w==4)
{
output_low(pin_d0);output_high(pin_d1);
output_b(4);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}

if(w==5)
{
output_low(pin_d0);output_high(pin_d1);
output_b(5);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}

if(w==6)
{
output_low(pin_d0);output_high(pin_d1);
output_b(6);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}

if(w==7)
{
output_low(pin_d0);output_high(pin_d1);
output_b(7);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}



if(w==8)
{
output_low(pin_d0);output_high(pin_d1);
output_b(8);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);}
if(w==9)
{
output_low(pin_d0);output_high(pin_d1);
output_b(9);delay_ms(40);
output_high(pin_d0);output_low(pin_d1);
output_b(0);delay_ms(40);
}
}
}




Download the code and simulation HERE




                  if you liked this tutorial visit us at :

              http://all-about-embedded.blogspot.com/

				
DOCUMENT INFO
Shared By:
Stats:
views:394
posted:8/15/2012
language:English
pages:8
Description: This tutorial explain how to connect keypad to PIC microcontroller and how to multiplex more than one seven segment to pic using bcd to seven segment decoder (7447)