KEYPAD INTERFACING WITH 8051(AT89S52) WITH SIMULATION IN PROTEUS

Photo of author

By Jackson Taylor

  • COMPILER -MIKRO C PRO
  • SIMULATION -PROTEUS 8.1
  • MICROCONTROLLER – AT89S52 
  • CRYSTAL – 11.0592MHz(use this crystal to get baud rate of 9600)

HARDWARE


CIRCUIT



SIMULATION


DOWNLOAD SIMULATION FILES
PROGRAM
#define R1 P1.F0  //pin 1
#define R2 P1.F1  //pin 2
#define R3 P1.F2  //pin 3
#define R4 P1.F3  //pin 4
#define C1 P3.F3  //pin 5
#define C2 P3.F4  //pin 6
#define C3 P3.F5  //pin 7
sbit LCD_RS at P2_3_bit;
sbit LCD_EN at P2_2_bit;
sbit LCD_D4 at P2_1_bit;
sbit LCD_D5 at P2_0_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connections
int key=12;
void keydelay(void);
void main()
{
C1=1; C2=1;C3=1;   //pull up
  Lcd_Init();                        // Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,”haii”);                 // Write text in first row
  delay_ms(500);
   Lcd_Cmd(_LCD_CLEAR);               // Clear display
while(1)
{
C1=0;C2=1;C3=1;
if(R1==0) {key=1;}
if(R2==0) {key=4;}
if(R3==0) {key=7;}
if(R4==0) {key=10;}
C1=1;C2=0;C3=1;
if(R1==0) {key=2;}
if(R2==0) {key=5;}
if(R3==0) {key=8;}
if(R4==0) {key=0;}
C1=1;C2=1;C3=0;
if(R1==0) {key=3;}
if(R2==0) {key=6;}
if(R3==0) {key=9;}
if(R4==0) {key=11;}
if(key<12) {Lcd_Chr(2, 3, key+0x30); key=12;keydelay();  }
}
}
void keydelay(void)
{
delay_ms(500);
}