I am extremely new to dealing with microcontrollers and programming in general.
The picture below is a circuit board using a PIC18F4520 microcontroller.
As of now, I am focused on the 4x4 matrix keypad and how it works but I am completely lost.
Articles online say that you connect the keypad's 8 pins to microcontroller ports but the circuit below only has 7 pins.
-
1\$\begingroup\$ "articles online" might simply not know your specific keypad, so what they write might or might not apply to you. We're the same – we don't know your keypad :) A datasheet, or a model number, might help. Anyways, your schematic shows there's actually 8 keypad pins – those labeled X1-X4 and Y1-Y4! Not quire sure why you think the seven in in blue would be what is connected to the keypad, considering the X1-Y4 connections are labeled with "Keypad 4×4". \$\endgroup\$Marcus Müller– Marcus Müller2021年11月11日 11:20:47 +00:00Commented Nov 11, 2021 at 11:20
-
1\$\begingroup\$ The trick here is probably reading the MC74C922 datasheet, it's actually not that pad, and illustrates the connections quite nicely! \$\endgroup\$Marcus Müller– Marcus Müller2021年11月11日 11:23:00 +00:00Commented Nov 11, 2021 at 11:23
-
\$\begingroup\$ It definitely did, thank you. But I am unsure of the function of the OE and DA pins \$\endgroup\$BeatriceUK– BeatriceUK2021年11月11日 11:52:38 +00:00Commented Nov 11, 2021 at 11:52
-
\$\begingroup\$ Read the data sheet, please. "DA" means "data available" and is explained on the front page. "OE" means "output enable" and controls the output pins. \$\endgroup\$the busybee– the busybee2021年11月11日 14:46:12 +00:00Commented Nov 11, 2021 at 14:46
-
1\$\begingroup\$ The 74C922 has some output pins, and these can be controlled into high impedance or driving. See the data sheet, please. (What is it these times, that nobody reads data sheets, oh dear.) \$\endgroup\$the busybee– the busybee2021年11月12日 13:30:51 +00:00Commented Nov 12, 2021 at 13:30
2 Answers 2
The keypad has eight pins:
There are only seven pins that connect the key pad module to the processor:
The 74C922 is a keypad encoder. It has a four bit output (ABCD) that tells you which of the sixteen keys of the keypad was pressed.
There are four pins for the four bits (ABCD,) an output enable (/OE) and data available (DA - active when a valid keypress is detected.) That's six pins. There's a seventh pin on the connector, but those six are responsible for the keypad.
The "articles online" that you have read assume that you are connection the keypad directly to the microprocessor so that the microprocessor can decode the key presses. The circuit example you give does it differently, though. It has the 74C922 decoding the keypad rather than the microprocessor.
If you would like to see how to decode a 4x4 matrix keypad in software, take a look at the Arduino keypad code. It shows you how to read a 4x4 matrix keypad.
Download the keypad.zip file and unpack it. Look in "Keypad.cpp" to see how it is done.
-
\$\begingroup\$ Oh that makes so much sense. I am still unclear how the position of the button pressed is determined though. Online articles have said that they set the 4 of the pins(rows) to logic'0' and the other 4 pins(columns) to logic '1' but I don't know if the pins are to be set as input/output. I am quite lost \$\endgroup\$BeatriceUK– BeatriceUK2021年11月11日 11:39:01 +00:00Commented Nov 11, 2021 at 11:39
-
\$\begingroup\$ I am using MPLAB software \$\endgroup\$BeatriceUK– BeatriceUK2021年11月11日 11:57:06 +00:00Commented Nov 11, 2021 at 11:57
-
\$\begingroup\$ The principles are the same. You can read the code files with any text editor. \$\endgroup\$JRE– JRE2021年11月11日 11:58:00 +00:00Commented Nov 11, 2021 at 11:58
-
\$\begingroup\$ How exactly does the decoding work? I know the 8 pins are used to determine which key is pressed, but what is the decoded output? \$\endgroup\$BeatriceUK– BeatriceUK2021年11月12日 08:39:08 +00:00Commented Nov 12, 2021 at 8:39
-
\$\begingroup\$ Do you mean the 74C922 or the Arduino code? The 74C922 gives you a 4 bit binary number. That number tells you which key was pressed - you'll have to look at the datasheet to see how the binary number maps to the keypad layout. The Arduino code gives you an array of 16 values. Each member in the array is the state of a key in the keypad. \$\endgroup\$JRE– JRE2021年11月12日 09:08:27 +00:00Commented Nov 12, 2021 at 9:08