0% found this document useful (0 votes)
5 views

Keyboard

The document contains a C program for interfacing with a keypad using a microcontroller. It initializes the serial communication, continuously prompts the user to press a key, and reads the key input from the keypad. The program includes functions for initialization, key reading, and delay management.

Uploaded by

priya004nka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Keyboard

The document contains a C program for interfacing with a keypad using a microcontroller. It initializes the serial communication, continuously prompts the user to press a key, and reads the key input from the keypad. The program includes functions for initialization, key reading, and delay management.

Uploaded by

priya004nka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAM:

#include <1pc214x.h>

voidserini (void);

voidir (unsigned char);


unsigned char key_wa(void);

unsigned char keypad (void);

void delay (void);

int main()

inti.k:

unsigned char a[]="PRESS ANY KEY":


serini();
while (1)

tr(0x0d);

tr(0x0A);

for(i=0;a[i]=0;i++)

tr(a[i]);

tr (0x0d);
tr(0x0A);

tr(key_wa());

for(k=0;k<150000;k++);

voidserini (void)

{
PINSEL0=0x00000005;

UOLCR=0x83;
UODLL= 0x5a;
U0DLM=0x00;

U0FDR=0xc1;

U0LCR=0x03;

}
voidtr (unsigned char a)

UOTHR=a;

while ((U0LSR& 1<<5)==0);

unsigned char keypad (void)

IO0DIR|= 0x0F00<<8;
IO0PIN= (IO0PIN&0xFFFOFFFF) |0x0E00<<8;
if ((100PIN & 0xF-000<<8)!= 0xF000<<8)

switch (IO0PIN & 0xF000<<8)

case 0x0007000<<8; delay();return 'c';

case 0x000B000<<8: delay();return 'd';

case 0x000D0000<<8: delay();return 'e';

case 0x000E000<<8: delay();return 'f';


}

IO0PIN =(IO0PIN&0xFFF0FFFF) | 0x0D00<<8;

if ((IO0PIN & 0xF000<<8) != 0xF000<<8)

switch (IO0PIN & 0xF000<<8)

{
case 0x0007000<<8; delay();return 19:

case 0x000B000<<8; delay();return '0';


case 0x000D000<<8: delay();return 'a';
case 0x000E000<<8 delay(); return 'b';

IO0PIN =(IO0PIN&0&FEOFFEF) | (0x0B00<<8;


if (IO0PIN & 0xF000<<8)!=0xF000<<8)

switch (IO0PIN & 0xF000<<8)

case 0x0007000<<8; delay();return '5';

case 0x000B000<<8;delay(); return '6';

case 0x000D000<<8;delay(); return '7";


case 0x000E000<<8;delay();return '8";
IO0PIN=(IO0PIN&0xFFF0FFFF) | 0x0B00<<8;

if ((IO0PIN & 0xF000<<8)!= 0xF000<<8)

switch (IO0PIN & 0xF000<<8)

case 0x0007000<<8: delay(); return '1';

case 0x000B000<<8; delay();return '2';


case 0x00D0000<<8: delay(); return '3';

case 0x000E000<<8: delay();return '4';

IO0PIN=(IO0PIN&0xFFTOFFTF) | (0x0B00<<8;

if ((IO0PIN & 0xF000<<8)!=0xF000<<8)

{
switch (IO0PIN & 0xF000<<8)

case 0x0007000<<8; delay();return '5';


case 0x000B000<<8: delay(); return "6":
case 0x000D000<<8: delay(); return '7';

case 0x000E000<<8: delay();return '8';

IO0PIN=(IO0PIN&0xFFF0FFFF) | 0x0700<<8;
if ((IO0PIN & 0xF000<<8)!=0xF000<<8)

switch (IO0PIN & 0xF000<<8)

case 0x0007000<<8; delay(); return '1';

case 0x000B000<<8: delay();return '2';

case 0x00D0000<<8; delay(); return '3';


case 0x000E000<<8: delay();return '4';
}

return 0xFF;

unsigned char key_wa (void)

unsigned char Read;


while ((Read=keypad())==0xFF);

return Read;

void delay()

unsignedinti,j;

for(i=0;i<0xff;i++)
for(j=0;j<0xfff;j++);

You might also like