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

Keypad Serial Communication

This document contains code for a microcontroller to interface with a 4x4 keypad and transmit the pressed key values via serial communication. It defines an interrupt service routine that runs when a key is pressed to read the keypad input and determine the pressed key. It then transmits the corresponding ASCII character value out the serial port. The main program configures the serial port and a timer for serial transmission and puts the microcontroller in a loop to continuously transmit any pressed key values.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Keypad Serial Communication

This document contains code for a microcontroller to interface with a 4x4 keypad and transmit the pressed key values via serial communication. It defines an interrupt service routine that runs when a key is pressed to read the keypad input and determine the pressed key. It then transmits the corresponding ASCII character value out the serial port. The main program configures the serial port and a timer for serial transmission and puts the microcontroller in a loop to continuously transmit any pressed key values.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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