Difference between revisions of "Xplore Flash for At89s52"
Line 64: | Line 64: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | =Demo Video= | ||
+ | {{#ev:youtube|Kxp8xFOSdP4|600|auto}} | ||
=Downloads= | =Downloads= | ||
− | [[File:Download Icon.jpeg|thumbnail|link=http://xplorelabz.com/wiki/images/3/3f/Hex_Keypad_8051.zip|8051_hex_keypad_Interface]] | + | [[File:Download Icon.jpeg|thumbnail|link=http://xplorelabz.com/wiki/images/3/3f/Hex_Keypad_8051.zip|8051_hex_keypad_Interface]]<br /> |
+ | <br /> | ||
=Feedback= | =Feedback= | ||
Your comments motivate us to do better, your doubts and questions help us learn! Feel free to comment below | Your comments motivate us to do better, your doubts and questions help us learn! Feel free to comment below | ||
{{DISQUS}} | {{DISQUS}} |
Revision as of 12:33, 27 March 2014
Basics
The keypad matrix or hex keypad comprising of 16 keys arranged as 4x4 matrix is one of the common interfaces done to a micrcontroller. These are similar to a telephone keypad that we normally come across. In this tutorial we will see about interfacing this keypad to 8051. We will write the code to scan the keys and display the pressed key on the LCD.
Working
For us human beings it takes a few seconds to press a key, but the controller can read the port pin and eventually the keypressed in milliseconds. Hence it is possible to scan a four or more rows and columns while the key is being pressed! In fact, when we will test the code we will realize that a single key press is detected multiple times.
- KeyBounce: Multiple keypress is also resulted out of mechanical construction of the keys. When we press and release a key, it not just presses once but debounces several times.
There are various ways to eliminate debounce, however we will use time delay to neglect the effect of keybounce.
Schematic:
Figure below shows the schematic of a keypad interfaced with 8051 micrcontroller. We have tested it with P89V51RD2, you may wish to try in on any other 8051 family MCUs.
{{#widget:Iframe
|url=
|width=700
|height=400
|border=5
}}
Download Schematic pdf
Code
As with all our other projects, we divide the files according to interfaces, hence we have lcd_4_bit.c as file for displaying messages on LCD, keypad.c has functions to scan and return a key pressed. The main code demonstrates how to read a key and display on the LCD.
/* Reg51.h contains the defnition of all ports and SFRs */ #include <reg51.h> #include "lcd.h" //User defined LCD library which conatins the lcd routines #include "keypad.h" //User defined library which conatins the keypad routines /* start the main program */ void main() { unsigned char key; /* Initilize the lcd before displaying any thing on the lcd */ LCD_Init(); /* Initilize the keypad port pins */ KEYPAD_Init(); LCD_DisplayString("Key Press: "); /*Go to second line and display the key pressed*/ LCD_GoToLineTwo(); while(1) { /* Read the key from Matrix Keypad */ key=KEYPAD_GetKey(); /* Display the Key Pressed */ LCD_DataWrite(key); } }
Demo Video
Downloads
Feedback
Your comments motivate us to do better, your doubts and questions help us learn! Feel free to comment below