

void E_clk() {
        delay_ms(1);
        LCD_E =0; 
        delay_ms(1);
        LCD_E=1;
        delay_ms(1);
        LCD_E =0; 
}

void main() {
        unsigned int i;
	
        //Toggle led 
        for (i = 0; i < 2; i++) {
                P2_7 = 1;
                delay_ms(50);
                P2_7 = 0;
                delay_ms(50);
        }

        //Power on
        //Wait more than 15 msecs after power is applied.
        delay_ms(40); 

        LCD_RS = 0; //instructions

        LCD_BUS_PORT = 0x30;
        E_clk();
        delay_ms(10);

        LCD_BUS_PORT = 0x30;
        E_clk();

        LCD_BUS_PORT = 0x30;
        E_clk();

        LCD_BUS_PORT = 0x20;
        E_clk();

        //0x28 (4Bit mode,2Lines,Small font)
        LCD_BUS_PORT = 0x20;
        E_clk();
        LCD_BUS_PORT = 0x80;
        E_clk();

        //0x08 (Display off)
        LCD_BUS_PORT = 0x00;
        E_clk();
        LCD_BUS_PORT = 0x80;
        E_clk();

        //0x01 (Clear the display) - Takes more than normal time
        LCD_BUS_PORT = 0x00;
        E_clk();
        LCD_BUS_PORT = 0x10;
        E_clk();
        delay_ms(10);


        //0x06 (Entry mode - no shifting, auto increase)
        LCD_BUS_PORT = 0x00;
        E_clk();
        LCD_BUS_PORT = 0x60;
        E_clk();

        while(1);
}

