
/******************************************************************************
* Name:    LCDD_Initilise
******************************************************************************/
void LCDD_Initialise()
{
    RS = 0;	        // write control bytes(RS -> PORTB bit3)
    DelayMs(15);	// power on delay
    PORTB = 0x30;	// attention!
    ECLOCK();
    DelayMs(5);
    ECLOCK();
    DelayUs(100);
    ECLOCK();
    DelayMs(5);
    PORTB = 0x20;	// set 4 bit mode
    ECLOCK();
    DelayUs(40);
    LCDD_WriteCommand(0x28);	// 4 bit mode, 1/16 duty, 5x8 font
    LCDD_WriteCommand(0x08);	// display off
    LCDD_WriteCommand(0x0F);	// display on, blink curson on
    LCDD_WriteCommand(0x06);	// entry mode
    DelayMs(5);
    LCDD_WriteCommand(DispCLR);
    LCDD_WriteCommand(RetHome);
}
/******************************************************************************
* Name:    LCDD_WriteCommand
******************************************************************************/
void LCDD_WriteCommand(byte nibbles)
{
    byte hiNibble = nibbles;
    DelayMs(1);
    hiNibble = hiNibble & 0x0f0;
    PORTB = hiNibble;
    ECLOCK();
    DelayMs(1);
    hiNibble = (nibbles << 4);	// get lower nibble and shift it hi
    PORTB = hiNibble;		// output lower 4 bits
    ECLOCK();
    DelayMs(1);
}
/******************************************************************************
* Name:    ECLOCK
******************************************************************************/
void ECLOCK()
{
    DelayUs(1);			// tas delay 
    E = HI;			// for write cycle only
    DelayUs(2);
    E = LOW;
    DelayUs(1);
}   
