Wednesday, June 22, 2016

Matrix Keypad and LCD Interfacing with Cortex-M3 (LPC1343)

Keypads are a part of Human Machine Interface and play really important role in a small embedded system where human interaction or human input is needed. 
Matrix keypads are well known for their simple architecture and ease of interfacing with any micro-controller. 
LCD display is an inevitable part in almost all embedded projects. Many guys find it hard to interface LCD module with there embedded device but the fact is that if you learn it properly, its a very easy job and by knowing it you can easily design embedded projects like digital voltmeter / ammeter, digital clock, home automation displays, status indicator display, digital code locks, digital speedometer, display for music players etc.
I have a LPC1343 Development board with me, which i purchased from NGX website
The board has monochrome graphical lcd (which i broke :-( ), so i removed the graphical lcd and connected the 16x2 LCD (thanks to board layout, they have connector for this also).

I connected LCD on following pins of micro-controller:-
  • VSS - GND
  • VDD - 5V (Make sure that, this is 5V if you are using 5V LCD)
  • VEE - Contrast Pin ( Connected to the output of pot, having around 1V)
  • LCD_RS - PIO1_2
  • LCD RW - PIO1_1
  • LCD_EN - PIO1_0
  • LCD_D0 - PIO2_0
  • LCD_D1 - PIO2_1
  • LCD_D2 - PIO2_2
  • LCD_D3 - PIO2_3
  • LCD_D4 - PIO2_7
  • LCD_D5 - PIO2_8
  • LCD_D6 - PIO2_9
  • LCD_D7 - PIO2_10
  • Backlight Supply - PIO3_1
  • Backlight Ground - GND
and Similarly 4x4 Keypad is connected with the following pins of Micro-controller.
  • ROW 1 - PIO1_4
  • ROW 2 - PIO1_6
  • ROW 3 - PIO1_7
  • ROW 4 - PIO1_8
  • COL  1 - PIO1_9
  • COL  1 - PIO2_4
  • COL  3 - PIO2_5
  • COL  4 - PIO2_6
Note Column are pulled by internal weak pull-ups.

The schematic is shown below:



The code is written in IAR Embedded Workbench version 7.60 and can be downloaded for free, from the link provided below. 
The LCD and Matrix Keypad Library are written in generic format and can be ported for any other micro-controller.
LCD Library is handled to minimize the update time by checking the busy flag, but one can use the delay feature as well. To use delay feature comment the following line in the lcd_16x2.h header file.

#define USE_LCD_BUSY_FLAG             /**< Use Busy Bit instead of Delay.*/

Coming to the keypad part, the specialty of the keypad library is that, it works for pins which are not connected on single port and not even in sequence. Apart from this one very good feature of the this library is that, on pressing and holding a particular key for 2 seconds, the repeater mode is activated and key values are returned every 100 milli-second. Have a look at the following video, to know what this repeater mode is and how it can be useful for you.


Project Description
Keypad has 16 keys, whenever a key is pressed its counter is increments by 1 and key-press with counter value is displayed on 16x2 LCD. Keypad Hold feature is added in algorithm which enables the repeat mode, which will increment counter speedily, when pressing a key for more than 2 seconds.

Code Written in IAR Embedded Workbench v7.60
Click Here to Download Source Code.

Update:
I had also written a tutorial for interfacing the Matrix and LCD with PIC micro-controller using the same library, so if you are Microchip PIC fan, you read and test the code by clicking here.

No comments:

Post a Comment