#include <REGX52.H>
#define LCD_PORT P0
#define EN P1_0
#define RS P1_2
#define RW P1_1

void delay(unsigned int count);
void lcd_command(char value);
void lcd_data(char value);
void lcd_display(unsigned char locn, char *dat);
void lcd_initial(void);

void lcd_initial(void) {
    delay(20);
    lcd_command(0x38);
    lcd_command(0x01);
    lcd_command(0x06);
    lcd_command(0x0C);
}

void lcd_command(char value) {
    LCD_PORT = value;
    RS = 0; RW = 0; EN = 1;
    delay(2);
    EN = 0;
    delay(2);
}

void lcd_data(char value) {
    LCD_PORT = value;
    RS = 1; RW = 0; EN = 1;
    delay(2);
    EN = 0;
    delay(2);
}

void lcd_display(unsigned char locn, char *dat) {
    lcd_command(locn);
    while (*dat) lcd_data(*dat++);
}

void delay(unsigned int count) {
    unsigned int x, y;
    for (x = 0; x < count; x++)
        for (y = 0; y < 1275; y++);
}

#define SW1 P2_0
#define SW2 P2_1
#define SW3 P2_2
#define BEEP P1_6

void main(void) {
    P2 = 0x07;
    BEEP = 1;
    lcd_initial();
    lcd_display(0x80, "Press Any Switch");
    while (1) {
        if (SW1 == 0) {
            while (SW1 == 0);
            BEEP = 0; delay(25); BEEP = 1;
            lcd_command(0x01); lcd_display(0x80, "Pressed Switch 1");
        }
        if (SW2 == 0) {
            while (SW2 == 0);
            BEEP = 0; delay(25); BEEP = 1;
            lcd_command(0x01); lcd_display(0x80, "Pressed Switch 2");
        }
        if (SW3 == 0) {
            while (SW3 == 0);
            BEEP = 0; delay(25); BEEP = 1;
            lcd_command(0x01); lcd_display(0x80, "Pressed Switch 3");
        }
    }
}
