Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing a 4x3 keypad to PIC16F877A

Status
Not open for further replies.

ah_loon

New Member
Hi,
I want to interface a 4x3 keypad to a PIC16F877A. I am connecting to PORT C0-C6. I understand that we need to use some pullup resistors connecting to the rows.
I connect the rows to 10kohms resistor then to the PIC. Is this correct as i have seen various different connections online.
 
There are no internal pullup's on port C.. so you'll need pullups on each row, the examples on the web are all different as sometimes the reading pins have internal pullps..i.e. portb bits 4 - 7 have internal pullup's on most pic's (also portb usually has interrupt on change, which is handy for a key pad)
 
There are no internal pullup's on port C.. so you'll need pullups on each row, the examples on the web are all different as sometimes the reading pins have internal pullps..i.e. portb bits 4 - 7 have internal pullup's on most pic's (also portb usually has interrupt on change, which is handy for a key pad)
Hi Ian,
I understand Port B have internal pullups. But i already used Port B for other output functions.
I read through some tutorials and found that the pullup resistors are connected to columns instead. I am getting confused on this. Can you help me understand better?
 
You only need pullups on the reading pins.. If you connect a keypad to PORTC (loosing a lot of peripherals) and the rows are 0 through 3 and the columns are 4 through 7
TRISC = 0xF0 (reading the top nibble ) You would put a pullup on pins 4,5,6 & 7 then read PORTC and AND 0xF0 whilst setting 0,1,2 & 3 to 0v in turn, while the rest are 5V.

It really doesn't matter what are rows and what are columns as long as you read one line at a time.
 
You only need pullups on the reading pins.. If you connect a keypad to PORTC (loosing a lot of peripherals) and the rows are 0 through 3 and the columns are 4 through 7
TRISC = 0xF0 (reading the top nibble ) You would put a pullup on pins 4,5,6 & 7 then read PORTC and AND 0xF0 whilst setting 0,1,2 & 3 to 0v in turn, while the rest are 5V.

It really doesn't matter what are rows and what are columns as long as you read one line at a time.

HI Rogers,

Thanks for the help.

I managed to get the keypad up and display the numbers when pressed the respective numbers.

I have a problem now, as i would need to use the keypad to key in 2 digit numbers and then compare the values with the measured readings from a sensor.
I am unable to display the keyin numbers.

Would need your help on this.
 
I have a problem now, as i would need to use the keypad to key in 2 digit numbers and then compare the values with the measured readings from a sensor.
I am unable to display the keyin numbers.
Are you trying to read to keys at the same time or one after the other?
 
Are you trying to read to keys at the same time or one after the other?

hi,
i need to keyin the values first. then compare it with the measured value from a sensor.
it is like keying a spec and the readings will compare.
 
i need to keyin the values first. then compare it with the measured value from a sensor.
it is like keying a spec and the readings will compare.
You will need to store the key numbers in a register and use that to display and compair too.
 
If there are only 2 input values its not really that hard. When you read the first digit, save it in a local variable. When the second digit is read, multiply the first by10 and add the second. you then will have a number 0 - 99 that you can compare
 
If there are only 2 input values its not really that hard. When you read the first digit, save it in a local variable. When the second digit is read, multiply the first by10 and add the second. you then will have a number 0 - 99 that you can compare

Yup. i am done with that portion. I have another question. If i were to use port E of PIC16F877a as output. Do i need to perform any additional codings?
 
Yup. i am done with that portion. I have another question. If i were to use port E of PIC16F877a as output. Do i need to perform any additional codings?

Just set the port for Digital (if needed) and set the Direction Register for Outputs.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top