Matrix Keypad Without Use of FlowCode Keypad Component

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Matrix Keypad Without Use of FlowCode Keypad Component

Post by fotios »

I ask your forgiveness if this issue has been already covered with the method described below. I did enough research in this direction on the forum but I could not find anything that helps, so I decided to try it by alone. My aim was to analyze the logic behind the source code of Matrix Keypad because I want to build a bigger one with 4 to 5 Rows and 5 Columns (4 X 5 or 5 X 5). I also want to use the internall "weak pull - ups" of Ports in which are connected the ROWS eliminating thus the use of external resistors. So the IOC interrupt will occurs when a ROW changes state from HI to LOW. The bigger keypad component offered by Flow Code is a 4 X 4 and its macro is programmed to fulfill the demands of EB014 e-block which of the ROWS are tied to 0V thru resistors and so its IOC interrupt logic is the inverse, i.e. LOW to HI.
In the attached fcf is described how we can implement the EB014 Matrix Keypad e-block code using simple Flow Code icons and some logical operations without the use of Flow Code “Keypad Component” and its related macro. Just two C code icons are used that are necessary to initialize the INTOSC module of micro and to place it in SLEEP mode.

E-blocks that used are:

A) EB014 Matrix Keypad
B) EB-005 LCD board as terminal
C) EB-006 Programming board.
KEYPAD_LCD.jpg
KEYPAD_LCD.jpg (135.48 KiB) Viewed 4977 times
The microcontroller used is an 18 pin P16F819 (you can change it with any equivalent micro, e.g. 16F88) that includes INTOSC module so there is no need for external XTAL or Oscillator. The EB014 Keypad is connected at Port B and the EB005 LCD display is connected at Port A. Some modifications are needed on the LCD board because its ENABLE input is by default connected at Port R"X".5, while in all 18 pin micros the RA.5 is the MCLR input and can’t be used as output.
So, to connect the ENABLE pin to e.g. Port RA.6 of micro firstly we have to remove the sextuple jumper from the "DEFAULT" to the "PATCH" DIL header. Then we can use 6 spare leads from used parts as jumpers to bridge the SIL sockets P1 - P2. In this way the 7th pin of P2, that is numbered "6" and is assigned to Port RA.6, can be connected to "E" pin of P1 that is assigned to the ENABLE input of LCD. See please in the picture.
LCD_MOD.jpg
LCD_MOD.jpg (163.41 KiB) Viewed 4977 times
The program code has obtained through a straightforward application of Flow Code icons. The 4 ROWS are connected to Ports RB.4 – RB.7 which are modified as Inputs and their IOC (or Port) interrupt is enabled. These four Ports are connected to 0V Rail thru four 100KΩ resistors and so are in LOW state. The 3 Columns are connected to Ports RB.0 - RB.1 -RB.2 and are modified as outputs. When a button on keypad is pressed applies a 5V signal on the corresponding ROW which in sequence changes state and causes an Interrupt On Change. This IOC interrupt weak up the micro and calls the macro “SCAN_KEY”.
When the keypad is inactive, the program runs continuously inside the MAIN Loop where the SLEEP command is executed.
Suppose that the button “5” is pressed. Then the IOC interrupt that occurs steers the program flow into “SCAN_SWITCH” macro and the Columns are set one by one in HI state starting from the RB.0. Accordingly the ROWS are detected thru the “switch ROW” icons if their state has changed from LOW to HIGH. In this instance, when the Column RB.1 is set to "1" the ROW RB.5 is also set to "1" because the circuit between them is closed thru the button "5". The HI state of ROW RB.5 is detected from the corresponding "switch ROW" icon and the program flow is turned into its branch “0x20”. Then the number “5” is printed on LCD thru the Component Macro “LCD Display – Print String “5”.
And so on.
In the end of macro "SCAN_SWITCH" all Columns are SET again in HIGH state.
I hope that this different approach on the programming of Matrix Keypad will be useful and to other non-experts in C language like myself.
Thanks for your attention.
Attachments
Matrix_Key_LCD.fcf
(21.58 KiB) Downloaded 709 times
Best Regards FOTIS ANAGNOSTOU

Post Reply