Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Connecting a 4x3 keypad to PIC16F877A

Status
Not open for further replies.

ah_loon

Newbie level 6
Joined
Aug 27, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,433
Hi,
I have a 4x3 keypad that i would like to connect to a PIC16F877A. I understand that i have to use some pullup resistors connecting at the rows. I have seen different versions in the forum as to how to connect.
I am connecting to Port C0-C6 of the PIC. I had already use 10kohms resistor connecting to the rows then directly to the PIC.
Is this correct?
 

Attachments

  • Keypad.jpg
    Keypad.jpg
    195 KB · Views: 102

It is better to use PORTB of PIC16F877A for the purpose because you can utilize the interrupt on change capability of the PORTB . Also, you can activate the internal pull up s....
 
The MCD2 DemoBoard2 (Pic16.com) I have has a key matrix on it.... As a start there is code comes with it for this function, and full schematics available.. Easily downloadable it might be a reasonable start for you buddy..

Use PORTB if it is spare, but you only need 4 pullups (1kish) so don't worry about sticking to PORTB if you need other functions of it (SSP/serial/etc). WPUB (or nRBPU) is the pullup control (0=On) if you use PORTB, but I always try and save it if I can. You can make your code call functions in a "psuedo" interrupt way if you want notification of key-change if you needed it to....

Kind regards
NEAL

Worth a look,
NEAL
 

Hi guys, Thanks for all the information and help.

After going through the links, i found that the pull up resistors are connected to the columns instead. I am getting confused on this.
 

Try this lesson with free C code and video, Keypad Lesson.
Hi shahrul,

Thanks for the useful guide. I managed to display the numbers keyin on the lcd.

Now i have a problem. I need to compare the keyin values against the readings from a sensor. I am unable to display the keyin numbers.

Please do help me on this.
 

Hi shahrul,

Thanks for the useful guide. I managed to display the numbers keyin on the lcd.

Now i have a problem. I need to compare the keyin values against the readings from a sensor. I am unable to display the keyin numbers.

Please do help me on this.
If you can't display keypad values, maybe you are problem on LCD code.
 

If you can't display keypad values, maybe you are problem on LCD code.
hi shahrul,

i am not sure where went wrong. maybe is the codes. could you help me on this?

as follow is the portion.
while(1)
{ //keypad scanning
clearrow1(); //Clear 1st output pin and set the others
scancolumn1(); //scan column 1-4
clearrow2(); //Clear 2nd output pin and set the others
scancolumn2(); //scan column
clearrow3(); //Clear 3rd output pin and set the others
scancolumn3(); //scan column
clearrow4(); //Clear 4th output pin and set the others
scancolumn4(); //scan column

if(num_count==2)
{

while(1)
{
//lcd_clr();
lcd_goto(0); //cursor start from beginning

//display character on LCD
send_char(' ');
send_char('S');
send_char('P');
send_char('E');
send_char('C');
send_char('.');
send_char('.');
send_char('=');

lcd_goto(20); //cursor go to 2nd line of the LCD

//display character on LCD
send_char(' ');
send_char('M');
send_char('E');
send_char('A');
send_char('S');
send_char('U');
send_char('R');
send_char('E');
send_char('D');
send_char('=');


while(1) //infinity loop
{

//tempA=temp;
//tempA=440;
lcd_goto(9);
keyin[2]=tempA;
dis_num(keyin[2]);
//dis_num((unsigned long)round(tempA));
send_char(0b11011111); //to set in degree celcius
send_char('C');
send_char(' ');
send_char(' ');
 

I don't like checking someone code. But, I see why so many while(1). If the program doing while(1), it will not do the others while(1)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top