Google

Tuesday, June 17, 2008

KEY BOARD interfacing with 89C51

Components Required:
89c51 micro controller
crystal oscillator -11.051 Mhz
capacitors -2 (33 p farad)
Matrix keyboard
LED
Circuit Diagram



Description
If you press any button in the matrix keyboard it controller will scan the corresponding ascii code that will send serially to the port pin specified . Corresponding ascii code we can see in LED blinkings.
C program
#include
#define COL P2
#define ROW P1
void msdelay(unsigned int value);
void sertx(unsigned char);
unsigned char keyboard[4][4]={ '7','8','9','/',
'4','5','6','*',
'1','2','3','-',
'a','0','=','+' };

void main()
{
unsigned char colloc,rowloc;
TMOD=0x20;
TH1=-24;
SCON=0x50;
TR1=1;
COL=0xff;
while(1)
{
do
{
ROW=0x00;
colloc=COL;
colloc&=0x0f;
} while(colloc!=0x0f);
do
{
do
{
msdelay(20);
colloc=COL;
colloc&=0x0f;
}while(colloc==0x0f);
msdelay(20);
colloc=COL;
colloc&=0x0f;
} while(colloc==0x0f);
while(1)
{
ROW=0xfe;
colloc=COL;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=0;
break;
}
ROW=0xfd;
colloc=COL;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=1;
break;
}
ROW=0xfb;
colloc=COL;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=2;
break;
}
ROW=0xf7;
colloc=COL;
colloc&=0x0f;
rowloc=3;
break;
}
if(colloc==0x0e)
sertx(keyboard[rowloc][0]);
else if(colloc==0x0d)
sertx(keyboard[rowloc][1]);
else if(colloc==0x0b)
sertx(keyboard[rowloc][2]);
else // (colloc==0x07)
sertx(keyboard[rowloc][3]);
}
}
void sertx(unsigned char x)
{
SBUF=x;
while(TI==0);
msdelay(20);
TI=0;
}
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<=1275;i++)
for(j=0;j<=value;j++);
}
HEX code


:030000000200CA31
:0C00CA00787FE4F6D8FD75811902011161
:10017A0010083738392F3435362A3132332D613069
:02018A003D2B0B
:10000300758920758DE8759850D28E75A0FFE4F53B
:100013009085A01853180FE518B40FF212015685F6
:10002300A01853180FE518640F60F112015685A04C
:100033001853180FE518640F60E27590FE85A01839
:1000430053180FE518640F6005E4F51980347590B3
:10005300FD85A01853180FE518640F600575190185
:1000630080207590FB85A01853180FE518640F6066
:1000730005751902800C7590F785A01853180F7534
:100083001903E518B40E0AE51925E025E0240880D4
:100093001CE518B40D0AE51925E025E02409800DB7
:1000A300E518B40B11E51925E025E0240AF8E6FF6D
:1000B30012018D020011E51925E025E0240BF8E675
:0700C300FF12018D02001184
:0B018D008F993099FD120156C2992293
:040156007F147E0094
:10015A00E4FDFCE4FBFAD3EB9FEA9E50070BBB00DD
:0F016A00010A80F20DBD00010CBC04E7BDFCE4EE
:010179002263
:1000D600020003E493A3F8E493A34003F68001F23D
:1000E60008DFF48029E493A3F85407240CC8C3332B
:1000F600C4540F4420C8834004F456800146F6DFFA
:10010600E4800B010204081020408090017AE47E0E
:10011600019360BCA3FF543F30E509541FFEE493EE
:10012600A360010ECF54C025E060A840B8E493A3B5
:10013600FAE493A3F8E493A3C8C582C8CAC583CAE0
:10014600F0A3C8C582C8CAC583CADFE9DEE780BE98
:01018C000072
:00000001FF

For C programe please mail to sekharstuff@yahoo.co.in

No comments: