Sunteți pe pagina 1din 6

Program: Interfacing of Keyboard with ARM

#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
unsigned int k;
unsigned int Read_Key;
unsigned char scan [] = { 0x00000E00,0x00000D00,0x00000B00,0x00000700};
unsigned int i;
void delay()
{
unsigned int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}
void send_serial_data(unsigned char serial)
{
while((U0LSR & 0x20)==0);
U0THR = serial;
}
int main (void)
{
unsigned int Fdiv;
TargetResetInit();
PINSEL0 = 0x00000050;

/* RxD0 and TxD0 */

U0LCR = 0x83;
/* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / 19200 ; /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
/* DLAB = 0 */
U0FCR = 0x07;
/* Enable and reset TX and RX FIFO. */
FIO4DIR = 0X00000FFF;
FIO3DIR = 0X008000FF;
while(1)
{
//First Row
FIO4SET = 0X00000e00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('0');
FIO3PIN = 0X00000000;
}
if((Read_Key==0x0b))
{
send_serial_data('1');
FIO3PIN = 0X00000001;
}

25

Exp.No:
Date :

INTERFACING OF KEYBOARD WITH ARM

Aim
To interface the Keypad with ARM 7 Controller
Components Required:
1. LPC 2378 ARM Development board
2. IAR Embedded Workbench 6.5
3. Flash Magic ISP Utility
Theory
A keypad is a set of buttons arranged in a block or "pad" which usually bear digits,
symbols and usually a complete set of alphabetical letters. If it mostly contains numbers then it
can also be called a numeric keypad. Here we are using 4 X 4 matrix keypad.
Interfacing keypad:
Fig. shows how to interface the 4 X 4 matrix keypad to two ports in microcontroller. The
rows are connected to an output port and the columns are connected to an input port. To detect a
pressed key, the microcontroller grounds all rows by providing 0 to the output latch, and then it
reads the columns. If the data read from the columns is D3-D0=1111, no key has been pressed
and the process continues until a key press is detected.

26

if( (Read_Key==0x0d))
{
send_serial_data('2');
FIO3PIN = 0X00000002;
}
if((Read_Key==0x0e))
{
send_serial_data('3');
FIO3PIN = 0X00000003;
}
FIO4CLR = 0X00000e00;
delay();
//Second Row
FIO4SET = 0X00000d00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('4');
FIO3PIN = 0X00000004;
}
if((Read_Key==0x0b))
{
send_serial_data('5');
FIO3PIN = 0X00000005;
}
if( (Read_Key==0x0d))
{
send_serial_data('6');
FIO3PIN = 0X00000006;
}
if( (Read_Key==0x0e))
{
send_serial_data('7');
FIO3PIN = 0X00000007;
}
FIO4CLR = 0X00000d00;
delay();
//Third Row
FIO4SET = 0X00000b00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('8');
FIO3PIN = 0X00000008;
}
if((Read_Key==0x0b))
{
send_serial_data('9');
FIO3PIN = 0X00000009;
}

27

However, if one of the column bits has a zero, this means that a key press has occurred.
For example, if D3-D0=1101, this means that a key in the D1 column has been pressed. After a
key press is detected, the microcontroller will go through the process of identifying the key.
Starting with the top row, the microcontroller grounds it by providing a low to row D0 only;
then it reads the columns.
If the data read is all 1s, no key in that row is activated and the process is moved to the
next row. It grounds the next row, reads the columns, and checks for any zero. This process
continues until the row is identified. After identification of the row in which the key has been
pressed, the next task is to find out which column the pressed key belongs to.
PROCEDURE:
1. Run the Application IAR Embedded Workbench 6.5
2. Create new project in the current work space. Create a new project by selecting the tool
chain as ARM and create empty project and click ok. Give Project Name and click
SAVE Button.
3. Select LPC2378 >Options menu
4. Select General options category. Enable target option file and select the device as NXP
LPC2378 and click ok.
5. Select C/C++ Compiler >Select Preprocessor and include (C:\Program Files\IAR
Systems\Embedded
Workbench
6.5\arm\inc\c,
C:\Program
Files\IAR
Systems\Embedded Workbench 6.5\arm\inc\NXP)
6. Enable Output Converter Menu and select output format as Intel extended and Enable
Override default option
7. Select Linker Category. Enable Override default option, click SAVE Button.
8. New>File Menu, for creating a new C file. File>Save As, for saving a file. Give your
File name ( Eg: KEYPAD.C) and click Save Button.
9. Right Click the project name option for select a C file in
workspace window. Select Add >Add (KEYPAD.C) Menu.
10. Select LPC2378>Rebuild all menu, for checking any error in your C file. If your
Cfile has no error.
11. Select LPC2378>Rebuild all menu, for checking any error in your C file.
12. If your project has no error, Building completed and Hex file generated.
13. This Hex file will be downloaded to the VIARM-2378 controller by Flash Magic
Software

28

if( (Read_Key==0x0d))
{
send_serial_data('a');
FIO3PIN = 0X0000000a;
}
if( (Read_Key==0x0e))
{
send_serial_data('b');
FIO3PIN = 0X0000000b;
}
FIO4CLR = 0X00000b00;
delay();
//Fourth Row
FIO4SET = 0X00000700;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('c');
FIO3PIN = 0X0000000c;
}
if((Read_Key==0x0b))
{
send_serial_data('d');
FIO3PIN = 0X0000000d;
}
if((Read_Key==0x0d))
{
send_serial_data('e');
FIO3PIN = 0X0000000e;
}
if( (Read_Key==0x0e))
{
send_serial_data('f');
FIO3PIN = 0X0000000f;
}
FIO4CLR = 0X00000700;
delay();
// send_serial_data('c');
}
return 0;
}

29

Steps To Be Followed In Flash Magic Software For Embed Into Kit:


Step 1: Open Flash Magic software
Step 2: Go to step 1: Communications
Select Com port
: COM1
Baud Rate
: 19200
Device
: LPC2378
Interface
: None (ISP)
Oscillator Freq (MHz) : 16.000000
Step 3: Go to step 2: Erase
Select Erase blocks used by Hex file
Step 4: Go to step 3: Hex file
Select Browse corresponding Hex file
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit

RESULT:

30

S-ar putea să vă placă și