ARM-Interface a 4x4 keyboard and display the key code on an LCD
Program
/** @brief When key is pressed, corresponding key is displayed on LCD
* @Connections :
* D0 (LCD) -> P1.19
* D1 (LCD) -> P1.20
* D2 (LCD) -> P1.21
* D3 (LCD) -> P1.22
* D4 (LCD) -> P1.23
* D5 (LCD) -> P1.24
* D6 (LCD) -> P1.25
* D7 (LCD) -> P1.26
* RS (LCD) -> P1.27
* EN (LCD) -> P1.28
* C1 (Keypad) -> P2.0
* C2 (Keypad) -> P2.1
* C3 (Keypad) -> P2.2
* C4 (Keypad) -> P2.3
* R1 (Keypad) -> P2.4
* R2 (Keypad) -> P2.5
* R3 (Keypad) -> P2.6
* R4 (Keypad) -> P2.7
*/
#include <lpc17xx.h>
#include "LCD.h"
#include "keypad.h"
char keypad(void);
char c;
/* start the main program */
int main()
{
/* Initialize the GPIO pins for LCD */
/* PORT1 D0, D7, RS, EN */
LCD_Init(19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
delay(100);
/* Initialize the GPIO pins for Keypad */
/* PORT2 C1 R1 */
Keypad_Init(0, 1, 2, 3, 4, 5, 6, 7);
delay(100);
/* Set LCD parameters like contrast, backlight, cursor position etc */
CMD_WRT(0x38);
CMD_WRT(0x0f);
CMD_WRT(0x06);
CMD_WRT(0x01);
delay(100);
CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("----RDL--");
CMD_WRT(0XC0);
while(1)
{
/* get the key pressed */
c = keypad();
/* write the key to LCD */
DATA_WRT(c);
delay(100);
}
}
* @Connections :
* D0 (LCD) -> P1.19
* D1 (LCD) -> P1.20
* D2 (LCD) -> P1.21
* D3 (LCD) -> P1.22
* D4 (LCD) -> P1.23
* D5 (LCD) -> P1.24
* D6 (LCD) -> P1.25
* D7 (LCD) -> P1.26
* RS (LCD) -> P1.27
* EN (LCD) -> P1.28
* C1 (Keypad) -> P2.0
* C2 (Keypad) -> P2.1
* C3 (Keypad) -> P2.2
* C4 (Keypad) -> P2.3
* R1 (Keypad) -> P2.4
* R2 (Keypad) -> P2.5
* R3 (Keypad) -> P2.6
* R4 (Keypad) -> P2.7
*/
#include <lpc17xx.h>
#include "LCD.h"
#include "keypad.h"
char keypad(void);
char c;
/* start the main program */
int main()
{
/* Initialize the GPIO pins for LCD */
/* PORT1 D0, D7, RS, EN */
LCD_Init(19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
delay(100);
/* Initialize the GPIO pins for Keypad */
/* PORT2 C1 R1 */
Keypad_Init(0, 1, 2, 3, 4, 5, 6, 7);
delay(100);
/* Set LCD parameters like contrast, backlight, cursor position etc */
CMD_WRT(0x38);
CMD_WRT(0x0f);
CMD_WRT(0x06);
CMD_WRT(0x01);
delay(100);
CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("----RDL--");
CMD_WRT(0XC0);
while(1)
{
/* get the key pressed */
c = keypad();
/* write the key to LCD */
DATA_WRT(c);
delay(100);
}
}
Hardware Connection
D0 (LCD) -> P1.19
D1 (LCD) -> P1.20
D2 (LCD) -> P1.21
D3 (LCD) -> P1.22
D4 (LCD) -> P1.23
D5 (LCD) -> P1.24
D6 (LCD) -> P1.25
D7 (LCD) -> P1.26
RS (LCD) -> P1.27
EN
(LCD) -> P1.28
C1 (Keypad on development board) ->
P2.0
C2 (Keypad on
development board) -> P2.1
C3 (Keypad on
development board) -> P2.2
C4 (Keypad on
development board) -> P2.3
R1 (Keypad on
development board) -> P2.4
R2 (Keypad on
development board) -> P2.5
R3 (Keypad on
development board) -> P2.6
R4 (Keypad on
development board) -> P2.7
Output
When the Key is
pressed, Corresponding key is displayed on the LCD. For example, if key ‘1’ is
pressed, on LCD it should show “Key
Pressed is 1”
No comments:
Post a Comment