You are on page 1of 2

Keypad and serial communication

#include<reg52.h>
void keypad(void);
void intr() interrupt 0
{
keypad();
}
void keypad()
{
unsigned char b,a;
b=P1&0x0f;
if(b==1 )
{a=0x30;}
else if(b==4)
{a=0x31;}
else if(b==5)
{a=0x32;}
else if(b==6)
{a=0x33;}
else if(b==8)
{a=0x34;}
else if(b==9)
{a=0x35;}
else if(b==10)
{a=0x36;}
else if(b==12)
{a=0x37;}
else if(b==13)
{a=0x38;}
else if(b==14)
{a=0x39;}
else if(b==2)
{a=0x3D;}
else if(b==3)
{a=0x2B;}
else if(b==7)
{a=0x2D;}
else if(b==11)
{a=0x2A;}
else if(b==15)
{a=0x2F;}
else if(b==0)
{a=0x43;}
SBUF=a;
while(TI==0);
TI=0;
}

void main()
{
P1=0xFF;
// To make port 1 an input port
IE=0x81;
// To enable external interrupt 0
TCON=0x01;
// TO enable Edge triggering
TMOD=0x20;
//
Mode 2 of timmer 1
TH1=0xFA;
TR1=1;
SCON=0x50;
//
8Bit Data with 1 stop Bit
while(1)
{
while(TF1=0);
TF1=0;
}
}

You might also like